From a8fe586e4831a27f8971607f1a75b2af62a5ea10 Mon Sep 17 00:00:00 2001 From: James Turner <zakalawe@mac.com> Date: Mon, 10 Mar 2014 12:00:51 +0000 Subject: [PATCH] Revert wiping of /fdm on reposition. This is too destructive for many established things, so revert it. Instead, make the FDM shell save /fdm state on postinit(), and restore it on re-init (which reposition invokes). --- src/FDM/fdm_shell.cxx | 21 +++++++++++++++++++++ src/FDM/fdm_shell.hxx | 5 ++++- src/Main/fg_init.cxx | 5 ++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/FDM/fdm_shell.cxx b/src/FDM/fdm_shell.cxx index dd5de9eb6..3263444c3 100644 --- a/src/FDM/fdm_shell.cxx +++ b/src/FDM/fdm_shell.cxx @@ -26,6 +26,7 @@ #include <cassert> #include <simgear/structure/exception.hxx> +#include <simgear/props/props_io.hxx> #include <FDM/fdm_shell.hxx> #include <FDM/flight.hxx> @@ -90,6 +91,17 @@ void FDMShell::init() createImplementation(); } +void FDMShell::postinit() +{ + _initialFdmProperties = new SGPropertyNode; + + if (!copyProperties(_props->getNode("fdm"), + _initialFdmProperties)) + { + SG_LOG(SG_FLIGHT, SG_ALERT, "Failed to save initial FDM property state"); + } +} + void FDMShell::shutdown() { if (_impl) { @@ -113,6 +125,15 @@ void FDMShell::shutdown() void FDMShell::reinit() { shutdown(); + + if ( copyProperties(_initialFdmProperties, fgGetNode("/fdm", true)) ) { + SG_LOG( SG_FLIGHT, SG_INFO, "Preserved state restored successfully" ); + } else { + SG_LOG( SG_FLIGHT, SG_WARN, + "FDM: Some errors restoring preserved state" ); + } + + init(); } diff --git a/src/FDM/fdm_shell.hxx b/src/FDM/fdm_shell.hxx index 0eb576609..1b4a368e5 100644 --- a/src/FDM/fdm_shell.hxx +++ b/src/FDM/fdm_shell.hxx @@ -46,7 +46,8 @@ public: virtual void init(); virtual void shutdown(); virtual void reinit(); - + virtual void postinit(); + virtual void bind(); virtual void unbind(); @@ -65,6 +66,8 @@ private: SGPropertyNode_ptr _wind_north, _wind_east,_wind_down; SGPropertyNode_ptr _control_fdm_atmo,_temp_degc,_pressure_inhg; SGPropertyNode_ptr _density_slugft, _data_logging, _replay_master; + + SGPropertyNode_ptr _initialFdmProperties; }; #endif // of FG_FDM_SHELL_HXX diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 9653a11ae..5b8d4b9b7 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -951,9 +951,8 @@ void fgStartReposition() fgSetBool("/sim/signals/reinit", true); fgSetBool("/sim/crashed", false); - globals->get_subsystem("flight")->unbind(); - - globals->get_props()->removeChild("fdm"); + FDMShell* fdm = static_cast<FDMShell*>(globals->get_subsystem("flight")); + fdm->unbind(); // update our position based on current presets // this will mark position as needed finalized which we'll do in the