]> git.mxchange.org Git - flightgear.git/commitdiff
Small rewrite of waypoints parsing fix to move global list to the globals.hxx
authorcurt <curt>
Sun, 18 Apr 2004 18:01:10 +0000 (18:01 +0000)
committercurt <curt>
Sun, 18 Apr 2004 18:01:10 +0000 (18:01 +0000)
file.

src/Main/fg_init.cxx
src/Main/globals.cxx
src/Main/globals.hxx
src/Main/options.cxx

index 4c3a1f1d4672eea96b60df680bf7d9fb5b3ceccd..6eb034f31519593be870bea14ca6655ada0d87c9 100644 (file)
@@ -140,7 +140,7 @@ SG_USING_STD(string);
 class Sound;
 
 extern const char *default_root;
-extern string_list waypoints;
+
 
 #ifdef FG_USE_CLOUDS_3D
   SkySceneLoader *sgCloud3d;
@@ -1003,42 +1003,22 @@ static bool fgSetPosFromFix( const string& id ) {
  
 static bool parseWaypoints()
   {
-    vector<string>::iterator i;
-    for (i = waypoints.begin(); 
-        i  != waypoints.end();
-        i++)
+    string_list *waypoints = globals->get_initial_waypoints();
+    if (waypoints) 
       {
-       NewWaypoint(*i);
-       // string arg = *i;
-//     string id, alt_str;
-//     double alt = 0.0;
-       
-//     string::size_type pos = arg.find( "@" );
-//     if ( pos != string::npos ) {
-//       id = arg.substr( 0, pos );
-//       alt_str = arg.substr( pos + 1 );
-//       cout << "id str = " << id << "  alt str = " << alt_str << endl;
-//       alt = atof( alt_str.c_str() );
-//       if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
-//         alt *= SG_FEET_TO_METER;
-//       }
-//     } else {
-//       id = arg;
-//     }
-       
-//     FGAirport a;
-//     if ( fgFindAirportID( id, &a ) ) {
-//       FGRouteMgr *rm = (FGRouteMgr *)globals->get_subsystem("route-manager");
-//       SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
-//       rm->add_waypoint( wp );
-         
-//       //return true;
-//     } else {
-//       return false;
-//     }
-//       }
-//     //    waypoints.begin() = waypoints.erase(waypoints.begin());
-//     return true;
+       vector<string>::iterator i;
+       for (i = waypoints->begin(); 
+            i  != waypoints->end();
+            i++)
+         {
+           NewWaypoint(*i);
+         }
+       // Now were done using the way points we can deallocate the
+       // memory they used
+       while (waypoints->begin() != waypoints->end())
+         waypoints->pop_back();
+       delete waypoints;
+       globals->set_initial_waypoints(0);
       }
    }
 
index 73d06b23ef99343d1320f46de0edb55d2cd80ddd..b6a932760287f986a205f4b694ac3dced31d1649 100644 (file)
@@ -73,7 +73,8 @@ FGGlobals::FGGlobals() :
     channel_options_list( NULL ),
     scenery( NULL ),
     tile_mgr( NULL ),
-    io( new FGIO )
+    io( new FGIO ),
+    initial_waypoints(0)
 {
 }
 
@@ -87,6 +88,11 @@ FGGlobals::~FGGlobals()
   delete props;
   delete commands;
   delete io;
+  
+  // make sure only to delete the initial waypoints list if it acually
+  // still exists. 
+  if (initial_waypoints)
+    delete initial_waypoints;
 }
 
 
index a650f83b514c04c480d6a58215f140410da51df4..071c97c24cd44ea5c4ba35488230aad386e2e418 100644 (file)
@@ -178,6 +178,10 @@ private:
     // list of serial port-like configurations
     string_list *channel_options_list;
 
+    // A list of initial waypoints that are read from the command line
+    // and or flight-plan file during initialization
+    string_list *initial_waypoints;
+
     // FlightGear scenery manager
     FGScenery *scenery;
 
@@ -327,6 +331,14 @@ public:
        channel_options_list = l;
     }
 
+    inline string_list *get_initial_waypoints () {
+        return initial_waypoints;
+    }
+  
+    inline void set_initial_waypoints (string_list *list) {
+        initial_waypoints = list;
+    }
+
     inline FGScenery * get_scenery () const { return scenery; }
     inline void set_scenery ( FGScenery *s ) { scenery = s; }
 
index ebcbefb398eb78d78a66227a6f1356baddc4668a..c719def4fdde8e82ad1604d7b3c303b1f4c07585 100644 (file)
@@ -67,8 +67,6 @@ SG_USING_NAMESPACE(std);
 
 #define NEW_DEFAULT_MODEL_HZ 120
 
-string_list waypoints;
-
 enum
 {
     FG_OPTIONS_OK = 0,
@@ -543,34 +541,11 @@ add_channel( const string& type, const string& channel_str ) {
 // Parse --wp=ID[@alt]
 static bool 
 parse_wp( const string& arg ) {
-  //string id, alt_str;
-  //double alt = 0.0;
-  //
-  //string::size_type pos = arg.find( "@" );
-  //if ( pos != string::npos ) {
-  //id = arg.substr( 0, pos );
-  //alt_str = arg.substr( pos + 1 );
-  //// cout << "id str = " << id << "  alt str = " << alt_str << endl;
-  //alt = atof( alt_str.c_str() );
-  //if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
-  //    alt *= SG_FEET_TO_METER;
-  //}
-  //} else {
-  //id = arg;
-  //}
-  //
-  //FGAirport a;
-  //if ( fgFindAirportID( id, &a ) ) {
-  //    FGRouteMgr *rm = (FGRouteMgr *)globals->get_subsystem("route-manager");
-  //SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
-  //rm->add_waypoint( wp );
-  //
-  //return true;
-  //} else {
-  //return false;
-  //}
-  //}
-  waypoints.push_back(arg);
+  string_list *waypoints = globals->get_initial_waypoints();
+  if (!waypoints)
+    waypoints = new string_list;
+  waypoints->push_back(arg);
+  globals->set_initial_waypoints(waypoints);
 }
 
 
@@ -578,32 +553,34 @@ parse_wp( const string& arg ) {
 static bool 
 parse_flightplan(const string& arg)
 {
-    sg_gzifstream in(arg.c_str());
-    if ( !in.is_open() ) {
-       return false;
-    }
-    while ( true ) {
-       string line;
-
+  string_list *waypoints = globals->get_initial_waypoints();
+  if (!waypoints)
+    waypoints = new string_list;
+  sg_gzifstream in(arg.c_str());
+  if ( !in.is_open() ) {
+    return false;
+  }
+  while ( true ) {
+    string line;
+    
 #if defined( macintosh )
-        getline( in, line, '\r' );
+    getline( in, line, '\r' );
 #else
-       getline( in, line, '\n' );
+    getline( in, line, '\n' );
 #endif
-
-        // catch extraneous (DOS) line ending character
-        if ( line[line.length() - 1] < 32 ) {
-            line = line.substr( 0, line.length()-1 );
-        }
-
-       if ( in.eof() ) {
-           break;
-       }
-       //parse_wp(line);
-       waypoints.push_back(line);
+    
+    // catch extraneous (DOS) line ending character
+    if ( line[line.length() - 1] < 32 ) {
+      line = line.substr( 0, line.length()-1 );
     }
-
-    return true;
+    
+    if ( in.eof() ) {
+      break;
+    }
+    waypoints->push_back(line);
+  }
+  globals->set_initial_waypoints(waypoints);
+  return true;
 }
 
 static int