]> git.mxchange.org Git - flightgear.git/commitdiff
Make --flight-plan option delegate to the route-manager loadRoute code, and hence...
authorJames Turner <zakalawe@mac.com>
Wed, 25 May 2011 07:21:45 +0000 (08:21 +0100)
committerJames Turner <zakalawe@mac.com>
Wed, 25 May 2011 07:21:45 +0000 (08:21 +0100)
src/Autopilot/route_mgr.cxx
src/Main/options.cxx

index 562c0ec68cd6f3c0ac6a187cd7d9c67c944119c0..1b37fa2562623dacee3a5c521fc2fdefeb1a260e 100644 (file)
@@ -224,6 +224,15 @@ void FGRouteMgr::init() {
 
 void FGRouteMgr::postinit()
 {
+  SGPath path(_pathNode->getStringValue());
+  if (path.exists()) {
+    SG_LOG(SG_AUTOPILOT, SG_INFO, "loading flight-plan from:" << path.str());
+    loadRoute();
+  }
+  
+// this code only matters for the --wp option now - perhaps the option
+// should be deprecated in favour of an explicit flight-plan file?
+// then the global initial waypoint list could die.
   string_list *waypoints = globals->get_initial_waypoints();
   if (waypoints) {
     string_list::iterator it;
index d61ffcf028f0d36f629b09324500c9f114bc0f04..df50b344ce9c328a6a5148b166656168f924fac5 100644 (file)
@@ -555,54 +555,6 @@ add_channel( const string& type, const string& channel_str ) {
     return true;
 }
 
-
-// The parse wp and parse flight-plan options don't work anymore, because
-// the route manager and the airport subsystems have not yet been initialized
-// at this stage.
-
-// Parse --wp=ID[@alt]
-static void
-parse_wp( const string& arg ) {
-    string_list *waypoints = globals->get_initial_waypoints();
-    if (!waypoints) {
-        waypoints = new string_list;
-        globals->set_initial_waypoints(waypoints);
-    }
-    waypoints->push_back(arg);
-}
-
-
-// Parse --flight-plan=[file]
-static bool
-parse_flightplan(const string& arg)
-{
-    string_list *waypoints = globals->get_initial_waypoints();
-    if (!waypoints) {
-        waypoints = new string_list;
-        globals->set_initial_waypoints(waypoints);
-    }
-
-    sg_gzifstream in(arg.c_str());
-    if ( !in.is_open() )
-        return false;
-
-    while ( true ) {
-        string line;
-        getline( in, line, '\n' );
-
-        // catch extraneous (DOS) line ending character
-        if ( line[line.length() - 1] < 32 )
-            line = line.substr( 0, line.length()-1 );
-
-        if ( in.eof() )
-            break;
-
-        waypoints->push_back(line);
-    }
-    return true;
-}
-
-
 static int
 fgOptLanguage( const char *arg )
 {
@@ -1067,14 +1019,12 @@ fgOptCeiling( const char *arg )
 static int
 fgOptWp( const char *arg )
 {
-    parse_wp( arg );
-    return FG_OPTIONS_OK;
-}
-
-static int
-fgOptFlightPlan( const char *arg )
-{
-    parse_flightplan ( arg );
+    string_list *waypoints = globals->get_initial_waypoints();
+    if (!waypoints) {
+        waypoints = new string_list;
+        globals->set_initial_waypoints(waypoints);
+    }
+    waypoints->push_back(arg);
     return FG_OPTIONS_OK;
 }
 
@@ -1496,7 +1446,7 @@ struct OptionDesc {
     {"turbulence",                   true,  OPTION_FUNC,   "", false, "", fgOptTurbulence },
     {"ceiling",                      true,  OPTION_FUNC,   "", false, "", fgOptCeiling },
     {"wp",                           true,  OPTION_FUNC,   "", false, "", fgOptWp },
-    {"flight-plan",                  true,  OPTION_FUNC,   "", false, "", fgOptFlightPlan },
+    {"flight-plan",                  true,  OPTION_STRING,   "/autopilot/route-manager/file-path", false, "", NULL },
     {"config",                       true,  OPTION_FUNC,   "", false, "", fgOptConfig },
     {"aircraft",                     true,  OPTION_STRING, "/sim/aircraft", false, "", 0 },
     {"vehicle",                      true,  OPTION_STRING, "/sim/aircraft", false, "", 0 },