Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to store the history of a box2d simulation. Currently I can't find any built-in mechanism for that.

I need to store the states of all non static objects in the last second, mainly for network latency correction.

I think I will use a multi dimensional array for all the rigid bodies positions and forces.

Is there a better way to achieve what I'm trying to do?

share|improve this question
up vote 3 down vote accepted

As far as my personal experience spans, I think you are really better off saving crucial data on data structures or arrays/matrices.

I suggest you don't store all data eagerly, though. You should only store data of objects that moved or had some change to it's resulting force on given frame. This will save you from storing data of objects that are standing still and not participating in any active collisions.

If you are in a scenario with a low density of objects movements and/or collisions over time, you can even do crazy things such as Braid's time rewinding thing, since storing past states (or past state changes) wouldn't be too costly.

share|improve this answer
From memory Braid uses some system based on the command pattern. I need to access immediately the state at time T-x. Do some processing and send the updates to all players. I'd like to allocate the memory once and simply run it like that. But I might be completely wrong when it comes to my approach. – Coyote Feb 6 '13 at 22:32
If the number of entities is low and doesn't change often, then you might be able to use your "allocate memory once" approach without blowing up your memory budget. – UBSophung Feb 6 '13 at 23:50

Your Answer


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.