diff --git a/src/Aircraft/replay.cxx b/src/Aircraft/replay.cxx index d5deeecd2..2baf32855 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,28 @@ 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 + double current_time = replay_time->getDoubleValue(); + if (current_time<0.0) + { + // initialize start time + fgSetDouble( "/sim/replay/start-time", get_start_time() ); + fgSetDouble( "/sim/replay/end-time", get_end_time() ); + double duration = fgGetDouble( "/sim/replay/duration" ); + if( duration && duration < (get_end_time() - get_start_time()) ) { + current_time = get_end_time() - duration; + } else { + current_time = get_start_time(); + } + } + bool IsFinished = replay( replay_time->getDoubleValue() ); + if ((IsFinished)&&(replay_looped->getBoolValue())) + current_time = -1; + else + current_time += dt * fgGetInt("/sim/speed-up"); + replay_time->setDoubleValue(current_time); + } return; // don't record the replay session case 2: // replay paused, no-op @@ -279,7 +298,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 +577,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 +591,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 +646,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; }; diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index 4c6ad3f04..806401cf9 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -729,7 +729,7 @@ bool FGJSBsim::copy_to_JSBsim() // turbulence_gain normalized: 0: none, 1/3: light, 2/3: moderate, 3/3: severe double tmp = turbulence_gain->getDoubleValue(); Atmosphere->SetProbabilityOfExceedence( - round(TurbulenceSeverityTable.GetValue( tmp ) ) + SGMiscd::roundToInt(TurbulenceSeverityTable.GetValue( tmp ) ) ); Atmosphere->SetWindspeed20ft(ground_wind->getDoubleValue()); break; diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 8f7a1c18c..45d4b901b 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -1247,17 +1247,7 @@ do_replay (const SGPropertyNode * arg) fgSetInt( "/sim/freeze/replay-state", 1 ); fgSetBool("/sim/freeze/master", 0 ); fgSetBool("/sim/freeze/clock", 0 ); - - FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" )); - - fgSetDouble( "/sim/replay/start-time", r->get_start_time() ); - fgSetDouble( "/sim/replay/end-time", r->get_end_time() ); - double duration = fgGetDouble( "/sim/replay/duration" ); - if( duration && duration < (r->get_end_time() - r->get_start_time()) ) { - fgSetDouble( "/sim/replay/time", r->get_end_time() - duration ); - } else { - fgSetDouble( "/sim/replay/time", r->get_start_time() ); - } + fgSetDouble( "/sim/replay/time", -1 ); // cout << "start = " << r->get_start_time() // << " end = " << r->get_end_time() << endl;