From: ThorstenB Date: Sat, 14 May 2011 07:17:51 +0000 (+0200) Subject: Looped replay feature X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6c3cd27a572360e8b67b18ba101859fef8c52f09;p=flightgear.git Looped replay feature New option for continuously repeated replay (LinuxTag FlightGear demo mode :) ) --- diff --git a/src/Aircraft/replay.cxx b/src/Aircraft/replay.cxx index d5deeecd2..890931a08 100644 --- a/src/Aircraft/replay.cxx +++ b/src/Aircraft/replay.cxx @@ -100,6 +100,7 @@ void FGReplay::init() disable_replay = fgGetNode( "/sim/replay/disable", true ); replay_master = fgGetNode( "/sim/freeze/replay-state", true ); replay_time = fgGetNode( "/sim/replay/time", true); + replay_looped = fgGetNode( "/sim/replay/looped", true); reinit(); } @@ -194,10 +195,15 @@ void FGReplay::update( double dt ) // replay inactive, keep recording break; case 1: - // replay active - replay( replay_time->getDoubleValue() ); - replay_time->setDoubleValue( replay_time->getDoubleValue() - + ( dt * fgGetInt("/sim/speed-up") ) ); + { + // replay active + bool IsFinished = replay( replay_time->getDoubleValue() ); + if ((IsFinished)&&(replay_looped->getBoolValue())) + replay_time->setDoubleValue(0.0); + else + replay_time->setDoubleValue( replay_time->getDoubleValue() + + ( dt * fgGetInt("/sim/speed-up") ) ); + } return; // don't record the replay session case 2: // replay paused, no-op @@ -279,7 +285,7 @@ void FGReplay::update( double dt ) FGReplayData *lt_front = long_term.front(); if ( sim_time - lt_front->sim_time > lt_list_time ) { - //stamp("point_10"); + //stamp("point_10"); while ( sim_time - lt_front->sim_time > lt_list_time ) { lt_front = long_term.front(); recycler.push_back(lt_front); @@ -558,9 +564,10 @@ static void interpolate( double time, const replay_list_type &list ) { /** * Replay a saved frame based on time, interpolate from the two * nearest saved frames. + * Returns true when replay sequence has finished, false otherwise. */ -void FGReplay::replay( double time ) { +bool FGReplay::replay( double time ) { // cout << "replay: " << time << " "; // find the two frames to interpolate between double t1, t2; @@ -571,6 +578,8 @@ void FGReplay::replay( double time ) { if ( time > t1 ) { // replay the most recent frame update_fdm( (*short_term.back()) ); + // replay is finished now + return true; // cout << "first frame" << endl; } else if ( time <= t1 && time >= t2 ) { interpolate( time, short_term ); @@ -624,7 +633,9 @@ void FGReplay::replay( double time ) { } } else { // nothing to replay + return true; } + return false; } diff --git a/src/Aircraft/replay.hxx b/src/Aircraft/replay.hxx index 3ad3aed0c..0d48ff4ef 100644 --- a/src/Aircraft/replay.hxx +++ b/src/Aircraft/replay.hxx @@ -74,7 +74,7 @@ public: virtual void unbind(); virtual void update( double dt ); - void replay( double time ); + bool replay( double time ); double get_start_time(); double get_end_time(); @@ -101,6 +101,7 @@ private: SGPropertyNode_ptr disable_replay; SGPropertyNode_ptr replay_master; SGPropertyNode_ptr replay_time; + SGPropertyNode_ptr replay_looped; };