In a multiplayer game, there may be hundreds or thousands of computers connected at the same time. All of the computers will have different configurations. Speed will vary on all these computers. So the questions is, how do we synchronize the clock over all these systems so that they are all in sync?
To work through this recipe, you will need a machine running Windows and Visual Studio.
In this recipe, we will look at, from a theoretical perspective, the two ways to synchronize clocks.
Take a look at the following pseudocode:
Method 1
Send a message to
UserA
. Note the time till he receives the message.Send a message to
UserB
. Note the time again.Calculate the median based on the values to decide an update time for updating the clock for both computers.
Method 2
Let the server do most of the calculations.
Let the client do some local calculations.
When the client receives the update from the server, then either correct its mistakes or interpolate...