From 94d870d930c5e8c631028404ebfc4287ab7439c6 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer <Torsten@t3r.de> Date: Tue, 8 Feb 2011 21:23:02 +0100 Subject: [PATCH 01/10] Support more than eight tanks I was naive enough to think that no aircraft ever uses more than eight tanks. Csabe proved me wrong and came up with a fix - Thanks. --- src/FDM/TankProperties.cxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/FDM/TankProperties.cxx b/src/FDM/TankProperties.cxx index 8cfc768b3..36f37be99 100644 --- a/src/FDM/TankProperties.cxx +++ b/src/FDM/TankProperties.cxx @@ -106,7 +106,8 @@ double TankProperties::getContent_m3() const void TankProperties::setContent_m3( double value ) { - _content_kg = value * _density_kgpm3; + // ugly hack to allow setting of a volumetric content without having the density + _content_kg = value * (_density_kgpm3>0.0?_density_kgpm3:755.0); } double TankProperties::getContent_gal_us() const @@ -172,9 +173,11 @@ void TankProperties::setContent_norm( double value ) TankPropertiesList::TankPropertiesList( SGPropertyNode_ptr rootNode ) { // we don't have a global rule how many tanks we support, so I assume eight. - // Because hard coded values suck, make it settable by a property - size_type n = rootNode->getIntValue( "numtanks", 8 ); - for( size_type i = 0; i < n; i++ ) { + // Because hard coded values suck, make it settable by a property. + // If tanks were configured, use that number + int n = rootNode->nChildren(); + if( n == 0 ) n = rootNode->getIntValue( "numtanks", 8 ); + for( int i = 0; i < n; i++ ) { push_back( new TankProperties( rootNode->getChild( "tank", i, true ) ) ); } From 8ca9f26e1be4642e8fe9243d50232253448d40e3 Mon Sep 17 00:00:00 2001 From: ThorstenB <brehmt@gmail.com> Date: Fri, 11 Feb 2011 18:53:35 +0100 Subject: [PATCH 02/10] Ivan Ngeow: Fixed compile for FreeBSD platforms. --- utils/TerraSync/terrasync.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/TerraSync/terrasync.cxx b/utils/TerraSync/terrasync.cxx index f1a2cc46b..d15078d9a 100644 --- a/utils/TerraSync/terrasync.cxx +++ b/utils/TerraSync/terrasync.cxx @@ -290,7 +290,7 @@ void sync_tree(const char* dir) { #if defined(_MSC_VER) || defined(__MINGW32__) typedef void (__cdecl * sighandler_t)(int); -#elif defined( __APPLE__ ) +#elif defined( __APPLE__ ) || defined (__FreeBSD__) typedef sig_t sighandler_t; #endif From c7cccd8758e66c0d4ac71bd75709bae29f3322e4 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer <Torsten@t3r.de> Date: Sat, 12 Feb 2011 21:36:58 +0100 Subject: [PATCH 03/10] TankProperty: a bugfix and a new properties - Fix initial number of TankProperty instances (thanks to Csaba) - Add new property for unusable fuel and compute "empty" state --- src/FDM/TankProperties.cxx | 48 ++++++++++++++++++++++++++++++++++++-- src/FDM/TankProperties.hxx | 12 ++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/FDM/TankProperties.cxx b/src/FDM/TankProperties.cxx index 36f37be99..cb4f82c98 100644 --- a/src/FDM/TankProperties.cxx +++ b/src/FDM/TankProperties.cxx @@ -38,12 +38,14 @@ static const double M3_PER_IMPGAL = 1.0/IMPGAL_PER_M3; TankProperties::TankProperties(SGPropertyNode_ptr rootNode ) : _content_kg(0.0), _density_kgpm3(0.0), - _capacity_m3(0.0) + _capacity_m3(0.0), + _unusable_m3(0.0) { _tiedProperties.setRoot( rootNode ); _tiedProperties.Tie("level-kg", this, &TankProperties::getContent_kg, &TankProperties::setContent_kg ); _tiedProperties.Tie("density-kgpm3", this, &TankProperties::getDensity_kgpm3, &TankProperties::setDensity_kgpm3 ); _tiedProperties.Tie("capacity-m3", this, &TankProperties::getCapacity_m3, &TankProperties::setCapacity_m3 ); + _tiedProperties.Tie("unusable-m3", this, &TankProperties::getUnusable_m3, &TankProperties::setUnusable_m3 ); _tiedProperties.Tie("level-m3", this, &TankProperties::getContent_m3, &TankProperties::setContent_m3 ); _tiedProperties.Tie("level-norm", this, &TankProperties::getContent_norm, &TankProperties::setContent_norm ); @@ -51,8 +53,14 @@ TankProperties::TankProperties(SGPropertyNode_ptr rootNode ) : _tiedProperties.Tie("level-lbs", this, &TankProperties::getContent_lbs, &TankProperties::setContent_lbs ); _tiedProperties.Tie("level-gal_us", this, &TankProperties::getContent_gal_us, &TankProperties::setContent_gal_us ); _tiedProperties.Tie("level-gal_imp", this, &TankProperties::getContent_gal_imp, &TankProperties::setContent_gal_imp ); + _tiedProperties.Tie("capacity-gal_us", this, &TankProperties::getCapacity_gal_us, &TankProperties::setCapacity_gal_us ); + _tiedProperties.Tie("unusable-gal_us", this, &TankProperties::getUnusable_gal_us, &TankProperties::setUnusable_gal_us ); + _tiedProperties.Tie("capacity-gal_imp", this, &TankProperties::getCapacity_gal_imp, &TankProperties::setCapacity_gal_imp ); + _tiedProperties.Tie("unusable-gal_imp", this, &TankProperties::getUnusable_gal_imp, &TankProperties::setUnusable_gal_imp ); + + _tiedProperties.Tie("empty", this, &TankProperties::getEmpty ); } TankProperties::~TankProperties() @@ -160,6 +168,37 @@ void TankProperties::setCapacity_gal_imp( double value ) _capacity_m3 = value * M3_PER_IMPGAL; } +double TankProperties::getUnusable_m3() const +{ + return _unusable_m3; +} + +void TankProperties::setUnusable_m3( double value ) +{ + _unusable_m3 = value; +} + +double TankProperties::getUnusable_gal_us() const +{ + return _unusable_m3 * USGAL_PER_M3; +} + +void TankProperties::setUnusable_gal_us( double value ) +{ + _unusable_m3 = value * M3_PER_USGAL; +} + + +double TankProperties::getUnusable_gal_imp() const +{ + return _unusable_m3 * IMPGAL_PER_M3; +} + +void TankProperties::setUnusable_gal_imp( double value ) +{ + _unusable_m3 = value * M3_PER_IMPGAL; +} + double TankProperties::getContent_norm() const { return _capacity_m3 > SGLimitsd::min() ? getContent_m3() / _capacity_m3 : 0.0; @@ -170,12 +209,17 @@ void TankProperties::setContent_norm( double value ) setContent_m3(_capacity_m3 * value); } +bool TankProperties::getEmpty() const +{ + return getContent_m3() <= _unusable_m3; +} + TankPropertiesList::TankPropertiesList( SGPropertyNode_ptr rootNode ) { // we don't have a global rule how many tanks we support, so I assume eight. // Because hard coded values suck, make it settable by a property. // If tanks were configured, use that number - int n = rootNode->nChildren(); + int n = rootNode->getChildren("tank").size(); if( n == 0 ) n = rootNode->getIntValue( "numtanks", 8 ); for( int i = 0; i < n; i++ ) { push_back( new TankProperties( rootNode->getChild( "tank", i, true ) ) ); diff --git a/src/FDM/TankProperties.hxx b/src/FDM/TankProperties.hxx index 27a2e9f40..f1ec8b4aa 100644 --- a/src/FDM/TankProperties.hxx +++ b/src/FDM/TankProperties.hxx @@ -64,15 +64,27 @@ public: double getCapacity_gal_imp() const; void setCapacity_gal_imp( double value ); + double getUnusable_m3() const; + void setUnusable_m3( double value ); + + double getUnusable_gal_us() const; + void setUnusable_gal_us( double value ); + + double getUnusable_gal_imp() const; + void setUnusable_gal_imp( double value ); + double getContent_norm() const; void setContent_norm( double value ); + bool getEmpty() const; + protected: simgear::TiedPropertyList _tiedProperties; double _content_kg; double _density_kgpm3; double _capacity_m3; + double _unusable_m3; }; class TankPropertiesList : std::vector<SGSharedPtr<TankProperties> > { From ae320ca46c78cdb34c0cd730733dfb8ef3c737df Mon Sep 17 00:00:00 2001 From: ThorstenB <brehmt@gmail.com> Date: Sun, 13 Feb 2011 16:50:23 +0100 Subject: [PATCH 04/10] Avoid crash and/or long delay on shutdown in METAR loader. Catching loader thread on subsystem destruction is too late, since it depends on other subsystems (which are destroyed earlier). => Need to stop & join thread during subsystem shutdown. Also changed loader sleep logic - to avoid excessive delays (up to 30 seconds) on shutdown. (Issues mostly happened when running offline with realwx enabled.) --- src/Environment/realwx_ctrl.cxx | 48 ++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/Environment/realwx_ctrl.cxx b/src/Environment/realwx_ctrl.cxx index 197f4cf52..087040486 100644 --- a/src/Environment/realwx_ctrl.cxx +++ b/src/Environment/realwx_ctrl.cxx @@ -191,6 +191,7 @@ public: NoaaMetarRealWxController( SGPropertyNode_ptr rootNode ); virtual ~NoaaMetarRealWxController(); virtual void update (bool first, double delta_time_sec); + virtual void shutdown (); class MetarLoadRequest { public: @@ -234,14 +235,17 @@ private: class MetarLoadThread : public OpenThreads::Thread { public: MetarLoadThread( long maxAge ); + virtual ~MetarLoadThread( ) { stop(); } void requestMetar( const MetarLoadRequest & metarRequest, bool background = true ); bool hasMetar() { return _responseQueue.size() > 0; } MetarLoadResponse getMetar() { return _responseQueue.pop(); } virtual void run(); + void stop(); private: void fetch( const MetarLoadRequest & ); long _maxAge; long _minRequestInterval; + volatile bool _stop; SGBlockingQueue <MetarLoadRequest> _requestQueue; SGBlockingQueue <MetarLoadResponse> _responseQueue; }; @@ -261,18 +265,20 @@ NoaaMetarRealWxController::NoaaMetarRealWxController( SGPropertyNode_ptr rootNod #endif } -NoaaMetarRealWxController::~NoaaMetarRealWxController() +void NoaaMetarRealWxController::shutdown() { #if defined(ENABLE_THREADS) if( _metarLoadThread ) { - MetarLoadRequest request(""); - _metarLoadThread->requestMetar(request); - _metarLoadThread->join(); delete _metarLoadThread; + _metarLoadThread = NULL; } #endif // ENABLE_THREADS } +NoaaMetarRealWxController::~NoaaMetarRealWxController() +{ +} + void NoaaMetarRealWxController::update( bool first, double dt ) { _positionTimeToLive -= dt; @@ -319,7 +325,7 @@ void NoaaMetarRealWxController::update( bool first, double dt ) "NoaaMetarRealWxController::update(): spawning load request for station-id '" << stationId << "'" ); MetarLoadRequest request( stationId ); - // load the metar for the neares airport in the foreground if the fdm is uninitialized + // load the metar for the nearest airport in the foreground if the fdm is uninitialized // to make sure a metar is received // before the automatic runway selection code runs. All subsequent calls // run in the background @@ -348,7 +354,8 @@ void NoaaMetarRealWxController::update( bool first, double dt ) #if defined(ENABLE_THREADS) NoaaMetarRealWxController::MetarLoadThread::MetarLoadThread( long maxAge ) : _maxAge(maxAge), - _minRequestInterval(2000) + _minRequestInterval(2000), + _stop(false) { } @@ -368,24 +375,41 @@ void NoaaMetarRealWxController::MetarLoadThread::requestMetar( const MetarLoadRe } } +void NoaaMetarRealWxController::MetarLoadThread::stop() +{ + // set stop flag and wake up the thread with an empty request + _stop = true; + MetarLoadRequest request(""); + requestMetar(request); + join(); +} + void NoaaMetarRealWxController::MetarLoadThread::run() { SGTimeStamp lastRun = SGTimeStamp::fromSec(0); for( ;; ) { SGTimeStamp dt = SGTimeStamp::now() - lastRun; - if( dt.getSeconds() * 1000 < _minRequestInterval ) - microSleep( (_minRequestInterval - dt.getSeconds() * 1000 ) * 1000 ); - - lastRun = SGTimeStamp::now(); + long delayMs = _minRequestInterval - dt.getSeconds() * 1000; + while (( delayMs > 0 ) && !_stop) + { + // sleep no more than 3 seconds at a time, otherwise shutdown response is too slow + long sleepMs = (delayMs>3000) ? 3000 : delayMs; + microSleep( sleepMs * 1000 ); + delayMs -= sleepMs; + } + if (_stop) + break; + + lastRun = SGTimeStamp::now(); + const MetarLoadRequest request = _requestQueue.pop(); - if( request._stationId.size() == 0 ) + if (( request._stationId.size() == 0 ) || _stop) break; fetch( request ); - } } From 45f526aca57baa4b61904dd406b1452d7f653eeb Mon Sep 17 00:00:00 2001 From: ThorstenB <brehmt@gmail.com> Date: Sun, 13 Feb 2011 18:31:26 +0100 Subject: [PATCH 05/10] Minor output format issue. --- src/Main/fg_commands.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 2c7a24e70..97f5ca399 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -247,7 +247,7 @@ do_reinit (const SGPropertyNode * arg) if (subsystem == 0) { result = false; SG_LOG( SG_GENERAL, SG_ALERT, - "Subsystem " << name << "not found" ); + "Subsystem " << name << " not found" ); } else { subsystem->reinit(); } @@ -280,7 +280,7 @@ do_suspend (const SGPropertyNode * arg) SGSubsystem * subsystem = globals->get_subsystem(name); if (subsystem == 0) { result = false; - SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found"); + SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found"); } else { subsystem->suspend(); } @@ -304,7 +304,7 @@ do_resume (const SGPropertyNode * arg) SGSubsystem * subsystem = globals->get_subsystem(name); if (subsystem == 0) { result = false; - SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found"); + SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found"); } else { subsystem->resume(); } From 4a351fdd8b357dd7ee48a679e983c82a70d5b4c0 Mon Sep 17 00:00:00 2001 From: ThorstenB <brehmt@gmail.com> Date: Sun, 13 Feb 2011 18:56:46 +0100 Subject: [PATCH 06/10] Update tile loader options whenever its config properties change New listener for tile-loader properties. --- src/Scenery/tilemgr.cxx | 39 ++++++++++++++++++++++++++++++++++++--- src/Scenery/tilemgr.hxx | 6 ++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index 81e84bfe6..adc200b86 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -52,10 +52,33 @@ using simgear::SGModelLib; using simgear::TileEntry; using simgear::TileCache; + +// helper: listen to property changes affecting tile loading +class LoaderPropertyWatcher : public SGPropertyChangeListener +{ +public: + LoaderPropertyWatcher(FGTileMgr* pTileMgr) : + _pTileMgr(pTileMgr) + { + } + + virtual void valueChanged(SGPropertyNode*) + { + _pTileMgr->configChanged(); + } + +private: + FGTileMgr* _pTileMgr; +}; + + FGTileMgr::FGTileMgr(): state( Start ), - vis( 16000 ) + vis( 16000 ), + _propListener(new LoaderPropertyWatcher(this)) { + _randomObjects = fgGetNode("/sim/rendering/random-objects", true); + _randomVegetation = fgGetNode("/sim/rendering/random-vegetation", true); } @@ -63,6 +86,8 @@ FGTileMgr::~FGTileMgr() { // remove all nodes we might have left behind osg::Group* group = globals->get_scenery()->get_terrain_branch(); group->removeChildren(0, group->getNumChildren()); + delete _propListener; + _propListener = NULL; } @@ -72,8 +97,11 @@ void FGTileMgr::init() { _options = new SGReaderWriterBTGOptions; _options->setMatlib(globals->get_matlib()); - _options->setUseRandomObjects(fgGetBool("/sim/rendering/random-objects", true)); - _options->setUseRandomVegetation(fgGetBool("/sim/rendering/random-vegetation", true)); + + _randomObjects.get()->addChangeListener(_propListener, false); + _randomVegetation.get()->addChangeListener(_propListener, false); + configChanged(); + osgDB::FilePathList &fp = _options->getDatabasePathList(); const string_list &sc = globals->get_fg_scenery(); fp.clear(); @@ -101,6 +129,11 @@ void FGTileMgr::reinit() update(0.0); } +void FGTileMgr::configChanged() +{ + _options->setUseRandomObjects(_randomObjects.get()->getBoolValue()); + _options->setUseRandomVegetation(_randomVegetation.get()->getBoolValue()); +} /* schedule a tile for loading, keep request for given amount of time. * Returns true if tile is already loaded. */ diff --git a/src/Scenery/tilemgr.hxx b/src/Scenery/tilemgr.hxx index 048fe7692..6b4a4e7ef 100644 --- a/src/Scenery/tilemgr.hxx +++ b/src/Scenery/tilemgr.hxx @@ -81,6 +81,9 @@ private: void update_queues(); SGPropertyNode* _visibilityMeters; + SGPropertyChangeListener* _propListener; + SGPropertyNode_ptr _randomObjects; + SGPropertyNode_ptr _randomVegetation; public: FGTileMgr(); @@ -93,6 +96,9 @@ public: virtual void update(double dt); + // update loader configuration options + void configChanged(); + int schedule_tiles_at(const SGGeod& location, double rangeM); From 7bc9749d916ecfe21f9e84b2ed1c7de07adb21e7 Mon Sep 17 00:00:00 2001 From: ThorstenB <brehmt@gmail.com> Date: Sun, 13 Feb 2011 19:24:54 +0100 Subject: [PATCH 07/10] Support scenery reloading (needs simgear update). TileMgr subsystem reinit: remove all scenery tiles from scenegraph and clear cache (simgear update required). "normal" sim resets: no TileMgr reset is needed (avoid reloading scenery). --- src/Main/fg_init.cxx | 3 +-- src/Scenery/tilemgr.cxx | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 0e83ba131..a615eddee 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1557,8 +1557,7 @@ void fgReInitSubsystems() globals->get_viewmgr()->reinit(); globals->get_subsystem("time")->reinit(); - globals->get_subsystem("tile-manager")->reinit(); - + // setup state to end re-init fgSetBool("/sim/signals/reinit", false); if ( !freeze ) { diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index adc200b86..6c19ec5c0 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -117,6 +117,9 @@ void FGTileMgr::init() { void FGTileMgr::reinit() { + // remove all old scenery nodes from scenegraph and clear cache + osg::Group* group = globals->get_scenery()->get_terrain_branch(); + group->removeChildren(0, group->getNumChildren()); tile_cache.init(); state = Inited; From 03aac3de8b82eb318b92d7c1674aedda28e4c838 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer <Torsten@t3r.de> Date: Mon, 14 Feb 2011 20:26:39 +0100 Subject: [PATCH 08/10] Refactor ridgelift: use simgear::TiedPropertyList --- src/Environment/ridge_lift.cxx | 34 ++++++---------------------------- src/Environment/ridge_lift.hxx | 2 ++ 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/Environment/ridge_lift.cxx b/src/Environment/ridge_lift.cxx index 9598f2bbb..5f0bd2639 100644 --- a/src/Environment/ridge_lift.cxx +++ b/src/Environment/ridge_lift.cxx @@ -103,42 +103,20 @@ void FGRidgeLift::init(void) void FGRidgeLift::bind() { string prop; + _tiedProperties.setRoot( fgGetNode("/environment/ridge-lift",true)); for( int i = 0; i < 5; i++ ) { - prop = CreateIndexedPropertyName("/environment/ridge-lift/probe-elev-m", i ); - fgTie( prop.c_str(), this, i, &FGRidgeLift::get_probe_elev_m); // read-only - - prop = CreateIndexedPropertyName("/environment/ridge-lift/probe-lat-deg", i ); - fgTie( prop.c_str(), this, i, &FGRidgeLift::get_probe_lat_deg); // read-only - - prop = CreateIndexedPropertyName("/environment/ridge-lift/probe-lon-deg", i ); - fgTie( prop.c_str(), this, i, &FGRidgeLift::get_probe_lon_deg); // read-only + _tiedProperties.Tie( "probe-elev-m", i, this, i, &FGRidgeLift::get_probe_elev_m ); + _tiedProperties.Tie( "probe-lat-deg", i, this, i, &FGRidgeLift::get_probe_lat_deg ); + _tiedProperties.Tie( "probe-lon-deg", i, this, i, &FGRidgeLift::get_probe_lon_deg ); } for( int i = 0; i < 4; i++ ) { - prop = CreateIndexedPropertyName("/environment/ridge-lift/slope", i ); - fgTie( prop.c_str(), this, i, &FGRidgeLift::get_slope); // read-only + _tiedProperties.Tie( "slope", i, this, i, &FGRidgeLift::get_slope ); } } void FGRidgeLift::unbind() { - string prop; - - for( int i = 0; i < 5; i++ ) { - - prop = CreateIndexedPropertyName("/environment/ridge-lift/probe-elev-m", i ); - fgUntie( prop.c_str() ); - - prop = CreateIndexedPropertyName("/environment/ridge-lift/probe-lat-deg", i ); - fgUntie( prop.c_str() ); - - prop = CreateIndexedPropertyName("/environment/ridge-lift/probe-lon-deg", i ); - fgUntie( prop.c_str() ); - } - - for( int i = 0; i < 4; i++ ) { - prop = CreateIndexedPropertyName("/environment/ridge-lift/slope", i ); - fgUntie( prop.c_str() ); - } + _tiedProperties.Untie(); } void FGRidgeLift::update(double dt) { diff --git a/src/Environment/ridge_lift.hxx b/src/Environment/ridge_lift.hxx index a5e97d620..642683c06 100644 --- a/src/Environment/ridge_lift.hxx +++ b/src/Environment/ridge_lift.hxx @@ -36,6 +36,7 @@ #include <string> using std::string; +#include <simgear/props/tiedpropertylist.hxx> class FGRidgeLift : public SGSubsystem { public: @@ -80,6 +81,7 @@ private: SGPropertyNode_ptr _user_latitude_node; SGPropertyNode_ptr _ground_elev_node; + simgear::TiedPropertyList _tiedProperties; }; #endif // _FG_RidgeLift_HXX From fff48bdd6a7293cb27c0ef0049526dd1c7d8b614 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer <Torsten@t3r.de> Date: Mon, 14 Feb 2011 20:44:20 +0100 Subject: [PATCH 09/10] Refactor controls.cxx: use simgear functions - use TiedPropertyList - use SG_CLAMP_RANGE --- src/Aircraft/controls.cxx | 1892 ++++++++++++++----------------------- src/Aircraft/controls.hxx | 59 +- 2 files changed, 762 insertions(+), 1189 deletions(-) diff --git a/src/Aircraft/controls.cxx b/src/Aircraft/controls.cxx index a37150c44..dcd4a553b 100644 --- a/src/Aircraft/controls.cxx +++ b/src/Aircraft/controls.cxx @@ -24,35 +24,10 @@ # include "config.h" #endif -#include <simgear/compiler.h> -#include <simgear/debug/logstream.hxx> #include <Main/fg_props.hxx> - +#include <simgear/sg_inlines.h> #include "controls.hxx" - -static const int MAX_NAME_LEN = 128; - - -//////////////////////////////////////////////////////////////////////// -// Inline utility methods. -//////////////////////////////////////////////////////////////////////// - -static inline void -CLAMP(double *x, double min, double max ) -{ - if ( *x < min ) { *x = min; } - if ( *x > max ) { *x = max; } -} - -static inline void -CLAMP(int *i, int min, int max ) -{ - if ( *i < min ) { *i = min; } - if ( *i > max ) { *i = max; } -} - - //////////////////////////////////////////////////////////////////////// // Implementation of FGControls. //////////////////////////////////////////////////////////////////////// @@ -198,13 +173,13 @@ FGControls::init () { throttle_idle = true; for ( int engine = 0; engine < MAX_ENGINES; engine++ ) { - throttle[engine] = 0.0; - mixture[engine] = 1.0; - fuel_pump[engine] = false; - prop_advance[engine] = 1.0; - magnetos[engine] = 0; - feed_tank[engine] = -1; // set to -1 to turn off all tanks 0 feeds all engines from center body tank - starter[engine] = false; + throttle[engine] = 0.0; + mixture[engine] = 1.0; + fuel_pump[engine] = false; + prop_advance[engine] = 1.0; + magnetos[engine] = 0; + feed_tank[engine] = -1; // set to -1 to turn off all tanks 0 feeds all engines from center body tank + starter[engine] = false; feather[engine] = false; ignition[engine] = false; fire_switch[engine] = false; @@ -243,829 +218,426 @@ FGControls::init () auto_coordination = fgGetNode("/sim/auto-coordination", true); } +static inline void _SetRoot( simgear::TiedPropertyList & tiedProperties, const char * root, int index = 0 ) +{ + tiedProperties.setRoot( fgGetNode( root, index, true ) ); +} void FGControls::bind () { - int index, i; + int index, i; - // flight controls - fgTie("/controls/flight/aileron", this, - &FGControls::get_aileron, &FGControls::set_aileron); - fgSetArchivable("/controls/flight/aileron"); + // flight controls + _SetRoot( _tiedProperties, "/controls/flight" ); - fgTie("/controls/flight/aileron-trim", this, - &FGControls::get_aileron_trim, &FGControls::set_aileron_trim); - fgSetArchivable("/controls/flight/aileron-trim"); + _tiedProperties.Tie( "aileron", this, &FGControls::get_aileron, &FGControls::set_aileron ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/flight/elevator", this, - &FGControls::get_elevator, &FGControls::set_elevator); - fgSetArchivable("/controls/flight/elevator"); + _tiedProperties.Tie( "aileron-trim", this, &FGControls::get_aileron_trim, &FGControls::set_aileron_trim ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/flight/elevator-trim", this, - &FGControls::get_elevator_trim, &FGControls::set_elevator_trim); - fgSetArchivable("/controls/flight/elevator-trim"); + _tiedProperties.Tie( "elevator", this, &FGControls::get_elevator, &FGControls::set_elevator ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/flight/rudder", this, - &FGControls::get_rudder, &FGControls::set_rudder); - fgSetArchivable("/controls/flight/rudder"); + _tiedProperties.Tie( "elevator-trim", this, &FGControls::get_elevator_trim, &FGControls::set_elevator_trim ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/flight/rudder-trim", this, - &FGControls::get_rudder_trim, &FGControls::set_rudder_trim); - fgSetArchivable("/controls/flight/rudder-trim"); + _tiedProperties.Tie( "rudder", this, &FGControls::get_rudder, &FGControls::set_rudder ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/flight/flaps", this, - &FGControls::get_flaps, &FGControls::set_flaps); - fgSetArchivable("/controls/flight/flaps"); + _tiedProperties.Tie( "rudder-trim", this, &FGControls::get_rudder_trim, &FGControls::set_rudder_trim ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/flight/slats", this, - &FGControls::get_slats, &FGControls::set_slats); - fgSetArchivable("/controls/flight/slats"); + _tiedProperties.Tie( "flaps", this, &FGControls::get_flaps, &FGControls::set_flaps ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/flight/BLC", this, - &FGControls::get_BLC, &FGControls::set_BLC); - fgSetArchivable("/controls/flight/BLC"); + _tiedProperties.Tie( "slats", this, &FGControls::get_slats, &FGControls::set_slats ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/flight/spoilers", this, - &FGControls::get_spoilers, &FGControls::set_spoilers); - fgSetArchivable("/controls/flight/spoilers"); + _tiedProperties.Tie( "BLC", this, &FGControls::get_BLC, &FGControls::set_BLC ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/flight/speedbrake", this, - &FGControls::get_speedbrake, &FGControls::set_speedbrake); - fgSetArchivable("/controls/flight/speedbrake"); + _tiedProperties.Tie( "spoilers", this, &FGControls::get_spoilers, &FGControls::set_spoilers ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/flight/wing-sweep", this, - &FGControls::get_wing_sweep, &FGControls::set_wing_sweep); - fgSetArchivable("/controls/flight/wing-sweep"); + _tiedProperties.Tie( "speedbrake", this, &FGControls::get_speedbrake, &FGControls::set_speedbrake ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/flight/wing-fold", this, - &FGControls::get_wing_fold, &FGControls::set_wing_fold); - fgSetArchivable("/controls/flight/wing-fold"); + _tiedProperties.Tie( "wing-sweep", this, &FGControls::get_wing_sweep, &FGControls::set_wing_sweep ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/flight/drag-chute", this, - &FGControls::get_drag_chute, &FGControls::set_drag_chute); - fgSetArchivable("/controls/flight/drag-chute"); + _tiedProperties.Tie( "wing-fold", this, &FGControls::get_wing_fold, &FGControls::set_wing_fold ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - // engines - fgTie("/controls/engines/throttle_idle", this, - &FGControls::get_throttle_idle, &FGControls::set_throttle_idle); - fgSetArchivable("/controls/engines/throttle_idle"); + _tiedProperties.Tie( "drag-chute", this, &FGControls::get_drag_chute, &FGControls::set_drag_chute ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - for (index = 0; index < MAX_ENGINES; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/throttle", index); - fgTie(name, this, index, - &FGControls::get_throttle, &FGControls::set_throttle); - fgSetArchivable(name); + // engines + _tiedProperties.setRoot( fgGetNode("/controls/engines", true ) ); - snprintf(name, MAX_NAME_LEN, "/controls/engines/engine[%d]/starter", index); - fgTie(name, this, index, - &FGControls::get_starter, &FGControls::set_starter); - fgSetArchivable(name); + _tiedProperties.Tie( "throttle_idle", this, &FGControls::get_throttle_idle, &FGControls::set_throttle_idle ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/fuel-pump", index); - fgTie(name, this, index, - &FGControls::get_fuel_pump, &FGControls::set_fuel_pump); - fgSetArchivable(name); + for (index = 0; index < MAX_ENGINES; index++) { + _SetRoot(_tiedProperties, "/controls/engines/engine", index ); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/fire-switch", index); - fgTie(name, this, index, - &FGControls::get_fire_switch, &FGControls::set_fire_switch); - fgSetArchivable(name); + _tiedProperties.Tie( "throttle", this, index, &FGControls::get_throttle, &FGControls::set_throttle ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/fire-bottle-discharge", index); - fgTie(name, this, index, - &FGControls::get_fire_bottle_discharge, - &FGControls::set_fire_bottle_discharge); - fgSetArchivable(name); + _tiedProperties.Tie( "starter", this, index, &FGControls::get_starter, &FGControls::set_starter ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, "/controls/engines/engine[%d]/cutoff", index); - fgTie(name, this, index, - &FGControls::get_cutoff, &FGControls::set_cutoff); - fgSetArchivable(name); + _tiedProperties.Tie( "fuel-pump", this, index, &FGControls::get_fuel_pump, &FGControls::set_fuel_pump ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, "/controls/engines/engine[%d]/mixture", index); - fgTie(name, this, index, - &FGControls::get_mixture, &FGControls::set_mixture); - fgSetArchivable(name); + _tiedProperties.Tie( "fire-switch", this, index, &FGControls::get_fire_switch, &FGControls::set_fire_switch ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/propeller-pitch", index); - fgTie(name, this, index, - &FGControls::get_prop_advance, - &FGControls::set_prop_advance); - fgSetArchivable(name); + _tiedProperties.Tie( "fire-bottle-discharge", this, index, &FGControls::get_fire_bottle_discharge, &FGControls::set_fire_bottle_discharge ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/magnetos", index); - fgTie(name, this, index, - &FGControls::get_magnetos, &FGControls::set_magnetos); - fgSetArchivable(name); - - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/feed_tank", index); - fgTie(name, this, index, - &FGControls::get_feed_tank, &FGControls::set_feed_tank); - fgSetArchivable(name); + _tiedProperties.Tie( "cutoff", this, index, &FGControls::get_cutoff, &FGControls::set_cutoff ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + _tiedProperties.Tie( "mixture", this, index, &FGControls::get_mixture, &FGControls::set_mixture ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, "/controls/engines/engine[%d]/WEP", index); - fgTie(name, this, index, - &FGControls::get_nitrous_injection, - &FGControls::set_nitrous_injection); - fgSetArchivable(name); + _tiedProperties.Tie( "propeller-pitch", this, index, &FGControls::get_prop_advance, &FGControls::set_prop_advance ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/cowl-flaps-norm", index); - fgTie(name, this, index, - &FGControls::get_cowl_flaps_norm, - &FGControls::set_cowl_flaps_norm); - fgSetArchivable(name); + _tiedProperties.Tie( "magnetos", this, index, &FGControls::get_magnetos, &FGControls::set_magnetos ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/propeller-feather", index); - fgTie(name, this, index, - &FGControls::get_feather, &FGControls::set_feather); - fgSetArchivable(name); + _tiedProperties.Tie( "feed_tank", this, index, &FGControls::get_feed_tank, &FGControls::set_feed_tank ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/ignition", index); - fgTie(name, this, index, - &FGControls::get_ignition, &FGControls::set_ignition); - fgSetArchivable(name); + _tiedProperties.Tie( "WEP", this, index, &FGControls::get_nitrous_injection, &FGControls::set_nitrous_injection ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/augmentation", index); - fgTie(name, this, index, - &FGControls::get_augmentation, - &FGControls::set_augmentation); - fgSetArchivable(name); + _tiedProperties.Tie( "cowl-flaps-norm", this, index, &FGControls::get_cowl_flaps_norm, &FGControls::set_cowl_flaps_norm ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/reverser", index); - fgTie(name, this, index, - &FGControls::get_reverser, &FGControls::set_reverser); - fgSetArchivable(name); + _tiedProperties.Tie( "propeller-feather", this, index, &FGControls::get_feather, &FGControls::set_feather ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/water-injection", index); - fgTie(name, this, index, - &FGControls::get_water_injection, - &FGControls::set_water_injection); - fgSetArchivable(name); + _tiedProperties.Tie( "ignition", this, index, &FGControls::get_ignition, &FGControls::set_ignition ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/condition", index); - fgTie(name, this, index, - &FGControls::get_condition, &FGControls::set_condition); - fgSetArchivable(name); - } + _tiedProperties.Tie( "augmentation", this, index, &FGControls::get_augmentation, &FGControls::set_augmentation ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - // fuel - fgTie("/controls/fuel/dump-valve", this, - &FGControls::get_dump_valve, &FGControls::set_dump_valve); - fgSetArchivable("/controls/fuel/dump-valve"); + _tiedProperties.Tie( "reverser", this, index, &FGControls::get_reverser, &FGControls::set_reverser ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - for (index = 0; index < MAX_TANKS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/fuel/tank[%d]/fuel_selector", index); - fgTie(name, this, index, - &FGControls::get_fuel_selector, - &FGControls::set_fuel_selector); - fgSetArchivable(name); + _tiedProperties.Tie( "water-injection", this, index, &FGControls::get_water_injection, &FGControls::set_water_injection ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, "/controls/fuel/tank[%d]/to_engine", index); - fgTie(name, this, index, - &FGControls::get_to_engine, &FGControls::set_to_engine); - fgSetArchivable(name); - - snprintf(name, MAX_NAME_LEN, "/controls/fuel/tank[%d]/to_tank", index); - fgTie(name, this, index, - &FGControls::get_to_tank, &FGControls::set_to_tank); - fgSetArchivable(name); - - for (i = 0; i < MAX_BOOSTPUMPS; i++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/fuel/tank[%d]/boost-pump[%d]", index, i); - fgTie(name, this, index * 2 + i, - &FGControls::get_boost_pump, - &FGControls::set_boost_pump); - fgSetArchivable(name); + _tiedProperties.Tie( "condition", this, index, &FGControls::get_condition, &FGControls::set_condition ) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); } - } - // gear - fgTie("/controls/gear/brake-left", this, - &FGControls::get_brake_left, - &FGControls::set_brake_left); - fgSetArchivable("/controls/gear/brake-left"); + // fuel + _SetRoot( _tiedProperties, "/controls/fuel" ); - fgTie("/controls/gear/brake-right", this, - &FGControls::get_brake_right, - &FGControls::set_brake_right); - fgSetArchivable("/controls/gear/brake-right"); + _tiedProperties.Tie( "dump-valve", this, &FGControls::get_dump_valve, &FGControls::set_dump_valve) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/gear/copilot-brake-left", this, - &FGControls::get_copilot_brake_left, - &FGControls::set_copilot_brake_left); - fgSetArchivable("/controls/gear/copilot-brake-left"); + for (index = 0; index < MAX_TANKS; index++) { + _SetRoot( _tiedProperties, "/controls/fuel/tank", index ); - fgTie("/controls/gear/copilot-brake-right", this, - &FGControls::get_copilot_brake_right, - &FGControls::set_copilot_brake_right); - fgSetArchivable("/controls/gear/copilot-brake-right"); + _tiedProperties.Tie( "fuel_selector", this, index, &FGControls::get_fuel_selector, &FGControls::set_fuel_selector) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/gear/brake-parking", this, - &FGControls::get_brake_parking, - &FGControls::set_brake_parking); - fgSetArchivable("/controls/gear/brake-parking"); + _tiedProperties.Tie( "to_engine", this, index, &FGControls::get_to_engine, &FGControls::set_to_engine) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/gear/steering", this, - &FGControls::get_steering, &FGControls::set_steering); - fgSetArchivable("/controls/gear/steering"); + _tiedProperties.Tie( "to_tank", this, index, &FGControls::get_to_tank, &FGControls::set_to_tank) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/gear/nose-wheel-steering", this, - &FGControls::get_nose_wheel_steering, - &FGControls::set_nose_wheel_steering); - fgSetArchivable("/controls/gear/nose-wheel-steering"); + for (i = 0; i < MAX_BOOSTPUMPS; i++) { + _tiedProperties.Tie( "boost-pump", i, + this, index * 2 + i, &FGControls::get_boost_pump, &FGControls::set_boost_pump) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + } + } - fgTie("/controls/gear/gear-down", this, - &FGControls::get_gear_down, &FGControls::set_gear_down); - fgSetArchivable("/controls/gear/gear-down"); + // gear + _SetRoot( _tiedProperties, "/controls/gear" ); - fgTie("/controls/gear/antiskid", this, - &FGControls::get_antiskid, &FGControls::set_antiskid); - fgSetArchivable("/controls/gear/antiskid"); + _tiedProperties.Tie( "brake-left", this, &FGControls::get_brake_left, &FGControls::set_brake_left) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/gear/tailhook", this, - &FGControls::get_tailhook, &FGControls::set_tailhook); - fgSetArchivable("/controls/gear/tailhook"); + _tiedProperties.Tie( "brake-right", this, &FGControls::get_brake_right, &FGControls::set_brake_right) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/gear/launchbar", this, - &FGControls::get_launchbar, &FGControls::set_launchbar); - fgSetArchivable("/controls/gear/launchbar"); + _tiedProperties.Tie( "copilot-brake-left", this, &FGControls::get_copilot_brake_left, &FGControls::set_copilot_brake_left) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/gear/catapult-launch-cmd", this, - &FGControls::get_catapult_launch_cmd, &FGControls::set_catapult_launch_cmd); - fgSetArchivable("/controls/gear/catapult-launch-cmd"); + _tiedProperties.Tie( "copilot-brake-right", this, &FGControls::get_copilot_brake_right, &FGControls::set_copilot_brake_right) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/gear/tailwheel-lock", this, - &FGControls::get_tailwheel_lock, - &FGControls::set_tailwheel_lock); - fgSetArchivable("/controls/gear/tailwheel-lock"); + _tiedProperties.Tie( "brake-parking", this, &FGControls::get_brake_parking, &FGControls::set_brake_parking) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - for (index = 0; index < MAX_WHEELS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/gear/wheel[%d]/alternate-extension", index); - fgTie(name, this, index, - &FGControls::get_alternate_extension, - &FGControls::set_alternate_extension); - fgSetArchivable(name); - } + _tiedProperties.Tie( "steering", this, &FGControls::get_steering, &FGControls::set_steering) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - // anti-ice - fgTie("/controls/anti-ice/wing-heat", this, - &FGControls::get_wing_heat, &FGControls::set_wing_heat); - fgSetArchivable("/controls/anti-ice/wing-heat"); + _tiedProperties.Tie( "nose-wheel-steering", this, &FGControls::get_nose_wheel_steering, &FGControls::set_nose_wheel_steering) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/anti-ice/pitot-heat", this, - &FGControls::get_pitot_heat, &FGControls::set_pitot_heat); - fgSetArchivable("/controls/anti-ice/pitot-heat"); + _tiedProperties.Tie( "gear-down", this, &FGControls::get_gear_down, &FGControls::set_gear_down) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/anti-ice/wiper", this, - &FGControls::get_wiper, &FGControls::set_wiper); - fgSetArchivable("/controls/anti-ice/wiper"); + _tiedProperties.Tie( "antiskid", this, &FGControls::get_antiskid, &FGControls::set_antiskid) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/anti-ice/window-heat", this, - &FGControls::get_window_heat, &FGControls::set_window_heat); - fgSetArchivable("/controls/anti-ice/window-heat"); + _tiedProperties.Tie( "tailhook", this, &FGControls::get_tailhook, &FGControls::set_tailhook) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - for (index = 0; index < MAX_ENGINES; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/anti-ice/engine[%d]/carb-heat", index); - fgTie(name, this, index, - &FGControls::get_carb_heat, &FGControls::set_carb_heat); - fgSetArchivable(name); + _tiedProperties.Tie( "launchbar", this, &FGControls::get_launchbar, &FGControls::set_launchbar) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/anti-ice/engine[%d]/inlet-heat", index); - fgTie(name, this, index, - &FGControls::get_inlet_heat, &FGControls::set_inlet_heat); - fgSetArchivable(name); - } + _tiedProperties.Tie( "catapult-launch-cmd", this, &FGControls::get_catapult_launch_cmd, &FGControls::set_catapult_launch_cmd) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - // hydraulics - for (index = 0; index < MAX_HYD_SYSTEMS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/hydraulic/system[%d]/engine-pump", index); - fgTie(name, this, index, - &FGControls::get_engine_pump, &FGControls::set_engine_pump); - fgSetArchivable(name); + _tiedProperties.Tie( "tailwheel-lock", this, &FGControls::get_tailwheel_lock, &FGControls::set_tailwheel_lock) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/hydraulic/system[%d]/electric-pump", index); - fgTie(name, this, index, - &FGControls::get_electric_pump, - &FGControls::set_electric_pump); - fgSetArchivable(name); - } + for (index = 0; index < MAX_WHEELS; index++) { + _SetRoot( _tiedProperties, "/controls/gear/wheel", index ); + _tiedProperties.Tie( "alternate-extension", this, index, &FGControls::get_alternate_extension, &FGControls::set_alternate_extension) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + } - // electric - fgTie("/controls/electric/battery-switch", this, - &FGControls::get_battery_switch, - &FGControls::set_battery_switch); - fgSetArchivable("/controls/electric/battery-switch"); - - fgTie("/controls/electric/external-power", this, - &FGControls::get_external_power, - &FGControls::set_external_power); - fgSetArchivable("/controls/electric/external-power"); + // anti-ice + _SetRoot( _tiedProperties, "/controls/anti-ice" ); - fgTie("/controls/electric/APU-generator", this, - &FGControls::get_APU_generator, - &FGControls::set_APU_generator); - fgSetArchivable("/controls/electric/APU-generator"); + _tiedProperties.Tie( "wing-heat", this, &FGControls::get_wing_heat, &FGControls::set_wing_heat) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - for (index = 0; index < MAX_ENGINES; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/electric/engine[%d]/generator", index); - fgTie(name, this, index, - &FGControls::get_generator_breaker, - &FGControls::set_generator_breaker); - fgSetArchivable(name); + _tiedProperties.Tie( "pitot-heat", this, &FGControls::get_pitot_heat, &FGControls::set_pitot_heat) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/electric/engine[%d]/bus-tie", index); - fgTie(name, this, index, - &FGControls::get_bus_tie, - &FGControls::set_bus_tie); - fgSetArchivable(name); - } + _tiedProperties.Tie( "wiper", this, &FGControls::get_wiper, &FGControls::set_wiper) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - // pneumatic - fgTie("/controls/pneumatic/APU-bleed", this, - &FGControls::get_APU_bleed, - &FGControls::set_APU_bleed); - fgSetArchivable("/controls/pneumatic/APU-bleed"); + _tiedProperties.Tie( "window-heat", this, &FGControls::get_window_heat, &FGControls::set_window_heat) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - for (index = 0; index < MAX_ENGINES; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/pneumatic/engine[%d]/bleed", index); - fgTie(name, this, index, - &FGControls::get_engine_bleed, - &FGControls::set_engine_bleed); - fgSetArchivable(name); - } + for (index = 0; index < MAX_ENGINES; index++) { + _SetRoot( _tiedProperties, "/controls/anti-ice/engine", index ); - // pressurization - fgTie("/controls/pressurization/mode", this, - &FGControls::get_mode, &FGControls::set_mode); - fgSetArchivable("/controls/pressurization/mode"); + _tiedProperties.Tie( "carb-heat", this, index, &FGControls::get_carb_heat, &FGControls::set_carb_heat) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/pressurization/dump", this, - &FGControls::get_dump, &FGControls::set_dump); - fgSetArchivable("/controls/pressurization/dump"); + _tiedProperties.Tie( "inlet-heat", this, index, &FGControls::get_inlet_heat, &FGControls::set_inlet_heat) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + } - fgTie("/controls/pressurization/outflow-valve", this, - &FGControls::get_outflow_valve, - &FGControls::set_outflow_valve); - fgSetArchivable("/controls/pressurization/outflow-valve"); + // hydraulics + for (index = 0; index < MAX_HYD_SYSTEMS; index++) { + _SetRoot( _tiedProperties, "/controls/hydraulic/system", index ); - for (index = 0; index < MAX_PACKS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/pressurization/pack[%d]/pack-on", index); - fgTie(name, this, index, - &FGControls::get_pack_on, &FGControls::set_pack_on); - fgSetArchivable(name); - } - - // lights - fgTie("/controls/lighting/landing-lights", this, - &FGControls::get_landing_lights, - &FGControls::set_landing_lights); - fgSetArchivable("/controls/lighting/landing-lights"); + _tiedProperties.Tie( "engine-pump", this, index, &FGControls::get_engine_pump, &FGControls::set_engine_pump) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/lighting/turn-off-lights", this, - &FGControls::get_turn_off_lights, - &FGControls::set_turn_off_lights); - fgSetArchivable("/controls/lighting/turn-off-lights"); - - fgTie("/controls/lighting/taxi-light", this, - &FGControls::get_taxi_light, &FGControls::set_taxi_light); - fgSetArchivable("/controls/lighting/taxi-light"); - - fgTie("/controls/lighting/logo-lights", this, - &FGControls::get_logo_lights, &FGControls::set_logo_lights); - fgSetArchivable("/controls/lighting/logo-lights"); - - fgTie("/controls/lighting/nav-lights", this, - &FGControls::get_nav_lights, &FGControls::set_nav_lights); - fgSetArchivable("/controls/lighting/nav-lights"); + _tiedProperties.Tie( "electric-pump", this, index, &FGControls::get_electric_pump, &FGControls::set_electric_pump) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + } - fgTie("/controls/lighting/beacon", this, - &FGControls::get_beacon, &FGControls::set_beacon); - fgSetArchivable("/controls/lighting/beacon"); - - fgTie("/controls/lighting/strobe", this, - &FGControls::get_strobe, &FGControls::set_strobe); - fgSetArchivable("/controls/lighting/strobe"); + // electric + _SetRoot( _tiedProperties, "/controls/electric" ); - fgTie("/controls/lighting/panel-norm", this, - &FGControls::get_panel_norm, &FGControls::set_panel_norm); - fgSetArchivable("/controls/lighting/panel-norm"); - - fgTie("/controls/lighting/instruments-norm", this, - &FGControls::get_instruments_norm, - &FGControls::set_instruments_norm); - fgSetArchivable("/controls/lighting/instruments-norm"); + _tiedProperties.Tie( "battery-switch", this, &FGControls::get_battery_switch, &FGControls::set_battery_switch) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/lighting/dome-norm", this, - &FGControls::get_dome_norm, &FGControls::set_dome_norm); - fgSetArchivable("/controls/lighting/dome-norm"); - - // armament - fgTie("/controls/armament/master-arm", this, - &FGControls::get_master_arm, &FGControls::set_master_arm); - fgSetArchivable("/controls/armament/master-arm"); + _tiedProperties.Tie( "external-power", this, &FGControls::get_external_power, &FGControls::set_external_power) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/armament/station-select", this, - &FGControls::get_station_select, - &FGControls::set_station_select); - fgSetArchivable("/controls/armament/station-select"); + _tiedProperties.Tie( "APU-generator", this, &FGControls::get_APU_generator, &FGControls::set_APU_generator) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/armament/release-all", this, - &FGControls::get_release_ALL, - &FGControls::set_release_ALL); - fgSetArchivable("/controls/armament/release-all"); + for (index = 0; index < MAX_ENGINES; index++) { + _SetRoot( _tiedProperties, "/controls/electric/engine", index ); - for (index = 0; index < MAX_STATIONS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/armament/station[%d]/stick-size", index); - fgTie(name, this, index, - &FGControls::get_stick_size, &FGControls::set_stick_size); - fgSetArchivable(name); + _tiedProperties.Tie( "generator", this, index, &FGControls::get_generator_breaker, &FGControls::set_generator_breaker) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - snprintf(name, MAX_NAME_LEN, - "/controls/armament/station[%d]/release-stick", index); - fgTie(name, this, index, - &FGControls::get_release_stick, &FGControls::set_release_stick); - fgSetArchivable(name); + _tiedProperties.Tie( "bus-tie", this, index, &FGControls::get_bus_tie, &FGControls::set_bus_tie) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + } - snprintf(name, MAX_NAME_LEN, - "/controls/armament/station[%d]/release-all", index); - fgTie(name, this, index, - &FGControls::get_release_all, &FGControls::set_release_all); - fgSetArchivable(name); + // pneumatic + _SetRoot( _tiedProperties, "/controls/pneumatic" ); - snprintf(name, MAX_NAME_LEN, - "/controls/armament/station[%d]/jettison-all", index); - fgTie(name, this, index, - &FGControls::get_jettison_all, &FGControls::set_jettison_all); - fgSetArchivable(name); - } + _tiedProperties.Tie( "APU-bleed", this, &FGControls::get_APU_bleed, &FGControls::set_APU_bleed) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - // seat - fgTie("/controls/seat/vertical-adjust", this, - &FGControls::get_vertical_adjust, - &FGControls::set_vertical_adjust); - fgSetArchivable("/controls/seat/vertical-adjust"); + for (index = 0; index < MAX_ENGINES; index++) { + _SetRoot( _tiedProperties, "/controls/pneumatic/engine", index ); - fgTie("/controls/seat/fore-aft-adjust", this, - &FGControls::get_fore_aft_adjust, - &FGControls::set_fore_aft_adjust); - fgSetArchivable("/controls/seat/fore-aft-adjust"); - - for (index = 0; index < MAX_EJECTION_SEATS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/seat/eject[%d]/initiate", index); - fgTie(name, this, index, - &FGControls::get_ejection_seat, - &FGControls::set_ejection_seat); - fgSetArchivable(name); + _tiedProperties.Tie( "bleed", this, index, &FGControls::get_engine_bleed, &FGControls::set_engine_bleed) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + } - snprintf(name, MAX_NAME_LEN, - "/controls/seat/eject[%d]/status", index); + // pressurization + _SetRoot( _tiedProperties, "/controls/pressurization" ); - fgTie(name, this, index, - &FGControls::get_eseat_status, - &FGControls::set_eseat_status); + _tiedProperties.Tie( "mode", this, &FGControls::get_mode, &FGControls::set_mode) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgSetArchivable(name); - } - - fgTie("/controls/seat/cmd_selector_valve", this, - &FGControls::get_cmd_selector_valve, - &FGControls::set_cmd_selector_valve); - fgSetArchivable("/controls/seat/eject/cmd_selector_valve"); + _tiedProperties.Tie( "dump", this, &FGControls::get_dump, &FGControls::set_dump) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + _tiedProperties.Tie( "outflow-valve", this, &FGControls::get_outflow_valve, &FGControls::set_outflow_valve) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - // APU - fgTie("/controls/APU/off-start-run", this, - &FGControls::get_off_start_run, - &FGControls::set_off_start_run); - fgSetArchivable("/controls/APU/off-start-run"); + for (index = 0; index < MAX_PACKS; index++) { + _SetRoot( _tiedProperties, "/controls/pressurization/pack", index ); - fgTie("/controls/APU/fire-switch", this, - &FGControls::get_APU_fire_switch, - &FGControls::set_APU_fire_switch); - fgSetArchivable("/controls/APU/fire-switch"); + _tiedProperties.Tie( "pack-on", this, index, &FGControls::get_pack_on, &FGControls::set_pack_on) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + } - // autoflight - for (index = 0; index < MAX_AUTOPILOTS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/autoflight/autopilot[%d]/engage", index); - fgTie(name, this, index, - &FGControls::get_autopilot_engage, - &FGControls::set_autopilot_engage); - fgSetArchivable(name); - } - - fgTie("/controls/autoflight/autothrottle-arm", this, - &FGControls::get_autothrottle_arm, - &FGControls::set_autothrottle_arm); - fgSetArchivable("/controls/autoflight/autothrottle-arm"); + // lights + _SetRoot( _tiedProperties, "/controls/lighting" ); - fgTie("/controls/autoflight/autothrottle-engage", this, - &FGControls::get_autothrottle_engage, - &FGControls::set_autothrottle_engage); - fgSetArchivable("/controls/autoflight/autothrottle-engage"); + _tiedProperties.Tie( "landing-lights", this, &FGControls::get_landing_lights, &FGControls::set_landing_lights) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/autoflight/heading-select", this, - &FGControls::get_heading_select, - &FGControls::set_heading_select); - fgSetArchivable("/controls/autoflight/heading-select"); + _tiedProperties.Tie( "turn-off-lights", this, &FGControls::get_turn_off_lights, &FGControls::set_turn_off_lights) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/autoflight/altitude-select", this, - &FGControls::get_altitude_select, - &FGControls::set_altitude_select); - fgSetArchivable("/controls/autoflight/altitude-select"); + _tiedProperties.Tie( "taxi-light", this, &FGControls::get_taxi_light, &FGControls::set_taxi_light) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/autoflight/bank-angle-select", this, - &FGControls::get_bank_angle_select, - &FGControls::set_bank_angle_select); - fgSetArchivable("/controls/autoflight/bank-angle-select"); + _tiedProperties.Tie( "logo-lights", this, &FGControls::get_logo_lights, &FGControls::set_logo_lights) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/autoflight/vertical-speed-select", this, - &FGControls::get_vertical_speed_select, - &FGControls::set_vertical_speed_select); - fgSetArchivable("/controls/autoflight/vertical-speed-select"); + _tiedProperties.Tie( "nav-lights", this, &FGControls::get_nav_lights, &FGControls::set_nav_lights) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/autoflight/speed-select", this, - &FGControls::get_speed_select, - &FGControls::set_speed_select); - fgSetArchivable("/controls/autoflight/speed-select"); + _tiedProperties.Tie( "beacon", this, &FGControls::get_beacon, &FGControls::set_beacon) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/autoflight/mach-select", this, - &FGControls::get_mach_select, - &FGControls::set_mach_select); - fgSetArchivable("/controls/autoflight/mach-select"); + _tiedProperties.Tie( "strobe", this, &FGControls::get_strobe, &FGControls::set_strobe) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/autoflight/vertical-mode", this, - &FGControls::get_vertical_mode, - &FGControls::set_vertical_mode); - fgSetArchivable("/controls/autoflight/vertical-mode"); + _tiedProperties.Tie( "panel-norm", this, &FGControls::get_panel_norm, &FGControls::set_panel_norm) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); - fgTie("/controls/autoflight/lateral-mode", this, - &FGControls::get_lateral_mode, - &FGControls::set_lateral_mode); - fgSetArchivable("/controls/autoflight/lateral-mode"); + _tiedProperties.Tie( "instruments-norm", this, &FGControls::get_instruments_norm, &FGControls::set_instruments_norm) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + _tiedProperties.Tie( "dome-norm", this, &FGControls::get_dome_norm, &FGControls::set_dome_norm) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + // armament + _SetRoot( _tiedProperties, "/controls/armament" ); + + _tiedProperties.Tie( "master-arm", this, &FGControls::get_master_arm, &FGControls::set_master_arm) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "station-select", this, &FGControls::get_station_select, &FGControls::set_station_select) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "release-all", this, &FGControls::get_release_ALL, &FGControls::set_release_ALL) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + for (index = 0; index < MAX_STATIONS; index++) { + _SetRoot( _tiedProperties, "/controls/armament/station", index ); + + _tiedProperties.Tie( "stick-size", this, index, &FGControls::get_stick_size, &FGControls::set_stick_size) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "release-stick", this, index, &FGControls::get_release_stick, &FGControls::set_release_stick) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "release-all", this, index, &FGControls::get_release_all, &FGControls::set_release_all) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "jettison-all", this, index, &FGControls::get_jettison_all, &FGControls::set_jettison_all) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + } + + // seat + _SetRoot( _tiedProperties, "/controls/seat" ); + + _tiedProperties.Tie( "vertical-adjust", this, &FGControls::get_vertical_adjust, &FGControls::set_vertical_adjust) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "fore-aft-adjust", this, &FGControls::get_fore_aft_adjust, &FGControls::set_fore_aft_adjust) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "cmd_selector_valve", this, &FGControls::get_cmd_selector_valve, &FGControls::set_cmd_selector_valve) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + for (index = 0; index < MAX_EJECTION_SEATS; index++) { + _SetRoot( _tiedProperties, "/controls/seat/eject", index ); + + _tiedProperties.Tie( "initiate", this, index, &FGControls::get_ejection_seat, &FGControls::set_ejection_seat) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "status", this, index, &FGControls::get_eseat_status, &FGControls::set_eseat_status) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + } + + // APU + _SetRoot( _tiedProperties, "/controls/APU" ); + + _tiedProperties.Tie( "off-start-run", this, &FGControls::get_off_start_run, &FGControls::set_off_start_run) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "fire-switch", this, &FGControls::get_APU_fire_switch, &FGControls::set_APU_fire_switch) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + // autoflight + for (index = 0; index < MAX_AUTOPILOTS; index++) { + + _SetRoot( _tiedProperties, "/controls/autoflight/autopilot", index ); + + _tiedProperties.Tie( "engage", this, index, &FGControls::get_autopilot_engage, &FGControls::set_autopilot_engage) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + } + + _SetRoot( _tiedProperties, "/controls/autoflight/" ); + + _tiedProperties.Tie( "autothrottle-arm", this, &FGControls::get_autothrottle_arm, &FGControls::set_autothrottle_arm) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "autothrottle-engage", this, &FGControls::get_autothrottle_engage, &FGControls::set_autothrottle_engage) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "heading-select", this, &FGControls::get_heading_select, &FGControls::set_heading_select) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "altitude-select", this, &FGControls::get_altitude_select, &FGControls::set_altitude_select) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "bank-angle-select", this, &FGControls::get_bank_angle_select, &FGControls::set_bank_angle_select) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "vertical-speed-select", this, &FGControls::get_vertical_speed_select, &FGControls::set_vertical_speed_select) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "speed-select", this, &FGControls::get_speed_select, &FGControls::set_speed_select) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "mach-select", this, &FGControls::get_mach_select, &FGControls::set_mach_select) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "vertical-mode", this, &FGControls::get_vertical_mode, &FGControls::set_vertical_mode) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); + + _tiedProperties.Tie( "lateral-mode", this, &FGControls::get_lateral_mode, &FGControls::set_lateral_mode) + ->setAttribute( SGPropertyNode::ARCHIVE, true ); } void FGControls::unbind () { - int index, i; - //Tie control properties. - fgUntie("/controls/flight/aileron"); - fgUntie("/controls/flight/aileron-trim"); - fgUntie("/controls/flight/elevator"); - fgUntie("/controls/flight/elevator-trim"); - fgUntie("/controls/flight/rudder"); - fgUntie("/controls/flight/rudder-trim"); - fgUntie("/controls/flight/flaps"); - fgUntie("/controls/flight/slats"); - fgUntie("/controls/flight/BLC"); - fgUntie("/controls/flight/spoilers"); - fgUntie("/controls/flight/speedbrake"); - fgUntie("/controls/flight/wing-sweep"); - fgUntie("/controls/flight/wing-fold"); - fgUntie("/controls/flight/drag-chute"); - for (index = 0; index < MAX_ENGINES; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/throttle", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/feed_tank", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/starter", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/fuel-pump", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/fire-switch", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/fire-bottle-discharge", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/throttle_idle", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, "/controls/engines/engine[%d]/cutoff", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, "/controls/engines/engine[%d]/mixture", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/propeller-pitch", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/magnetos", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, "/controls/engines/engine[%d]/WEP", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/cowl-flaps-norm", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/propeller-feather", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/ignition", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/augmentation", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/reverser", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/water-injection", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/engines/engine[%d]/condition", index); - fgUntie(name); - } - fgUntie("/controls/fuel/dump-valve"); - for (index = 0; index < MAX_TANKS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/fuel/tank[%d]/fuel_selector", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, "/controls/fuel/tank[%d]/to_engine", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, "/controls/fuel/tank[%d]/to_tank", index); - fgUntie(name); - for (i = 0; index < MAX_BOOSTPUMPS; i++) { - snprintf(name, MAX_NAME_LEN, - "/controls/fuel/tank[%d]/boost-pump[%d]", index, i); - fgUntie(name); - } - } - fgUntie("/controls/gear/brake-left"); - fgUntie("/controls/gear/brake-right"); - fgUntie("/controls/gear/brake-parking"); - fgUntie("/controls/gear/steering"); - fgUntie("/controls/gear/nose-wheel-steering"); - fgUntie("/controls/gear/gear-down"); - fgUntie("/controls/gear/antiskid"); - fgUntie("/controls/gear/tailhook"); - fgUntie("/controls/gear/launchbar"); - fgUntie("/controls/gear/catapult-launch-cmd"); - fgUntie("/controls/gear/tailwheel-lock"); - for (index = 0; index < MAX_WHEELS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/gear/wheel[%d]/alternate-extension", index); - fgUntie(name); - } - fgUntie("/controls/anti-ice/wing-heat"); - fgUntie("/controls/anti-ice/pitot-heat"); - fgUntie("/controls/anti-ice/wiper"); - fgUntie("/controls/anti-ice/window-heat"); - for (index = 0; index < MAX_ENGINES; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/anti-ice/engine[%d]/carb-heat", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/anti-ice/engine[%d]/inlet-heat", index); - fgUntie(name); - } - for (index = 0; index < MAX_HYD_SYSTEMS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/hydraulic/system[%d]/engine-pump", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/hydraulic/system[%d]/electric-pump", index); - fgUntie(name); - } - fgUntie("/controls/electric/battery-switch"); - fgUntie("/controls/electric/external-power"); - fgUntie("/controls/electric/APU-generator"); - for (index = 0; index < MAX_ENGINES; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/electric/engine[%d]/generator", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/electric/engine[%d]/bus-tie", index); - fgUntie(name); - } - fgUntie("/controls/pneumatic/APU-bleed"); - for (index = 0; index < MAX_ENGINES; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/pneumatic/engine[%d]/bleed", index); - fgUntie(name); - } - fgUntie("/controls/pressurization/mode"); - fgUntie("/controls/pressurization/dump"); - for (index = 0; index < MAX_PACKS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/pressurization/pack[%d]/pack-on", index); - fgUntie(name); - } - fgUntie("/controls/lighting/landing-lights"); - fgUntie("/controls/lighting/turn-off-lights"); - fgUntie("/controls/lighting/taxi-light"); - fgUntie("/controls/lighting/logo-lights"); - fgUntie("/controls/lighting/nav-lights"); - fgUntie("/controls/lighting/beacon"); - fgUntie("/controls/lighting/strobe"); - fgUntie("/controls/lighting/panel-norm"); - fgUntie("/controls/lighting/instruments-norm"); - fgUntie("/controls/lighting/dome-norm"); - - fgUntie("/controls/armament/master-arm"); - fgUntie("/controls/armament/station-select"); - fgUntie("/controls/armament/release-all"); - for (index = 0; index < MAX_STATIONS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/armament/station[%d]/stick-size", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/armament/station[%d]/release-stick", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/armament/station[%d]/release-all", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/armament/station[%d]/jettison-all", index); - fgUntie(name); - } - - fgUntie("/controls/seat/vertical-adjust"); - fgUntie("/controls/seat/fore-aft-adjust"); - for (index = 0; index < MAX_EJECTION_SEATS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/seat/eject[%d]/initiate", index); - fgUntie(name); - snprintf(name, MAX_NAME_LEN, - "/controls/seat/eject[%d]/status", index); - fgUntie(name); - } - fgUntie("/controls/seat/cmd_selector_valve"); - - fgUntie("/controls/APU/off-start-run"); - fgUntie("/controls/APU/fire-switch"); - for (index = 0; index < MAX_AUTOPILOTS; index++) { - char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, - "/controls/autoflight/autopilot[%d]/engage", index); - fgUntie(name); - } - fgUntie("/controls/autoflight/autothrottle-arm"); - fgUntie("/controls/autoflight/autothrottle-engage"); - fgUntie("/controls/autoflight/heading-select"); - fgUntie("/controls/autoflight/altitude-select"); - fgUntie("/controls/autoflight/bank-angle-select"); - fgUntie("/controls/autoflight/vertical-speed-select"); - fgUntie("/controls/autoflight/speed-select"); - fgUntie("/controls/autoflight/mach-select"); - fgUntie("/controls/autoflight/vertical-mode"); - fgUntie("/controls/autoflight/lateral-mode"); -} + _tiedProperties.Untie(); +} void @@ -1082,220 +654,220 @@ FGControls::update (double dt) void FGControls::set_aileron (double pos) { - aileron = pos; - CLAMP( &aileron, -1.0, 1.0 ); - - // check for autocoordination - if ( auto_coordination->getBoolValue() ) { - set_rudder( aileron / 2.0 ); - } + aileron = pos; + SG_CLAMP_RANGE<double>( aileron, -1.0, 1.0 ); + + // check for autocoordination + if ( auto_coordination->getBoolValue() ) { + set_rudder( aileron / 2.0 ); + } } void FGControls::move_aileron (double amt) { - aileron += amt; - CLAMP( &aileron, -1.0, 1.0 ); - - // check for autocoordination - if ( auto_coordination->getBoolValue() ) { - set_rudder( aileron / 2.0 ); - } + aileron += amt; + SG_CLAMP_RANGE<double>( aileron, -1.0, 1.0 ); + + // check for autocoordination + if ( auto_coordination->getBoolValue() ) { + set_rudder( aileron / 2.0 ); + } } void FGControls::set_aileron_trim( double pos ) { aileron_trim = pos; - CLAMP( &aileron_trim, -1.0, 1.0 ); + SG_CLAMP_RANGE<double>( aileron_trim, -1.0, 1.0 ); } void FGControls::move_aileron_trim( double amt ) { aileron_trim += amt; - CLAMP( &aileron_trim, -1.0, 1.0 ); + SG_CLAMP_RANGE<double>( aileron_trim, -1.0, 1.0 ); } void FGControls::set_elevator( double pos ) { elevator = pos; - CLAMP( &elevator, -1.0, 1.0 ); + SG_CLAMP_RANGE<double>( elevator, -1.0, 1.0 ); } void FGControls::move_elevator( double amt ) { elevator += amt; - CLAMP( &elevator, -1.0, 1.0 ); + SG_CLAMP_RANGE<double>( elevator, -1.0, 1.0 ); } void FGControls::set_elevator_trim( double pos ) { elevator_trim = pos; - CLAMP( &elevator_trim, -1.0, 1.0 ); + SG_CLAMP_RANGE<double>( elevator_trim, -1.0, 1.0 ); } void FGControls::move_elevator_trim( double amt ) { elevator_trim += amt; - CLAMP( &elevator_trim, -1.0, 1.0 ); + SG_CLAMP_RANGE<double>( elevator_trim, -1.0, 1.0 ); } void FGControls::set_rudder( double pos ) { rudder = pos; - CLAMP( &rudder, -1.0, 1.0 ); + SG_CLAMP_RANGE<double>( rudder, -1.0, 1.0 ); } void FGControls::move_rudder( double amt ) { rudder += amt; - CLAMP( &rudder, -1.0, 1.0 ); + SG_CLAMP_RANGE<double>( rudder, -1.0, 1.0 ); } void FGControls::set_rudder_trim( double pos ) { rudder_trim = pos; - CLAMP( &rudder_trim, -1.0, 1.0 ); + SG_CLAMP_RANGE<double>( rudder_trim, -1.0, 1.0 ); } void FGControls::move_rudder_trim( double amt ) { rudder_trim += amt; - CLAMP( &rudder_trim, -1.0, 1.0 ); + SG_CLAMP_RANGE<double>( rudder_trim, -1.0, 1.0 ); } void FGControls::set_flaps( double pos ) { flaps = pos; - CLAMP( &flaps, 0.0, 1.0 ); + SG_CLAMP_RANGE<double>( flaps, 0.0, 1.0 ); } void FGControls::move_flaps( double amt ) { flaps += amt; - CLAMP( &flaps, 0.0, 1.0 ); + SG_CLAMP_RANGE<double>( flaps, 0.0, 1.0 ); } void FGControls::set_slats( double pos ) { slats = pos; - CLAMP( &slats, 0.0, 1.0 ); + SG_CLAMP_RANGE<double>( slats, 0.0, 1.0 ); } void FGControls::move_slats( double amt ) { slats += amt; - CLAMP( &slats, 0.0, 1.0 ); + SG_CLAMP_RANGE<double>( slats, 0.0, 1.0 ); } void FGControls::set_BLC( bool val ) { - BLC = val; + BLC = val; } void FGControls::set_spoilers( double pos ) { spoilers = pos; - CLAMP( &spoilers, 0.0, 1.0 ); + SG_CLAMP_RANGE<double>( spoilers, 0.0, 1.0 ); } void FGControls::move_spoilers( double amt ) { spoilers += amt; - CLAMP( &spoilers, 0.0, 1.0 ); + SG_CLAMP_RANGE<double>( spoilers, 0.0, 1.0 ); } void FGControls::set_speedbrake( double pos ) { speedbrake = pos; - CLAMP( &speedbrake, 0.0, 1.0 ); + SG_CLAMP_RANGE<double>( speedbrake, 0.0, 1.0 ); } void FGControls::move_speedbrake( double amt ) { speedbrake += amt; - CLAMP( &speedbrake, 0.0, 1.0 ); + SG_CLAMP_RANGE<double>( speedbrake, 0.0, 1.0 ); } void FGControls::set_wing_sweep( double pos ) { wing_sweep = pos; - CLAMP( &wing_sweep, 0.0, 1.0 ); + SG_CLAMP_RANGE<double>( wing_sweep, 0.0, 1.0 ); } void FGControls::move_wing_sweep( double amt ) { wing_sweep += amt; - CLAMP( &wing_sweep, 0.0, 1.0 ); + SG_CLAMP_RANGE<double>( wing_sweep, 0.0, 1.0 ); } void FGControls::set_wing_fold( bool val ) { - wing_fold = val; + wing_fold = val; } void FGControls::set_drag_chute( bool val ) { - drag_chute = val; + drag_chute = val; } void FGControls::set_throttle_idle( bool val ) { - throttle_idle = val; + throttle_idle = val; } void FGControls::set_throttle( int engine, double pos ) { - if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - throttle[i] = pos; - CLAMP( &throttle[i], 0.0, 1.0 ); + if ( engine == ALL_ENGINES ) { + for ( int i = 0; i < MAX_ENGINES; i++ ) { + throttle[i] = pos; + SG_CLAMP_RANGE<double>( throttle[i], 0.0, 1.0 ); + } + } else { + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + throttle[engine] = pos; + SG_CLAMP_RANGE<double>( throttle[engine], 0.0, 1.0 ); + } } - } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - throttle[engine] = pos; - CLAMP( &throttle[engine], 0.0, 1.0 ); - } - } } void FGControls::move_throttle( int engine, double amt ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - throttle[i] += amt; - CLAMP( &throttle[i], 0.0, 1.0 ); - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + throttle[i] += amt; + SG_CLAMP_RANGE<double>( throttle[i], 0.0, 1.0 ); + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - throttle[engine] += amt; - CLAMP( &throttle[engine], 0.0, 1.0 ); - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + throttle[engine] += amt; + SG_CLAMP_RANGE<double>( throttle[engine], 0.0, 1.0 ); + } } } @@ -1303,13 +875,13 @@ void FGControls::set_starter( int engine, bool flag ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - starter[i] = flag; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + starter[i] = flag; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - starter[engine] = flag; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + starter[engine] = flag; + } } } @@ -1317,13 +889,13 @@ void FGControls::set_fuel_pump( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - fuel_pump[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + fuel_pump[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - fuel_pump[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + fuel_pump[engine] = val; + } } } @@ -1331,13 +903,13 @@ void FGControls::set_fire_switch( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - fire_switch[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + fire_switch[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - fire_switch[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + fire_switch[engine] = val; + } } } @@ -1345,13 +917,13 @@ void FGControls::set_fire_bottle_discharge( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - fire_bottle_discharge[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + fire_bottle_discharge[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - fire_bottle_discharge[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + fire_bottle_discharge[engine] = val; + } } } @@ -1359,13 +931,13 @@ void FGControls::set_cutoff( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - cutoff[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + cutoff[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - cutoff[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + cutoff[engine] = val; + } } } @@ -1373,17 +945,17 @@ void FGControls::set_feed_tank( int engine, int tank ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - feed_tank[i] = tank; - CLAMP( &feed_tank[i], -1, 4 ); - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + feed_tank[i] = tank; + SG_CLAMP_RANGE<int>( feed_tank[i], -1, 4 ); + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - feed_tank[engine] = tank; - CLAMP( &feed_tank[engine], -1, 4 ); - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + feed_tank[engine] = tank; + SG_CLAMP_RANGE<int>( feed_tank[engine], -1, 4 ); + } } - // feed_tank[engine] = engine; + // feed_tank[engine] = engine; } @@ -1391,15 +963,15 @@ void FGControls::set_mixture( int engine, double pos ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - mixture[i] = pos; - CLAMP( &mixture[i], 0.0, 1.0 ); - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + mixture[i] = pos; + SG_CLAMP_RANGE<double>( mixture[i], 0.0, 1.0 ); + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - mixture[engine] = pos; - CLAMP( &mixture[engine], 0.0, 1.0 ); - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + mixture[engine] = pos; + SG_CLAMP_RANGE<double>( mixture[engine], 0.0, 1.0 ); + } } } @@ -1407,15 +979,15 @@ void FGControls::move_mixture( int engine, double amt ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - mixture[i] += amt; - CLAMP( &mixture[i], 0.0, 1.0 ); - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + mixture[i] += amt; + SG_CLAMP_RANGE<double>( mixture[i], 0.0, 1.0 ); + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - mixture[engine] += amt; - CLAMP( &mixture[engine], 0.0, 1.0 ); - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + mixture[engine] += amt; + SG_CLAMP_RANGE<double>( mixture[engine], 0.0, 1.0 ); + } } } @@ -1423,15 +995,15 @@ void FGControls::set_prop_advance( int engine, double pos ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - prop_advance[i] = pos; - CLAMP( &prop_advance[i], 0.0, 1.0 ); - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + prop_advance[i] = pos; + SG_CLAMP_RANGE<double>( prop_advance[i], 0.0, 1.0 ); + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - prop_advance[engine] = pos; - CLAMP( &prop_advance[engine], 0.0, 1.0 ); - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + prop_advance[engine] = pos; + SG_CLAMP_RANGE<double>( prop_advance[engine], 0.0, 1.0 ); + } } } @@ -1439,15 +1011,15 @@ void FGControls::move_prop_advance( int engine, double amt ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - prop_advance[i] += amt; - CLAMP( &prop_advance[i], 0.0, 1.0 ); - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + prop_advance[i] += amt; + SG_CLAMP_RANGE<double>( prop_advance[i], 0.0, 1.0 ); + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - prop_advance[engine] += amt; - CLAMP( &prop_advance[engine], 0.0, 1.0 ); - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + prop_advance[engine] += amt; + SG_CLAMP_RANGE<double>( prop_advance[engine], 0.0, 1.0 ); + } } } @@ -1455,15 +1027,15 @@ void FGControls::set_magnetos( int engine, int pos ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - magnetos[i] = pos; - CLAMP( &magnetos[i], 0, 3 ); - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + magnetos[i] = pos; + SG_CLAMP_RANGE<int>( magnetos[i], 0, 3 ); + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - magnetos[engine] = pos; - CLAMP( &magnetos[engine], 0, 3 ); - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + magnetos[engine] = pos; + SG_CLAMP_RANGE<int>( magnetos[engine], 0, 3 ); + } } } @@ -1471,15 +1043,15 @@ void FGControls::move_magnetos( int engine, int amt ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - magnetos[i] += amt; - CLAMP( &magnetos[i], 0, 3 ); - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + magnetos[i] += amt; + SG_CLAMP_RANGE<int>( magnetos[i], 0, 3 ); + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - magnetos[engine] += amt; - CLAMP( &magnetos[engine], 0, 3 ); - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + magnetos[engine] += amt; + SG_CLAMP_RANGE<int>( magnetos[engine], 0, 3 ); + } } } @@ -1487,13 +1059,13 @@ void FGControls::set_nitrous_injection( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - nitrous_injection[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + nitrous_injection[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - nitrous_injection[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + nitrous_injection[engine] = val; + } } } @@ -1502,15 +1074,15 @@ void FGControls::set_cowl_flaps_norm( int engine, double pos ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - cowl_flaps_norm[i] = pos; - CLAMP( &cowl_flaps_norm[i], 0.0, 1.0 ); - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + cowl_flaps_norm[i] = pos; + SG_CLAMP_RANGE<double>( cowl_flaps_norm[i], 0.0, 1.0 ); + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - cowl_flaps_norm[engine] = pos; - CLAMP( &cowl_flaps_norm[engine], 0.0, 1.0 ); - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + cowl_flaps_norm[engine] = pos; + SG_CLAMP_RANGE<double>( cowl_flaps_norm[engine], 0.0, 1.0 ); + } } } @@ -1518,15 +1090,15 @@ void FGControls::move_cowl_flaps_norm( int engine, double amt ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - cowl_flaps_norm[i] += amt; - CLAMP( &cowl_flaps_norm[i], 0.0, 1.0 ); - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + cowl_flaps_norm[i] += amt; + SG_CLAMP_RANGE<double>( cowl_flaps_norm[i], 0.0, 1.0 ); + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - cowl_flaps_norm[engine] += amt; - CLAMP( &cowl_flaps_norm[engine], 0.0, 1.0 ); - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + cowl_flaps_norm[engine] += amt; + SG_CLAMP_RANGE<double>( cowl_flaps_norm[engine], 0.0, 1.0 ); + } } } @@ -1534,13 +1106,13 @@ void FGControls::set_feather( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - feather[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + feather[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - feather[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + feather[engine] = val; + } } } @@ -1548,15 +1120,15 @@ void FGControls::set_ignition( int engine, int pos ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - ignition[i] = pos; - CLAMP( &ignition[i], 0, 3 ); - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + ignition[i] = pos; + SG_CLAMP_RANGE<int>( ignition[i], 0, 3 ); + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - ignition[engine] = pos; - CLAMP( &ignition[engine], 0, 3 ); - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + ignition[engine] = pos; + SG_CLAMP_RANGE<int>( ignition[engine], 0, 3 ); + } } } @@ -1564,13 +1136,13 @@ void FGControls::set_augmentation( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - augmentation[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + augmentation[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - augmentation[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + augmentation[engine] = val; + } } } @@ -1578,13 +1150,13 @@ void FGControls::set_reverser( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - reverser[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + reverser[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - reverser[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + reverser[engine] = val; + } } } @@ -1592,13 +1164,13 @@ void FGControls::set_water_injection( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - water_injection[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + water_injection[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - water_injection[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + water_injection[engine] = val; + } } } @@ -1606,15 +1178,15 @@ void FGControls::set_condition( int engine, double val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - condition[i] = val; - CLAMP( &condition[i], 0.0, 1.0 ); - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + condition[i] = val; + SG_CLAMP_RANGE<double>( condition[i], 0.0, 1.0 ); + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - condition[engine] = val; - CLAMP( &condition[engine], 0.0, 1.0 ); - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + condition[engine] = val; + SG_CLAMP_RANGE<double>( condition[engine], 0.0, 1.0 ); + } } } @@ -1629,13 +1201,13 @@ void FGControls::set_fuel_selector( int tank, bool pos ) { if ( tank == ALL_TANKS ) { - for ( int i = 0; i < MAX_TANKS; i++ ) { - fuel_selector[i] = pos; - } + for ( int i = 0; i < MAX_TANKS; i++ ) { + fuel_selector[i] = pos; + } } else { - if ( (tank >= 0) && (tank < MAX_TANKS) ) { - fuel_selector[tank] = pos; - } + if ( (tank >= 0) && (tank < MAX_TANKS) ) { + fuel_selector[tank] = pos; + } } } @@ -1643,13 +1215,13 @@ void FGControls::set_to_engine( int tank, int engine ) { if ( tank == ALL_TANKS ) { - for ( int i = 0; i < MAX_TANKS; i++ ) { - to_engine[i] = engine; - } + for ( int i = 0; i < MAX_TANKS; i++ ) { + to_engine[i] = engine; + } } else { - if ( (tank >= 0) && (tank < MAX_TANKS) ) { - to_engine[tank] = engine; - } + if ( (tank >= 0) && (tank < MAX_TANKS) ) { + to_engine[tank] = engine; + } } } @@ -1657,13 +1229,13 @@ void FGControls::set_to_tank( int tank, int dest_tank ) { if ( tank == ALL_TANKS ) { - for ( int i = 0; i < MAX_TANKS; i++ ) { - to_tank[i] = dest_tank; - } + for ( int i = 0; i < MAX_TANKS; i++ ) { + to_tank[i] = dest_tank; + } } else { - if ( (tank >= 0) && (tank < MAX_TANKS) ) { - to_tank[tank] = dest_tank; - } + if ( (tank >= 0) && (tank < MAX_TANKS) ) { + to_tank[tank] = dest_tank; + } } } @@ -1671,13 +1243,13 @@ void FGControls::set_boost_pump( int index, bool val ) { if ( index == -1 ) { - for ( int i = 0; i < (MAX_TANKS * MAX_BOOSTPUMPS); i++ ) { - boost_pump[i] = val; - } + for ( int i = 0; i < (MAX_TANKS * MAX_BOOSTPUMPS); i++ ) { + boost_pump[i] = val; + } } else { - if ( (index >= 0) && (index < (MAX_TANKS * MAX_BOOSTPUMPS)) ) { - boost_pump[index] = val; - } + if ( (index >= 0) && (index < (MAX_TANKS * MAX_BOOSTPUMPS)) ) { + boost_pump[index] = val; + } } } @@ -1686,56 +1258,56 @@ void FGControls::set_brake_left( double pos ) { brake_left = pos; - CLAMP(&brake_left, 0.0, 1.0); + SG_CLAMP_RANGE<double>(brake_left, 0.0, 1.0); } void FGControls::move_brake_left( double amt ) { brake_left += amt; - CLAMP( &brake_left, 0.0, 1.0 ); + SG_CLAMP_RANGE<double>( brake_left, 0.0, 1.0 ); } void FGControls::set_brake_right( double pos ) { brake_right = pos; - CLAMP(&brake_right, 0.0, 1.0); + SG_CLAMP_RANGE<double>(brake_right, 0.0, 1.0); } void FGControls::move_brake_right( double amt ) { brake_right += amt; - CLAMP( &brake_right, 0.0, 1.0 ); + SG_CLAMP_RANGE<double>( brake_right, 0.0, 1.0 ); } void FGControls::set_copilot_brake_left( double pos ) { copilot_brake_left = pos; - CLAMP(&brake_left, 0.0, 1.0); + SG_CLAMP_RANGE<double>(brake_left, 0.0, 1.0); } void FGControls::set_copilot_brake_right( double pos ) { copilot_brake_right = pos; - CLAMP(&brake_right, 0.0, 1.0); + SG_CLAMP_RANGE<double>(brake_right, 0.0, 1.0); } void FGControls::set_brake_parking( double pos ) { brake_parking = pos; - CLAMP(&brake_parking, 0.0, 1.0); + SG_CLAMP_RANGE<double>(brake_parking, 0.0, 1.0); } void FGControls::set_steering( double angle ) { steering = angle; - CLAMP(&steering, -80.0, 80.0); + SG_CLAMP_RANGE<double>(steering, -80.0, 80.0); } void @@ -1748,43 +1320,43 @@ void FGControls::move_steering( double angle ) { steering += angle; - CLAMP(&steering, -80.0, 80.0); + SG_CLAMP_RANGE<double>(steering, -80.0, 80.0); } void FGControls::set_gear_down( bool gear ) { - gear_down = gear; + gear_down = gear; } void FGControls::set_antiskid( bool state ) { - antiskid = state; + antiskid = state; } void FGControls::set_tailhook( bool state ) { - tailhook = state; + tailhook = state; } void FGControls::set_launchbar( bool state ) { - launchbar = state; + launchbar = state; } void FGControls::set_catapult_launch_cmd( bool state ) { - catapult_launch_cmd = state; + catapult_launch_cmd = state; } void FGControls::set_tailwheel_lock( bool state ) { - tailwheel_lock = state; + tailwheel_lock = state; } @@ -1792,51 +1364,51 @@ void FGControls::set_alternate_extension( int wheel, bool val ) { if ( wheel == ALL_WHEELS ) { - for ( int i = 0; i < MAX_WHEELS; i++ ) { - alternate_extension[i] = val; - } + for ( int i = 0; i < MAX_WHEELS; i++ ) { + alternate_extension[i] = val; + } } else { - if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) { - alternate_extension[wheel] = val; - } + if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) { + alternate_extension[wheel] = val; + } } } void FGControls::set_wing_heat( bool state ) { - wing_heat = state; + wing_heat = state; } void FGControls::set_pitot_heat( bool state ) { - pitot_heat = state; + pitot_heat = state; } void FGControls::set_wiper( int state ) { - wiper = state; + wiper = state; } void FGControls::set_window_heat( bool state ) { - window_heat = state; + window_heat = state; } void FGControls::set_carb_heat( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - carb_heat[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + carb_heat[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - carb_heat[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + carb_heat[engine] = val; + } } } @@ -1844,13 +1416,13 @@ void FGControls::set_inlet_heat( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - inlet_heat[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + inlet_heat[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - inlet_heat[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + inlet_heat[engine] = val; + } } } @@ -1858,13 +1430,13 @@ void FGControls::set_engine_pump( int system, bool val ) { if ( system == ALL_HYD_SYSTEMS ) { - for ( int i = 0; i < MAX_HYD_SYSTEMS; i++ ) { - engine_pump[i] = val; - } + for ( int i = 0; i < MAX_HYD_SYSTEMS; i++ ) { + engine_pump[i] = val; + } } else { - if ( (system >= 0) && (system < MAX_HYD_SYSTEMS) ) { - engine_pump[system] = val; - } + if ( (system >= 0) && (system < MAX_HYD_SYSTEMS) ) { + engine_pump[system] = val; + } } } @@ -1872,45 +1444,45 @@ void FGControls::set_electric_pump( int system, bool val ) { if ( system == ALL_HYD_SYSTEMS ) { - for ( int i = 0; i < MAX_HYD_SYSTEMS; i++ ) { - electric_pump[i] = val; - } + for ( int i = 0; i < MAX_HYD_SYSTEMS; i++ ) { + electric_pump[i] = val; + } } else { - if ( (system >= 0) && (system < MAX_HYD_SYSTEMS) ) { - electric_pump[system] = val; - } + if ( (system >= 0) && (system < MAX_HYD_SYSTEMS) ) { + electric_pump[system] = val; + } } } void FGControls::set_battery_switch( bool state ) { - battery_switch = state; + battery_switch = state; } void FGControls::set_external_power( bool state ) { - external_power = state; + external_power = state; } void FGControls::set_APU_generator( bool state ) { - APU_generator = state; + APU_generator = state; } void FGControls::set_generator_breaker( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - generator_breaker[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + generator_breaker[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - generator_breaker[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + generator_breaker[engine] = val; + } } } @@ -1918,192 +1490,192 @@ void FGControls::set_bus_tie( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - bus_tie[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + bus_tie[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - bus_tie[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + bus_tie[engine] = val; + } } } void FGControls::set_APU_bleed( bool state ) { - APU_bleed = state; + APU_bleed = state; } void FGControls::set_engine_bleed( int engine, bool val ) { if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - engine_bleed[i] = val; - } + for ( int i = 0; i < MAX_ENGINES; i++ ) { + engine_bleed[i] = val; + } } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - engine_bleed[engine] = val; - } + if ( (engine >= 0) && (engine < MAX_ENGINES) ) { + engine_bleed[engine] = val; + } } } void FGControls::set_mode( int new_mode ) { - mode = new_mode; + mode = new_mode; } void FGControls::set_outflow_valve( double pos ) { - outflow_valve = pos; - CLAMP( &outflow_valve, 0.0, 1.0 ); + outflow_valve = pos; + SG_CLAMP_RANGE<double>( outflow_valve, 0.0, 1.0 ); } void FGControls::move_outflow_valve( double amt ) { - outflow_valve += amt; - CLAMP( &outflow_valve, 0.0, 1.0 ); + outflow_valve += amt; + SG_CLAMP_RANGE<double>( outflow_valve, 0.0, 1.0 ); } void FGControls::set_dump( bool state ) { - dump = state; + dump = state; } void FGControls::set_pack_on( int pack, bool val ) { if ( pack == ALL_PACKS ) { - for ( int i = 0; i < MAX_PACKS; i++ ) { - pack_on[i] = val; - } + for ( int i = 0; i < MAX_PACKS; i++ ) { + pack_on[i] = val; + } } else { - if ( (pack >= 0) && (pack < MAX_PACKS) ) { - pack_on[pack] = val; - } + if ( (pack >= 0) && (pack < MAX_PACKS) ) { + pack_on[pack] = val; + } } } void FGControls::set_landing_lights( bool state ) { - landing_lights = state; + landing_lights = state; } void FGControls::set_turn_off_lights( bool state ) { - turn_off_lights = state; + turn_off_lights = state; } void FGControls::set_taxi_light( bool state ) { - taxi_light = state; + taxi_light = state; } void FGControls::set_logo_lights( bool state ) { - logo_lights = state; + logo_lights = state; } void FGControls::set_nav_lights( bool state ) { - nav_lights = state; + nav_lights = state; } void FGControls::set_beacon( bool state ) { - beacon = state; + beacon = state; } void FGControls::set_strobe( bool state ) { - strobe = state; + strobe = state; } void FGControls::set_panel_norm( double intensity ) { - panel_norm = intensity; - CLAMP( &panel_norm, 0.0, 1.0 ); + panel_norm = intensity; + SG_CLAMP_RANGE<double>( panel_norm, 0.0, 1.0 ); } void FGControls::move_panel_norm( double amt ) { - panel_norm += amt; - CLAMP( &panel_norm, 0.0, 1.0 ); + panel_norm += amt; + SG_CLAMP_RANGE<double>( panel_norm, 0.0, 1.0 ); } void FGControls::set_instruments_norm( double intensity ) { - instruments_norm = intensity; - CLAMP( &instruments_norm, 0.0, 1.0 ); + instruments_norm = intensity; + SG_CLAMP_RANGE<double>( instruments_norm, 0.0, 1.0 ); } void FGControls::move_instruments_norm( double amt ) { - instruments_norm += amt; - CLAMP( &instruments_norm, 0.0, 1.0 ); + instruments_norm += amt; + SG_CLAMP_RANGE<double>( instruments_norm, 0.0, 1.0 ); } void FGControls::set_dome_norm( double intensity ) { - dome_norm = intensity; - CLAMP( &dome_norm, 0.0, 1.0 ); + dome_norm = intensity; + SG_CLAMP_RANGE<double>( dome_norm, 0.0, 1.0 ); } void FGControls::move_dome_norm( double amt ) { - dome_norm += amt; - CLAMP( &dome_norm, 0.0, 1.0 ); + dome_norm += amt; + SG_CLAMP_RANGE<double>( dome_norm, 0.0, 1.0 ); } void FGControls::set_master_arm( bool val ) { - master_arm = val; + master_arm = val; } void FGControls::set_station_select( int station ) { - station_select = station; - CLAMP( &station_select, 0, MAX_STATIONS ); + station_select = station; + SG_CLAMP_RANGE<int>( station_select, 0, MAX_STATIONS ); } void FGControls::set_release_ALL( bool val ) { - release_ALL = val; + release_ALL = val; } void FGControls::set_stick_size( int station, int size ) { if ( station == ALL_STATIONS ) { - for ( int i = 0; i < MAX_STATIONS; i++ ) { - stick_size[i] = size; - CLAMP( &stick_size[i], 1, 20 ); - } + for ( int i = 0; i < MAX_STATIONS; i++ ) { + stick_size[i] = size; + SG_CLAMP_RANGE<int>( stick_size[i], 1, 20 ); + } } else { - if ( (station >= 0) && (station < MAX_STATIONS) ) { - stick_size[station] = size; - CLAMP( &stick_size[station], 1, 20 ); - } + if ( (station >= 0) && (station < MAX_STATIONS) ) { + stick_size[station] = size; + SG_CLAMP_RANGE<int>( stick_size[station], 1, 20 ); + } } } @@ -2111,13 +1683,13 @@ void FGControls::set_release_stick( int station, bool val ) { if ( station == ALL_STATIONS ) { - for ( int i = 0; i < MAX_STATIONS; i++ ) { - release_stick[i] = val; - } + for ( int i = 0; i < MAX_STATIONS; i++ ) { + release_stick[i] = val; + } } else { - if ( (station >= 0) && (station < MAX_STATIONS) ) { - release_stick[station] = val; - } + if ( (station >= 0) && (station < MAX_STATIONS) ) { + release_stick[station] = val; + } } } @@ -2125,13 +1697,13 @@ void FGControls::set_release_all( int station, bool val ) { if ( station == ALL_STATIONS ) { - for ( int i = 0; i < MAX_STATIONS; i++ ) { - release_all[i] = val; - } + for ( int i = 0; i < MAX_STATIONS; i++ ) { + release_all[i] = val; + } } else { - if ( (station >= 0) && (station < MAX_STATIONS) ) { - release_all[station] = val; - } + if ( (station >= 0) && (station < MAX_STATIONS) ) { + release_all[station] = val; + } } } @@ -2139,42 +1711,42 @@ void FGControls::set_jettison_all( int station, bool val ) { if ( station == ALL_STATIONS ) { - for ( int i = 0; i < MAX_STATIONS; i++ ) { - jettison_all[i] = val; - } + for ( int i = 0; i < MAX_STATIONS; i++ ) { + jettison_all[i] = val; + } } else { - if ( (station >= 0) && (station < MAX_STATIONS) ) { - jettison_all[station] = val; - } + if ( (station >= 0) && (station < MAX_STATIONS) ) { + jettison_all[station] = val; + } } } void FGControls::set_vertical_adjust( double pos ) { - vertical_adjust = pos; - CLAMP( &vertical_adjust, -1.0, 1.0 ); + vertical_adjust = pos; + SG_CLAMP_RANGE<double>( vertical_adjust, -1.0, 1.0 ); } void FGControls::move_vertical_adjust( double amt ) { - vertical_adjust += amt; - CLAMP( &vertical_adjust, -1.0, 1.0 ); + vertical_adjust += amt; + SG_CLAMP_RANGE<double>( vertical_adjust, -1.0, 1.0 ); } void FGControls::set_fore_aft_adjust( double pos ) { - fore_aft_adjust = pos; - CLAMP( &fore_aft_adjust, -1.0, 1.0 ); + fore_aft_adjust = pos; + SG_CLAMP_RANGE<double>( fore_aft_adjust, -1.0, 1.0 ); } void FGControls::move_fore_aft_adjust( double amt ) { - fore_aft_adjust += amt; - CLAMP( &fore_aft_adjust, -1.0, 1.0 ); + fore_aft_adjust += amt; + SG_CLAMP_RANGE<double>( fore_aft_adjust, -1.0, 1.0 ); } void @@ -2187,7 +1759,7 @@ FGControls::set_ejection_seat( int which_seat, bool val ) } else { if ( (which_seat >= 0) && (which_seat <= MAX_EJECTION_SEATS) ) { if ( eseat_status[which_seat] == SEAT_SAFED || - eseat_status[which_seat] == SEAT_FAIL ) + eseat_status[which_seat] == SEAT_FAIL ) { // we can never eject if SEAT_SAFED or SEAT_FAIL val = false; @@ -2215,143 +1787,143 @@ FGControls::set_eseat_status( int which_seat, int val ) void FGControls::set_cmd_selector_valve( int val ) { - cmd_selector_valve = val; + cmd_selector_valve = val; } void FGControls::set_off_start_run( int pos ) { - off_start_run = pos; - CLAMP( &off_start_run, 0, 3 ); + off_start_run = pos; + SG_CLAMP_RANGE<int>( off_start_run, 0, 3 ); } void FGControls::set_APU_fire_switch( bool val ) { - APU_fire_switch = val; + APU_fire_switch = val; } void FGControls::set_autothrottle_arm( bool val ) { - autothrottle_arm = val; + autothrottle_arm = val; } void FGControls::set_autothrottle_engage( bool val ) { - autothrottle_engage = val; + autothrottle_engage = val; } void FGControls::set_heading_select( double heading ) { - heading_select = heading; - CLAMP( &heading_select, 0.0, 360.0 ); + heading_select = heading; + SG_CLAMP_RANGE<double>( heading_select, 0.0, 360.0 ); } void FGControls::move_heading_select( double amt ) { - heading_select += amt; - CLAMP( &heading_select, 0.0, 360.0 ); + heading_select += amt; + SG_CLAMP_RANGE<double>( heading_select, 0.0, 360.0 ); } void FGControls::set_altitude_select( double altitude ) { - altitude_select = altitude; - CLAMP( &altitude_select, -1000.0, 100000.0 ); + altitude_select = altitude; + SG_CLAMP_RANGE<double>( altitude_select, -1000.0, 100000.0 ); } void FGControls::move_altitude_select( double amt ) { - altitude_select += amt; - CLAMP( &altitude_select, -1000.0, 100000.0 ); + altitude_select += amt; + SG_CLAMP_RANGE<double>( altitude_select, -1000.0, 100000.0 ); } void FGControls::set_bank_angle_select( double angle ) { - bank_angle_select = angle; - CLAMP( &bank_angle_select, 10.0, 30.0 ); + bank_angle_select = angle; + SG_CLAMP_RANGE<double>( bank_angle_select, 10.0, 30.0 ); } void FGControls::move_bank_angle_select( double amt ) { - bank_angle_select += amt; - CLAMP( &bank_angle_select, 10.0, 30.0 ); + bank_angle_select += amt; + SG_CLAMP_RANGE<double>( bank_angle_select, 10.0, 30.0 ); } void FGControls::set_vertical_speed_select( double speed ) { - vertical_speed_select = speed; - CLAMP( &vertical_speed_select, -3000.0, 4000.0 ); + vertical_speed_select = speed; + SG_CLAMP_RANGE<double>( vertical_speed_select, -3000.0, 4000.0 ); } void FGControls::move_vertical_speed_select( double amt ) { - vertical_speed_select += amt; - CLAMP( &vertical_speed_select, -3000.0, 4000.0 ); + vertical_speed_select += amt; + SG_CLAMP_RANGE<double>( vertical_speed_select, -3000.0, 4000.0 ); } void FGControls::set_speed_select( double speed ) { - speed_select = speed; - CLAMP( &speed_select, 60.0, 400.0 ); + speed_select = speed; + SG_CLAMP_RANGE<double>( speed_select, 60.0, 400.0 ); } void FGControls::move_speed_select( double amt ) { - speed_select += amt; - CLAMP( &speed_select, 60.0, 400.0 ); + speed_select += amt; + SG_CLAMP_RANGE<double>( speed_select, 60.0, 400.0 ); } void FGControls::set_mach_select( double mach ) { - mach_select = mach; - CLAMP( &mach_select, 0.4, 4.0 ); + mach_select = mach; + SG_CLAMP_RANGE<double>( mach_select, 0.4, 4.0 ); } void FGControls::move_mach_select( double amt ) { - mach_select += amt; - CLAMP( &mach_select, 0.4, 4.0 ); + mach_select += amt; + SG_CLAMP_RANGE<double>( mach_select, 0.4, 4.0 ); } void FGControls::set_vertical_mode( int mode ) { - vertical_mode = mode; - CLAMP( &vertical_mode, 0, 4 ); + vertical_mode = mode; + SG_CLAMP_RANGE<int>( vertical_mode, 0, 4 ); } void FGControls::set_lateral_mode( int mode ) { - lateral_mode = mode; - CLAMP( &lateral_mode, 0, 4 ); + lateral_mode = mode; + SG_CLAMP_RANGE<int>( lateral_mode, 0, 4 ); } void FGControls::set_autopilot_engage( int ap, bool val ) { if ( ap == ALL_AUTOPILOTS ) { - for ( int i = 0; i < MAX_AUTOPILOTS; i++ ) { - autopilot_engage[i] = val; - } + for ( int i = 0; i < MAX_AUTOPILOTS; i++ ) { + autopilot_engage[i] = val; + } } else { - if ( (ap >= 0) && (ap < MAX_AUTOPILOTS) ) { - autopilot_engage[ap] = val; - } + if ( (ap >= 0) && (ap < MAX_AUTOPILOTS) ) { + autopilot_engage[ap] = val; + } } } diff --git a/src/Aircraft/controls.hxx b/src/Aircraft/controls.hxx index d9ea286f7..a738bc27f 100644 --- a/src/Aircraft/controls.hxx +++ b/src/Aircraft/controls.hxx @@ -25,6 +25,7 @@ #define _CONTROLS_HXX #include <simgear/structure/subsystem_mgr.hxx> +#include <simgear/props/tiedpropertylist.hxx> // Define a structure containing the control parameters @@ -34,65 +35,65 @@ class FGControls : public SGSubsystem public: enum { - ALL_ENGINES = -1, - MAX_ENGINES = 12 + ALL_ENGINES = -1, + MAX_ENGINES = 12 }; enum { - ALL_WHEELS = -1, - MAX_WHEELS = 3 + ALL_WHEELS = -1, + MAX_WHEELS = 3 }; enum { - ALL_TANKS = -1, - MAX_TANKS = 8 + ALL_TANKS = -1, + MAX_TANKS = 8 }; enum { - ALL_BOOSTPUMPS = -1, - MAX_BOOSTPUMPS = 2 + ALL_BOOSTPUMPS = -1, + MAX_BOOSTPUMPS = 2 }; enum { - ALL_HYD_SYSTEMS = -1, - MAX_HYD_SYSTEMS = 4 + ALL_HYD_SYSTEMS = -1, + MAX_HYD_SYSTEMS = 4 }; enum { - ALL_PACKS = -1, - MAX_PACKS = 4 + ALL_PACKS = -1, + MAX_PACKS = 4 }; enum { - ALL_LIGHTS = -1, - MAX_LIGHTS = 4 + ALL_LIGHTS = -1, + MAX_LIGHTS = 4 }; enum { - ALL_STATIONS = -1, - MAX_STATIONS = 12 + ALL_STATIONS = -1, + MAX_STATIONS = 12 }; enum { - ALL_AUTOPILOTS = -1, - MAX_AUTOPILOTS = 3 + ALL_AUTOPILOTS = -1, + MAX_AUTOPILOTS = 3 }; enum { - ALL_EJECTION_SEATS = -1, - MAX_EJECTION_SEATS = 10 + ALL_EJECTION_SEATS = -1, + MAX_EJECTION_SEATS = 10 }; enum { - SEAT_SAFED = -1, - SEAT_ARMED = 0, - SEAT_FAIL = 1 + SEAT_SAFED = -1, + SEAT_ARMED = 0, + SEAT_FAIL = 1 }; enum { - CMD_SEL_NORM = -1, - CMD_SEL_AFT = 0, - CMD_SEL_SOLO = 1 + CMD_SEL_NORM = -1, + CMD_SEL_AFT = 0, + CMD_SEL_SOLO = 1 }; private: @@ -252,7 +253,7 @@ private: SGPropertyNode_ptr auto_coordination; - + simgear::TiedPropertyList _tiedProperties; public: FGControls(); @@ -266,7 +267,7 @@ public: // Reset function void reset_all(void); - + // Query functions // controls/flight/ inline double get_aileron() const { return aileron; } @@ -298,7 +299,7 @@ public: inline bool get_cutoff(int engine) const { return cutoff[engine]; } inline double get_mixture(int engine) const { return mixture[engine]; } inline double get_prop_advance(int engine) const { - return prop_advance[engine]; + return prop_advance[engine]; } inline int get_magnetos(int engine) const { return magnetos[engine]; } inline int get_feed_tank(int engine) const { return feed_tank[engine]; } From ddd04d91ca2b8bcabd9a3869364a3edd517c886d Mon Sep 17 00:00:00 2001 From: Torsten Dreyer <Torsten@t3r.de> Date: Mon, 14 Feb 2011 20:45:59 +0100 Subject: [PATCH 10/10] TankProperties: don't allow negative values --- src/FDM/TankProperties.cxx | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/FDM/TankProperties.cxx b/src/FDM/TankProperties.cxx index cb4f82c98..d42871a61 100644 --- a/src/FDM/TankProperties.cxx +++ b/src/FDM/TankProperties.cxx @@ -26,6 +26,7 @@ #include "TankProperties.hxx" #include <simgear/math/SGMath.hxx> +#include <simgear/sg_inlines.h> #include <Main/fg_props.hxx> static const double LBS_PER_KG = 2.20462262; @@ -74,7 +75,7 @@ double TankProperties::getContent_kg() const void TankProperties::setContent_kg( double value ) { - _content_kg = value; + _content_kg = SG_MAX2<double>(value, 0.0); } double TankProperties::getDensity_kgpm3() const @@ -84,7 +85,7 @@ double TankProperties::getDensity_kgpm3() const void TankProperties::setDensity_kgpm3( double value ) { - _density_kgpm3 = value; + _density_kgpm3 = SG_MAX2<double>(value, 0.0); } double TankProperties::getDensity_ppg() const @@ -94,7 +95,7 @@ double TankProperties::getDensity_ppg() const void TankProperties::setDensity_ppg( double value ) { - _density_kgpm3 = value * KG_PER_LBS / M3_PER_USGAL; + _density_kgpm3 = SG_MAX2<double>(value * KG_PER_LBS / M3_PER_USGAL, 0.0); } double TankProperties::getContent_lbs() const @@ -104,7 +105,7 @@ double TankProperties::getContent_lbs() const void TankProperties::setContent_lbs( double value ) { - _content_kg = value * KG_PER_LBS; + _content_kg = SG_MAX2<double>(value * KG_PER_LBS, 0.0); } double TankProperties::getContent_m3() const @@ -115,7 +116,7 @@ double TankProperties::getContent_m3() const void TankProperties::setContent_m3( double value ) { // ugly hack to allow setting of a volumetric content without having the density - _content_kg = value * (_density_kgpm3>0.0?_density_kgpm3:755.0); + _content_kg = SG_MAX2<double>(value * (_density_kgpm3>0.0?_density_kgpm3:755.0), 0.0); } double TankProperties::getContent_gal_us() const @@ -145,7 +146,7 @@ double TankProperties::getCapacity_m3() const void TankProperties::setCapacity_m3( double value ) { - _capacity_m3 = value; + _capacity_m3 = SG_MAX2<double>(value, 0.0); } double TankProperties::getCapacity_gal_us() const @@ -155,7 +156,7 @@ double TankProperties::getCapacity_gal_us() const void TankProperties::setCapacity_gal_us( double value ) { - _capacity_m3 = value * M3_PER_USGAL; + _capacity_m3 = SG_MAX2<double>(value * M3_PER_USGAL, 0.0); } double TankProperties::getCapacity_gal_imp() const @@ -165,7 +166,7 @@ double TankProperties::getCapacity_gal_imp() const void TankProperties::setCapacity_gal_imp( double value ) { - _capacity_m3 = value * M3_PER_IMPGAL; + _capacity_m3 = SG_MAX2<double>(value * M3_PER_IMPGAL, 0.0); } double TankProperties::getUnusable_m3() const @@ -175,7 +176,7 @@ double TankProperties::getUnusable_m3() const void TankProperties::setUnusable_m3( double value ) { - _unusable_m3 = value; + _unusable_m3 = SG_MAX2<double>(value, 0.0); } double TankProperties::getUnusable_gal_us() const @@ -185,7 +186,7 @@ double TankProperties::getUnusable_gal_us() const void TankProperties::setUnusable_gal_us( double value ) { - _unusable_m3 = value * M3_PER_USGAL; + _unusable_m3 = SG_MAX2<double>(value * M3_PER_USGAL, 0.0); } @@ -196,7 +197,7 @@ double TankProperties::getUnusable_gal_imp() const void TankProperties::setUnusable_gal_imp( double value ) { - _unusable_m3 = value * M3_PER_IMPGAL; + _unusable_m3 = SG_MAX2<double>(value * M3_PER_IMPGAL, 0.0); } double TankProperties::getContent_norm() const