Jump to content
  • Advertisement
Sign in to follow this  
sufficientreason

Buffering Timestamped States and Wraparound

This topic is 2503 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

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!

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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,

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!