]> git.mxchange.org Git - flightgear.git/commitdiff
initialize the heading-indicator/offset-deg in it's class
authorTorsten Dreyer <Torsten@t3r.de>
Wed, 1 Feb 2012 21:24:06 +0000 (22:24 +0100)
committerTorsten Dreyer <Torsten@t3r.de>
Wed, 1 Feb 2012 21:24:06 +0000 (22:24 +0100)
Don't initialize the offset in the main loop but in
the init method of the implementing class. This ensures
it gets initialized if you instantiate more than one
heading-indicator and does not initialize the property for
unsused heading-indicators (no more stray heading-indicator-fg
property anymore).

src/Instrumentation/heading_indicator.cxx
src/Instrumentation/heading_indicator_fg.cxx
src/Main/main.cxx

index e4b0c2438ddc27ff91fa678d0d8f3f57d1b1e15c..2cbbb9f2469b31e9fbf2dd39e318d24a17d8d3fa 100644 (file)
@@ -17,6 +17,7 @@
 #include <Main/fg_props.hxx>
 #include <Main/util.hxx>
 
+#include <simgear/magvar/magvar.hxx>
 
 HeadingIndicator::HeadingIndicator ( SGPropertyNode *node )
     :
@@ -37,7 +38,10 @@ HeadingIndicator::init ()
     branch = "/instrumentation/" + _name;
 
     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
-    _offset_node = node->getChild("offset-deg", 0, true);
+    if( NULL == (_offset_node = node->getChild("offset-deg", 0, false)) ) {
+      _offset_node = node->getChild("offset-deg", 0, true);
+      _offset_node->setDoubleValue( -globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES );
+    }
     _heading_in_node = fgGetNode("/orientation/heading-deg", true);
     _suction_node = fgGetNode(_suction.c_str(), true);
     _heading_out_node = node->getChild("indicated-heading-deg", 0, true);
index dfa099c51e6c4a9d1cb6a4224cf2244bd5364d17..a485f5cdc7adc1f5e69fcaf50faf5d88a245b715 100644 (file)
@@ -18,6 +18,8 @@
 #include <Main/fg_props.hxx>
 #include <Main/util.hxx>                           
 
+#include <simgear/magvar/magvar.hxx>
+
 using std::string;
 
 HeadingIndicatorFG::HeadingIndicatorFG ( SGPropertyNode *node )
@@ -60,7 +62,10 @@ HeadingIndicatorFG::init ()
        _heading_in_node = fgGetNode("/orientation/heading-deg", true);
 
     SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
-    _offset_node = node->getChild("offset-deg", 0, true);
+    if( NULL == (_offset_node = node->getChild("offset-deg", 0, false)) ) {
+      _offset_node = node->getChild("offset-deg", 0, true);
+      _offset_node->setDoubleValue( -globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES );
+    }
     _serviceable_node = node->getChild("serviceable", 0, true);
        _error_node = node->getChild("heading-bug-error-deg", 0, true);
        _nav1_error_node = node->getChild("nav1-course-error-deg", 0, true);
index b4948b259bec3ac57a88f52eec2fbdab4902b988..6e70ff89428033a5b4a3dbd1cbddd437c885ec3e 100644 (file)
@@ -387,9 +387,6 @@ static void fgIdleFunction ( void ) {
                                    fgGetDouble("/position/altitude-ft")
                                    * SG_FEET_TO_METER,
                                    globals->get_time_params()->getJD() );
-        double var = globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
-        fgSetDouble("/instrumentation/heading-indicator/offset-deg", -var);
-        fgSetDouble("/instrumentation/heading-indicator-fg/offset-deg", -var);
 
         fgSplashProgress("initializing subsystems");