Some follow up patches from Norman Vine.
This commit is contained in:
parent
fb5d5960a9
commit
7cd113fa2f
4 changed files with 75 additions and 63 deletions
|
@ -80,6 +80,11 @@ void reInit(puObject *cb)
|
||||||
// if( AptId.c_str() != "\0" )
|
// if( AptId.c_str() != "\0" )
|
||||||
// fgSetPosFromAirportID( AptId );
|
// fgSetPosFromAirportID( AptId );
|
||||||
|
|
||||||
|
SGTime *t = globals->get_time_params();
|
||||||
|
delete t;
|
||||||
|
t = fgInitTime();
|
||||||
|
globals->set_time_params( t );
|
||||||
|
|
||||||
fgReInitSubsystems();
|
fgReInitSubsystems();
|
||||||
|
|
||||||
// reduntant(fgReInitSubsystems) ?
|
// reduntant(fgReInitSubsystems) ?
|
||||||
|
|
|
@ -63,6 +63,7 @@
|
||||||
#include <simgear/math/sg_geodesy.hxx>
|
#include <simgear/math/sg_geodesy.hxx>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <simgear/timing/sg_time.hxx>
|
#include <simgear/timing/sg_time.hxx>
|
||||||
|
#include <simgear/timing/lowleveltime.h>
|
||||||
|
|
||||||
#include <Aircraft/aircraft.hxx>
|
#include <Aircraft/aircraft.hxx>
|
||||||
#include <FDM/UIUCModel/uiuc_aircraftdir.h>
|
#include <FDM/UIUCModel/uiuc_aircraftdir.h>
|
||||||
|
@ -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
|
// This is the top level init routine which calls all the other
|
||||||
// initialization routines. If you are adding a subsystem to flight
|
// initialization routines. If you are adding a subsystem to flight
|
||||||
// gear, its initialization call should located in this routine.
|
// gear, its initialization call should located in this routine.
|
||||||
|
@ -622,8 +678,8 @@ bool fgInitSubsystems( void ) {
|
||||||
|
|
||||||
if ( global_tile_mgr.init() ) {
|
if ( global_tile_mgr.init() ) {
|
||||||
// Load the local scenery data
|
// Load the local scenery data
|
||||||
global_tile_mgr.update( fgGetDouble("/position/longitude-deg"),
|
global_tile_mgr.update( longitude->getDoubleValue(),
|
||||||
fgGetDouble("/position/latitude-deg") );
|
latitude->getDoubleValue() );
|
||||||
} else {
|
} else {
|
||||||
SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
|
SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
#include <simgear/timing/sg_time.hxx>
|
||||||
|
|
||||||
#include STL_STRING
|
#include STL_STRING
|
||||||
|
|
||||||
|
@ -79,6 +80,9 @@ bool fgSetPosFromAirportID( const string& id );
|
||||||
// Set position and heading given an airport id and heading (degrees)
|
// Set position and heading given an airport id and heading (degrees)
|
||||||
bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg );
|
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
|
#endif // _FG_INIT_HXX
|
||||||
|
|
||||||
|
|
|
@ -561,9 +561,8 @@ void fgRenderFrame( void ) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
|
thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
|
||||||
( global_multi_loop *
|
( global_multi_loop * fgGetInt("/sim/speed-up") )
|
||||||
fgGetInt("/sim/speed-up") ) /
|
/ (double)fgGetInt("/sim/model-hz") );
|
||||||
(double)fgGetInt("/sim/model-hz") );
|
|
||||||
|
|
||||||
double actual_visibility = thesky->get_visibility();
|
double actual_visibility = thesky->get_visibility();
|
||||||
// cout << "actual visibility = " << actual_visibility << endl;
|
// cout << "actual visibility = " << actual_visibility << endl;
|
||||||
|
@ -1518,59 +1517,7 @@ int mainLoop( int argc, char **argv ) {
|
||||||
fgGetDouble("/orientation/heading-deg") );
|
fgGetDouble("/orientation/heading-deg") );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any time after globals is created we are ready to use the
|
SGTime *t = fgInitTime();
|
||||||
// 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() );
|
|
||||||
|
|
||||||
globals->set_time_params( t );
|
globals->set_time_params( t );
|
||||||
|
|
||||||
// Do some quick general initializations
|
// Do some quick general initializations
|
||||||
|
|
Loading…
Add table
Reference in a new issue