From 7cd113fa2f3f7a12c638f7473d827a55bae49a36 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 6 Feb 2002 23:31:33 +0000 Subject: [PATCH] Some follow up patches from Norman Vine. --- src/GUI/gui_local.cxx | 15 +++++++---- src/Main/fg_init.cxx | 60 +++++++++++++++++++++++++++++++++++++++++-- src/Main/fg_init.hxx | 4 +++ src/Main/main.cxx | 59 +++--------------------------------------- 4 files changed, 75 insertions(+), 63 deletions(-) diff --git a/src/GUI/gui_local.cxx b/src/GUI/gui_local.cxx index e351f5099..f537d6089 100644 --- a/src/GUI/gui_local.cxx +++ b/src/GUI/gui_local.cxx @@ -73,13 +73,18 @@ void reInit(puObject *cb) globals->restoreInitialState(); - // Unsuccessful KLUDGE to fix the 'every other time' - // problem when doing a 'reset' after a 'goto airport' + // Unsuccessful KLUDGE to fix the 'every other time' + // problem when doing a 'reset' after a 'goto airport' - // string AptId( fgGetString("/sim/startup/airport-id") ); - // if( AptId.c_str() != "\0" ) - // fgSetPosFromAirportID( AptId ); + // string AptId( fgGetString("/sim/startup/airport-id") ); + // if( AptId.c_str() != "\0" ) + // fgSetPosFromAirportID( AptId ); + SGTime *t = globals->get_time_params(); + delete t; + t = fgInitTime(); + globals->set_time_params( t ); + fgReInitSubsystems(); // reduntant(fgReInitSubsystems) ? diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index c0922a598..8174feee8 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -63,6 +63,7 @@ #include #include #include +#include #include #include @@ -583,6 +584,61 @@ void fgInitView() { } +SGTime *fgInitTime() { + // Initialize time + static const SGPropertyNode *longitude + = fgGetNode("/position/longitude-deg"); + static const SGPropertyNode *latitude + = fgGetNode("/position/latitude-deg"); + + SGPath zone( globals->get_fg_root() ); + zone.append( "Timezone" ); + SGTime *t = new SGTime( longitude->getDoubleValue() + * SGD_DEGREES_TO_RADIANS, + latitude->getDoubleValue() + * SGD_DEGREES_TO_RADIANS, + zone.str() ); + + // Handle potential user specified time offsets + time_t cur_time = t->get_cur_time(); + time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) ); + time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) ); + time_t aircraftLocalTime = + sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) ); + + // Okay, we now have six possible scenarios + int offset = fgGetInt("/sim/startup/time-offset"); + const string &offset_type = fgGetString("/sim/startup/time-offset-type"); + if (offset_type == "system-offset") { + globals->set_warp( offset ); + } else if (offset_type == "gmt-offset") { + globals->set_warp( offset - (currGMT - systemLocalTime) ); + } else if (offset_type == "latitude-offset") { + globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) ); + } else if (offset_type == "system") { + globals->set_warp( offset - cur_time ); + } else if (offset_type == "gmt") { + globals->set_warp( offset - currGMT ); + } else if (offset_type == "latitude") { + globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) - + cur_time ); + } else { + SG_LOG( SG_GENERAL, SG_ALERT, + "FG_TIME::Unsupported offset type " << offset_type ); + exit( -1 ); + } + + SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = " + << globals->get_warp() ); + + globals->set_warp_delta( 0 ); + + t->update( 0.0, 0.0, globals->get_warp() ); + + return t; +} + + // This is the top level init routine which calls all the other // initialization routines. If you are adding a subsystem to flight // gear, its initialization call should located in this routine. @@ -622,8 +678,8 @@ bool fgInitSubsystems( void ) { if ( global_tile_mgr.init() ) { // Load the local scenery data - global_tile_mgr.update( fgGetDouble("/position/longitude-deg"), - fgGetDouble("/position/latitude-deg") ); + global_tile_mgr.update( longitude->getDoubleValue(), + latitude->getDoubleValue() ); } else { SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" ); exit(-1); diff --git a/src/Main/fg_init.hxx b/src/Main/fg_init.hxx index ea53fdb8b..23350450e 100644 --- a/src/Main/fg_init.hxx +++ b/src/Main/fg_init.hxx @@ -36,6 +36,7 @@ #endif #include +#include #include STL_STRING @@ -79,6 +80,9 @@ bool fgSetPosFromAirportID( const string& id ); // Set position and heading given an airport id and heading (degrees) bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ); +// Initialize various time dependent systems (lighting, sun position, etc.) +// returns a new instance of the SGTime class +SGTime *fgInitTime(); #endif // _FG_INIT_HXX diff --git a/src/Main/main.cxx b/src/Main/main.cxx index c935e4da2..f1042f9fd 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -561,9 +561,8 @@ void fgRenderFrame( void ) { #endif thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER, - ( global_multi_loop * - fgGetInt("/sim/speed-up") ) / - (double)fgGetInt("/sim/model-hz") ); + ( global_multi_loop * fgGetInt("/sim/speed-up") ) + / (double)fgGetInt("/sim/model-hz") ); double actual_visibility = thesky->get_visibility(); // cout << "actual visibility = " << actual_visibility << endl; @@ -1518,59 +1517,7 @@ int mainLoop( int argc, char **argv ) { fgGetDouble("/orientation/heading-deg") ); } - // Any time after globals is created we are ready to use the - // property system - static const SGPropertyNode *longitude - = fgGetNode("/position/longitude-deg", true); - static const SGPropertyNode *latitude - = fgGetNode("/position/latitude-deg", true); - - - // Initialize time - SGPath zone( globals->get_fg_root() ); - zone.append( "Timezone" ); - SGTime *t = new SGTime( longitude->getDoubleValue() - * SGD_DEGREES_TO_RADIANS, - latitude->getDoubleValue() - * SGD_DEGREES_TO_RADIANS, - zone.str() ); - - // Handle potential user specified time offsets - time_t cur_time = t->get_cur_time(); - time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) ); - time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) ); - time_t aircraftLocalTime = - sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) ); - - // Okay, we now have six possible scenarios - int offset = fgGetInt("/sim/startup/time-offset"); - const string &offset_type = fgGetString("/sim/startup/time-offset-type"); - if (offset_type == "system-offset") { - globals->set_warp( offset ); - } else if (offset_type == "gmt-offset") { - globals->set_warp( offset - (currGMT - systemLocalTime) ); - } else if (offset_type == "latitude-offset") { - globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) ); - } else if (offset_type == "system") { - globals->set_warp( offset - cur_time ); - } else if (offset_type == "gmt") { - globals->set_warp( offset - currGMT ); - } else if (offset_type == "latitude") { - globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) - - cur_time ); - } else { - SG_LOG( SG_GENERAL, SG_ALERT, - "Unsupported offset type " << offset_type ); - exit( -1 ); - } - - SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = " - << globals->get_warp() ); - - globals->set_warp_delta( 0 ); - - t->update( 0.0, 0.0, globals->get_warp() ); - + SGTime *t = fgInitTime(); globals->set_time_params( t ); // Do some quick general initializations