Network
-
Network code structure and network protocol.
Table of Contents
This is what I've learnt from a cursory reading of the
XPilot source.
- Server broadcasts game state updates (new things, changed things, destroyed things, new positions, new velocities) to each player as it learns of each one either from other players or from its collision detection or physics code.
- Client receives each message and updates its state accordingly.
- Server sends 'done' message, signifying that it will not act further until the clients have done some computation.
- Client checks for user input.
- Client updates the objects for which it is responsible (moves its plane, its bullets, etc).
- Client sends changes as it computes them.
- Server receives them and updates accordingly.
- Client sends 'done'.
- Server does collision detection.
- Server updates the objects for which it is responsbile (moves soldiers).
- Server sends game state updates (new things, changed things, destroyed things, new positions, new velocities) to each player.
Synchronisation
In order to synchronise the clients and ensure one does
not run faster than another, the server controls the
progress of clients by requiring they receive its 'done'
message before updating. Similarly, each client requires
the server receive its 'done' message before updating.
Therefore the server and client take turns proactively
computing and sending, and reactivley receiving and
updating their state.
I'm not sure if it would be good to go ahead with this design.
I'll come back to it after doing some more research on the
topic.