]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/navradio.cxx
fix another crash at the poles
[flightgear.git] / src / Instrumentation / navradio.cxx
index 166060b75973cb7747f4627cd9ddce451e66c96e..073e28621429d085fdf99d366a31770e8f368e67 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <sstream>
 #include <cstring>
+#include <cstdio>
 
 #include <simgear/sg_inlines.h>
 #include <simgear/timing/sg_time.hxx>
@@ -34,6 +35,7 @@
 #include <simgear/structure/exception.hxx>
 #include <simgear/math/interpolater.hxx>
 #include <simgear/misc/strutils.hxx>
+#include <simgear/sound/sample_group.hxx>
 
 #include <Navaids/navrecord.hxx>
 #include <Sound/audioident.hxx>
@@ -96,13 +98,14 @@ SGPropertyNode_ptr createServiceableProp(SGPropertyNode* aParent,
   return n;  
 }
 
+static std::auto_ptr<SGInterpTable> static_terminalRangeInterp,
+  static_lowRangeInterp, static_highRangeInterp;
+
 // Constructor
 FGNavRadio::FGNavRadio(SGPropertyNode *node) :
-    term_tbl(NULL),
-    low_tbl(NULL),
-    high_tbl(NULL),
     _operable(false),
     play_count(0),
+    _nav_search(true),
     _last_freq(0.0),
     target_radial(0.0),
     effective_range(0.0),
@@ -127,18 +130,21 @@ FGNavRadio::FGNavRadio(SGPropertyNode *node) :
     _gsNeedleDeflectionNorm(0.0),
     _audioIdent(NULL)
 {
-    SGPath path( globals->get_fg_root() );
-    SGPath term = path;
-    term.append( "Navaids/range.term" );
-    SGPath low = path;
-    low.append( "Navaids/range.low" );
-    SGPath high = path;
-    high.append( "Navaids/range.high" );
-
-    term_tbl = new SGInterpTable( term.str() );
-    low_tbl = new SGInterpTable( low.str() );
-    high_tbl = new SGInterpTable( high.str() );
-
+    if (!static_terminalRangeInterp.get()) {
+    // one-time interpolator init
+      SGPath path( globals->get_fg_root() );
+      SGPath term = path;
+      term.append( "Navaids/range.term" );
+      SGPath low = path;
+      low.append( "Navaids/range.low" );
+      SGPath high = path;
+      high.append( "Navaids/range.high" );
+      
+      static_terminalRangeInterp.reset(new SGInterpTable(term.str()));
+      static_lowRangeInterp.reset(new SGInterpTable(low.str()));
+      static_highRangeInterp.reset(new SGInterpTable(high.str()));
+    }
+  
     string branch("/instrumentation/" + _name);
     _radio_node = fgGetNode(branch.c_str(), _num, true);
 }
@@ -155,10 +161,6 @@ FGNavRadio::~FGNavRadio()
       nav_slaved_to_gps_node->removeChangeListener(this);
     }
     
-    delete term_tbl;
-    delete low_tbl;
-    delete high_tbl;
-
     delete _audioIdent;
 }
 
@@ -309,17 +311,17 @@ double FGNavRadio::adjustNavRange( double stationElev, double aircraftElev,
     //      << " station elev = " << stationElev << endl;
 
     if ( nominalRange < 25.0 + SG_EPSILON ) {
-       // Standard Terminal Service Volume
-       return term_tbl->interpolate( alt ) * usability_factor;
+      // Standard Terminal Service Volume
+      return static_terminalRangeInterp->interpolate( alt ) * usability_factor;
     } else if ( nominalRange < 50.0 + SG_EPSILON ) {
        // Standard Low Altitude Service Volume
        // table is based on range of 40, scale to actual range
-       return low_tbl->interpolate( alt ) * nominalRange / 40.0
+      return static_lowRangeInterp->interpolate( alt ) * nominalRange / 40.0
            * usability_factor;
     } else {
        // Standard High Altitude Service Volume
        // table is based on range of 130, scale to actual range
-       return high_tbl->interpolate( alt ) * nominalRange / 130.0
+      return static_highRangeInterp->interpolate( alt ) * nominalRange / 130.0
            * usability_factor;
     }
 }
@@ -570,7 +572,7 @@ void FGNavRadio::updateReceiver(double dt)
     } // of false courses disabled
     
     const double VOR_FULL_ARC = 20.0; // VOR is -10 .. 10 degree swing
-    _cdiDeflection *= VOR_FULL_ARC / _localizerWidth; // increased localiser sensitivity
+    _cdiDeflection *= VOR_FULL_ARC / _localizerWidth; // increased localizer sensitivity
     
     if (backcourse_node->getBoolValue()) {
       _cdiDeflection = -_cdiDeflection;
@@ -581,7 +583,7 @@ void FGNavRadio::updateReceiver(double dt)
       r = ( r<0.0 ? -r-180.0 : -r+180.0 );
     }
     _cdiDeflection = r;
-  } // of non-localiser case
+  } // of non-localizer case
   
   SG_CLAMP_RANGE(_cdiDeflection, -10.0, 10.0 );
   _cdiDeflection *= signal_quality_norm;