[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Feature in planning stages: Sands of Time



If anyone's ever played "Prince of Persia: Sands of Time" you know what I'm about to say.  Rewind support.

I have this really awesome NES emulator on my DS and it offers the ability to rewind a few seconds of the game regardless of circumstance.  It leaves me with feature-envy though.  Two things that will be possible if I get this feature to ever work:

1) Saved states: These are staples of game-centric emulators
2) Rewind: This is related to saved states except the emulator keeps a circular buffer of states captured at regular intervals.  At the push of a key you can flip back to the previous states.  This will, of course, discard the current state so it has its drawbacks.

One thing that comes to mind is that the first take on this will NOT capture disk changes that are in-flight.  Because of this, you cannot use this to undo an accidental file erasure or the like.  It will be more of a big universal UNDO feature for anything that is memory-based.

To really pull this off, I have to consider how much memory can be afforded and how many states can be held without exhausting Java's heap.  I suppose it could be determined on-the-fly by examining how much heap is available at any given point.

Anyway, the first pass was to go through the emulator code and mark everything that corresponds to the current state, be it a CPU variable or a page of memory, softswitch state, etc.  That has been done using @Stateful annotations to serve as markers.  The next pass is to do a rough-cut of state preservation and restoration and it will take a lot of time.  On the positive side, this will not require changing any existing code since the @Stateful annotations can be located as markers -- all the state code will live in a new class away from existing code.  This has a nice effect of keeping things tidy and not convoluted.

I'm still worried about how to cleanly keep track of memory changes, as I'd like to avoid really big memory copy penalties for unchanged areas of RAM.  The memory spy feature has opened my eyes to how little memory actually changes in a lot of games.  Anyway, it will take a few passes before the feature is ready for prime time.  At least I left you guys with a stable build that plays Airheart in the meantime.  Eventually you'll be able to pull the prince off that bed of spikes or un-explode your Moon Patrol rover.  Or just un-erase that line of code you accidentally creamed via an unfortunate typo.

Hopefully I can make fast progress on this but who knows what strange things I'm going to encounter as I proceed further... :-)

-B