#include <cassert>
#include <simgear/structure/exception.hxx>
+#include <simgear/props/props_io.hxx>
#include <FDM/fdm_shell.hxx>
#include <FDM/flight.hxx>
#include <FDM/YASim/YASim.hxx>
#endif
-/*
- * Evil global variable required by Network/FGNative,
- * see that class for more information
- */
-FGInterface* evil_global_fdm_state = NULL;
+using std::string;
FDMShell::FDMShell() :
_tankProperties( fgGetNode("/consumables/fuel", true) ),
- _impl(NULL),
_dataLogging(false)
{
}
FDMShell::~FDMShell()
{
- delete _impl;
+ SG_LOG(SG_GENERAL, SG_INFO, "destorying FDM shell");
}
void FDMShell::init()
createImplementation();
}
+void FDMShell::postinit()
+{
+ _initialFdmProperties = new SGPropertyNode;
+
+ if (!copyProperties(_props->getNode("fdm", true),
+ _initialFdmProperties))
+ {
+ SG_LOG(SG_FLIGHT, SG_ALERT, "Failed to save initial FDM property state");
+ }
+}
+
+void FDMShell::shutdown()
+{
+ if (_impl) {
+ fgSetBool("/sim/fdm-initialized", false);
+ _impl->unbind();
+ _impl.clear();
+ }
+
+ _props.clear();
+ _wind_north.clear();
+ _wind_east.clear();
+ _wind_down.clear();
+ _control_fdm_atmo.clear();
+ _temp_degc.clear();
+ _pressure_inhg.clear();
+ _density_slugft .clear();
+ _data_logging.clear();
+ _replay_master.clear();
+}
+
void FDMShell::reinit()
{
- if (_impl) {
- fgSetBool("/sim/fdm-initialized", false);
- evil_global_fdm_state = NULL;
- _impl->unbind();
- delete _impl;
- _impl = NULL;
- }
+ 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();
}
}
_impl->bind();
- evil_global_fdm_state = _impl;
fgSetBool("/sim/fdm-initialized", true);
fgSetBool("/sim/signals/fdm-initialized", true);
}
}
}
+FGInterface* FDMShell::getInterface() const
+{
+ return _impl;
+}
+
void FDMShell::createImplementation()
{
assert(!_impl);
double dt = 1.0 / fgGetInt("/sim/model-hz");
string model = fgGetString("/sim/flight-model");
+ bool fdmUnavailable = false;
+
if ( model == "ufo" ) {
_impl = new FGUFO( dt );
} else if ( model == "external" ) {
_impl = new FGExternalPipe( dt, pipe_path, pipe_protocol );
} else if ( model == "null" ) {
_impl = new FGNullFDM( dt );
- }
-#ifdef ENABLE_LARCSIM
+ }
else if ( model == "larcsim" ) {
+#ifdef ENABLE_LARCSIM
_impl = new FGLaRCsim( dt );
- }
+#else
+ fdmUnavailable = true;
#endif
-#ifdef ENABLE_JSBSIM
+ }
else if ( model == "jsb" ) {
+#ifdef ENABLE_JSBSIM
_impl = new FGJSBsim( dt );
- }
+#else
+ fdmUnavailable = true;
#endif
+ }
#ifdef ENABLE_SP_FDM
else if ( model == "ada" ) {
_impl = new FGADA( dt );
} else if ( model == "magic" ) {
_impl = new FGMagicCarpet( dt );
}
+#else
+ else if (( model == "ada" )||(model == "acms")||( model == "balloon" )||( model == "magic" ))
+ {
+ fdmUnavailable = true;
+ }
#endif
-#ifdef ENABLE_YASIM
else if ( model == "yasim" ) {
+#ifdef ENABLE_YASIM
_impl = new YASim( dt );
- }
+#else
+ fdmUnavailable = true;
#endif
- else {
+ } else {
throw sg_exception(string("Unrecognized flight model '") + model
+ "', cannot init flight dynamics model.");
}
+ if (fdmUnavailable)
+ {
+ // FDM type is known, but its support was disabled at compile-time.
+ throw sg_exception(string("Support for flight model '") + model
+ + ("' is not available with this binary (deprecated/disabled).\n"
+ "If you still need it, please rebuild FlightGear and enable its support."));
+ }
}