I'm asking for a game that I develop right now. The game is using TCP communication, there's server and multiple clients. While players in a room are playing the game, I send state update commands in a custom binary protocol every 33 ms. (30 FPS) Problem is those states are huge - there are players moving, objects spawning and also destructible blocks.
If I were to send all this data a single state update to every player will be huge, resulting in huge bandwidth.
So I'm thinking different approach:
- Initially send the huge state with all moving and stationary objects, when the room starts
- Do the state update commands every 33 ms, but include just the moving objects, and not include the state and location of the stationary objects.
- For stationary objects, issue separate commands to tell they are destroyed or spawned and expect clients to update their copy of the state.
My concern is that it may somehow happen that due to not including the stationary objects in every state update, clients may somehow miss the separate commands that update on those and not reflect that change in their copy of the state.
Here is a visual representation of what I imagine:
Less bandwidth (is it less reliable?):
game started -> obj1 {id,location}, obj2{id,location}, obj3{id,location}
state update 1 -> obj1 {id,location}, obj2{id,location} #assumes obj3 is there
state update 2 -> obj1 {id,location}, obj2{id,location} #assumes obj3 is there
state update 3 -> obj1 {id,location}, obj2{id,location} #assumes obj3 is there
object removed -> obj3 #removing the object locally
state update 4 -> obj1 {id,location}, obj2{id,location} #obj3 not present at this point
More bandwidth - include all objects in every state update and assume if something is not present, it has been removed (is it more reliable?):
game started -> obj1 {id,location}, obj2{id,location}, obj3{id,location}
state update 1 -> obj1 {id,location}, obj2{id,location}, obj3{id,location}
state update 2 -> obj1 {id,location}, obj2{id,location}, obj3{id,location}
state update 3 -> obj1 {id,location}, obj2{id,location} #obj3 is not here, so removing it locally
state update 4 -> obj1 {id,location}, obj2{id,location} #obj3 not present at this point