Jump to content

  • Log In with Google      Sign In   
  • Create Account

Checking sanity of my tick synchronization


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 fholm   Members   -  Reputation: 262

Like
0Likes
Like

Posted 10 January 2014 - 11:07 AM

So I have been working on my FPS game and its networking lately and I have been thinking about a case I have not really considered yet. My server sends data to the clients on every third simulation frame, this ends up being 20 times per second with my 60 Hz simulation rate. Every packet has the servers simulation frame number (tick) attached to it.

 

Currently the client synchronizes it's own tick number to the first packet received from the server like this:

int clientTick = serverTick - 3;

And then increases it's own tick for every simulation-frame which passes locally after this. The reason that i subtract 3 from the server tick is because I buffer the packets locally on the client in a de-jitter buffer, and then de-queue them from the buffer based on the client local tick number. So we basically "rewind" 3 ticks in time to setup this local delay to handle packet jitter.

 

The end result is that we expect to have 1-2 packets in this buffer on the client, and that if we have > 2 packets in the buffer we have drifted behind the server more then intended and need to speed up our local simulation a bit. Now, this seems to be working and is the by far best solution to this problem I have come up with.

 

Is this a sane way to solve this problem? It seems sane to me, and seems to be working, but just wanna get some feedback.

 



Sponsor:

#2 hplus0603   Moderators   -  Reputation: 5301

Like
0Likes
Like

Posted 10 January 2014 - 01:13 PM

Yes, it seems sane. You build up a little more latency than you have to, though. With just 3 steps per packet, one packet of buffer might not be so bad.

 

There's the converse case you need to deal with: The client runs ahead of the server. If you find that it's time to decode more data, but you haven't yet received anything from the server, you want to be bumping the tick offset by one or two. Same thing if you find that you have two packets in the buffer when there should only be one; bump the offset the other way (it sounds like you already do this part.)


enum Bool { True, False, FileNotFound };

#3 fholm   Members   -  Reputation: 262

Like
0Likes
Like

Posted 10 January 2014 - 02:13 PM

So yeah, the inverse where the client is too far ahead, what you are saying then is to just do ++clientTick once or twice to let the client keep stepping forward? I was thinking i could just stop the world on the client completely, I mean this is an FPS after all and if you are not receiving your data on time your experience is going to suck anyway.

 

Edit: Or maybe you mean to decrease the client tick count if we have no data, actually ;p


Edited by fholm, 10 January 2014 - 02:21 PM.


#4 hplus0603   Moderators   -  Reputation: 5301

Like
0Likes
Like

Posted 11 January 2014 - 11:29 AM

Edit: Or maybe you mean to decrease the client tick count if we have no data, actually


Exactly.
enum Bool { True, False, FileNotFound };

#5 fholm   Members   -  Reputation: 262

Like
0Likes
Like

Posted 11 January 2014 - 01:08 PM

 

Edit: Or maybe you mean to decrease the client tick count if we have no data, actually


Exactly.

 

 

This seems to be working wonderfully, one followup question: Would you stall the local tick count to so it stays on the current tick it expects a packet for constantly? basically at the end of every frame, subtract one from the tick count. Currently I am doing this and it seems to be working fine.

 

Or would you subtract more each frame, and let it "run up" to the frame it's looking for data for every time, and if the data is still not there, reset it and run up to it again?


Edited by fholm, 11 January 2014 - 01:10 PM.


#6 hplus0603   Moderators   -  Reputation: 5301

Like
0Likes
Like

Posted 12 January 2014 - 03:09 PM

Would you stall the local tick count to so it stays on the current tick it expects a packet for constantly?


That sounds like a fine way of doing it.

If you want to do extra effort, you can keep a relative speed between client and server, so that if you find that you keep having to stall (or keep having to jump ahead,) you can adjust the scaling factor to adjust for clock rate differences. For 99% of games, though, this is unlikely to be needed.
enum Bool { True, False, FileNotFound };




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS