X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2Ffdm_shell.cxx;h=f06303e2024b565ec1ce2d87fa100f34c39c1d5a;hb=8b05d7b2111aac07e048eed65433a2bb0ef37e1d;hp=6c2d095370322c0ae5abf1c6a8edf5bb2fc38b44;hpb=a0588272dc51ef0b2630f981cf1a913665cdc87a;p=flightgear.git diff --git a/src/FDM/fdm_shell.cxx b/src/FDM/fdm_shell.cxx index 6c2d09537..f06303e20 100644 --- a/src/FDM/fdm_shell.cxx +++ b/src/FDM/fdm_shell.cxx @@ -1,7 +1,30 @@ +// 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 #endif +#include #include #include @@ -12,7 +35,7 @@ #include // all the FDMs, since we are the factory method -#if ENABLE_SP_FDM +#ifdef ENABLE_SP_FDM #include #include #include @@ -26,6 +49,7 @@ #include #include + /* * Evil global variable required by Network/FGNative, * see that class for more information @@ -33,6 +57,7 @@ FGInterface* evil_global_fdm_state = NULL; FDMShell::FDMShell() : + _tankProperties( fgGetNode("/consumables/fuel", true) ), _impl(NULL), _dataLogging(false) { @@ -46,13 +71,25 @@ FDMShell::~FDMShell() void FDMShell::init() { _props = globals->get_props(); + fgSetBool("/sim/fdm-initialized", false); + + _wind_north = _props->getNode("environment/wind-from-north-fps", true); + _wind_east = _props->getNode("environment/wind-from-east-fps", true); + _wind_down = _props->getNode("environment/wind-from-down-fps", true); + _control_fdm_atmo = _props->getNode("environment/params/control-fdm-atmosphere", true); + _temp_degc = _props->getNode("environment/temperature-degc", true); + _pressure_inhg = _props->getNode("environment/pressure-inhg", true); + _density_slugft = _props->getNode("environment/density-slugft3", true); + _data_logging = _props->getNode("/sim/temp/fdm-data-logging", true); + _replay_master = _props->getNode("/sim/freeze/replay-state", true); + 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; @@ -64,18 +101,19 @@ void FDMShell::reinit() 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) @@ -89,7 +127,7 @@ 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"); @@ -100,6 +138,7 @@ void FDMShell::update(double dt) _impl->bind(); evil_global_fdm_state = _impl; + fgSetBool("/sim/fdm-initialized", true); fgSetBool("/sim/signals/fdm-initialized", true); } } @@ -110,46 +149,42 @@ void FDMShell::update(double dt) // 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)); + _wind_north->getDoubleValue(), + _wind_east->getDoubleValue(), + _wind_down->getDoubleValue()); - if (_props->getBoolValue("environment/params/control-fdm-atmosphere")) { + if (_control_fdm_atmo->getBoolValue()) { // convert from Rankine to Celsius - double tempDegC = _props->getDoubleValue("environment/temperature-degc"); + double tempDegC = _temp_degc->getDoubleValue(); _impl->set_Static_temperature((9.0/5.0) * (tempDegC + 273.15)); // convert from inHG to PSF - double pressureInHg = _props->getDoubleValue("environment/pressure-inhg"); + double pressureInHg = _pressure_inhg->getDoubleValue(); _impl->set_Static_pressure(pressureInHg * 70.726566); // keep in slugs/ft^3 - _impl->set_Density(_props->getDoubleValue("environment/density-slugft3")); + _impl->set_Density(_density_slugft->getDoubleValue()); } - bool doLog = _props->getBoolValue("/sim/temp/fdm-data-logging", false); + bool doLog = _data_logging->getBoolValue(); if (doLog != _dataLogging) { _dataLogging = doLog; _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"); - } + switch(_replay_master->getIntValue()) + { + case 0: + // normal FDM operation + _impl->update(dt); + break; + case 3: + // resume FDM operation at current replay position + _impl->reinit(); + break; + default: + // replay is active + break; + } } void FDMShell::createImplementation() @@ -163,7 +198,7 @@ void FDMShell::createImplementation() _impl = new FGLaRCsim( dt ); } else if ( model == "jsb" ) { _impl = new FGJSBsim( dt ); -#if ENABLE_SP_FDM +#ifdef ENABLE_SP_FDM } else if ( model == "ada" ) { _impl = new FGADA( dt ); } else if ( model == "acms" ) { @@ -239,4 +274,3 @@ void FDMShell::createImplementation() } } -