1
0
Fork 0

Try to set initial position in a bit more intelligent way (and earlier in

the process so time initialization can have a chance to work.)
This commit is contained in:
curt 2000-07-21 22:54:14 +00:00
parent 6797b97530
commit 81b266aa4a
3 changed files with 41 additions and 15 deletions

View file

@ -136,14 +136,11 @@ bool fgInitConfig ( int argc, char **argv ) {
} }
// Set initial position and orientation // Set current_options lon/lat given an airport id
bool fgInitPosition( void ) { bool fgSetPosFromAirportID( const string& id ) {
string id; FGAirport a;
FGInterface *f; double lon, lat;
f = current_aircraft.fdm_state;
id = current_options.get_airport_id();
if ( id.length() ) { if ( id.length() ) {
// set initial position from airport id // set initial position from airport id
@ -151,7 +148,6 @@ bool fgInitPosition( void ) {
path.append( "Airports" ); path.append( "Airports" );
path.append( "simple.mk4" ); path.append( "simple.mk4" );
FGAirports airports( path.c_str() ); FGAirports airports( path.c_str() );
FGAirport a;
FG_LOG( FG_GENERAL, FG_INFO, FG_LOG( FG_GENERAL, FG_INFO,
"Attempting to set starting position from airport code " "Attempting to set starting position from airport code "
@ -170,17 +166,38 @@ bool fgInitPosition( void ) {
if ( ! airports.search( id, &a ) ) { if ( ! airports.search( id, &a ) ) {
FG_LOG( FG_GENERAL, FG_ALERT, FG_LOG( FG_GENERAL, FG_ALERT,
"Failed to find " << id << " in database." ); "Failed to find " << id << " in database." );
exit(-1); return false;
} else { } else {
f->set_Longitude( a.longitude * DEG_TO_RAD ); current_options.set_lon( a.longitude );
f->set_Latitude( a.latitude * DEG_TO_RAD ); current_options.set_lat( a.latitude );
} }
} else { } else {
// set initial position from default or command line coordinates return false;
}
FG_LOG( FG_GENERAL, FG_INFO,
"Position for " << id << " is ("
<< a.longitude << ", "
<< a.latitude << ")" );
return true;
}
// Set initial position and orientation
bool fgInitPosition( void ) {
FGInterface *f = current_aircraft.fdm_state;
string id = current_options.get_airport_id();
if ( id.length() ) {
// set initial position from airport id
if ( ! fgSetPosFromAirportID( id ) ) {
exit(-1);
}
}
// set initial position from default or command line coordinates
f->set_Longitude( current_options.get_lon() * DEG_TO_RAD ); f->set_Longitude( current_options.get_lon() * DEG_TO_RAD );
f->set_Latitude( current_options.get_lat() * DEG_TO_RAD ); f->set_Latitude( current_options.get_lat() * DEG_TO_RAD );
}
FG_LOG( FG_GENERAL, FG_INFO, FG_LOG( FG_GENERAL, FG_INFO,
"starting altitude is = " << current_options.get_altitude() ); "starting altitude is = " << current_options.get_altitude() );

View file

@ -49,6 +49,10 @@ bool fgInitSubsystems( void );
void fgReInitSubsystems( void ); void fgReInitSubsystems( void );
// Set current_options lon/lat given an airport id
bool fgSetPosFromAirportID( const string& id );
#endif // _FG_INIT_H #endif // _FG_INIT_H

View file

@ -1312,6 +1312,11 @@ int main( int argc, char **argv ) {
// fonts !!! // fonts !!!
guiInit(); guiInit();
// set current_options lon/lat if an airport id is specified
if ( current_options.get_airport_id().length() ) {
fgSetPosFromAirportID( current_options.get_airport_id() );
}
// Initialize time // Initialize time
FGPath zone( current_options.get_fg_root() ); FGPath zone( current_options.get_fg_root() );
zone.append( "Timezone" ); zone.append( "Timezone" );