thanks
for the client-server, I don’t send the inputs but directly the player positions. I was not able to do the input stuff as in CS for two main reasons:
- I can’t rollback the physics simulation with box2d
- box2d is float based so even if I could rollback I’m never sure that the simulation done on the server would be the same as the one done on client side.
So basically I’m not sending inputs because I use box2d
The way it works now for the player movement:
- the client and server synchronize their clock when connecting
- when the client moves, it directly impacts the player position in local (no wait for server validation)
- the client send his position + linearspeed + orientation + angular speed to the server 30 times per second
- the server gets the message, and update the player position based on the position received + speed (taking into account the delay to get the message)
- the server is then sending if necessary all the player positions to all the players 20 times per second (dedicated servers can adjust this value if needed / enough bandwidth)
- the client update each player position the same way as the server (taking into account the delay) except that the position is not directly affected but there is some interpolation done to avoid as much as possible weird player teleporting
- between two updates, the clients and server continue to move the player according to the linear and angular speed …
And when firing a bullet:
- the client fires the bullet in local and sends a message to the server
- the server validates that the client can fire a bullet, then fires the bullet taking into account the delay between the server and client.
So basically the bullet will be fired on the same position as on the client, but is accelerated at the beginning to keep sync with the client. - after firing the bullet, the server send to all the other clients the same fire message
- the clients fire the bullet, applying the same mechanism as the server.
So for the bullets, that’s pretty accurate. But for the player movement it’s less because of the unpredictability of the movements
With this, the server needs a bandwidth of about 144 kbytes/s for 16 players.
I said it was horrible also to synchronize game states, all the entities and so on. And also it’s limiting in term of visual effects.
In a single player game it’s not an issue if for exemple an explosion effect goes through walls (it’s quite common …), as you don’t see behind the wall
But here as there may be another player behind the wall, all the effects should be well contained to avoid breaking the purpose of the fog of war.
So this is very limiting … in a single player game I could do way better effects with tons of particles and big plasma waves and so on … without worrying about collisions with the environment …