Sign in to follow this  

Rediculous question

This topic is 4658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My game server and client both send updates to each other 20 times per second. Each packet has an unsigned int ID which is incremented each time the server or client sends. So, this means that there should be a wrap to 0 at about 2^32 /20/60/60/24 = 2485 days = 6.8 years. Should this problem even be dealt with? I suppose all that needs to be worried about is
if(packet.id>last_read_packet){
    //use teh packet lolol!
}
I suppose I'd solve it by checking if the difference is around 4 billion. But, that's if I really need to worry about it.

Share this post


Link to post
Share on other sites
Quote:
Original post by matt_j

if(packet.id>=2^32-LAG_FACTOR){
tell_user_to_get_a_life___and_then_quit();
}



Yep, thats the best solution. I use it, too. But only in debug mode..

Share this post


Link to post
Share on other sites
Quote:
Original post by matt_j

if(packet.id>=2^32-LAG_FACTOR){
tell_user_to_get_a_life___and_then_quit();
}


[lol] Great! But you shouldn't even waste the CPU cycles checking every time. I mean when the number gets that high it will just loop over, giving anyone who tries running your game over 6 years a suprise [smile]

Share this post


Link to post
Share on other sites
When you deal with things that can cycle around, your best bet is to always deal with differences, rather than absolute numbers. Thus:


void some_function( size_t a, size_t b ) {
if( ssize_t(a-b) < 0 ) {
you_are_behind();
}
else {
you_are_ahead();
}
}


When wrapping, it doesn't matter in this case -- as long as your CPU is 2's complement, of course :-)

Share this post


Link to post
Share on other sites
Or, after 6.8 years, people's games will crash, and I'll get bug reports. So, I'll get on the compiler, change the version number from "1.0" to "1.1", re-compile, and make sure the affected users download it.

Yup, that solves anything. If the bug pops up again, it should probably be easy to fix...

Share this post


Link to post
Share on other sites
you do start at 0 each round right?
Unless you're talking about an official game server, no one is ever going to run past the wrap time in a row.
And even if it is so, Every official game server out there, even for MMOG, has been down for maintenance within a single year.

So, you don't have to patch it. Sounds fine like it is.

About that difference algorithm, yeah thats the good way, but add this for the wrap: check if the difference is too big and with the proper sign. Say, half the size of the datatype.

Share this post


Link to post
Share on other sites

This topic is 4658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this