SkySceneLoader *sgCloud3d;
-// Read in configuration (file and command line) and just set fg_root
+
+// Scan the command line options for an fg_root definition and set
+// just that.
+static string fgScanForRoot (int argc, char **argv) {
+ int i = 1;
+
+ SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
+
+ while ( i < argc ) {
+ SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
+
+ string arg = argv[i];
+ if ( arg.find( "--fg-root=" ) == 0 ) {
+ return arg.substr( 10 );
+ }
+
+ i++;
+ }
+
+ return "";
+}
+
+
+// Scan the user config files for an fg_root definition and set just
+// that.
+static string fgScanForRoot (const string& path) {
+ sg_gzifstream in( path );
+ if ( !in.is_open() )
+ return "";
+
+ SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
+
+ in >> skipcomment;
+#ifndef __MWERKS__
+ while ( ! in.eof() ) {
+#else
+ char c = '\0';
+ while ( in.get(c) && c != '\0' ) {
+ in.putback(c);
+#endif
+ string line;
+
+#if defined( macintosh )
+ getline( in, line, '\r' );
+#else
+ 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 ( line.find( "--fg-root=" ) == 0 ) {
+ return line.substr( 10 );
+ }
+
+ in >> skipcomment;
+ }
+
+ return "";
+}
+
+
+// Read in configuration (files and command line options) but only set
+// fg_root
bool fgInitFGRoot ( int argc, char **argv ) {
string root;
char* envp;
}
+// Scan the command line options for an aircraft definition and set
+// just that.
+static string fgScanForAircraft (int argc, char **argv) {
+ int i = 1;
+
+ SG_LOG(SG_GENERAL, SG_INFO, "Scanning for aircraft: command line");
+
+ while ( i < argc ) {
+ SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
+
+ string arg = argv[i];
+ if ( arg.find( "--aircraft=" ) == 0 ) {
+ return arg.substr( 11 );
+ }
+
+ i++;
+ }
+
+ return "";
+}
+
+
+// Scan the user config files for an aircrafg definition and set just
+// that.
+static string fgScanForAircraft (const string& path) {
+ sg_gzifstream in( path );
+ if ( !in.is_open() ) {
+ return "";
+ }
+
+ SG_LOG( SG_GENERAL, SG_INFO, "Scanning for aircraft: " << path );
+
+ in >> skipcomment;
+#ifndef __MWERKS__
+ while ( ! in.eof() ) {
+#else
+ char c = '\0';
+ while ( in.get(c) && c != '\0' ) {
+ in.putback(c);
+#endif
+ string line;
+
+#if defined( macintosh )
+ getline( in, line, '\r' );
+#else
+ 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 ( line.find( "--aircraft=" ) == 0 ) {
+ return line.substr( 11 );
+ }
+
+ in >> skipcomment;
+ }
+
+ return "";
+}
+
+
+// Read in configuration (files and command line options) but only set
+// aircraft
+bool fgInitFGAircraft ( int argc, char **argv ) {
+ string aircraft;
+ char* envp;
+
+ // First parse command line options looking for --aircraft=, this
+ // will override anything specified in a config file
+ aircraft = fgScanForAircraft(argc, argv);
+
+#if defined( unix ) || defined( __CYGWIN__ )
+ // Next check home directory for .fgfsrc.hostname file
+ if ( aircraft.empty() ) {
+ envp = ::getenv( "HOME" );
+ if ( envp != NULL ) {
+ SGPath config( envp );
+ config.append( ".fgfsrc" );
+ char name[256];
+ gethostname( name, 256 );
+ config.concat( "." );
+ config.concat( name );
+ aircraft = fgScanForRoot(config.str());
+ }
+ }
+#endif
+
+ // Next check home directory for .fgfsrc file
+ if ( aircraft.empty() ) {
+ envp = ::getenv( "HOME" );
+ if ( envp != NULL ) {
+ SGPath config( envp );
+ config.append( ".fgfsrc" );
+ aircraft = fgScanForRoot(config.str());
+ }
+ }
+
+ // if an aircraft was specified, set the property name
+ if ( !aircraft.empty() ) {
+ SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
+ fgSetString("/sim/aircraft", aircraft.c_str() );
+ } else {
+ SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
+ }
+
+ return true;
+}
+
+
// Return the current base package version
string fgBasePackageVersion() {
SGPath base_path( globals->get_fg_root() );
// Read in configuration (file and command line)
bool fgInitConfig ( int argc, char **argv ) {
- // First, set some sane default values
+ // First, set some sane default values
fgSetDefaults();
// Read global preferences from $FG_ROOT/preferences.xml
SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
// Detect the required language as early as possible
- if (fgDetectLanguage() != true)
- return false;
+ if ( !fgDetectLanguage() ) {
+ return false;
+ }
+
+ // Scan user config files and command line for a specified aircraft.
+ fgInitFGAircraft(argc, argv);
- // Read the default aircraft config file.
- do_options(argc, argv); // preparse options for default aircraft
string aircraft = fgGetString("/sim/aircraft", "");
- if (aircraft.size() > 0) {
- SGPath aircraft_path(globals->get_fg_root());
- aircraft_path.append("Aircraft");
- aircraft_path.append(aircraft);
- aircraft_path.concat("-set.xml");
- SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
- << " from " << aircraft_path.str());
- try {
- readProperties(aircraft_path.str(), globals->get_props());
- } catch (const sg_exception &e) {
- string message = "Error reading default aircraft: ";
- message += e.getFormattedMessage();
- SG_LOG(SG_INPUT, SG_ALERT, message);
- exit(2);
- }
+ if ( aircraft.size() > 0 ) {
+ SGPath aircraft_path(globals->get_fg_root());
+ aircraft_path.append("Aircraft");
+ aircraft_path.append(aircraft);
+ aircraft_path.concat("-set.xml");
+ SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
+ << " from " << aircraft_path.str());
+ try {
+ readProperties(aircraft_path.str(), globals->get_props());
+ } catch (const sg_exception &e) {
+ string message = "Error reading default aircraft: ";
+ message += e.getFormattedMessage();
+ SG_LOG(SG_INPUT, SG_ALERT, message);
+ exit(2);
+ }
} else {
- SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
+ SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
}
+ // parse options after loading aircraft to ensure any user
+ // overrides of defaults are honored.
do_options(argc, argv);
return true;
}
-void fgSetPosFromGlideSlope(void) {
- double gs = fgGetDouble("/velocities/glideslope");
+void fgSetPosFromGlideSlope() {
+ double gs = fgGetDouble("/sim/presets/glideslope");
double od = fgGetDouble("/sim/presets/offset-distance");
double alt = fgGetDouble("/sim/presets/altitude-ft");
- //if glideslope and offset-distance are set and altitude is
- //not, calculate the initial altitude
+ // if glideslope and offset-distance are set and altitude is not,
+ // calculate the initial altitude
if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
od *= SG_NM_TO_METER * SG_METER_TO_FEET;
alt = fabs(od*tan(gs));
od = alt/tan(gs);
od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
fgSetDouble("/sim/presets/offset-distance",od);
- SG_LOG(SG_GENERAL,SG_INFO, "Calculated offset distance as: "
+ SG_LOG(SG_GENERAL, SG_INFO, "Calculated offset distance as: "
<< od << " nm");
} else if( fabs(gs) > 0.01 ) {
- SG_LOG(SG_GENERAL,SG_ALERT, "Glideslope given but not altitude"
- << " or offset-distance. Resetting"
- << " glideslope to zero" );
- fgSetDouble("/velocities/glideslope",0);
+ SG_LOG( SG_GENERAL, SG_ALERT,
+ "Glideslope given but not altitude or offset-distance." );
+ SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
+ fgSetDouble("/sim/presets/glideslope",0);
}
-
}
+
// General house keeping initializations
bool fgInitGeneral( void ) {
string root;
}
// Initialize GLUT and define a main window
-int fgGlutInit( int *argc, char **argv ) {
+static bool fgGlutInit( int *argc, char **argv ) {
#if !defined( macintosh )
// GLUT will extract all glut specific options so later on we only
general.set_glDepthBits( tmp );
SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );
- return 1;
+ return true;
}
// Initialize GLUT event handlers
-int fgGlutInitEvents( void ) {
+static bool fgGlutInitEvents( void ) {
// call fgReshape() on window resizes
glutReshapeFunc( fgReshape );
// draw the scene
glutDisplayFunc( fgRenderFrame );
- return 1;
+ return true;
}
-// Main loop
-int mainLoop( int argc, char **argv ) {
+// Main top level initialization
+static bool fgMainInit( int argc, char **argv ) {
#if defined( macintosh )
freopen ("stdout.txt", "w", stdout );
// Initialize the Aircraft directory to "" (UIUC)
aircraft_dir = "";
- // Load the configuration parameters
+ // Load the configuration parameters. (Command line options
+ // overrides config file options. Config file options override
+ // defaults.)
if ( !fgInitConfig(argc, argv) ) {
SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
exit(-1);
// we never actually get here ... but to avoid compiler warnings,
// etc.
- return 0;
+ return false;
}
// FIXME: add other, more specific
// exceptions.
try {
- mainLoop(argc, argv);
+ fgMainInit(argc, argv);
} catch (sg_throwable &t) {
// We must use cerr rather than
// logging, since logging may be
result += seconds / 3600.0;
}
+ cout << " parse_time() = " << sign * result << endl;
+
return(sign * result);
}
} else if ( arg.find( "--pitch=" ) == 0 ) {
fgSetDouble("/sim/presets/pitch-deg", atof(arg.substr(8)));
} else if ( arg.find( "--glideslope=" ) == 0 ) {
- fgSetDouble("/velocities/glideslope", atof(arg.substr(13))
- *SG_DEGREES_TO_RADIANS);
+ fgSetDouble("/sim/presets/glideslope",
+ atof(arg.substr(13)) * SG_DEGREES_TO_RADIANS );
} else if ( arg.find( "--roc=" ) == 0 ) {
fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
} else if ( arg.find( "--fg-root=" ) == 0 ) {
}
-// Scan the command line options for an fg_root definition and set
-// just that.
-string
-fgScanForRoot (int argc, char **argv)
-{
- int i = 1;
-
- SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
-
- while ( i < argc ) {
- SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
-
- string arg = argv[i];
- if ( arg.find( "--fg-root=" ) == 0 ) {
- return arg.substr( 10 );
- }
-
- i++;
- }
-
- return "";
-}
-
-
-// Scan the config file for an fg_root definition and set just that.
-string
-fgScanForRoot (const string& path)
-{
- sg_gzifstream in( path );
- if ( !in.is_open() )
- return "";
-
- SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
-
- in >> skipcomment;
-#ifndef __MWERKS__
- while ( ! in.eof() ) {
-#else
- char c = '\0';
- while ( in.get(c) && c != '\0' ) {
- in.putback(c);
-#endif
- string line;
-
-#if defined( macintosh )
- getline( in, line, '\r' );
-#else
- 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 ( line.find( "--fg-root=" ) == 0 ) {
- return line.substr( 10 );
- }
-
- in >> skipcomment;
- }
-
- return "";
-}
-
-
// Parse the command line options
void
fgParseArgs (int argc, char **argv)