From f9b28c103d528de232e74c9fbf2f38a71a6bd77c Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 7 Jul 2000 17:27:37 +0000 Subject: [PATCH] Updates to go along with SGTime tweaks in SimGear. --- src/Main/Makefile.am | 1 + src/Main/bfi.cxx | 8 ++--- src/Main/fg_init.cxx | 1 - src/Main/keyboard.cxx | 9 ++--- src/Main/main.cxx | 66 +++++++++++++++++++++++++++++++---- src/Time/sunpos.cxx | 1 + src/WeatherCM/FGWeatherDefs.h | 4 +-- 7 files changed, 72 insertions(+), 18 deletions(-) diff --git a/src/Main/Makefile.am b/src/Main/Makefile.am index 18e96056f..705c7aba4 100644 --- a/src/Main/Makefile.am +++ b/src/Main/Makefile.am @@ -36,6 +36,7 @@ fgfs_SOURCES = \ bfi.cxx bfi.hxx \ fg_init.cxx fg_init.hxx \ fg_io.cxx fg_io.hxx \ + globals.cxx globals.hxx \ keyboard.cxx keyboard.hxx \ options.cxx options.hxx \ save.cxx save.hxx \ diff --git a/src/Main/bfi.cxx b/src/Main/bfi.cxx index 441004135..4962fa083 100644 --- a/src/Main/bfi.cxx +++ b/src/Main/bfi.cxx @@ -54,6 +54,7 @@ # include #endif +#include "globals.hxx" #include "options.hxx" #include "save.hxx" #include "fg_init.hxx" @@ -393,13 +394,12 @@ FGBFI::setTimeGMT (time_t 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(), - current_options.get_time_offset(), - current_options.get_time_offset_type() ); + 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 ); + * FEET_TO_METER, + globals->get_warp() ); needReinit(); } diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index cbd19bf91..adb7877e9 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -245,7 +245,6 @@ bool fgInitGeneral( void ) { // Returns non-zero if a problem encountered. bool fgInitSubsystems( void ) { fgLIGHT *l = &cur_light_params; - SGTime *t = SGTime::cur_time_params; FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems"); FG_LOG( FG_GENERAL, FG_INFO, "========== =========="); diff --git a/src/Main/keyboard.cxx b/src/Main/keyboard.cxx index 328e15146..458ad8dd4 100644 --- a/src/Main/keyboard.cxx +++ b/src/Main/keyboard.cxx @@ -67,6 +67,7 @@ #endif #include "bfi.hxx" +#include "globals.hxx" #include "keyboard.hxx" #include "options.hxx" #include "save.hxx" @@ -194,14 +195,14 @@ void GLUTkey(unsigned char k, int x, int y) { fgHUDInit2(¤t_aircraft); return; case 77: // M key - t->adjust_warp(-60); + globals->inc_warp( -60 ); fgUpdateSkyAndLightingParams(); return; case 80: // P key current_options.toggle_panel(); break; case 84: // T key - t->adjust_warp_delta(-30); + globals->inc_warp_delta( -30 ); fgUpdateSkyAndLightingParams(); return; case 87: // W key @@ -339,7 +340,7 @@ void GLUTkey(unsigned char k, int x, int y) { fgHUDInit(¤t_aircraft); // normal HUD return; case 109: // m key - t->adjust_warp (+60); + globals->inc_warp( 60 ); fgUpdateSkyAndLightingParams(); return; case 112: // p key @@ -367,7 +368,7 @@ void GLUTkey(unsigned char k, int x, int y) { } return; case 116: // t key - t->adjust_warp_delta (+30); + globals->inc_warp_delta( 30 ); fgUpdateSkyAndLightingParams(); return; case 118: // v key diff --git a/src/Main/main.cxx b/src/Main/main.cxx index db9644435..3946503ba 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -73,6 +73,7 @@ #include #include #include +#include #include @@ -105,6 +106,7 @@ #include "bfi.hxx" #include "fg_init.hxx" #include "fg_io.hxx" +#include "globals.hxx" #include "keyboard.hxx" #include "options.hxx" #include "splash.hxx" @@ -796,11 +798,16 @@ static void fgMainLoop( void ) { cur_fdm_state->get_Altitude() * FEET_TO_METER); */ // update "time" + if ( globals->get_warp_delta() != 0 ) { + globals->inc_warp( globals->get_warp_delta() ); + } + t->update( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), - cur_fdm_state->get_Altitude()* FEET_TO_METER ); + cur_fdm_state->get_Altitude()* FEET_TO_METER, + globals->get_warp() ); - if ( t->get_warp_delta() != 0 ) { + if ( globals->get_warp_delta() != 0 ) { fgUpdateSkyAndLightingParams(); } @@ -1277,6 +1284,9 @@ int main( int argc, char **argv ) { aircraft_dir = ""; // Initialize the Aircraft directory to "" (UIUC) + // needs to happen before we parse command line options + globals = new FGGlobals; + // Load the configuration parameters if ( !fgInitConfig(argc, argv) ) { FG_LOG( FG_GENERAL, FG_ALERT, "Config option parsing failed ..." ); @@ -1310,11 +1320,53 @@ int main( int argc, char **argv ) { // 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(), - current_options.get_time_offset(), - current_options.get_time_offset_type() ); - SGTime::cur_time_params->update( 0.0, 0.0, 0.0 ); + SGTime::cur_time_params->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() ) ); + + // Okay, we now have six possible scenarios + switch ( current_options.get_time_offset_type() ) { + case SG_TIME_SYS_OFFSET: + globals->set_warp( current_options.get_time_offset() ); + break; + case SG_TIME_GMT_OFFSET: + globals->set_warp( current_options.get_time_offset() - + (currGMT - systemLocalTime) ); + break; + case SG_TIME_LAT_OFFSET: + globals->set_warp( current_options.get_time_offset() - + (aircraftLocalTime - systemLocalTime) ); + break; + case SG_TIME_SYS_ABSOLUTE: + globals->set_warp( current_options.get_time_offset() - cur_time ); + //printf("warp = %d\n", warp); + break; + case SG_TIME_GMT_ABSOLUTE: + globals->set_warp( current_options.get_time_offset() - currGMT ); + break; + case SG_TIME_LAT_ABSOLUTE: + globals->set_warp( current_options.get_time_offset() - + (aircraftLocalTime - systemLocalTime) - + cur_time ); + break; + default: + FG_LOG( FG_GENERAL, FG_ALERT, "Unsupported type" ); + exit( -1 ); + } + + FG_LOG( FG_GENERAL, FG_INFO, "After time init, warp = " + << globals->get_warp() ); + + globals->set_warp_delta( 0 ); + + SGTime::cur_time_params->update( 0.0, 0.0, 0.0, globals->get_warp() ); // Do some quick general initializations if( !fgInitGeneral()) { diff --git a/src/Time/sunpos.cxx b/src/Time/sunpos.cxx index a79d7d260..bba9faa88 100644 --- a/src/Time/sunpos.cxx +++ b/src/Time/sunpos.cxx @@ -258,6 +258,7 @@ void fgUpdateSunPos( void ) { v = ¤t_view; FG_LOG( FG_EVENT, FG_INFO, " Updating Sun position" ); + FG_LOG( FG_EVENT, FG_INFO, " Gst = " << t->getGst() ); fgSunPositionGST(t->getGst(), &l->sun_lon, &sun_gd_lat); diff --git a/src/WeatherCM/FGWeatherDefs.h b/src/WeatherCM/FGWeatherDefs.h index f0af6fcfb..f357a9f3e 100644 --- a/src/WeatherCM/FGWeatherDefs.h +++ b/src/WeatherCM/FGWeatherDefs.h @@ -57,8 +57,8 @@ typedef float WeatherPrecision; #define MINIMUM_WEATHER_VISIBILITY 10.0 /* metres */ #define DEFAULT_WEATHER_VISIBILITY 32000.0 /* metres */ //prefered way the database is working -// #define PREFERED_WORKING_TYPE default_mode -#define PREFERED_WORKING_TYPE use_internet +#define PREFERED_WORKING_TYPE default_mode +// #define PREFERED_WORKING_TYPE use_internet #define FG_WEATHER_DEFAULT_TEMPERATURE (15.0+273.16) /*15°C or 288.16°K*/ #define FG_WEATHER_DEFAULT_VAPORPRESSURE (0.0) /*in Pascal 1 Pa = N/m^2*/ -- 2.39.5