Sign in to follow this  

Tracking game events

This topic is 2347 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. How do I represent events that have occurred in my game? I want to store them in a timeline and track through it, doing or undoing gameplay. For example, a Starcraft player can watch a replay which, rather than simply storing a video of a match, stores the events that occurred, when they occurred, etc. For another example, in Braid, a Mario-like platformer where you can jump on enemies to kill them, if the player dies he can hold down a button and reverse back through time to an earlier state. This requires being able to remove objects at the time they were created, etc.

How do I store these events? They need to be reversable, and need to change the game's state, but most importantly when they reference certain entities they need to do so in a way that doesn't use pointers. I imagine that if I will run into segfaults or memory errors if I rely on storing pointers to the objects that need to be created.

It occurs to me that this is very similar to sending updates in a multiplayer game since a message telling the client to destroy an enemy cannot simply reference that enemy's memory address. How do I reference entities in a stable, consistent, and efficient manner?

Thanks.

Share this post


Link to post
Share on other sites
Well, you're right, I don't know how either works, so I don't know which I need. I know I need to store when things happen -- not just store a variable over time, but track events -- in such a way that I can do or undo them. I need these events to be able to reference entities somehow as well.

Share this post


Link to post
Share on other sites
OK... so... you want to be able to rewind/undo things? Or do you really mean that you don't know what you want? (In which case we'll have to solve that first!)

Are you familiar with the [url="http://en.wikipedia.org/wiki/Memento_pattern"]memento pattern[/url]? It's a common approach for supporting undo/rollback type features. Depending on what you are actually trying to accomplish, which you still haven't really explained, it may range from a suitable solution to a decent starting point to help you think about your own approaches.

Share this post


Link to post
Share on other sites
Starcraft probably just stores the mouse and keyboard events along with the time they occurred. Then when the replay is played all those actions are just reproduced.

Share this post


Link to post
Share on other sites
[quote name='beatlefan' timestamp='1310412823' post='4833932']
Starcraft probably just stores the mouse and keyboard events along with the time they occurred. Then when the replay is played all those actions are just reproduced.
[/quote]

There's a lot more to it than that; things like randomly chosen results must be synchronized (usually using a shared-seed method), AI decision making has to be taken into account, and so on. Replays are actually fairly sophisticated systems... but a rewinding mechanism like in Braid is an order of magnitude more challenging.

Blow did a talk at GDC this year about how he built his system. It should be available on the GDC Vault and possibly other video sites on the web; I highly recommend it.

Share this post


Link to post
Share on other sites
[quote name='whiterook6' timestamp='1310397775' post='4833762']Hi. How do I represent events that have occurred in my game? I want to store them in a timeline and track through it, doing or undoing gameplay.[/quote]
One way to do it:

1. Determine the minimum amount of information needed to represent the state of the game.
2. Make a data structure containing these pieces of information.
3. Make a function to restore/generate the entire game-state from the above structure.
4. Add an (updated) instance of this structure to some list in each iteration.

This is not a particularly memory friendly solution, but it should solve your problem.

Share this post


Link to post
Share on other sites
ApochPiQ, I figure being able to store events (not window messages and such, but in-game events) is the first step, then rewinding them comes later. Also I need to figure out how to represent a state change in the game -- a ship exploding, a Goomba getting crushed, etc. If objects are created and destroyed at any time, how do I have an event refer, say, to [i]this[/i] ship and not [i]that[/i] ship?

I can't just use pointers because reproducing the events won't always use the same memory locations. My roommate, who has at least some experience in this matter, says that entities can be given their own unique ID, and that that, in conjunction with a hash table, can link events to entities without resorting to pointers. Is that a good way to do things?

Share this post


Link to post
Share on other sites
[font="arial, verdana, tahoma, sans-serif"][size="2"]linky - [url="http://www.gamasutra.com/view/feature/2029/developing_your_own_replay_system.php"]http://www.gamasutra...play_system.php[/url][/size][/font][font="arial, verdana, tahoma, sans-serif"][size="2"][quote name='ApochPiQ' timestamp='1310403454' post='4833813']StarCraft replays and Braid-style time-rewinding are [i]dramatically[/i] different problems.[/quote]They're actually implemented the same way.[/size][/font][font="arial, verdana, tahoma, sans-serif"][size="2"]A series of inputs is written to a stream, along with a periodic 'full game-state'. e.g. 1 input delta per frame, plus one full game-state per second.[/size][/font][font="arial, verdana, tahoma, sans-serif"][size="2"]This allows you to start the replay at any of the full game-states (or rewind to any of them), and then play forward from there using the stored inputs.[quote name='ApochPiQ' timestamp='1310413276' post='4833937'][/size][/font]Blow did a talk at GDC this year about how he built his system. It should be available on the GDC Vault and possibly other video sites on the web; I highly recommend it.[/quote]I can't find a link at the moment, but he also published his replay compression code about 5 years ago. There's other games that are also this code (for regular replays, not necessarily time-rewinding).

Share this post


Link to post
Share on other sites
Wasn't aware that SC's replays were that sophisticated, interesting.

I've done replay systems in the past that don't support bookmarking/fast-forwarding/rewinding, and they were comparatively trivial. Having never actually watched a SC replay in-game, I must admit I was unaware that they were doing anything that potent.

Share this post


Link to post
Share on other sites

This topic is 2347 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this