I'm building a HTML5 / Websockets based multiplayer canvas game for Facebook and I've been working on the server code for a few days now. While the games pretty simple with a 2d top down, WSAD controls and mouseclick fires a projectile to the cursor x/y - I've never had to do real-time multiplayer before. I've read a few great documents but I'm hoping I can overview my general understanding of the topic and someone can validate the approach and/or point out areas for improvement.
Authoritative multiplayer server, client-side prediction and entity interpolation (and questions below)
- Client connects to server
- Client syncs time to server
- Server has two main update loops:
- Update the game physics (or game state) on the server at a frequency of 30 per second (tick rate?)
- Broadcast the game state to all clients at a frequency of 10 per second
- Client stores three updates before being allowed to move, this builds up the cache for entity interpolation between update states (old to new with one redundency in case of packet loss)
- Upon input from the user, the client sends input commands to server at a frequency of 10 per second - these input commands are time stamped with the clients time
- Client moves player on screen as a prediction of what the server will return as the final (authoritative) position of client
- Server applies all updates to its physics / state in the previously mentioned update loop
- Server sends out time stamped world updates.
- Client (if is behind server time && has updates in the queue) linearly interpolates the old position to the new.
At 1: possibility to use NTP time and sync between the two?
At 5: time stamped? Is the main purpose here to time-stamp each packet
At 7: The input commands that come in will be out of sync per different latencies of the clients. I'm guessing this needs to be sorted before being applied? Or is this overkill?
At 9: is the lerp always a fixed amount? 0.5f for example? Should I be doing something smarter?
Lots of questions I know but any help would be appreciated!!