Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm looking to make a deterministic replay in my 2D game. I want to follow a similar approach to braid in storing the relevant information every frame (at 60 frames per second).

I wanted to know what the best way to store this information is. My friend suggested using a hashtable and being new to C# I'm sort of leaning towards just using an array, but I wanted to see if there were other schools of thought.

I've read posts like this How to design a replay system and this "Super meatboy"-ish replay which were very informative, but not very specific to C# and XNA.

My game is 2D and does not have all that many moving parts. At any given time there is probably less than 50 bodies I would need to track the position/rotation of.

Curious to hear your thoughts.

share|improve this question
add comment

1 Answer

Do you need to index things with anything other than an integer? If all you need to do is something like:

a[1] = ...

Then there's no reason to use hash table. In this case arrays will be more efficient than hash table in all cases assuming you don't delete stuff in the middle and shift.

Assuming what you want is store last X frames, make an array of size X.

Assume initially a[0] is most recent frame, a[X-1] is least recent frame.

Make a counter c that points the least recent frame. c = X -1 initially

For each new frame to add,

a[c] = curFrame //replace least recent frame with most recent
c-- //update counter
if(c < 0) //need to wrap c around if it goes negative
  c = X-1

To iterate from most recent to least recent:

for(int i = 1; i <= X ; i ++) //starts at c + 1, the most recent frame
    a[(c + i)%X] ... // % (modulo) wraps it around

If you need to do something like:

h["lol"] = ....

Then yea, you might need to use a hash table.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.