Rewinding time, what would be the best way to do it?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Bobbias
Prole
Posts: 36
Joined: Sat Jun 29, 2013 1:26 pm

Re: Rewinding time, what would be the best way to do it?

Post by Bobbias »

micha wrote:This refers to the post two above:
Plu wrote:We only need to store the point where the behaviour changes from "falling" to "moving" (ie; the impact point with the ground, or the point where it walked off the platform)
Ok, I understand. So in the forward simulation there are time-episodes that are reversible and there are moments, when information about the past is lost (behaviour change from falling to moving). So we need to keep track of these moments. Then it is generally possible to reconstruct any previous state of the system (given the current state and the pile of "lost information").
I have to admit that here I am discussing something that I haven't tried myself, but I still doubt that this approach is very practical. Have you tried implementing such a system?

I made a small calculation to see how fast the memory is filled, if you record a game: A double has 64bit = 8 byte. If we have 50 Objects on screen and each objects contains 10 numbers to characterize it's state and if we record 60 frames per second for 10 seconds, then we end up with
8*50*10*60*10 = 2,400,000 byte = 2.4 Mb. That isn't as bad as I expected. But still, yes you can get into a range that will not fit into your memory. So if I wanted to record a game in order to player it backwards, I would have to be careful to select the essential data and only store these. Otherwise it could grow too fast. So maybe an event-based approach is better, than a state-based approach. And this is already what you suggested.

Thanks for discussion. It made me thinking and I learned something.

Starcraft 2's replay system is capable of tracking the events of hundreds of units over sometimes an hour or ore of game time in a replay file which is often less than 100kb. While I'm sure they put some effort into making the replay files as small as possible, it's not unrealistic to expect to save every state change for every object in a small game for a short period of time in under 1mb.

I don't know TOO much about how SC2's replays work, but I know the basic idea. Every time a player does an action such as building a unit, ordering it to move to a location, etc. it saves the frame that the event happened on, and the event. The way it handles ordering a collection of units is that every time you select or deselect a unit, that is also recorded as an action in the replay, so when you record the "attack here" action, you don't also need to save which units are being ordered, because you must have already recorded the player selecting them.

Here's an example screenshot showing the list of actions from the beginning of a game using the SC2Gears replay analyzer tool:
Image
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Rewinding time, what would be the best way to do it?

Post by Plu »

Have you tried implementing such a system?
Not in an action game, but I have done something similar for a browser based game that required the ability to store events to walk through time in order to calculate gamestate. And yeah, it's complicated stuff. If the OP says "max 5 seconds backwards" I would probably skip that solution and do the more straight forward "save every frame in the the last 5 seconds in a table" approach as you probably won't max out your memory fast enough to worry about it.

It'll save you some coding headache. :)
Bobbias
Prole
Posts: 36
Joined: Sat Jun 29, 2013 1:26 pm

Re: Rewinding time, what would be the best way to do it?

Post by Bobbias »

Yeah often simple answers are better than complex yet powerful ones... I just wanted to point out that it's very doable (and show a bit of how it works) to create a system that can remember extended periods of time with potentially hundreds or thousands of objects and various actions, and still store it in an absurdly small amount of space.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Rewinding time, what would be the best way to do it?

Post by Robin »

retrotails wrote:this NEEDS vsync, otherwise RAM use could get out of hand.
Small thingy: don't rely on vsync. Some systems don't provide it, even if you ask for it, and then the RAM usage would get out of hand anyway. Instead, keep a time variable, add dt to it, and only store a frame once the total time passed 1/60 s or 1/30 s. Then subtract that number from the time variable.
Help us help you: attach a .love.
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: Rewinding time, what would be the best way to do it?

Post by retrotails »

Robin wrote:
retrotails wrote:this NEEDS vsync, otherwise RAM use could get out of hand.
Small thingy: don't rely on vsync. Some systems don't provide it, even if you ask for it, and then the RAM usage would get out of hand anyway. Instead, keep a time variable, add dt to it, and only store a frame once the total time passed 1/60 s or 1/30 s. Then subtract that number from the time variable.
I know I should have, but it was just a warning for those running my demo. Also I like frame limits anyway, mostly because I like to always get perfect results.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Rewinding time, what would be the best way to do it?

Post by micha »

Bobbias wrote:Starcraft 2's replay system is capable of tracking the events of hundreds of units over sometimes an hour or ore of game time in a replay file which is often less than 100kb. While I'm sure they put some effort into making the replay files as small as possible, it's not unrealistic to expect to save every state change for every object in a small game for a short period of time in under 1mb.
I was thinking about games with a replay function as well. I played super meat boy recently and it records the game in each level for multiple tries. But this is a forward replay. Sure, when the game is deterministic then it is enough to record the players input to replay the game forward. For a backward replay you'd either have to store additional information (see goomba example above) or you need to run a forward simulation each frame.
paulsix
Prole
Posts: 1
Joined: Sat Jun 22, 2013 8:52 pm

Re: Rewinding time, what would be the best way to do it?

Post by paulsix »

Actually, I implemented rewind to my meat boy game, but the way I do it is to wait 1 second and store the event at that frame,

When rewinding, it interpolates the information through the various frames, and deletes the said events from the table.

Pretty inefficient, but it seems to work overnight, and doesn't hog my RAM too much.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests