From: curt Date: Fri, 7 Jul 2000 20:28:51 +0000 (+0000) Subject: More SGTime tidying. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=436db300535140f7f1c7b6e11d996a1e6f55f758;p=flightgear.git More SGTime tidying. --- diff --git a/src/Cockpit/cockpit.cxx b/src/Cockpit/cockpit.cxx index 9b14ab5ad..eecbf69ee 100644 --- a/src/Cockpit/cockpit.cxx +++ b/src/Cockpit/cockpit.cxx @@ -43,6 +43,7 @@ #include #include +#include
#include
#include
#include @@ -101,8 +102,7 @@ char* get_formated_gmt_time( void ) { static char buf[32]; - SGTime *t = SGTime::cur_time_params; - const struct tm *p = t->getGmt(); + const struct tm *p = globals->get_time_params()->getGmt(); sprintf( buf, "%d/%d/%4d %d:%02d:%02d", p->tm_mon+1, p->tm_mday, 1900 + p->tm_year, p->tm_hour, p->tm_min, p->tm_sec); diff --git a/src/Cockpit/sp_panel.cxx b/src/Cockpit/sp_panel.cxx index 933099ec6..136fbefbc 100644 --- a/src/Cockpit/sp_panel.cxx +++ b/src/Cockpit/sp_panel.cxx @@ -29,9 +29,9 @@ #include #include -#include #include
+#include
#include "panel.hxx" #include "steam.hxx" @@ -63,7 +63,7 @@ FG_USING_STD(map); static char * panelGetTime () { static char buf[1024]; // FIXME: not thread-safe - struct tm * t = SGTime::cur_time_params->getGmt(); + struct tm * t = globals->get_time_params()->getGmt(); sprintf(buf, " %.2d:%.2d:%.2d", t->tm_hour, t->tm_min, t->tm_sec); return buf; diff --git a/src/Main/bfi.cxx b/src/Main/bfi.cxx index 4962fa083..c0a06a987 100644 --- a/src/Main/bfi.cxx +++ b/src/Main/bfi.cxx @@ -378,7 +378,7 @@ FGBFI::setAircraftDir (const string &dir) time_t FGBFI::getTimeGMT () { - return SGTime::cur_time_params->get_cur_time(); + return globals->get_time_params()->get_cur_time(); } @@ -392,14 +392,14 @@ FGBFI::setTimeGMT (time_t time) // and solar system current_options.set_time_offset(time); current_options.set_time_offset_type(SG_TIME_GMT_ABSOLUTE); - SGTime::cur_time_params->init( cur_fdm_state->get_Longitude(), - cur_fdm_state->get_Latitude(), - current_options.get_fg_root() ); - SGTime::cur_time_params->update( cur_fdm_state->get_Longitude(), - cur_fdm_state->get_Latitude(), - cur_fdm_state->get_Altitude() - * FEET_TO_METER, - globals->get_warp() ); + globals->get_time_params()->init( cur_fdm_state->get_Longitude(), + cur_fdm_state->get_Latitude(), + current_options.get_fg_root() ); + globals->get_time_params()->update( cur_fdm_state->get_Longitude(), + cur_fdm_state->get_Latitude(), + cur_fdm_state->get_Altitude() + * FEET_TO_METER, + globals->get_warp() ); needReinit(); } diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 5521a2bf6..d21fce514 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -25,6 +25,9 @@ #define _GLOBALS_HXX +#include + + class FGGlobals { private: @@ -40,6 +43,9 @@ private: // to make time progress faster than normal (or even run in reverse.) long int warp_delta; + // Time structure + SGTime *time_params; + public: FGGlobals(); @@ -55,6 +61,9 @@ public: inline long int get_warp_delta() const { return warp_delta; } inline void set_warp_delta( long int d ) { warp_delta = d; } inline void inc_warp_delta( long int d ) { warp_delta += d; } + + inline SGTime *get_time_params() const { return time_params; } + inline void set_time_params( SGTime *t ) { time_params = t; } }; diff --git a/src/Main/keyboard.cxx b/src/Main/keyboard.cxx index 458ad8dd4..3171b28d7 100644 --- a/src/Main/keyboard.cxx +++ b/src/Main/keyboard.cxx @@ -48,7 +48,6 @@ #include #include #include -#include #include #include @@ -84,7 +83,6 @@ void GLUTkey(unsigned char k, int x, int y) { int speed; f = current_aircraft.fdm_state; - t = SGTime::cur_time_params; v = ¤t_view; FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k ); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 3946503ba..638bf612f 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -278,8 +278,6 @@ void fgRenderFrame( void ) { FGBFI::update(); fgLIGHT *l = &cur_light_params; - SGTime *t = SGTime::cur_time_params; - // FGView *v = ¤t_view; static double last_visibility = -9999; double angle; @@ -442,7 +440,7 @@ void fgRenderFrame( void ) { cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude() * FEET_TO_METER, cur_light_params.sun_rotation, - SGTime::cur_time_params->getGst(), + globals->get_time_params()->getGst(), ephem->getSunRightAscension(), ephem->getSunDeclination(), 50000.0, ephem->getMoonRightAscension(), @@ -607,10 +605,7 @@ void fgRenderFrame( void ) { // Update internal time dependent calculations (i.e. flight model) void fgUpdateTimeDepCalcs(int multi_loop, int remainder) { static fdm_state_list fdm_list; - // FGInterface fdm_state; fgLIGHT *l = &cur_light_params; - SGTime *t = SGTime::cur_time_params; - // FGView *v = ¤t_view; int i; // update the flight model @@ -698,7 +693,7 @@ void fgUpdateTimeDepCalcs(int multi_loop, int remainder) { l->UpdateAdjFog(); // Update solar system - ephem->update( t, cur_fdm_state->get_Latitude() ); + ephem->update( globals->get_time_params(), cur_fdm_state->get_Latitude() ); // Update radio stack model current_radiostack->update( cur_fdm_state->get_Longitude(), @@ -724,7 +719,6 @@ static const double alt_adjust_m = alt_adjust_ft * FEET_TO_METER; // What should we do when we have nothing else to do? Let's get ready // for the next move and update the display? static void fgMainLoop( void ) { - SGTime *t; static long remainder = 0; long elapsed; #ifdef FANCY_FRAME_COUNTER @@ -735,7 +729,7 @@ static void fgMainLoop( void ) { static int frames = 0; #endif // FANCY_FRAME_COUNTER - t = SGTime::cur_time_params; + SGTime *t = globals->get_time_params(); FG_LOG( FG_ALL, FG_DEBUG, "Running Main Loop"); FG_LOG( FG_ALL, FG_DEBUG, "======= ==== ===="); @@ -815,7 +809,7 @@ static void fgMainLoop( void ) { cur_magvar.update( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude()* FEET_TO_METER, - SGTime::cur_time_params->getJD() ); + globals->get_time_params()->getJD() ); // Get elapsed time (in usec) for this past frame elapsed = fgGetTimeInterval(); @@ -1316,20 +1310,15 @@ int main( int argc, char **argv ) { guiInit(); // Initialize time - SGTime::cur_time_params = new SGTime( current_options.get_fg_root() ); - // SGTime::cur_time_params->init( cur_fdm_state->get_Longitude(), - // cur_fdm_state->get_Latitude() ); - // SGTime::cur_time_params->update( cur_fdm_state->get_Longitude() ); - SGTime::cur_time_params->init( 0.0, 0.0, current_options.get_fg_root() ); + SGTime *t = new SGTime( current_options.get_fg_root() ); + t->init( 0.0, 0.0, current_options.get_fg_root() ); - // Handle user specified offsets - // current_options.get_time_offset(), - // current_options.get_time_offset_type() ); - - time_t cur_time = SGTime::cur_time_params->get_cur_time(); - time_t currGMT = SGTime::cur_time_params->get_gmt( gmtime(&cur_time) ); - time_t systemLocalTime = SGTime::cur_time_params->get_gmt( localtime(&cur_time) ); - time_t aircraftLocalTime = SGTime::cur_time_params->get_gmt( fgLocaltime(&cur_time, SGTime::cur_time_params->get_zonename() ) ); + // Handle potential user specified time offsets + time_t cur_time = t->get_cur_time(); + time_t currGMT = t->get_gmt( gmtime(&cur_time) ); + time_t systemLocalTime = t->get_gmt( localtime(&cur_time) ); + time_t aircraftLocalTime = + t->get_gmt( fgLocaltime(&cur_time, t->get_zonename() ) ); // Okay, we now have six possible scenarios switch ( current_options.get_time_offset_type() ) { @@ -1366,7 +1355,9 @@ int main( int argc, char **argv ) { globals->set_warp_delta( 0 ); - SGTime::cur_time_params->update( 0.0, 0.0, 0.0, globals->get_warp() ); + t->update( 0.0, 0.0, 0.0, globals->get_warp() ); + + globals->set_time_params( t ); // Do some quick general initializations if( !fgInitGeneral()) { @@ -1399,7 +1390,7 @@ int main( int argc, char **argv ) { FGPath ephem_data_path( current_options.get_fg_root() ); ephem_data_path.append( "Astro" ); ephem = new FGEphemeris( ephem_data_path.c_str() ); - ephem->update( SGTime::cur_time_params, 0.0 ); + ephem->update( globals->get_time_params(), 0.0 ); FGPath sky_tex_path( current_options.get_fg_root() ); sky_tex_path.append( "Textures" ); diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 455482178..6e2ee313a 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -52,8 +52,9 @@ bool global_fullscreen = true; # include #endif -#include "views.hxx" +#include "globals.hxx" #include "options.hxx" +#include "views.hxx" FG_USING_STD(string); FG_USING_NAMESPACE(std); @@ -432,12 +433,12 @@ long int fgOPTIONS::parse_date( const string& date) num[i] = '\0'; gmt.tm_sec = atoi(num); } - time_t theTime = SGTime::cur_time_params->get_gmt(gmt.tm_year, - gmt.tm_mon, - gmt.tm_mday, - gmt.tm_hour, - gmt.tm_min, - gmt.tm_sec); + time_t theTime = globals->get_time_params()->get_gmt(gmt.tm_year, + gmt.tm_mon, + gmt.tm_mday, + gmt.tm_hour, + gmt.tm_min, + gmt.tm_sec); //printf ("Date is %s\n", ctime(&theTime)); //printf ("in seconds that is %d\n", theTime); //exit(1); diff --git a/src/Network/garmin.cxx b/src/Network/garmin.cxx index 2505c39db..41aa2a48b 100644 --- a/src/Network/garmin.cxx +++ b/src/Network/garmin.cxx @@ -23,9 +23,9 @@ #include #include -#include #include +#include
#include "iochannel.hxx" #include "garmin.hxx" @@ -67,7 +67,7 @@ bool FGGarmin::gen_message() { int deg; double min; - SGTime *t = SGTime::cur_time_params; + SGTime *t = globals->get_time_params(); char utc[10]; sprintf( utc, "%02d%02d%02d", diff --git a/src/Network/nmea.cxx b/src/Network/nmea.cxx index c5f33701f..369f30aff 100644 --- a/src/Network/nmea.cxx +++ b/src/Network/nmea.cxx @@ -23,9 +23,9 @@ #include #include -#include #include +#include
#include "iochannel.hxx" #include "nmea.hxx" @@ -68,7 +68,7 @@ bool FGNMEA::gen_message() { int deg; double min; - SGTime *t = SGTime::cur_time_params; + SGTime *t = globals->get_time_params(); char utc[10]; sprintf( utc, "%02d%02d%02d", diff --git a/src/Time/light.cxx b/src/Time/light.cxx index 56099286c..05cd0370b 100644 --- a/src/Time/light.cxx +++ b/src/Time/light.cxx @@ -54,7 +54,6 @@ FG_USING_STD(string); #include #include #include -#include #include #include
@@ -100,7 +99,6 @@ void fgLIGHT::Init( void ) { // update lighting parameters based on current sun position void fgLIGHT::Update( void ) { FGInterface *f; - SGTime *t; // if the 4th field is 0.0, this specifies a direction ... GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; // base sky color @@ -110,7 +108,6 @@ void fgLIGHT::Update( void ) { double deg, ambient, diffuse, sky_brightness; f = current_aircraft.fdm_state; - t = SGTime::cur_time_params; FG_LOG( FG_EVENT, FG_INFO, "Updating light parameters." ); diff --git a/src/Time/moonpos.cxx b/src/Time/moonpos.cxx index ca6c7abfd..6a7e895d8 100644 --- a/src/Time/moonpos.cxx +++ b/src/Time/moonpos.cxx @@ -58,8 +58,8 @@ #include #include #include -#include +#include
#include
#include @@ -337,7 +337,6 @@ static void fgMoonPositionGST(double gst, double *lon, double *lat) { // update the cur_time_params structure with the current moon position void fgUpdateMoonPos( void ) { fgLIGHT *l; - SGTime *t; FGView *v; sgVec3 nup, nmoon, v0, surface_to_moon; Point3D p, rel_moonpos; @@ -345,7 +344,7 @@ void fgUpdateMoonPos( void ) { double moon_gd_lat, sl_radius; l = &cur_light_params; - t = SGTime::cur_time_params; + SGTime *t = globals->get_time_params(); v = ¤t_view; FG_LOG( FG_EVENT, FG_INFO, " Updating Moon position" ); diff --git a/src/Time/sunpos.cxx b/src/Time/sunpos.cxx index bba9faa88..68c35421c 100644 --- a/src/Time/sunpos.cxx +++ b/src/Time/sunpos.cxx @@ -60,8 +60,8 @@ #include #include #include -#include +#include
#include
#include @@ -246,7 +246,6 @@ static void fgSunPositionGST(double gst, double *lon, double *lat) { // update the cur_time_params structure with the current sun position void fgUpdateSunPos( void ) { fgLIGHT *l; - SGTime *t; FGView *v; sgVec3 nup, nsun, v0, surface_to_sun; Point3D p, rel_sunpos; @@ -254,7 +253,7 @@ void fgUpdateSunPos( void ) { double sun_gd_lat, sl_radius; l = &cur_light_params; - t = SGTime::cur_time_params; + SGTime *t = globals->get_time_params(); v = ¤t_view; FG_LOG( FG_EVENT, FG_INFO, " Updating Sun position" ); diff --git a/src/Time/tmp.cxx b/src/Time/tmp.cxx index d2fec7dcc..988a5f3b3 100644 --- a/src/Time/tmp.cxx +++ b/src/Time/tmp.cxx @@ -26,9 +26,9 @@ #endif #include -#include #include +#include
#include
#include "light.hxx" @@ -58,9 +58,9 @@ FGMagVar cur_magvar; // periodic time updater wrapper void fgUpdateLocalTime() { - SGTime::cur_time_params->updateLocal( cur_fdm_state->get_Longitude(), - cur_fdm_state->get_Latitude(), - current_options.get_fg_root() ); + globals->get_time_params()->updateLocal( cur_fdm_state->get_Longitude(), + cur_fdm_state->get_Latitude(), + current_options.get_fg_root() ); }