]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/options.cxx
- Added ultra-light traffic is now a separate traffic class that can have its
[flightgear.git] / src / Main / options.cxx
index 8ed6affd8127c2155cf7e4488b1b0804884101c8..518b1babf265bac95b4b86d6c8b401bacffdcfb7 100644 (file)
@@ -42,6 +42,7 @@
 #include <simgear/math/sg_random.h>
 #include <simgear/misc/sgstream.hxx>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/scene/material/mat.hxx>
 
 // #include <Include/general.hxx>
 // #include <Airports/simple.hxx>
@@ -98,7 +99,6 @@ atoi( const string& str )
 #endif
 }
 
-
 /**
  * Set a few fail-safe default property values.
  *
@@ -204,6 +204,8 @@ fgSetDefaults ()
     fgSetBool("/sim/rendering/shading", true);
     fgSetBool("/sim/rendering/skyblend", true);
     fgSetBool("/sim/rendering/textures", true);
+       fgTie( "/sim/rendering/filtering", SGGetTextureFilter, SGSetTextureFilter, false);
+    fgSetInt("/sim/rendering/filtering", 1);
     fgSetBool("/sim/rendering/wireframe", false);
     fgSetBool("/sim/rendering/horizon-effect", false);
     fgSetBool("/sim/rendering/enhanced-lighting", false);
@@ -528,11 +530,7 @@ parse_fov( const string& arg ) {
 static bool
 add_channel( const string& type, const string& channel_str ) {
     SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
-
     globals->get_channel_options_list()->push_back( type + "," + channel_str );
-    
-    // cout << "here" << endl;
-
     return true;
 }
 
@@ -881,7 +879,7 @@ fgSetupProxy( const char *arg )
 {
     string options = arg;
     string host, port, auth;
-    unsigned int pos;
+    string::size_type pos;
 
     host = port = auth = "";
     if ((pos = options.find("@")) != string::npos) 
@@ -1330,6 +1328,7 @@ struct OptionDesc {
     {"enable-skyblend",              false, OPTION_BOOL,   "/sim/rendering/skyblend", true, "", 0 },
     {"disable-textures",             false, OPTION_BOOL,   "/sim/rendering/textures", false, "", 0 },
     {"enable-textures",              false, OPTION_BOOL,   "/sim/rendering/textures", true, "", 0 },
+    {"texture-filtering",           false, OPTION_INT,    "/sim/rendering/filtering", 1, "", 0 },
     {"disable-wireframe",            false, OPTION_BOOL,   "/sim/rendering/wireframe", false, "", 0 },
     {"enable-wireframe",             false, OPTION_BOOL,   "/sim/rendering/wireframe", true, "", 0 },
     {"geometry",                     true,  OPTION_FUNC,   "", false, "", fgOptGeometry },
@@ -1399,6 +1398,46 @@ struct OptionDesc {
 };
 
 
+// Set a property for the --prop: option. Syntax: --prop:[<type>:]<name>=<value>
+// <type> can be "double" etc. but also only the first letter "d".
+// Examples:  --prop:alpha=1  --prop:bool:beta=true  --prop:d:gamma=0.123
+static bool
+set_property(const string& arg)
+{
+    string::size_type pos = arg.find('=');
+    if (pos == arg.npos || pos == 0 || pos + 1 == arg.size())
+        return false;
+
+    string name = arg.substr(0, pos);
+    string value = arg.substr(pos + 1);
+    string type;
+    pos = name.find(':');
+
+    if (pos != name.npos && pos != 0 && pos + 1 != name.size()) {
+        type = name.substr(0, pos);
+        name = name.substr(pos + 1);
+    }
+    SGPropertyNode *n = fgGetNode(name.c_str(), true);
+
+    if (type.empty())
+        return n->setUnspecifiedValue(value.c_str());
+    else if (type == "s" || type == "string")
+        return n->setStringValue(value.c_str());
+    else if (type == "d" || type == "double")
+        return n->setDoubleValue(strtod(value.c_str(), 0));
+    else if (type == "f" || type == "float")
+        return n->setFloatValue(atof(value.c_str()));
+    else if (type == "l" || type == "long")
+        return n->setLongValue(strtol(value.c_str(), 0, 0));
+    else if (type == "i" || type == "int")
+        return n->setIntValue(atoi(value.c_str()));
+    else if (type == "b" || type == "bool")
+        return n->setBoolValue(value == "true" || atoi(value.c_str()) != 0);
+
+    return false;
+}
+
+
 // Parse a single option
 static int
 parse_option (const string& arg)
@@ -1423,15 +1462,9 @@ parse_option (const string& arg)
     } else if ( arg.find( "--show-aircraft") == 0) {
         return(FG_OPTIONS_SHOW_AIRCRAFT);
     } else if ( arg.find( "--prop:" ) == 0 ) {
-        string assign = arg.substr(7);
-       string::size_type pos = assign.find('=');
-       if ( pos == arg.npos || pos == 0 || pos + 1 == assign.size() ) {
-           SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
+        if (!set_property(arg.substr(7))) {
+            SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
             return FG_OPTIONS_ERROR;
-        } else {
-           string name = assign.substr(0, pos);
-           string value = assign.substr(pos + 1);
-           fgSetString(name.c_str(), value.c_str());
         }
     } else if ( arg.find( "--" ) == 0 ) {
         size_t pos = arg.find( '=' );
@@ -1673,21 +1706,21 @@ fgUsage (bool verbose)
                     tmp.append(", -");
                     tmp.append(short_name->getStringValue());
                 }
-
-                char cstr[96];
+                               
                 if (tmp.size() <= 25) {
-                    snprintf(cstr, 96, "   --%-27s", tmp.c_str());
+                    msg+= "   --";
+                    msg += tmp;
+                    msg.append( 27-tmp.size(), ' ');
                 } else {
-                    snprintf(cstr, 96, "\n   --%s\n%32c", tmp.c_str(), ' ');
+                    msg += "\n   --";
+                    msg += tmp + '\n';
+                    msg.append(32, ' ');
                 }
-
                 // There may be more than one <description> tag assosiated
                 // with one option
 
-                msg += cstr;
-                vector<SGPropertyNode_ptr>desc =
-                                          option[k]->getChildren("description");
-
+                vector<SGPropertyNode_ptr> desc;
+                desc = option[k]->getChildren("description");
                 if (desc.size() > 0) {
                    for ( unsigned int l = 0; l < desc.size(); l++) {
 
@@ -1702,9 +1735,7 @@ fgUsage (bool verbose)
                          string t_str = trans_desc[m]->getStringValue();
 
                          if ((m > 0) || ((l > 0) && m == 0)) {
-                            snprintf(cstr, 96, "%32c", ' ');
-                            msg += cstr;
-
+                            msg.append( 32, ' ');
                          }
 
                          // If the string is too large to fit on the screen,
@@ -1713,9 +1744,8 @@ fgUsage (bool verbose)
                          while ( t_str.size() > 47 ) {
 
                             unsigned int m = t_str.rfind(' ', 47);
-                            msg += t_str.substr(0, m);
-                            snprintf(cstr, 96, "\n%32c", ' ');
-                            msg += cstr;
+                            msg += t_str.substr(0, m) + '\n';
+                            msg.append( 32, ' ');
 
                             t_str.erase(t_str.begin(), t_str.begin() + m + 1);
                         }
@@ -1726,8 +1756,8 @@ fgUsage (bool verbose)
             }
         }
 
-        SGPropertyNode *name =
-                            locale->getNode(section[j]->getStringValue("name"));
+        SGPropertyNode *name;
+        name = locale->getNode(section[j]->getStringValue("name"));
 
         if (!msg.empty() && name) {
            cout << endl << name->getStringValue() << ":" << endl;
@@ -1810,25 +1840,27 @@ static void fgSearchAircraft(const SGPath &path, string_list &aircraft,
                status = node->getNode("status");
           }
 
-          char cstr[96];
-         //additionally display status information where it is available
-          
-          if (strlen(dire->d_name) <= 27) {
-             snprintf(cstr, 96, "   %-27s  %s", dire->d_name,
-                      (desc) ? desc->getStringValue() : "");
-
-          } else {
-             snprintf(cstr, 96, "   %-27s\n%32c%s", dire->d_name, ' ',
-                      (desc) ? desc->getStringValue() : "");
+          //additionally display status information where it is available
+
+          string descStr("   ");
+          descStr += dire->d_name;
+          if (desc) {
+              if (descStr.size() <= 27+3) {
+                descStr.append(29+3-descStr.size(), ' ');
+              } else {
+                descStr += '\n';
+                descStr.append( 32, ' ');
+              }
+              descStr += desc->getStringValue();
           }
-
-         SGPropertyNode * required_status
+  
+          SGPropertyNode * required_status
                              = fgGetNode ("/sim/aircraft-min-status", true);
          
          // If the node holds the value "all", then there wasn't any status 
          // level specified, so we simply go ahead and output ALL aircraft
          if (strcmp(required_status->getStringValue(),"all")==0) {        
-                 aircraft.push_back(cstr);
+                 aircraft.push_back(descStr);
                  }
          else
          {
@@ -1840,7 +1872,7 @@ static void fgSearchAircraft(const SGPath &path, string_list &aircraft,
          //Compare (minimally) required status level with actual aircraft status:
           if ( getNumMaturity(status->getStringValue() ) >= 
                getNumMaturity(required_status->getStringValue() ) )
-                                 aircraft.push_back(cstr); }
+                                 aircraft.push_back(descStr); }
                                                  
          }