Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Buffering Timestamped States and Wraparound


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
3 replies to this topic

#1 sufficientreason   Members   -  Reputation: 103

Like
0Likes
Like

Posted 10 February 2012 - 07:20 PM

Hi everyone,

I'm trying to create a buffer of game states for interpolation, each with a unique incrementing timestep marker. I want the buffer to always be able to retrieve the state with the lowest timestamp. The states are not guaranteed to be inserted in order in the buffer (they're being transmitted via UDP), so this raises an issue with wraparound.

I'm using C# uints, but let's say for a moment that I'm just using bytes with a range of 0-255. Beginning at timestep 253, the order of output states would be tagged 253, 254, 255, 0, 1, 2, 3. When we mix up the order, the buffer could receive the list [0, 254, 3, 2, 253, 255, 1]. Using normal comparison, a sorted list would arrange these as [0, 1, 2, 3, 253, 254, 255], but I need [253, 254, 255, 0, 1, 2, 3]. We can assume that the buffer will never have more than, say, 100 entries in it (or, more accurately, more than half the maximum value for the datatype of the timestamp).

Ideally I'd like to just write a special IComparer<uint> in C# and use a SortedList<uint, State>. I need fast insertion, and the buffer always has to be able to quickly retrieve the lowest-timestep state. I know this has to be a solved problem, but I can't find it anywhere. Any help? Thanks!

Sponsor:

#2 DvDmanDT   Members   -  Reputation: 281

Like
0Likes
Like

Posted 10 February 2012 - 07:47 PM

Loop through and see if both 0 and 255 exists, and if so, add 255 if value is below 127 while comparing? If you can store last frames highest value, you might be able to skip the loop step though.

#3 Telastyn   Members   -  Reputation: 3332

Like
1Likes
Like

Posted 10 February 2012 - 10:57 PM

Why go through the headache and processing to save a few bytes? Just use DateTime.Ticks or some other non-wraparound sized timestamp...

Though timestamps aren't exactly super reliable across machines regardless... I'm not sure what you're using them for.

#4 sufficientreason   Members   -  Reputation: 103

Like
0Likes
Like

Posted 11 February 2012 - 12:52 AM

Yeah, you're right. That's just a simpler way to do it. I thought I would tag states by the "tick" they were generated on, but that didn't even turn out to be accurate enough. Nevermind. Thank you though,




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