]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/options.cxx
Hopefully fix the shadow disappearing because of range animation issue in a more...
[flightgear.git] / src / Main / options.cxx
index 5ca9cd2cffe7781c4e7304b129dacaa161902933..78ec58d87138524195ee0ebcafb7e92de92fa8d6 100644 (file)
@@ -80,6 +80,7 @@ using std::cout;
 using std::cerr;
 using std::endl;
 using std::vector;
+using std::cin;
 
 #define NEW_DEFAULT_MODEL_HZ 120
 
@@ -175,7 +176,7 @@ fgSetDefaults ()
     // specified so we can do the right thing for voodoo-1/2 cards.
     // fgSetString("/sim/startup/mouse-pointer", "disabled");
     fgSetString("/sim/control-mode", "joystick");
-    fgSetBool("/sim/auto-coordination", false);
+    fgSetBool("/controls/flight/auto-coordination", false);
 #if defined(WIN32)
     fgSetString("/sim/startup/browser-app", "webrun.bat");
 #elif defined(__APPLE__)
@@ -333,7 +334,6 @@ parseIntValue(char** ppParserPos, int* pValue,int min, int max, const char* fiel
     }
 }
 
-#ifndef HAVE_RINT
 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
 static double
 parse_time(const string& time_in) {
@@ -414,7 +414,6 @@ parse_time(const string& time_in) {
 
     return(sign * result);
 }
-#endif
 
 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
 static long int
@@ -901,29 +900,20 @@ fgOptTraceRead( const char *arg )
 static int
 fgOptLogLevel( const char *arg )
 {
-    fgSetString("/sim/logging/classes", "all");
     fgSetString("/sim/logging/priority", arg);
-
-    string priority = arg;
-    logbuf::set_log_classes(SG_ALL);
-    if (priority == "bulk") {
-      logbuf::set_log_priority(SG_BULK);
-    } else if (priority == "debug") {
-      logbuf::set_log_priority(SG_DEBUG);
-    } else if (priority == "info") {
-      logbuf::set_log_priority(SG_INFO);
-    } else if (priority == "warn") {
-      logbuf::set_log_priority(SG_WARN);
-    } else if (priority == "alert") {
-      logbuf::set_log_priority(SG_ALERT);
-    } else {
-      SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
-    }
-    SG_LOG(SG_GENERAL, SG_DEBUG, "Logging priority is " << priority);
+    setLoggingPriority(arg);
 
     return FG_OPTIONS_OK;
 }
 
+static int
+fgOptLogClasses( const char *arg )
+{
+    fgSetString("/sim/logging/classes", arg);
+    setLoggingClasses (arg);
+
+    return FG_OPTIONS_OK;
+}
 
 static int
 fgOptTraceWrite( const char *arg )
@@ -1341,6 +1331,8 @@ struct OptionDesc {
     } fgOptionArray[] = {
 
     {"language",                     true,  OPTION_FUNC,   "", false, "", fgOptLanguage },
+    {"disable-rembrandt",            false, OPTION_BOOL,   "/sim/rendering/rembrandt", false, "", 0 },
+    {"enable-rembrandt",             false, OPTION_BOOL,   "/sim/rendering/rembrandt", true, "", 0 },
     {"disable-game-mode",            false, OPTION_BOOL,   "/sim/startup/game-mode", false, "", 0 },
     {"enable-game-mode",             false, OPTION_BOOL,   "/sim/startup/game-mode", true, "", 0 },
     {"disable-splash-screen",        false, OPTION_BOOL,   "/sim/startup/splash-screen", false, "", 0 },
@@ -1369,8 +1361,8 @@ struct OptionDesc {
     {"disable-anti-alias-hud",       false, OPTION_BOOL,   "/sim/hud/color/antialiased", false, "", 0 },
     {"enable-anti-alias-hud",        false, OPTION_BOOL,   "/sim/hud/color/antialiased", true, "", 0 },
     {"control",                      true,  OPTION_STRING, "/sim/control-mode", false, "", 0 },
-    {"disable-auto-coordination",    false, OPTION_BOOL,   "/sim/auto-coordination", false, "", 0 },
-    {"enable-auto-coordination",     false, OPTION_BOOL,   "/sim/auto-coordination", true, "", 0 },
+    {"disable-auto-coordination",    false, OPTION_BOOL,   "/controls/flight/auto-coordination", false, "", 0 },
+    {"enable-auto-coordination",     false, OPTION_BOOL,   "/controls/flight/auto-coordination", true, "", 0 },
     {"browser-app",                  true,  OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
     {"disable-hud",                  false, OPTION_BOOL,   "/sim/hud/visibility[1]", false, "", 0 },
     {"enable-hud",                   false, OPTION_BOOL,   "/sim/hud/visibility[1]", true, "", 0 },
@@ -1467,7 +1459,7 @@ struct OptionDesc {
     {"hud-tris",                     false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
     {"hud-culled",                   false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
     {"atcsim",                       true,  OPTION_CHANNEL, "", false, "dummy", 0 },
-    {"atlas",                        true,  OPTION_CHANNEL, "", false, "", 0 },
+    {"atlas",                        true,  OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
     {"httpd",                        true,  OPTION_CHANNEL, "", false, "", 0 },
 #ifdef FG_JPEG_SERVER
     {"jpg-httpd",                    true,  OPTION_CHANNEL, "", false, "", 0 },
@@ -1493,13 +1485,14 @@ struct OptionDesc {
     {"jsclient",                     true,  OPTION_CHANNEL, "", false, "", 0 },
     {"proxy",                        true,  OPTION_FUNC,    "", false, "", fgSetupProxy },
     {"callsign",                     true,  OPTION_FUNC,    "", false, "", fgOptCallSign},
-    {"multiplay",                    true,  OPTION_CHANNEL, "", false, "", 0 },
+    {"multiplay",                    true,  OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
 #ifdef FG_HAVE_HLA
     {"hla",                          true,  OPTION_CHANNEL, "", false, "", 0 },
 #endif
     {"trace-read",                   true,  OPTION_FUNC | OPTION_MULTI,   "", false, "", fgOptTraceRead },
     {"trace-write",                  true,  OPTION_FUNC | OPTION_MULTI,   "", false, "", fgOptTraceWrite },
     {"log-level",                    true,  OPTION_FUNC,   "", false, "", fgOptLogLevel },
+    {"log-class",                    true,  OPTION_FUNC,   "", false, "", fgOptLogClasses },
     {"view-offset",                  true,  OPTION_FUNC | OPTION_MULTI,   "", false, "", fgOptViewOffset },
     {"visibility",                   true,  OPTION_FUNC,   "", false, "", fgOptVisibilityMeters },
     {"visibility-miles",             true,  OPTION_FUNC,   "", false, "", fgOptVisibilityMiles },
@@ -1562,6 +1555,10 @@ public:
   {
     OptionValueVec::const_iterator it = values.begin();
     for (; it != values.end(); ++it) {
+      if (!it->desc) {
+        continue; // ignore markers
+      }
+      
       if (it->desc->option == key) {
         return it;
       }
@@ -1582,6 +1579,10 @@ public:
   
   int processOption(OptionDesc* desc, const string& arg_value)
   {
+    if (!desc) {
+      return FG_OPTIONS_OK; // tolerate marker options
+    }
+    
     switch ( desc->type & 0xffff ) {
       case OPTION_BOOL:
         fgSetBool( desc->property, desc->b_param );
@@ -1649,10 +1650,36 @@ public:
     
     return FG_OPTIONS_OK;
   }
+    
+  /**
+   * insert a marker value into the values vector. This is necessary
+   * when processing options, to ensure the correct ordering, where we scan
+   * for marker values in reverse, and then forwards within each group.
+   */
+  void insertGroupMarker()
+  {
+    values.push_back(OptionValue(NULL, "-"));
+  }
+  
+  /**
+   * given a current iterator into the values, find the preceeding group marker,
+   * or return the beginning of the value vector.
+   */
+  OptionValueVec::const_iterator rfindGroup(OptionValueVec::const_iterator pos) const
+  {
+    while (--pos != values.begin()) {
+      if (pos->desc == NULL) {
+        return pos; // found a marker, we're done
+      }
+    }
+    
+    return pos;
+  }
   
   bool showHelp,
     verbose,
     showAircraft;
+
   OptionDescDict options;
   OptionValueVec values;
   simgear::PathList propertyFiles;
@@ -1712,6 +1739,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
       p->propertyFiles.push_back(f);
     }
   } // of arguments iteration
+  p->insertGroupMarker(); // command line is one group
   
 // then config files
   SGPath config;
@@ -1852,6 +1880,7 @@ void Options::readConfig(const SGPath& path)
     in >> skipcomment;
   }
 
+  p->insertGroupMarker(); // each config file is a group
 }
   
 int Options::parseOption(const string& s)
@@ -1900,6 +1929,7 @@ int Options::addOption(const string &key, const string &value)
 {
   OptionDesc* desc = p->findOption(key);
   if (!desc) {
+    SG_LOG(SG_GENERAL, SG_ALERT, "unknown option:" << key);
     return FG_OPTIONS_ERROR;
   }
   
@@ -1936,6 +1966,10 @@ string_list Options::valuesForOption(const std::string& key) const
   string_list result;
   OptionValueVec::const_iterator it = p->values.begin();
   for (; it != p->values.end(); ++it) {
+    if (!it->desc) {
+      continue; // ignore marker values
+    }
+    
     if (it->desc->option == key) {
       result.push_back(it->value);
     }
@@ -1953,12 +1987,33 @@ void Options::processOptions()
     exit(0);
   }
   
-  BOOST_FOREACH(const OptionValue& v, p->values) {
-    int result = p->processOption(v.desc, v.value);
-    if (result == FG_OPTIONS_ERROR) {
-      showUsage();
-      exit(-1);
+  // processing order is complicated. We must process groups LIFO, but the
+  // values *within* each group in FIFO order, to retain consistency with
+  // older versions of FG, and existing user configs.
+  // in practice this means system.fgfsrc must be *processed* before
+  // .fgfsrc, which must be processed before the command line args, and so on.
+  OptionValueVec::const_iterator groupEnd = p->values.end();
+    
+  while (groupEnd != p->values.begin()) {
+    OptionValueVec::const_iterator groupBegin = p->rfindGroup(groupEnd);
+  // run over the group in FIFO order
+    OptionValueVec::const_iterator it;
+    for (it = groupBegin; it != groupEnd; ++it) {      
+      int result = p->processOption(it->desc, it->value);
+      switch(result)
+      {
+          case FG_OPTIONS_ERROR:
+              showUsage();
+              exit(-1); // exit and return an error
+          case FG_OPTIONS_EXIT:
+              exit(0);  // clean exit
+              break;
+          default:
+              break;
+      }
     }
+    
+    groupEnd = groupBegin;
   }
   
   BOOST_FOREACH(const SGPath& file, p->propertyFiles) {
@@ -2136,8 +2191,8 @@ void Options::showUsage() const
     cout << "For a complete list of options use --help --verbose" << endl;
   }
 #ifdef _MSC_VER
-  cout << "Hit a key to continue..." << endl;
-  cin.get();
+  std::cout << "Hit a key to continue..." << std::endl;
+  std::cin.get();
 #endif
 }
   
@@ -2200,7 +2255,7 @@ void Options::setupRoot()
   globals->set_fg_root(root);
   
 // validate it
-  static char required_version[] = "2.5.0";
+  static char required_version[] = FLIGHTGEAR_VERSION;
   string base_version = fgBasePackageVersion();
   if ( !(base_version == required_version) ) {
     // tell the operator how to use this application