diff --git a/src/FDM/JSBSim/FGFDMExec.cpp b/src/FDM/JSBSim/FGFDMExec.cpp index 83f8fb288..2110fb0d9 100644 --- a/src/FDM/JSBSim/FGFDMExec.cpp +++ b/src/FDM/JSBSim/FGFDMExec.cpp @@ -133,8 +133,12 @@ FGFDMExec::FGFDMExec(FGPropertyManager* root) modelLoaded = false; IsSlave = false; + // Multiple FDM's are stopped for now. We need to ensure that + // the "user" instance always gets the zeroeth instance number, + // because there may be instruments or scripts tied to properties + // in the jsbsim[0] node. IdFDM = FDMctr; - FDMctr++; + //FDMctr++; try { char* num = getenv("JSBSIM_DEBUG"); diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index 3e0b677d3..53be9685a 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -142,6 +142,10 @@ FGJSBsim::FGJSBsim( double dt ) } } + reset_on_crash = fgGetBool("/sim/reset-on-crash", false); + crashed = false; + fgSetBool("/sim/crashed", false); + fdmex = new FGFDMExec( (FGPropertyManager*)globals->get_props() ); // Register ground callback. @@ -813,11 +817,10 @@ bool FGJSBsim::copy_from_JSBsim() speedbrake_pos_pct->setDoubleValue( FCS->GetDsbPos(ofNorm) ); spoilers_pos_pct->setDoubleValue( FCS->GetDspPos(ofNorm) ); - // force a sim reset if crashed (altitude AGL < 0) + // crashed (altitude AGL < 0) if (get_Altitude_AGL() < 0.0) { - fgSetBool("/sim/crashed", true); - SGPropertyNode* node = fgGetNode("/sim/presets", true); - globals->get_commands()->execute("old-reinit-dialog", node); + crash_message = "Attempted to fly under ground."; + crash_handler(); } return true; @@ -1093,3 +1096,17 @@ void FGJSBsim::update_ic(void) } } +void FGJSBsim::crash_handler(void) +{ + if (crashed) return; // we already crashed + crashed = true; + fgSetBool("/sim/crashed", true); + SG_LOG( SG_FLIGHT, SG_WARN, " Crash: " << crash_message ); + if (reset_on_crash) { + SGPropertyNode* node = fgGetNode("/sim/presets", true); + globals->get_commands()->execute("old-reinit-dialog", node); + } else { + fgSetBool("/sim/freeze/master", true); + fgSetBool("/sim/freeze/clock", true); + } +} diff --git a/src/FDM/JSBSim/JSBSim.hxx b/src/FDM/JSBSim/JSBSim.hxx index 623cc69c4..64f1dfcb1 100644 --- a/src/FDM/JSBSim/JSBSim.hxx +++ b/src/FDM/JSBSim/JSBSim.hxx @@ -205,6 +205,9 @@ public: void do_trim(void); void update_ic(void); + //** Handle a crash of the user aircraft. */ + void crash_handler(); + private: FGFDMExec *fdmex; FGInitialCondition *fgic; @@ -263,6 +266,10 @@ private: void init_gear(void); void update_gear(void); + bool reset_on_crash; + bool crashed; + string crash_message; + };