Rewinding

GE 10.0 adds support for rewind. Once triggered this allows time to run backwards and all GE objects will reverse their paths. The rewind may also be configured to “undo” the following GE actions:

  • ApplyImpulse/Set Velocity
  • Maneuvers
  • Add a game object
  • Remove a game object

This undo feature is enabled by the toggle “Record for Rewind” in the GE inspector (under the Advanced section). This toggle results in the instantiation of a class GERewindMgr that records the above actions and the state information required to perform and undo. Note that this means as the game evolves forward in time this record may become sizeable.

A demonstration of this capability can be found in the scene RewindExample in Demos/Scenes.

Initiating Rewind

A rewind is initiated by a call to GE.

 ge.SetTimeReversed(true);

(returning to forward evolution is performed by calling this method with argument false).

Invoking this call will result in GE switching to a time reversed inner loop. Prior to this all objects evolving due to NBody gravity will have their velocities reversed so that as the numerical integration evolves they will go backwards. “On-rails” objects do not require this, since their internal code returns a position for a specific time and they operate in a time-symmetric way. Note that even when time is running backwards, queries for the velocity of objects will return the result assuming that time is evolving forward.

If time zero is reached the rewind code in GE will set evolution to false and gravitational physics evolution will pause.

Rewind Callbacks

The rewind code allows a callback to be registered to get updates as rewind events are handled. A callback is registered via:

    ge.GetWorldState().GetGERewindMgr().SetRewindCallback(RewindCallback);

The signature of the rewind callback is:

private bool RewindCallback(GERewindMgr.RewindEntry rewindEntry)
{
    LogAndDisplay("Callback for: " + rewindEntry.ToString());
    return false;
}

The boolean return value is used to signal to the rewind manager whether the callback handled the rewind event. By returning false this example indicates that the rewind manager code should do the “undo” required for event.

Adding/Removing Game Objects

The adding and removing logic for the rewind manager needs to make some assumptions about game object management.

If a game object has been added to the scene during normal forward evolution, then when undoing this action the rewind manager will remove the object from GE and set the game object as inactive (i.e. it will not delete it from the scene).

If a game object has been removed, then the undo must re-add it. This is only possible if the object is still available in the scene and can be made active again. This requires that game logic that removes bodies keeps the objects in the scene in an inactive state.