From 991beb0b5ecf08df56ad77f6a49b0e20c191be11 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Mon, 21 Mar 2011 23:07:05 +0100 Subject: [PATCH] replay/FDM shell subsystem refactoring Move final bits of replay code to where it belongs. Use subsystem suspend/resume for FDM shell during instant replay. --- src/Aircraft/replay.cxx | 143 ++++++++++++++++++++++++++-------------- src/Aircraft/replay.hxx | 3 + src/FDM/fdm_shell.cxx | 34 ++++------ src/FDM/fdm_shell.hxx | 3 +- 4 files changed, 112 insertions(+), 71 deletions(-) diff --git a/src/Aircraft/replay.cxx b/src/Aircraft/replay.cxx index 6c5c410d8..9ecc353d8 100644 --- a/src/Aircraft/replay.cxx +++ b/src/Aircraft/replay.cxx @@ -25,12 +25,14 @@ #endif #include +#include #include
#include #include #include #include +#include #include "replay.hxx" @@ -46,7 +48,9 @@ const double FGReplay::lt_dt = 5.0; // long term sample rate (sec) * Constructor */ -FGReplay::FGReplay() { +FGReplay::FGReplay() : + last_replay_state(0) +{ } @@ -54,35 +58,44 @@ FGReplay::FGReplay() { * Destructor */ -FGReplay::~FGReplay() { - while ( !short_term.empty() ) { - //cerr << "Deleting Short term" <getBoolValue() ) { - if ( sim_time != 0.0 ) { - // we were recording data - init(); - } - return; + if (( sim_time != 0.0 )&& + ( disable_replay->getBoolValue() )) + { + // we were recording data + reinit(); } - //stamp("point_01"); - if ( replay_master->getIntValue() > 0 ) { - // don't record the replay session - return; + + int replay_state = replay_master->getIntValue(); + + if ((replay_state > 0)&& + (last_replay_state == 0)) + { + // replay is starting, suspend FDM + /* FIXME we need to suspend/resume the FDM - not the entire FDM shell. + * FDM isn't available via the global subsystem manager yet, so need a + * method at the FDMshell for now */ + ((FDMShell*) globals->get_subsystem("flight"))->getFDM()->suspend(); + } + else + if ((replay_state == 0)&& + (last_replay_state > 0)) + { + // replay is finished, resume FDM + ((FDMShell*) globals->get_subsystem("flight"))->getFDM()->resume(); + } + + // remember recent state + last_replay_state = replay_state; + + switch(replay_state) + { + case 0: + // replay inactive, keep recording + break; + case 1: + // replay active + replay( replay_time->getDoubleValue() ); + replay_time->setDoubleValue( replay_time->getDoubleValue() + + ( dt * fgGetInt("/sim/speed-up") ) ); + return; // don't record the replay session + case 2: + // replay paused, no-op + return; // don't record the replay session + default: + throw sg_range_exception("unknown FGReplay state"); } + + // flight recording + //cerr << "Recording replay" << endl; sim_time += dt; @@ -180,12 +222,13 @@ void FGReplay::update( double dt ) { if (!recycler.size()) { stamp("Replay_01"); r = new FGReplayData; - stamp("Replay_02"); + stamp("Replay_02"); } else { - r = recycler.front(); - recycler.pop_front(); - //stamp("point_04be"); + r = recycler.front(); + recycler.pop_front(); + //stamp("point_04be"); } + r->sim_time = sim_time; //r->ctrls = c; //stamp("point_04e"); diff --git a/src/Aircraft/replay.hxx b/src/Aircraft/replay.hxx index bad1ce8b1..3ad3aed0c 100644 --- a/src/Aircraft/replay.hxx +++ b/src/Aircraft/replay.hxx @@ -79,6 +79,7 @@ public: double get_end_time(); private: + void clear(); static const double st_list_time; // 60 secs of high res data static const double mt_list_time; // 10 mins of 1 fps data @@ -91,6 +92,7 @@ private: double sim_time; double last_mt_time; double last_lt_time; + int last_replay_state; replay_list_type short_term; replay_list_type medium_term; @@ -98,6 +100,7 @@ private: replay_list_type recycler; SGPropertyNode_ptr disable_replay; SGPropertyNode_ptr replay_master; + SGPropertyNode_ptr replay_time; }; diff --git a/src/FDM/fdm_shell.cxx b/src/FDM/fdm_shell.cxx index 7d936e3d1..401483e4b 100644 --- a/src/FDM/fdm_shell.cxx +++ b/src/FDM/fdm_shell.cxx @@ -139,8 +139,8 @@ void FDMShell::update(double dt) // pull environmental data in, since the FDMs are lazy _impl->set_Velocities_Local_Airmass( _props->getDoubleValue("environment/wind-from-north-fps", 0.0), - _props->getDoubleValue("environment/wind-from-east-fps", 0.0), - _props->getDoubleValue("environment/wind-from-down-fps", 0.0)); + _props->getDoubleValue("environment/wind-from-east-fps", 0.0), + _props->getDoubleValue("environment/wind-from-down-fps", 0.0)); if (_props->getBoolValue("environment/params/control-fdm-atmosphere")) { // convert from Rankine to Celsius @@ -160,24 +160,8 @@ void FDMShell::update(double dt) _impl->ToggleDataLogging(doLog); } -// FIXME - replay manager should handle most of this - int replayState = fgGetInt("/sim/freeze/replay-state", 0); - if (replayState == 0) { - _impl->update(dt); // normal code path - } else if (replayState == 1) { - // should be inside FGReplay! - SGPropertyNode* replay_time = fgGetNode("/sim/replay/time", true); - FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" )); - r->replay( replay_time->getDoubleValue() ); - replay_time->setDoubleValue( replay_time->getDoubleValue() - + ( dt - * fgGetInt("/sim/speed-up") ) ); - - } else if (replayState == 2) { - // paused replay, no-op - } else { - throw sg_range_exception("unknown FGReplay state"); - } + if (!_impl->is_suspended()) + _impl->update(dt); } void FDMShell::createImplementation() @@ -268,3 +252,13 @@ void FDMShell::createImplementation() } +/* + * Return FDM subsystem. + */ + +SGSubsystem* FDMShell::getFDM() +{ + /* FIXME we could drop/replace this method, when _impl was a added + * to the global subsystem manager - like other proper subsystems... */ + return _impl; +} diff --git a/src/FDM/fdm_shell.hxx b/src/FDM/fdm_shell.hxx index 759be1c9e..04bbf1b72 100644 --- a/src/FDM/fdm_shell.hxx +++ b/src/FDM/fdm_shell.hxx @@ -50,7 +50,8 @@ public: virtual void unbind(); virtual void update(double dt); - + SGSubsystem* getFDM(); + private: void createImplementation(); -- 2.39.5