Some various massaging and clean ups of initialization code.
This commit is contained in:
parent
c5ebb65efd
commit
52a322decc
6 changed files with 234 additions and 116 deletions
|
@ -141,7 +141,72 @@ extern const char *default_root;
|
|||
|
||||
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;
|
||||
|
@ -205,6 +270,118 @@ bool fgInitFGRoot ( int argc, char **argv ) {
|
|||
}
|
||||
|
||||
|
||||
// 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() );
|
||||
|
@ -386,7 +563,7 @@ do_options (int argc, char ** argv)
|
|||
// 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
|
||||
|
@ -395,31 +572,35 @@ bool fgInitConfig ( int argc, char **argv ) {
|
|||
SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
|
||||
|
||||
// Detect the required language as early as possible
|
||||
if (fgDetectLanguage() != true)
|
||||
return false;
|
||||
|
||||
// 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);
|
||||
}
|
||||
} else {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
|
||||
if ( !fgDetectLanguage() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Scan user config files and command line for a specified aircraft.
|
||||
fgInitFGAircraft(argc, argv);
|
||||
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
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;
|
||||
|
@ -634,13 +815,13 @@ bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
|
|||
}
|
||||
|
||||
|
||||
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));
|
||||
|
@ -651,17 +832,17 @@ void fgSetPosFromGlideSlope(void) {
|
|||
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;
|
||||
|
|
|
@ -45,7 +45,8 @@
|
|||
SG_USING_STD(string);
|
||||
|
||||
|
||||
// Read in configuration (file and command line) and just set fg_root
|
||||
// Read in configuration (files and command line optoins) but only set
|
||||
// fg_root
|
||||
bool fgInitFGRoot ( int argc, char **argv );
|
||||
|
||||
|
||||
|
|
|
@ -1388,7 +1388,7 @@ void fgReshape( int width, int height ) {
|
|||
}
|
||||
|
||||
// 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
|
||||
|
@ -1470,12 +1470,12 @@ int fgGlutInit( int *argc, char **argv ) {
|
|||
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 );
|
||||
|
||||
|
@ -1488,11 +1488,11 @@ int fgGlutInitEvents( void ) {
|
|||
// 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 );
|
||||
|
@ -1557,7 +1557,9 @@ int mainLoop( int argc, char **argv ) {
|
|||
// 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);
|
||||
|
@ -1743,7 +1745,7 @@ int mainLoop( int argc, char **argv ) {
|
|||
|
||||
// we never actually get here ... but to avoid compiler warnings,
|
||||
// etc.
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1831,7 +1833,7 @@ int main ( int argc, char **argv ) {
|
|||
// 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
|
||||
|
|
|
@ -326,6 +326,8 @@ parse_time(const string& time_in) {
|
|||
result += seconds / 3600.0;
|
||||
}
|
||||
|
||||
cout << " parse_time() = " << sign * result << endl;
|
||||
|
||||
return(sign * result);
|
||||
}
|
||||
|
||||
|
@ -758,8 +760,8 @@ parse_option (const string& arg)
|
|||
} 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 ) {
|
||||
|
@ -1020,72 +1022,6 @@ parse_option (const string& arg)
|
|||
}
|
||||
|
||||
|
||||
// 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)
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
#endif
|
||||
|
||||
extern void fgSetDefaults ();
|
||||
extern string fgScanForRoot (int argc, char ** argv);
|
||||
extern string fgScanForRoot (const string &file_path);
|
||||
extern void fgParseArgs (int argc, char ** argv);
|
||||
extern void fgParseOptions (const string &file_path);
|
||||
extern void fgUsage (bool verbose = false);
|
||||
|
|
|
@ -1384,7 +1384,7 @@ bool fgBinObjLoad( const string& path, const bool is_base,
|
|||
*bounding_radius = obj.get_gbs_radius();
|
||||
|
||||
point_list const& nodes = obj.get_wgs84_nodes();
|
||||
point_list const& colors = obj.get_colors();
|
||||
// point_list const& colors = obj.get_colors();
|
||||
point_list const& normals = obj.get_normals();
|
||||
point_list const& texcoords = obj.get_texcoords();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue