From 015ecb54f3dcc84dc45058de82cb95333c49182c Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Wed, 17 Sep 2014 22:38:40 +0200 Subject: [PATCH] Load a flight recorder tape from the command line Adds new option --load-tape=foobar to load a flight recorder tape from the command line. Loads foobar.fgtape from the directory specified in /sim/replay/tape-directory and starts replay. --- src/Main/options.cxx | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 0389faa19..9b9946e27 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -1392,6 +1393,43 @@ fgOptSetProperty(const char* raw) return ret ? FG_OPTIONS_OK : FG_OPTIONS_ERROR; } +static int +fgOptLoadTape(const char* arg) +{ + // load a flight recorder tape but wait until the fdm is initialized + class DelayedTapeLoader : SGPropertyChangeListener { + public: + DelayedTapeLoader( const char * tape ) : + _tape(tape) + { + SGPropertyNode_ptr n = fgGetNode("/sim/signals/fdm-initialized", true); + n->addChangeListener( this ); + } + + virtual ~ DelayedTapeLoader() {} + + virtual void valueChanged(SGPropertyNode * node) + { + node->removeChangeListener( this ); + + // tell the replay subsystem to load the tape + FGReplay* replay = (FGReplay*) globals->get_subsystem("replay"); + SGPropertyNode_ptr arg = new SGPropertyNode(); + arg->setStringValue("tape", _tape ); + arg->setBoolValue( "same-aircraft", 0 ); + replay->loadTape(arg); + + delete this; // commence suicide + } + private: + std::string _tape; + + }; + + new DelayedTapeLoader(arg); + return FG_OPTIONS_OK; +} + /* @@ -1632,6 +1670,7 @@ struct OptionDesc { {"fgviewer", false, OPTION_IGNORE, "", false, "", 0}, {"no-default-config", false, OPTION_IGNORE, "", false, "", 0}, {"prop", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptSetProperty}, + {"load-tape", true, OPTION_FUNC, "", false, "", fgOptLoadTape }, {0} };