We are building a multiplayer game that supports replays. The replays work like this:
All state updates from the server get saved into a file. When we are replaying the file we just take the initial state recieved from the server and apply the state updates. This works fine. We can play, fast-forward, pause and go ba… oh wait.
What would be the best way to actually allow players to view the replay backwards?
Some implementation details, we use a huge state struct (well, not really, but you could see it as such). This struct gets updated over the network (UDP) by calculating differences between the last sent struct and the current one. The client interpolates between the last two recieved structs and extrapolates when needed (when ping > throttle of updates). In addition we use an acked event system for stuff that hasn’t to be drawn smoothly on the screen but needs to be, well, acked.
A couple of suggestions (assuming you can make a snapshot at any point, and you’re storing forward deltas).
1.. If the replay is short and the state isn’t too big, actually generate snapshots for each frame in the sequence and “render” them in reverse.
2.. If the whole state is very big, then only generate a snapshot for the last frame of the reversed replay. Then apply X forward deltas to the snap shot to generate the first frame of the reversed replay. Render that. Then apply X-1 deltas, and render that, repeat until X = 0, when you’re at the end of replay (just the first snap shot).
3.. If its too slow to apply X updates to a snapshots to “rewind” then make a series of snap shots N frames apart, and do the same reverse trick in #2, over a narrower range.
Remember that even if you have a reversed game state ready to render – you’ll still have to render all your effects in reverse, which most effect systems probably aren’t geared for.