+// fdm_shell.cxx -- encapsulate FDM implementations as well-behaved subsystems
+//
+// Written by James Turner, started June 2010.
+//
+// Copyright (C) 2010 Curtis L. Olson - http://www.flightgear.org/~curt
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// $Id$
+
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
+#include <cassert>
#include <simgear/structure/exception.hxx>
#include <FDM/fdm_shell.hxx>
#include <FDM/NullFDM.hxx>
#include <FDM/YASim/YASim.hxx>
+
/*
* Evil global variable required by Network/FGNative,
* see that class for more information
FGInterface* evil_global_fdm_state = NULL;
FDMShell::FDMShell() :
+ _tankProperties( fgGetNode("/consumables/fuel", true) ),
_impl(NULL),
_dataLogging(false)
{
void FDMShell::init()
{
_props = globals->get_props();
+ fgSetBool("/sim/fdm-initialized", false);
createImplementation();
}
void FDMShell::reinit()
{
if (_impl) {
- fgSetBool("/sim/signals/fdm-initialized", false);
+ fgSetBool("/sim/fdm-initialized", false);
evil_global_fdm_state = NULL;
_impl->unbind();
delete _impl;
void FDMShell::bind()
{
+ _tankProperties.bind();
if (_impl && _impl->get_inited()) {
if (_impl->get_bound()) {
throw sg_exception("FDMShell::bind of bound FGInterface impl");
}
-
_impl->bind();
}
}
void FDMShell::unbind()
{
- _impl->unbind();
+ if( _impl ) _impl->unbind();
+ _tankProperties.unbind();
}
void FDMShell::update(double dt)
double lon = fgGetDouble("/sim/presets/longitude-deg");
double lat = fgGetDouble("/sim/presets/latitude-deg");
- double range = 1000.0; // in metres
+ double range = 1000.0; // in meters
SGGeod geod = SGGeod::fromDeg(lon, lat);
if (globals->get_scenery()->scenery_available(geod, range)) {
SG_LOG(SG_FLIGHT, SG_INFO, "Scenery loaded, will init FDM");
_impl->bind();
evil_global_fdm_state = _impl;
+ fgSetBool("/sim/fdm-initialized", true);
fgSetBool("/sim/signals/fdm-initialized", true);
}
}
// 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
_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()
}
+/*
+ * 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;
+}