General advice on making a replay system ?

Started by
7 comments, last by andur 12 years, 11 months ago
I've already made the beginning of a 2d (4p max) multiplayer game on ipad. I'm using cocos2d. The games last maximum 1 minute. I want to get a replay of the most epic ones and use them to decorate the front menu (kind of sceensaver function)
I've already done some replay system (for the same game on PC), but they had some problems/bugs. Mainly from a lack of a consistent interface across all the game objects for replays. I know it's very vague sorry.

My question is, do you have any general advice on making a replay system ?

Even if it's stupid advice. Like "implement StartRecord() and StopRecord()", any advice from someone who has implemented one. Like a postmortem on gamasutra would be great
Advertisement
Gamasutra: Developing Your Own Replay System

Previous GDNet topic
I created a replay system my game. In my case, the task was made a lot easier because I'd thought about that feature from the very beginning and the game code design was designed in a way to make replays easy.

If it's not too late, I'd suggest designing your code with this in mind. The most important part is to isolate everything as much as possible. In my case, the main game is encapsulated in a class that has a function which is basically Update(input)
The game only relies on the arguments to the update function and doesn't try to read anything externally. That way you can pass in either inputs from an actual device or prerecorded inputs and everything will work the same. Also, when you start a new game, an entirely new instance of the game class is created, so there's no issues with accidentally forgetting to reset variables or the like.


The biggest problem I had was floating points. It turns out that due to the boneheaded design of the Intel FPU, floating point math is not necessarily deterministic in the sense that the same source code can lead to different results. (I believe that it is deterministic at the machine code level if you're careful with rounding modes, but who wants to program that way?). I discovered that there were actually differences between my game behavior between debug and release builds due to this problem. I ended up linking the debug build of my game to a version of the physics engine compiled in release mode, which made most of the problems go away. It could still theoretically be nondeterminsitic but I have yet to see a problem.
I trust exceptions about as far as I can throw them.
Thanks very interesting.
I will go the route of recording the inputs, it's definitely the easiest. And try to make it as seamless as possible in my code. I need to work within the cocos2d framework though but it should be possible

Also the gamasutra article mentions using a stream to avoid having to create data structures. This seems like a brilliant idea, I'll try that
Personally, I just used std::stream and store the (run length encoded) numbers in text form. Binary would save space but it's more complicated to code and it's nice to be able to inspect the replays manually anyway.
I trust exceptions about as far as I can throw them.
Without reading the article, or have any prior experience of writing replays, here's what my brain came out with:

1. Fixed-rate framerate. 30fps, or whatever. At least the logic part of your game, if you go with multithreaded.
2. Record all actions with timestamps and frame when they occur. Actions should also record all randomized values.
3. You are going to end up with a long list of actions.
4. Replay them.

Without reading the article, or have any prior experience of writing replays, here's what my brain came out with:

1. Fixed-rate framerate. 30fps, or whatever. At least the logic part of your game, if you go with multithreaded.
2. Record all actions with timestamps and frame when they occur. Actions should also record all randomized values.
3. You are going to end up with a long list of actions.
4. Replay them.


That's the basic idea, but RLE is more efficient than timestamping while being just as easy to implement.
I trust exceptions about as far as I can throw them.
My replay system that i used basically stored all the objects on the screen at a fixed time, like every 60 mS. I found minor inconsistencies when using the Input method that and I didn't always get the same replay. So, to guarantee I didn't have that issue, I just stored the location of the objects (as well as when sounds go off). Make sure you squeeze this into as small a format as you can, but, for 1 minute, this shouldn't be that big. You could look at using zlib to compress and uncompress when storing it off.

FWIW, it's really neat, as I would record the last stage of my side-scrolling shoot-em up, and, after you beat the game, while the credits are rolling, it would be replaying the last level in the background. i thought it was awesome :)

GL!

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)


I've already made the beginning of a 2d (4p max) multiplayer game on ipad. I'm using cocos2d. The games last maximum 1 minute. I want to get a replay of the most epic ones and use them to decorate the front menu (kind of sceensaver function)
I've already done some replay system (for the same game on PC), but they had some problems/bugs. Mainly from a lack of a consistent interface across all the game objects for replays. I know it's very vague sorry.

My question is, do you have any general advice on making a replay system ?

Even if it's stupid advice. Like "implement StartRecord() and StopRecord()", any advice from someone who has implemented one. Like a postmortem on gamasutra would be great


Since you have a multiplayer game (this assumes its playable over the network and not just local multiplayer), just record the initial game state when you want to start the replay, and record all of the network messages afterwards (both that you send and receive). Playing back the network messages will give you a full replay. If the game only lasts a minute maximum, just always record all of the network messages.

This topic is closed to new replies.

Advertisement