]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/gps.cxx
better use unset() for unsetting ...
[flightgear.git] / src / Instrumentation / gps.cxx
index 53cd82ec94a04ec4b05585801e1fca0f7fb845fe..aff76facf897f1441b919fa1e6ee8224f00ffa60 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "gps.hxx"
 
-SG_USING_STD(string);
+using std::string;
 
 
 GPS::GPS ( SGPropertyNode *node)
@@ -41,58 +41,29 @@ GPS::GPS ( SGPropertyNode *node)
       _wp1_altitude_m(0),
       _alt_dist_ratio(0),
       _distance_m(0),
-      _course_deg(0)
-{
-    int i;
-    for ( i = 0; i < node->nChildren(); ++i ) {
-        SGPropertyNode *child = node->getChild(i);
-        string cname = child->getName();
-        string cval = child->getStringValue();
-        if ( cname == "name" ) {
-            name = cval;
-        } else if ( cname == "number" ) {
-            num = child->getIntValue();
-        } else {
-            SG_LOG( SG_INSTR, SG_WARN, "Error in gps config logic" );
-            if ( name.length() ) {
-                SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
-            }
-        }
-    }
-}
-
-GPS::GPS ()
-    : _last_valid(false),
-      _last_longitude_deg(0),
-      _last_latitude_deg(0),
-      _last_altitude_m(0),
-      _last_speed_kts(0),
-      _wp0_latitude_deg(0),
-      _wp0_longitude_deg(0),
-      _wp0_altitude_m(0),
-      _wp1_latitude_deg(0),
-      _wp1_longitude_deg(0),
-      _wp1_altitude_m(0),
-      _alt_dist_ratio(0),
-      _distance_m(0),
-      _course_deg(0)
+      _course_deg(0),
+      _name(node->getStringValue("name", "gps")),
+      _num(node->getIntValue("number", 0)),
+      route(0)
 {
 }
 
 GPS::~GPS ()
 {
+    delete route;
 }
 
 void
 GPS::init ()
 {
+    delete route; // in case init is called twice
     route = new SGRoute;
     route->clear();
 
     string branch;
-    branch = "/instrumentation/" + name;
+    branch = "/instrumentation/" + _name;
 
-    SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
+    SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
 
     _longitude_node = fgGetNode("/position/longitude-deg", true);
     _latitude_node = fgGetNode("/position/latitude-deg", true);
@@ -162,7 +133,7 @@ GPS::init ()
     _true_track_node =
         node->getChild("indicated-track-true-deg", 0, true);
     _magnetic_track_node =
-        node->getChild("indicated-track_magnetic-deg", 0, true);
+        node->getChild("indicated-track-magnetic-deg", 0, true);
     _speed_node =
         node->getChild("indicated-ground-speed-kt", 0, true);
     _odometer_node =
@@ -340,7 +311,7 @@ GPS::update (double delta_time_sec)
         // If the get-nearest-airport-node is true.
         // Get the nearest airport, and set it as waypoint 1.
         if (_get_nearest_airport_node->getBoolValue()) {
-            const FGAirport* a = globals->get_airports()->search(longitude_deg, latitude_deg, false);
+            const FGAirport* a = globals->get_airports()->search(longitude_deg, latitude_deg);
             if(a) {
                 _wp1_ID_node->setStringValue(a->getId().c_str());
                 wp1_longitude_deg = a->getLongitude();