Live data from Hacker News

Conceptually, how does replay work in a game?

stackoverflow.com

1–10 of 15 posts

Re: Conceptually, how does replay work in a game?

#2
For something so basic, I always find this very tricky to get right. Interference from global state can sneak in all from a lot of different unexpected ways.

One of my games allowed people to save replays and levels to the web. The online infrastructure, creation of the editor and debugging of replays dwarfed the time taken to create the game in the first place, making the game take over 4x as long as it otherwise would have. (Note the levels and replays list is only from the last day, never got around to doing an all time best.)

http://www.rocksolidarcade.com/games/stuntpilot2/

Re: Conceptually, how does replay work in a game?

#4
Interesting.

Starcraft 2 introduced replay rewinding which I think is even more interesting.

I guess that it loads a replay at the time you're watching it simply by replaying the game with the help of actions and at the same time it stores states of the game and then if you rewind (you can't continuously rewind like a VCR, you pick a state in the past and you go on from there) it loads that state.

It sounds so easy when you write it like this but I'm sure it's a lot harder than it sounds.

Re: Conceptually, how does replay work in a game?

#5
Having worked in both games and the desktop world, implementing replays is a lot like implementing undo/redo, and they're both an immense time-suck. It's easy for developers on the different sub-systems to create something that on the surface seems complete but is doing a bad job of recording and responding to the needed events. Inevitably either the original developer or the poor sucker tasked with implementing undo has to go back in and rewrite the code, which takes longer than everyone expects.

Re: Conceptually, how does replay work in a game?

#6

Having worked in both games and the desktop world, implementing replays is a lot like implementing undo/redo, and they're both an immense time-suck. It's easy for developers on the different sub-systems to create something that on the surface seems complete but is doing a bad job of recording and responding to the needed events. Inevitably either the original developer or the poor sucker tasked with implementing undo…

Unless, of course, you already need determinism for multi-player to work. Real time strategy games, first person shooters with complex AI, and other games that are networked in lock-step are already completely deterministic and have to be for it to work at all. You basically get replays for free that way, but it has to be a conscious effort of the entire team to maintain determinism.

Luckily, determinism is something that you can verify with an automated process. After each checkin, run some automated tests on a server farm. Run them twice. During the first run, take a full game world state snapshot periodically. During the second run, verify that the world state is identical since the first run. If it isn't, re-run the test twice. Take snapshots more frequently during the interval where determinism broke. Recurse like a binary search. You can automatically pin-point the exact frame where the simulations diverge.

One you have a replay file and the exact frame, you have the best bug report on the planet. "This replay is build 12345 and crashes on frame 54321". Fire it up in the debugger, run a system command "fast forward to frame 54321" and then just start stepping. Oh, it crashes on that line? Let's drill into that: restart replay, set breakpoint, run to frame 54321, step-in. Freaking beautiful.

Re: Conceptually, how does replay work in a game?

#7
This method of storing replays frequently leads to brokenness when the game logic updates due to patches. IL2: Sturmovik had replays like this and if you ran an old replay on a newer version, the replay planes would end up running off the runway or similar.

IIRC, the Starcraft 2 beta keeps old versions of the game engine around to let you play back older replays.

A similar technique is occasionally used in non-server-based multiplayer games - here's a Gamasutra post-mortem for _X-Wing vs. TIE Fighter_ where sending inputs across machines is discussed: http://www.gamasutra.com/view/feature/3374/the_internet_suck...

Re: Conceptually, how does replay work in a game?

#8
post #7

This method of storing replays frequently leads to brokenness when the game logic updates due to patches. IL2: Sturmovik had replays like this and if you ran an old replay on a newer version, the replay planes would end up running off the runway or similar. IIRC, the Starcraft 2 beta keeps old versions of the game engine around to let you play back older replays. A similar technique is occasionally used in non-server…

I was big into Supreme Commander in the first 6 months after its release. They had a phenomenal online database of every ranked replay as well as ranking which would point users to great high-level replays.

Early on, Supreme Commander was great at putting out balance changes and hotfixes. Unfortunately, every single patch would completely empty the online database and would also break any replays you stored on your computer! People managed to hack together a version switcher eventually, but I still ended up losing lots of awesome replays.

Re: Conceptually, how does replay work in a game?

#10
One of the neatest ways replays are implemented is in MAME (Multiple Arcade Machine Emulator). The replay is recorded by just recording all of the inputs given to the emulator during the course of the game. Since the entire system is deterministic, you can watch a replay by having MAME just play back the game with the inputs stored in the file.
Post reply on HN