Jump to content

  • Log In with Google      Sign In   
  • Create Account


What are good ways to implement a "game playback" feature?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Nübček Pænus   Members   -  Reputation: 153

Like
0Likes
Like

Posted 15 December 2013 - 12:07 AM

I'm writing a simulation program. I need a way to record and then play back the entire simulation, at any given point. Kind of like how games like Age of Empires 2 does it, not as in actual video recording of the player's screen. My simulation consists of a really large grid of moving/changing objects. I've already had to dump the core of the program and I'm in the process of replacing it with a messaging system, so that any information that is WRITTEN to the simulation is done in a mesage format (eg. pObject->sendMessage_setDirection()) and information that is READ from the simulation is done regularly (eg. pObject->getDirection()).

 

This is turning out to be very hard to maintain. Every time I add a new object or a new kind of message for an existing object I have to add new code snippets all around. Mostly because messages have to travel from the top of the simulation through 2-3 layers down to the actual object, and every layer needs to know how to handle or route each and every message.

 

So I'm wondering if there's some clever way to go about this besides my approach. My program is relatively young so I can afford to make large changes at this point, specially if it'll make developing the rest of it easier. Recording pixel-by-pixel (video) isn't an option because the grids are supposed to be able to get really large (for example 64,000x64,000 tiles). I also thought about reading through the entire simulation after every tick (a "tick" is the smallest unit I need to record) and saving it to a file but again, it can be really large, so doing this every tick would make the whole thing very slow.

 

Thanks in advance.


Edited by OpOpOpOp, 15 December 2013 - 12:10 AM.


Sponsor:

#2 Paradigm Shifter   Crossbones+   -  Reputation: 5213

Like
2Likes
Like

Posted 15 December 2013 - 03:41 AM

One way is to store user input and playback a recording of the input.

 

This requires that state is properly reset at the start of the playback. Random numbers must also be seeded the same so that AI makes the same decisions. Some thing that require randomness but aren't critical (e.g. particle systems etc.) can use a separate source of random numbers which you don't require to be repeated exactly.

 

It can be quite tricky to get that system right though, and if you make a change to logic you invalidate the replay data. Also you can't rewind except to the start unless you save checkpoints (i.e. all the data and state) at regular intervals.

 

Timing issues can mess it up too so you probably want to use a fixed timestep and playback at the same rate.


Edited by Paradigm Shifter, 15 December 2013 - 03:41 AM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#3 BGB   Crossbones+   -  Reputation: 1549

Like
1Likes
Like

Posted 15 December 2013 - 04:04 AM

some games have recorded things like demos and similar, mostly by recording internal events (generally those that represent what the user sees).

so, whenever something moves or happens in-game, it is recorded.

 

to playback the demo later, you replay the events, typically on a timer, so it is as-if these things were happening again, and all the events are seemingly recreated on-screen.

 

recording user input has also been done in various games, but tends to be a lot more problematic:

if there is any non-deterministic behavior in the system (such as timing behaviors due to variability in framerate, AI logic timers, etc...), or something subtly changes from one version to another, then these tend to be very prone to blow up and have everything go berserk, whereas recorded game events tend to be a lot more stable.



#4 Paradigm Shifter   Crossbones+   -  Reputation: 5213

Like
1Likes
Like

Posted 15 December 2013 - 04:15 AM

Yes the event system is more robust. You can also store undo information in each event then you can also play the replay backwards (which is useful for games where you can rewind time).

 

The "command" pattern is worth having a look at if you want to do that it is designed for undo/redo functionality.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#5 DaBono   Members   -  Reputation: 942

Like
1Likes
Like

Posted 15 December 2013 - 06:02 AM

In a game (or actually a simulation) I worked on, we abused the networking system for this. We made a special kind of 'client' that would not connect through the network, but ran on the server locally. It would store all the game state updates sent to the clients in a file. Periodically, the whole game state (say, your save game) would be stored as well, serving as a kind of keyframe.

Then, at a later time, that file could be used as a replay.

 

Is it ideal? No.

In a large game, you'd selectively send updates to clients. So if units are not near the player, you'd not (or more sparsely) send updates. Also, it requires you to have networking code in place, which not everybody does, of course.

But for us, it was the quickest way to get things working.

 

Oh, and a link I found interesting: http://gdcvault.com/play/1018138/Implementing-a-Rewindable-Instant-Replay



#6 the incredible smoker   Members   -  Reputation: 286

Like
1Likes
Like

Posted 15 December 2013 - 09:50 AM

I played Tiger Woods one day, and the replay missed the put,

maybe they all accept the risk of having a re-play instead of a replay ?, not that i had to try again here in Tiger Woods, i still won the game,

some games let you play again after the replay goes wrong, by using all the same variables from the game i guess.

The weirdness, i rather have no replay at all in my own games.


Edited by the incredible smoker, 15 December 2013 - 09:53 AM.

S T O P   C R I M E !

Visual Pro 2005 C++ DX9 Cubase VST 3.70  Working on : LevelContainer class & LevelEditor


#7 Paradigm Shifter   Crossbones+   -  Reputation: 5213

Like
3Likes
Like

Posted 15 December 2013 - 10:01 AM

Lol that's shocking! In a golf game it's easy just to store the ball position every frame (since it makes sense to precalculate the trajectory when you hit it) and just run that back. Electronic Arse more like!


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#8 Nübček Pænus   Members   -  Reputation: 153

Like
1Likes
Like

Posted 15 December 2013 - 02:17 PM

One way is to store user input and playback a recording of the input.

 

This requires that state is properly reset at the start of the playback. Random numbers must also be seeded the same so that AI makes the same decisions. Some thing that require randomness but aren't critical (e.g. particle systems etc.) can use a separate source of random numbers which you don't require to be repeated exactly.

 

It can be quite tricky to get that system right though, and if you make a change to logic you invalidate the replay data. Also you can't rewind except to the start unless you save checkpoints (i.e. all the data and state) at regular intervals.

 

Timing issues can mess it up too so you probably want to use a fixed timestep and playback at the same rate.

That's actually what I had done before. Problem is the simulation sometimes takes too long on a tick so live playback of all the computations can be slow, and it cannot be rewinded, which is necessary here.

 

 

some games have recorded things like demos and similar, mostly by recording internal events (generally those that represent what the user sees).

so, whenever something moves or happens in-game, it is recorded.

 

to playback the demo later, you replay the events, typically on a timer, so it is as-if these things were happening again, and all the events are seemingly recreated on-screen.

 

recording user input has also been done in various games, but tends to be a lot more problematic:

if there is any non-deterministic behavior in the system (such as timing behaviors due to variability in framerate, AI logic timers, etc...), or something subtly changes from one version to another, then these tend to be very prone to blow up and have everything go berserk, whereas recorded game events tend to be a lot more stable.

That's what I'm doing right now, event/command recording. Apparently that's the best way even though it's complex.

 

Thanks everyone!



#9 snowmanZOMG   Members   -  Reputation: 830

Like
0Likes
Like

Posted 17 December 2013 - 09:28 AM

You might want to check out http://www.gamasutra.com/view/news/197635/.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS