Aaron M
Aaron M

Reputation: 2563

delta compression using protocol buffers

I am working on a multi-player fps, and I am thinking about how perform delta compression on a game state object.

In reading about how Q3 did networking, I think that delta compression can be achieved by serializing the object to a binary state and then only sending a binary diff between the last known received object and current object. Is that the correct way to handle delta compression?

Upvotes: 4

Views: 2147

Answers (1)

Hogan
Hogan

Reputation: 70538

Well you have two choices.

  • You can serialize State A and State B and run a diff on result. (As you describe).

or

  • You can use knowledge of the structure to find the difference between State A and State B and serialize the structural difference.

Which comes down to this -- is the structure of the data defined in such a way that taking a delta is faster than running a general purpose diff?

I believe it often is. Lets take a simple example. Our game world defines two items P1 and P2 (they run around the world) at any point of time the game state is defined as P1(x,y,z) and P2(x,y,z). Thus the structural delta is the difference between 6 variables (x,y,z for two players). Calculating this is quick -- it is 3 math operations. However, who knows how these will serialize -- and then the diff routine will have to do a lot of work (at least one loop) to find the delta of the result.

But it gets even better than that. Since your game engine knows you care about deltas as things change it can store the deltas in a list and be ready to send the deltas without any calculation (for example everytime a P moves it stores the change).

Upvotes: 1

Related Questions