10 September, 2009

timing is crucial

Today I have been figuring out how to make time to be same on each client in netplay. This is needed because when one client sends his position and moves at the same time, the position will be off when his position reaches everyone else. So instead this clients sends his position and a timestamp saying when he was at that position. And then when people receive this position, they can check the timestamp and calculate a more accurate position from this.

So I found my answer in the XNA forum, it's kind of easy actually:
  1. Server starts a timer and sends a message to all clients to start their timer also
  2. When the clients receives this message they start their timers too and sends a message back telling the server they have started their timers
  3. When the server receives these messages it checks it's timer and calculates how long it took to get this responds. This time divided by two is the time it took for the first message to be sent, and also how much the clients timer needs to be adjusted.
  4. Server sends a new message to each client to adjust their timer by the time calculated above.
  5. Clients adjusts their timers
Now all timers should be almost the same and can be used in the way I just described.

No comments:

Post a Comment