]> git.mxchange.org Git - flightgear.git/commitdiff
Make the radio interpolation tables static.
authorJames Turner <zakalawe@mac.com>
Wed, 26 Sep 2012 22:10:37 +0000 (23:10 +0100)
committerJames Turner <zakalawe@mac.com>
Wed, 26 Sep 2012 22:10:37 +0000 (23:10 +0100)
No need to read these again for each navradio - and the marker beacon doesn't use them at all.

src/Instrumentation/marker_beacon.cxx
src/Instrumentation/marker_beacon.hxx
src/Instrumentation/navradio.cxx
src/Instrumentation/navradio.hxx

index 41b981536a6262e6da037e66b03e5523bda64518..50c85edafd9b442ab81fd1482400e9965aebb83c 100644 (file)
@@ -39,7 +39,6 @@
 #include <string>
 using std::string;
 
-
 // Constructor
 FGMarkerBeacon::FGMarkerBeacon(SGPropertyNode *node) :
     audio_vol(NULL),
@@ -51,18 +50,6 @@ FGMarkerBeacon::FGMarkerBeacon(SGPropertyNode *node) :
     _time_before_search_sec(0.0),
     _sgr(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() );
-
     for ( int i = 0; i < node->nChildren(); ++i ) {
         SGPropertyNode *child = node->getChild(i);
         string cname = child->getName();
@@ -85,9 +72,6 @@ FGMarkerBeacon::FGMarkerBeacon(SGPropertyNode *node) :
 // Destructor
 FGMarkerBeacon::~FGMarkerBeacon()
 {
-    delete term_tbl;
-    delete low_tbl;
-    delete high_tbl;
 }
 
 
index 5836f92ea3a4d1aa4b21c0d16339f28e3d63ec5e..7ed085aaad5ea65224142faf7659749ecc1e52fd 100644 (file)
 
 #include <simgear/compiler.h>
 #include <simgear/structure/subsystem_mgr.hxx>
-#include <simgear/math/interpolater.hxx>
 #include <simgear/timing/timestamp.hxx>
 
 class SGSampleGroup;
 
 class FGMarkerBeacon : public SGSubsystem
 {
-    SGInterpTable *term_tbl;
-    SGInterpTable *low_tbl;
-    SGInterpTable *high_tbl;
 
     // Inputs
     SGPropertyNode_ptr lon_node;
@@ -60,7 +56,7 @@ class FGMarkerBeacon : public SGSubsystem
     bool middle_blink;
     bool inner_blink;
 
-    string name;
+    std::string name;
     int num;
 
     // internal periodic station search timer
index 166060b75973cb7747f4627cd9ddce451e66c96e..fa528521e8a300da810f47e3930eabd1a4cfe230 100644 (file)
@@ -96,11 +96,11 @@ 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),
     _last_freq(0.0),
@@ -127,18 +127,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 +158,6 @@ FGNavRadio::~FGNavRadio()
       nav_slaved_to_gps_node->removeChangeListener(this);
     }
     
-    delete term_tbl;
-    delete low_tbl;
-    delete high_tbl;
-
     delete _audioIdent;
 }
 
@@ -309,17 +308,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;
     }
 }
index 0debf55dd8217404d2be78f5dc4b8c76457d59fd..abb288421b5b6076ac0bd96806f84129c3ef5a1b 100644 (file)
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/timing/timestamp.hxx>
 
-// forward decls
-class SGInterpTable;
-
 class SGSampleGroup;
 class FGNavRecord;
 typedef SGSharedPtr<FGNavRecord> FGNavRecordPtr;
 
 class FGNavRadio : public SGSubsystem, public SGPropertyChangeListener
 {
-    SGInterpTable *term_tbl;
-    SGInterpTable *low_tbl;
-    SGInterpTable *high_tbl;
-
     SGPropertyNode_ptr _radio_node;
     SGPropertyNode_ptr bus_power_node;