FlightGear into SimGear so it can be used by other projects.
#include <Main/bfi.hxx>
#include <Main/fg_init.hxx>
#include <Main/options.hxx>
-#include <Time/fg_time.hxx>
#include "auto_gui.hxx"
#include "newauto.hxx"
#include <Main/views.hxx>
#include <Scenery/scenery.hxx>
#include <Time/fg_timer.hxx>
-#include <Time/fg_time.hxx>
#include <GUI/gui.h>
#include "cockpit.hxx"
#include <map>
#include <simgear/debug/logstream.hxx>
+#include <simgear/timing/fg_time.hxx>
+
#include <Main/bfi.hxx>
-#include <Time/fg_time.hxx>
#include "panel.hxx"
#include "steam.hxx"
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/fgpath.hxx>
#include <simgear/screen/screen-dump.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <Include/general.hxx>
#include <Aircraft/aircraft.hxx>
#ifdef FG_NETWORK_OLK
#include <NetworkOLK/network.h>
#endif
-#include <Time/fg_time.hxx>
#if defined( WIN32 ) && !defined( __CYGWIN__ )
# include <simgear/screen/win32-printer.h>
int ww, wh, need_warp = 0;
float W, H;
double offset;
-// FGTime *t = FGTime::cur_time_params;
-// if( mouse_timed_out ) {
-// if( t->get_cur_time() > mouse_off_time ) {
-// moused_timed_out = 0;
-// TurnCursorOn();
-// glutPostRedisplay () ;
-// }
-// }
if (mouse_mode == MOUSE_POINTER) {
puMouse ( x, y ) ;
if ( current_options.get_panel_status() ) {
// FGView *v = ¤t_view;
- FGTime *t = FGTime::cur_time_params;
-
- if( (toggle_pause = !t->getPause()) )
- t->togglePauseMode();
+ if( (toggle_pause = !current_options.get_pause()) )
+ current_options.toggle_pause();
if(toggle_pause)
- t->togglePauseMode();
+ current_options.toggle_pause();
}
}
FGAirport a;
- FGTime *t = FGTime::cur_time_params;
- int PauseMode = t->getPause();
+ int PauseMode = current_options.get_pause();
if(!PauseMode)
- t->togglePauseMode();
+ current_options.toggle_pause();
char *s;
AptDialogInput->getValue(&s);
mkDialog(AptId.c_str());
}
}
- if( PauseMode != t->getPause() )
- t->togglePauseMode();
+ if( PauseMode != current_options.get_pause() )
+ current_options.toggle_pause();
}
void AptDialog_Reset(puObject *)
{
string NetId;
- FGTime *t = FGTime::cur_time_params;
- int PauseMode = t->getPause();
+ int PauseMode = current_options.get_pause();
if(!PauseMode)
- t->togglePauseMode();
+ current_options.toggle_pause();
/*
The following needs some cleanup because
"string options.NetId" and "char *net_callsign"
/* Entering a callsign indicates : user wants Net HUD Info */
net_hud_display = 1;
- if( PauseMode != t->getPause() )
- t->togglePauseMode();
+ if( PauseMode != current_options.get_pause() )
+ current_options.toggle_pause();
}
void NewCallSign(puObject *cb)
{
char *NetFGD;
- FGTime *t = FGTime::cur_time_params;
- int PauseMode = t->getPause();
- if(!PauseMode) t->togglePauseMode();
+ int PauseMode = current_options.get_pause();
+ if(!PauseMode) current_options.toggle_pause();
NetFGDHostDialogInput->getValue( &NetFGD );
strcpy( fgd_host, NetFGD);
NetFGDPortLoDialogInput->getValue( (int *) &base_port );
NetFGDPortHiDialogInput->getValue( (int *) &end_port );
NetFGDDialog_Cancel( NULL );
- if( PauseMode != t->getPause() )
- t->togglePauseMode();
+ if( PauseMode != current_options.get_pause() )
+ current_options.toggle_pause();
}
void NetFGDDialog_SCAN (puObject *)
char *NetFGD;
int fgd_port;
- FGTime *t = FGTime::cur_time_params;
- int PauseMode = t->getPause();
- if(!PauseMode) t->togglePauseMode();
+ int PauseMode = current_options.get_pause();
+ if(!PauseMode) current_options.toggle_pause();
// printf("Vor getvalue %s\n");
NetFGDHostDialogInput->getValue( &NetFGD );
// printf("Vor strcpy %s\n", (char *) NetFGD);
base_port, end_port);
net_resolv_fgd(fgd_host);
printf("Resolve : %d\n", net_r);
- if( PauseMode != t->getPause() ) t->togglePauseMode();
+ if( PauseMode != current_options.get_pause() ) {
+ current_options.toggle_pause();
+ }
if ( net_r == 0 ) {
fgd_port = 10000;
strcpy( fgd_name, "");
// you use USB devices, they appear in a semi-random order. Sigh.
void to_find_A ( int firstcall, float **ptr, int axes, int axis )
{ int a;
- if (firstcall) (*ptr) = NULL;
- for ( a = 0; a < jsN; a++ )
- if ( ( NULL != js[a] )
- && ( NULL == *ptr )
- && ( axes == js[a]->getNumAxes() )
- && ( (js_ax[a])[axis] > 0.5 )
- ) { ( *ptr) = (js_ax[a]) + axis;
- (**ptr) = 0;
+
+ if (firstcall) {
+ (*ptr) = NULL;
+ }
+
+ for ( a = 0; a < jsN; a++ ) {
+ if ( NULL != js[a] ) {
+ if ( NULL == *ptr ) {
+ if ( axes == js[a]->getNumAxes() ) {
+ cout << "axis[" << a << "][" << axis << "] = "
+ << (js_ax[a])[axis] << endl;
+ if ( (js_ax[a])[axis] > 0.5 ) {
+ ( *ptr) = (js_ax[a]) + axis;
+ (**ptr) = 0;
+ }
+ }
}
+ }
+ }
}
// this finds a specific button on a given controller device
for ( i = 0; i < jsN; i ++ )
{ js[i] = new jsJoystick ( i );
if ( js[i]->notWorking () )
- { // not working
-//BUG free ( js[i] );
+ {
+ delete js[i];
js[i] = NULL;
} else {
j = js[i]->getNumAxes();
to_find_A ( 1, &to_aileron , 6, 0 ); // Yoke
to_find_A ( 0, &to_aileron , 2, 0 ); // Analog JS
+ to_find_A ( 0, &to_aileron , 4, 0 ); // Gaming JS
+
to_find_A ( 1, &to_elevator , 6, 1 ); // Yoke
to_find_A ( 0, &to_elevator , 2, 1 ); // Analog JS
+ to_find_A ( 0, &to_elevator , 4, 1 ); // Gaming JS
to_find_A ( 1, &to_throttle , 6, 3 ); // Yoke
to_find_A ( 0, &to_throttle , 2, 0 ); // Analog JS, presume second
- to_find_A ( 0, &to_throttle , 4, 2 ); // gaming joystick
+ to_find_A ( 0, &to_throttle , 4, 3 ); // Game JS
- to_find_A ( 1, &to_rudder , 4, 3 ); // Pedals or gaming joystick
+ to_find_A ( 1, &to_rudder , 4, 2 ); // Pedals or gaming joystick
to_find_A ( 0, &to_rudder , 2, 1 ); // Analog JS, maybe second
to_find_A ( 1, &to_viewhat , 6, 4 ); // Yoke
$(top_builddir)/src/Autopilot/libAutopilot.a \
$(top_builddir)/src/Cockpit/libCockpit.a \
$(top_builddir)/src/Controls/libControls.a \
- $(top_builddir)/src/Ephemeris/libEphemeris.a \
$(top_builddir)/src/FDM/libFlight.a \
$(top_builddir)/src/FDM/Balloon/libBalloon.a \
$(top_builddir)/src/FDM/JSBsim/libJSBsim.a \
$(WEATHER_LIBS) \
$(top_builddir)/src/Joystick/libJoystick.a \
$(SERIAL_LIBS) \
- -lsgsky -lsgscreen -lsgmath -lsgbucket -lsgdebug -lsgmagvar -lsgmisc \
+ -lsgsky -lsgephem -lsgtiming -lsgscreen -lsgmath -lsgbucket \
+ -lsgdebug -lsgmagvar -lsgmisc \
-lplibpu -lplibfnt -lplibssg -lplibsg \
-lmk4 -lz \
$(opengl_LIBS) \
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
+#include <simgear/ephemeris/ephemeris.hxx>
#include <simgear/math/fg_types.hxx>
#include <simgear/misc/props.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <Aircraft/aircraft.hxx>
#include <FDM/UIUCModel/uiuc_aircraftdir.h>
#include <Controls/controls.hxx>
#include <Autopilot/newauto.hxx>
#include <Scenery/scenery.hxx>
-#include <Time/fg_time.hxx>
#include <Time/light.hxx>
#include <Time/event.hxx>
#include <Time/sunpos.hxx>
+#include <Time/tmp.hxx>
#include <Cockpit/radiostack.hxx>
-#include <Ephemeris/ephemeris.hxx>
#ifndef FG_OLD_WEATHER
# include <WeatherCM/FGLocalWeatherDatabase.h>
#else
fgUpdateSunPos();
fgUpdateMoonPos();
cur_light_params.Update();
- FGTime::cur_time_params->updateLocal();
+ fgUpdateLocalTime();
fgUpdateWeatherDatabase();
fgRadioSearch();
// FIXME: need to update lighting
// and solar system
current_options.set_time_offset(time);
- current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_ABSOLUTE);
+ current_options.set_time_offset_type(SG_TIME_GMT_ABSOLUTE);
FGTime::cur_time_params->init( cur_fdm_state->get_Longitude(),
- cur_fdm_state->get_Latitude() );
+ cur_fdm_state->get_Latitude(),
+ current_options.get_fg_root(),
+ current_options.get_time_offset(),
+ current_options.get_time_offset_type() );
FGTime::cur_time_params->update( cur_fdm_state->get_Longitude(),
cur_fdm_state->get_Latitude(),
cur_fdm_state->get_Altitude()
double
FGBFI::getMagVar ()
{
- return FGTime::cur_time_params->getMagVar() * RAD_TO_DEG;
+ return cur_magvar.get_magvar() * RAD_TO_DEG;
}
double
FGBFI::getMagDip ()
{
- return FGTime::cur_time_params->getMagDip() * RAD_TO_DEG;
+ return cur_magvar.get_magdip() * RAD_TO_DEG;
}
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
#include <simgear/misc/fgpath.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <Aircraft/aircraft.hxx>
#include <Airports/simple.hxx>
#include <Scenery/scenery.hxx>
#include <Scenery/tilemgr.hxx>
#include <Time/event.hxx>
-#include <Time/fg_time.hxx>
#include <Time/light.hxx>
#include <Time/sunpos.hxx>
#include <Time/moonpos.hxx>
+#include <Time/tmp.hxx>
#ifndef FG_OLD_WEATHER
# include <WeatherCM/FGLocalWeatherDatabase.h>
&fgLIGHT::Update),
fgEVENT::FG_EVENT_READY, 30000 );
// update the current timezone each 30 minutes
- global_events.Register( "fgTIME::updateLocal()",
- fgMethodCallback<FGTime>(FGTime::cur_time_params,
- &FGTime::updateLocal),
+ global_events.Register( "fgUpdateLocalTime()", fgUpdateLocalTime,
fgEVENT::FG_EVENT_READY, 1800000);
// Initialize the weather modeling subsystem
void fgReInitSubsystems( void )
{
- FGTime *t = FGTime::cur_time_params;
-
- int toggle_pause = t->getPause();
+ int toggle_pause = current_options.get_pause();
if( !toggle_pause )
- t->togglePauseMode();
+ current_options.toggle_pause();
fgInitPosition();
if( global_tile_mgr.init() ) {
current_autopilot->reset();
if( !toggle_pause )
- t->togglePauseMode();
+ current_options.toggle_pause();
}
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/fgpath.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <Aircraft/aircraft.hxx>
#include <Autopilot/auto_gui.hxx>
#include <GUI/gui.h>
#include <Scenery/tilemgr.hxx>
#include <Objects/matlib.hxx>
-#include <Time/fg_time.hxx>
#include <Time/light.hxx>
+#include <Time/tmp.hxx>
#ifndef FG_OLD_WEATHER
# include <WeatherCM/FGLocalWeatherDatabase.h>
#include "views.hxx"
-// Force an update of the sky and lighting parameters
-static void local_update_sky_and_lighting_params( void ) {
- FGTime::cur_time_params->updateLocal();
- cur_light_params.Update();
-}
-
-
// Handle keyboard events
void GLUTkey(unsigned char k, int x, int y) {
FGInterface *f;
return;
case 77: // M key
t->adjust_warp(-60);
- local_update_sky_and_lighting_params();
+ fgUpdateSkyAndLightingParams();
return;
case 80: // P key
current_options.toggle_panel();
break;
case 84: // T key
t->adjust_warp_delta(-30);
- local_update_sky_and_lighting_params();
+ fgUpdateSkyAndLightingParams();
return;
case 87: // W key
#if defined(FX) && !defined(WIN32)
return;
case 109: // m key
t->adjust_warp (+60);
- local_update_sky_and_lighting_params();
+ fgUpdateSkyAndLightingParams();
return;
case 112: // p key
- t->togglePauseMode();
+ current_options.toggle_pause();
{
FGBucket p( f->get_Longitude() * RAD_TO_DEG,
return;
case 116: // t key
t->adjust_warp_delta (+30);
- local_update_sky_and_lighting_params();
+ fgUpdateSkyAndLightingParams();
return;
case 118: // v key
current_options.cycle_view_mode();
{
int toggle_pause;
FG_LOG(FG_INPUT, FG_INFO, "ReIniting TileCache");
- FGTime *t = FGTime::cur_time_params;
- if( (toggle_pause = !t->getPause()) )
- t->togglePauseMode();
+ if( (toggle_pause = !current_options.get_pause()) )
+ current_options.toggle_pause();
BusyCursor(0);
if( global_tile_mgr.init() ) {
// Load the local scenery data
}
BusyCursor(1);
if(toggle_pause)
- t->togglePauseMode();
+ current_options.toggle_pause();
return;
}
case GLUT_KEY_F3: // F3 Take a screen shot
#include <simgear/constants.h> // for VERSION
#include <simgear/debug/logstream.hxx>
+#include <simgear/ephemeris/ephemeris.hxx>
#include <simgear/math/fg_geodesy.hxx>
#include <simgear/math/polar3d.hxx>
#include <simgear/math/fg_random.h>
#include <simgear/misc/fgpath.hxx>
#include <simgear/sky/sky.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <Include/general.hxx>
#include <Aircraft/aircraft.hxx>
-#include <Ephemeris/ephemeris.hxx>
#include <Autopilot/newauto.hxx>
#include <Cockpit/cockpit.hxx>
#include <Scenery/scenery.hxx>
#include <Scenery/tilemgr.hxx>
#include <Time/event.hxx>
-#include <Time/fg_time.hxx>
#include <Time/fg_timer.hxx>
#include <Time/sunpos.hxx>
+#include <Time/tmp.hxx>
#ifndef FG_OLD_WEATHER
# include <WeatherCM/FGLocalWeatherDatabase.h>
if ( current_options.get_wireframe() ) {
clear_mask |= GL_COLOR_BUFFER_BIT;
}
- if ( current_options.get_panel_status() ) {
- // we can't clear the screen when the panel is active
- } else if ( current_options.get_skyblend() ) {
+
+ if ( current_options.get_skyblend() ) {
if ( current_options.get_textures() ) {
// glClearColor(black[0], black[1], black[2], black[3]);
glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
multi_loop = 1;
}
- if ( !t->getPause() ) {
+ if ( !current_options.get_pause() ) {
// run Autopilot system
current_autopilot->run();
cur_fdm_state->get_Latitude(),
cur_fdm_state->get_Altitude()* FEET_TO_METER );
+ if ( t->get_warp_delta() != 0 ) {
+ fgUpdateSkyAndLightingParams();
+ }
+
+ // update magvar model
+ cur_magvar.update( cur_fdm_state->get_Longitude(),
+ cur_fdm_state->get_Latitude(),
+ cur_fdm_state->get_Altitude()* FEET_TO_METER,
+ FGTime::cur_time_params->getJD() );
+
// Get elapsed time (in usec) for this past frame
elapsed = fgGetTimeInterval();
FG_LOG( FG_ALL, FG_DEBUG,
guiInit();
// Initialize time
- FGTime::cur_time_params = new FGTime();
+ FGTime::cur_time_params = new FGTime( current_options.get_fg_root() );
// FGTime::cur_time_params->init( cur_fdm_state->get_Longitude(),
// cur_fdm_state->get_Latitude() );
// FGTime::cur_time_params->update( cur_fdm_state->get_Longitude() );
- FGTime::cur_time_params->init( 0.0, 0.0 );
+ FGTime::cur_time_params->init( 0.0, 0.0,
+ current_options.get_fg_root(),
+ current_options.get_time_offset(),
+ current_options.get_time_offset_type() );
FGTime::cur_time_params->update( 0.0, 0.0, 0.0 );
// Do some quick general initializations
ephem->getPlanets(), 60000.0,
ephem->getNumStars(),
ephem->getStars(), 60000.0 );
- thesky->add_cloud_layer( 213.0, 50.0, 50.0, SG_CLOUD_MOSTLY_SUNNY );
- thesky->add_cloud_layer( 2600.0, 200.0, 50.0, SG_CLOUD_MOSTLY_SUNNY );
- thesky->add_cloud_layer( 6000.0, 20.0, 10.0, SG_CLOUD_CIRRUS );
+
+ thesky->add_cloud_layer( 2600.0, 200.0, 50.0, 40000.0,
+ SG_CLOUD_MOSTLY_SUNNY );
+ thesky->add_cloud_layer( 6000.0, 20.0, 10.0, 40000.0,
+ SG_CLOUD_CIRRUS );
+
+ // thesky->add_cloud_layer( 1000.0, 200.0, 50.0, SG_CLOUD_MOSTLY_SUNNY );
+ // thesky->add_cloud_layer( 1800.0, 400.0, 100.0, SG_CLOUD_OVERCAST );
+ // thesky->add_cloud_layer( 5000.0, 20.0, 10.0, SG_CLOUD_CIRRUS );
// Terrain branch
terrain = new ssgBranch;
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/fgstream.hxx>
#include <simgear/misc/props.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <Include/general.hxx>
#include <Cockpit/cockpit.hxx>
#ifdef FG_NETWORK_OLK
# include <NetworkOLK/network.h>
#endif
-#include <Time/fg_time.hxx>
#include "views.hxx"
#include "options.hxx"
network_olk(false)
{
// set initial values/defaults
- time_offset_type=FG_TIME_SYS_OFFSET;
+ time_offset_type = SG_TIME_SYS_OFFSET;
char* envp = ::getenv( "FG_ROOT" );
if ( envp != NULL ) {
void
fgOPTIONS::toggle_panel() {
- FGTime *t = FGTime::cur_time_params;
-
- int toggle_pause = t->getPause();
-
- if( !toggle_pause )
- t->togglePauseMode();
+ if( !pause )
+ toggle_pause();
if( panel_status ) {
panel_status = false;
// fgReshape( xsize, ysize);
fgReshape( current_view.get_winWidth(), current_view.get_winHeight() );
- if( !toggle_pause )
- t->togglePauseMode();
+ if( !pause )
+ toggle_pause();
}
double
tile_diameter = tile_radius * 2 + 1;
} else if ( arg.find( "--time-offset" ) != string::npos ) {
time_offset = parse_time_offset( (arg.substr(14)) );
- //time_offset_type = FG_TIME_SYS_OFFSET;
+ //time_offset_type = SG_TIME_SYS_OFFSET;
} else if ( arg.find( "--time-match-real") != string::npos ) {
//time_offset = parse_time_offset(arg.substr(18));
- time_offset_type = FG_TIME_SYS_OFFSET;
+ time_offset_type = SG_TIME_SYS_OFFSET;
} else if ( arg.find( "--time-match-local") != string::npos ) {
//time_offset = parse_time_offset(arg.substr(18));
- time_offset_type = FG_TIME_LAT_OFFSET;
+ time_offset_type = SG_TIME_LAT_OFFSET;
} else if ( arg.find( "--start-date-sys=") != string::npos ) {
time_offset = parse_date( (arg.substr(17)) );
- time_offset_type = FG_TIME_SYS_ABSOLUTE;
+ time_offset_type = SG_TIME_SYS_ABSOLUTE;
} else if ( arg.find( "--start-date-lat=") != string::npos ) {
time_offset = parse_date( (arg.substr(17)) );
- time_offset_type = FG_TIME_LAT_ABSOLUTE;
+ time_offset_type = SG_TIME_LAT_ABSOLUTE;
} else if ( arg.find( "--start-date-gmt=") != string::npos ) {
time_offset = parse_date( (arg.substr(17)) );
- time_offset_type = FG_TIME_GMT_ABSOLUTE;
+ time_offset_type = SG_TIME_GMT_ABSOLUTE;
} else if ( arg == "--hud-tris" ) {
tris_or_culled = 0;
#endif
#include <simgear/math/fg_types.hxx>
+#include <simgear/timing/fg_time.hxx>
#include STL_STRING
#include <vector>
FG_RADIUS_MAX = 4
};
- enum
- {
- FG_TIME_SYS_OFFSET = 1,
- FG_TIME_GMT_OFFSET = 2,
- FG_TIME_LAT_OFFSET = 3,
- FG_TIME_SYS_ABSOLUTE = 4,
- FG_TIME_GMT_ABSOLUTE = 5,
- FG_TIME_LAT_ABSOLUTE = 6
- };
-
enum fgControlMode
{
FG_JOYSTICK = 0,
// Time options
int time_offset; // Use this value to change time.
- int time_offset_type; // Will be set to one of the FG_TIME_* enums,
- // To deterine how time_offset should be used
+ sgTimingOffsetType time_offset_type; // Will be set to one of the
+ // SG_TIME_* enums, to deterine how
+ // time_offset should be used
// Serial port configuration strings
string_list channel_options_list;
inline int get_tris_or_culled() const { return tris_or_culled; }
inline int get_time_offset() const { return time_offset; }
- inline int get_time_offset_type() const { return time_offset_type; };
+ inline sgTimingOffsetType get_time_offset_type() const {
+ return time_offset_type;
+ };
inline string_list get_channel_options_list() const {
return channel_options_list;
inline void set_intro_music (bool value) { intro_music = value; }
inline void set_mouse_pointer (int value) { mouse_pointer = value; }
inline void set_pause (bool value) { pause = value; }
+ inline void toggle_pause () { pause = !pause; }
inline void set_anti_alias_hud (bool value) { anti_alias_hud = value; }
inline void set_hud_status( bool status ) { hud_status = status; }
inline void set_sound (bool value) { sound = value; }
inline void set_units (int value) { units = value; }
inline void set_tris_or_culled (int value) { tris_or_culled = value; }
inline void set_time_offset (int value) { time_offset = value; }
- inline void set_time_offset_type (int value) { time_offset_type = value; }
+ inline void set_time_offset_type (sgTimingOffsetType value) {
+ time_offset_type = value;
+ }
inline void cycle_view_mode() {
if ( view_mode == FG_VIEW_PILOT ) {
view_mode = FG_VIEW_FOLLOW;
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
#include <simgear/math/vector.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <Aircraft/aircraft.hxx>
#include <Cockpit/panel.hxx>
#include <Scenery/scenery.hxx>
-#include <Time/fg_time.hxx>
#include "options.hxx"
#include "views.hxx"
#include <simgear/compiler.h>
#include <simgear/math/point3d.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <list>
#include <plib/sg.h> // plib include
#include <FDM/flight.hxx>
-#include <Time/fg_time.hxx>
#include <Time/light.hxx>
#include "options.hxx"
Autopilot \
Cockpit \
Controls \
- Ephemeris \
FDM \
GUI \
Joystick \
#include <simgear/debug/logstream.hxx>
#include <simgear/math/fg_geodesy.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <FDM/flight.hxx>
-#include <Time/fg_time.hxx>
#include "iochannel.hxx"
#include "garmin.hxx"
#include <simgear/debug/logstream.hxx>
#include <simgear/math/fg_geodesy.hxx>
-
-#include <Time/fg_time.hxx>
+#include <simgear/timing/fg_time.hxx>
#include "iochannel.hxx"
#include "native.hxx"
#include <simgear/debug/logstream.hxx>
#include <simgear/math/fg_geodesy.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <FDM/flight.hxx>
-#include <Time/fg_time.hxx>
#include "iochannel.hxx"
#include "nmea.hxx"
#include <simgear/debug/logstream.hxx>
#include <simgear/math/fg_geodesy.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <FDM/flight.hxx>
-#include <Time/fg_time.hxx>
#include "iochannel.hxx"
#include "pve.hxx"
#include <simgear/debug/logstream.hxx>
#include <simgear/math/fg_geodesy.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <FDM/flight.hxx>
-#include <Time/fg_time.hxx>
#include "iochannel.hxx"
#include "ray.hxx"
#include <simgear/debug/logstream.hxx>
#include <simgear/math/fg_geodesy.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <FDM/flight.hxx>
-#include <Time/fg_time.hxx>
#include "iochannel.hxx"
#include "rul.hxx"
libTime_a_SOURCES = \
event.cxx event.hxx \
- fg_time.cxx fg_time.hxx \
fg_timer.cxx fg_timer.hxx \
- geocoord.cxx geocoord.h \
light.cxx light.hxx \
- lowleveltime.cxx lowleveltime.h \
- timezone.cxx timezone.h \
moonpos.cxx moonpos.hxx \
sunpos.cxx sunpos.hxx \
- timestamp.hxx
+ timestamp.hxx \
+ tmp.cxx tmp.hxx
+ # fg_time.cxx fg_time.hxx \
+ # geocoord.cxx geocoord.h \
+ # lowleveltime.cxx lowleveltime.h \
+ # timezone.cxx timezone.h
INCLUDES += -I$(top_builddir) -I$(top_builddir)/src
#include <simgear/compiler.h>
+#include <simgear/timing/fg_time.hxx>
#include <Include/fg_callback.hxx>
#include <list> // STL list
#include STL_STRING
-#include "fg_time.hxx"
#include "timestamp.hxx"
FG_USING_STD(deque);
+++ /dev/null
-// fg_time.cxx -- data structures and routines for managing time related stuff.
-//
-// Written by Curtis Olson, started August 1997.
-//
-// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
-// $Id$
-
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <simgear/compiler.h>
-
-#ifdef FG_HAVE_STD_INCLUDES
-# include <cmath>
-# include <cstdio>
-# include <cstdlib>
-# include <ctime>
-#else
-# include <math.h>
-# include <stdio.h>
-# include <stdlib.h>
-# include <time.h>
-#endif
-
-#ifdef HAVE_SYS_TIMEB_H
-# include <sys/timeb.h> // for ftime() and struct timeb
-#endif
-#ifdef HAVE_UNISTD_H
-# include <unistd.h> // for gettimeofday()
-#endif
-#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h> // for get/setitimer, gettimeofday, struct timeval
-#endif
-
-#include <simgear/constants.h>
-#include <simgear/debug/logstream.hxx>
-#include <simgear/magvar/magvar.hxx>
-#include <simgear/misc/fgpath.hxx>
-
-#include <FDM/flight.hxx>
-#include <Main/options.hxx>
-#include <Time/light.hxx>
-
-#include "fg_time.hxx"
-#include "timezone.h"
-#include "lowleveltime.h"
-#include "moonpos.hxx"
-#include "sunpos.hxx"
-
-
-#define DEGHR(x) ((x)/15.)
-#define RADHR(x) DEGHR(x*RAD_TO_DEG)
-
-
-// #define MK_TIME_IS_GMT 0 // default value
-// #define TIME_ZONE_OFFSET_WORK 0 // default value
-
-
-FGTime::FGTime()
-{
- if (cur_time_params) {
- FG_LOG( FG_GENERAL, FG_ALERT,
- "Error: only one instance of FGTime allowed" );
- exit(-1);
- }
-
- cur_time_params = this;
-
- FGPath buffer( current_options.get_fg_root() );
- buffer.append( "Timezone" );
- buffer.append( "zone.tab" );
- FG_LOG( FG_EVENT, FG_INFO, "Reading timezone info from: " << buffer.str() );
- tzContainer = new TimezoneContainer( buffer.c_str() );
- warp=0;
- warp_delta=0;
-}
-
-
-FGTime::~FGTime()
-{
- delete tzContainer;
- delete zonename;
-}
-
-void FGTime::updateLocal()
-{
- FGInterface* f;
- f = cur_fdm_state;
- time_t currGMT;
- time_t aircraftLocalTime;
- GeoCoord location(RAD_TO_DEG * f->get_Latitude(),
- RAD_TO_DEG * f->get_Longitude());
- GeoCoord* nearestTz = tzContainer->getNearest(location);
- FGPath buffer( current_options.get_fg_root() );
- buffer.append ("Timezone" );
- buffer.append ( nearestTz->getDescription() );
- if (zonename)
- delete zonename;
- zonename = strdup(buffer.c_str());
- currGMT = get_gmt(gmtime(&cur_time));
- aircraftLocalTime = get_gmt((fgLocaltime(&cur_time, buffer.c_str())));
- localOffset = aircraftLocalTime - currGMT;
- // cerr << "Using " << localOffset << " as local time offset Timezone is "
- // << zonename << endl;
-}
-
-// Initialize the time dependent variables (maybe I'll put this in the
-// constructor later)
-void FGTime::init( double lon, double lat ) {
- FG_LOG( FG_EVENT, FG_INFO, "Initializing Time" );
- gst_diff = -9999.0;
- FG_LOG( FG_EVENT, FG_DEBUG,
- "time offset = " << current_options.get_time_offset() );
- time_t timeOffset = current_options.get_time_offset();
- int offsetType = current_options.get_time_offset_type();
-
- time_t currGMT;
- time_t systemLocalTime;
- time_t aircraftLocalTime;
-
- // would it be better to put these sanity checks in the options
- // parsing code? (CLO)
-
- cur_time = time(NULL);
-
- // printf ("Current greenwich mean time = %24s", asctime(gmtime(&cur_time)));
- // printf ("Current local time = %24s", asctime(localtime(&cur_time)));
- // time_t tmp = cur_time;
- GeoCoord location( RAD_TO_DEG * lat, RAD_TO_DEG * lon );
-
- GeoCoord* nearestTz = tzContainer->getNearest(location);
-
- FGPath buffer( current_options.get_fg_root() );
- buffer.append( "Timezone" );
- buffer.append( nearestTz->getDescription() );
-
- // printf("Using %s for timezone information\n", buffer);
- zonename = strdup( buffer.c_str() );
- //show( buffer.c_str(), cur_time, 1);
- //printf ("Current greenwich mean time = %24s", asctime(gmtime(&cur_time)));
- //printf ("Current local time = %24s", asctime(localtime(&cur_time)));
- currGMT = get_gmt(gmtime(&cur_time));
- systemLocalTime = get_gmt(localtime(&cur_time));
- aircraftLocalTime = get_gmt(fgLocaltime(&cur_time, buffer.c_str()));
- //printf ("Current greenwich mean time = %24s", asctime(gmtime(&cur_time)));
- //printf ("Current local time = %24s", asctime(localtime(&cur_time)));
-
- //printf("LT = %d\n", computerLocalTime);
- // Okay, in principle, this trick allows to calculate the
- // difference between GMT and localtime, in seconds.
- // printf("Gmt = %d, SLT = %d, (difference = %d)\n", currGMT, systemLocalTime, (currGMT - systemLocalTime));
- // printf("Gmt = %d, ALT = %d, (difference = %d)\n", currGMT, aircraftLocalTime, (currGMT - aircraftLocalTime));
- // exit(1);
- // Okay, we now have six possible scenarios
- switch (offsetType)
- {
- case fgOPTIONS::FG_TIME_SYS_OFFSET:
- warp = timeOffset;
- break;
- case fgOPTIONS::FG_TIME_GMT_OFFSET:
- warp = timeOffset - (currGMT - systemLocalTime);
- break;
- case fgOPTIONS::FG_TIME_LAT_OFFSET:
- // warp = timeOffset - (currGMT - systemLocalTime +
- // (currGMT - aircraftLocalTime));
- warp = timeOffset - (aircraftLocalTime - systemLocalTime);
- break;
- case fgOPTIONS::FG_TIME_SYS_ABSOLUTE:
- warp = timeOffset - cur_time;
- //printf("warp = %d\n", warp);
- break;
- case fgOPTIONS::FG_TIME_GMT_ABSOLUTE:
- warp = timeOffset - currGMT;
- break;
- case fgOPTIONS::FG_TIME_LAT_ABSOLUTE:
- warp = timeOffset - (aircraftLocalTime - systemLocalTime) -
- cur_time;
- break;
- default:
- printf("Unsupported type\n");
- exit(1);
- }
-
- warp_delta = 0;
- pause = current_options.get_pause();
-}
-
-
-// given a date in months, mn, days, dy, years, yr, return the
-// modified Julian date (number of days elapsed since 1900 jan 0.5),
-// mjd. Adapted from Xephem.
-
-void FGTime::cal_mjd (int mn, double dy, int yr)
-{
- //static double last_mjd, last_dy;
- //double mjd;
- //static int last_mn, last_yr;
- int b, d, m, y;
- long c;
-
- if (mn == last_mn && yr == last_yr && dy == last_dy) {
- mjd = last_mjd;
- //return(mjd);
- }
-
- m = mn;
- y = (yr < 0) ? yr + 1 : yr;
- if (mn < 3) {
- m += 12;
- y -= 1;
- }
-
- if (yr < 1582 || (yr == 1582 && (mn < 10 || (mn == 10 && dy < 15)))) {
- b = 0;
- } else {
- int a;
- a = y/100;
- b = 2 - a + a/4;
- }
-
- if (y < 0) {
- c = (long)((365.25*y) - 0.75) - 694025L;
- } else {
- c = (long)(365.25*y) - 694025L;
- }
-
- d = (int)(30.6001*(m+1));
-
- mjd = b + c + d + dy - 0.5;
-
- last_mn = mn;
- last_dy = dy;
- last_yr = yr;
- last_mjd = mjd;
-
- //return(mjd);
-}
-
-
-// given an mjd, calculate greenwich mean sidereal time, gst
-void FGTime::utc_gst ()
-{
- double day = floor(mjd-0.5)+0.5;
- double hr = (mjd-day)*24.0;
- double T, x;
-
- T = ((int)(mjd - 0.5) + 0.5 - J2000)/36525.0;
- x = 24110.54841 + (8640184.812866 + (0.093104 - 6.2e-6 * T) * T) * T;
- x /= 3600.0;
- gst = (1.0/SIDRATE)*hr + x;
-
- FG_LOG( FG_EVENT, FG_DEBUG, " gst => " << gst );
-}
-
-
-// given Julian Date and Longitude (decimal degrees West) compute
-// Local Sidereal Time, in decimal hours.
-//
-// Provided courtesy of ecdowney@noao.edu (Elwood Downey)
-
-double FGTime::sidereal_precise (double lng)
-{
- double lstTmp;
-
- /* printf ("Current Lst on JD %13.5f at %8.4f degrees West: ",
- mjd + MJD0, lng); */
-
- // convert to required internal units
- lng *= DEG_TO_RAD;
-
- // compute LST and print
- utc_gst();
- lstTmp = gst - RADHR (lng);
- lstTmp -= 24.0*floor(lstTmp/24.0);
- // printf ("%7.4f\n", lstTmp);
-
- // that's all
- return (lstTmp);
-}
-
-
-// return a courser but cheaper estimate of sidereal time
-double FGTime::sidereal_course(double lng)
-{
- //struct tm *gmt;
- //double lstTmp;
- time_t start_gmt, now;
- double diff, part, days, hours, lstTmp;
- char tbuf[64];
-
- //gmt = t->gmt;
- //now = t->cur_time;
- now = cur_time;
- start_gmt = get_gmt(gmt->tm_year, 2, 21, 12, 0, 0);
-
- FG_LOG( FG_EVENT, FG_DEBUG, " COURSE: GMT = " << format_time(gmt, tbuf) );
- FG_LOG( FG_EVENT, FG_DEBUG, " March 21 noon (GMT) = " << start_gmt );
-
- diff = (now - start_gmt) / (3600.0 * 24.0);
-
- FG_LOG( FG_EVENT, FG_DEBUG,
- " Time since 3/21/" << gmt->tm_year << " GMT = " << diff );
-
- part = fmod(diff, 1.0);
- days = diff - part;
- hours = gmt->tm_hour + gmt->tm_min/60.0 + gmt->tm_sec/3600.0;
-
- lstTmp = (days - lng)/15.0 + hours - 12;
-
- while ( lstTmp < 0.0 ) {
- lstTmp += 24.0;
- }
-
- FG_LOG( FG_EVENT, FG_DEBUG,
- " days = " << days << " hours = " << hours << " lon = "
- << lng << " lst = " << lstTmp );
-
- return(lstTmp);
-}
-
-
-// Update time variables such as gmt, julian date, and sidereal time
-void FGTime::update( double lon, double lat, double alt_m ) {
- double gst_precise, gst_course;
-
- FG_LOG( FG_EVENT, FG_DEBUG, "Updating time" );
-
- // get current Unix calendar time (in seconds)
- warp += warp_delta;
- cur_time = time(NULL) + warp;
- FG_LOG( FG_EVENT, FG_DEBUG,
- " Current Unix calendar time = " << cur_time
- << " warp = " << warp << " delta = " << warp_delta );
-
- if ( warp_delta ) {
- // time is changing so force an update
- local_update_sky_and_lighting_params();
- }
-
- // get GMT break down for current time
- gmt = gmtime(&cur_time);
- FG_LOG( FG_EVENT, FG_DEBUG,
- " Current GMT = " << gmt->tm_mon+1 << "/"
- << gmt->tm_mday << "/" << gmt->tm_year << " "
- << gmt->tm_hour << ":" << gmt->tm_min << ":"
- << gmt->tm_sec );
-
- // calculate modified Julian date
- // t->mjd = cal_mjd ((int)(t->gmt->tm_mon+1), (double)t->gmt->tm_mday,
- // (int)(t->gmt->tm_year + 1900));
- cal_mjd ((int)(gmt->tm_mon+1), (double)gmt->tm_mday,
- (int)(gmt->tm_year + 1900));
-
- // add in partial day
- mjd += (gmt->tm_hour / 24.0) + (gmt->tm_min / (24.0 * 60.0)) +
- (gmt->tm_sec / (24.0 * 60.0 * 60.0));
-
- // convert "back" to Julian date + partial day (as a fraction of one)
- jd = mjd + MJD0;
- FG_LOG( FG_EVENT, FG_DEBUG, " Current Julian Date = " << jd );
-
- // printf(" Current Longitude = %.3f\n", FG_Longitude * RAD_TO_DEG);
-
- // Calculate local side real time
- if ( gst_diff < -100.0 ) {
- // first time through do the expensive calculation & cheap
- // calculation to get the difference.
- FG_LOG( FG_EVENT, FG_INFO, " First time, doing precise gst" );
- gst_precise = gst = sidereal_precise(0.00);
- gst_course = sidereal_course(0.00);
-
- gst_diff = gst_precise - gst_course;
-
- lst = sidereal_course(-(lon * RAD_TO_DEG)) + gst_diff;
- } else {
- // course + difference should drift off very slowly
- gst = sidereal_course( 0.00 ) + gst_diff;
- lst = sidereal_course( -(lon * RAD_TO_DEG)) + gst_diff;
- }
-
- // Calculate local magnetic variation
- double field[6];
- // cout << "alt_m = " << alt_m << endl;
- magvar = SGMagVar( lat, lon, alt_m / 1000.0, (long)jd, field );
- magdip = atan(field[5]/sqrt(field[3]*field[3]+field[4]*field[4]));
-
- FG_LOG( FG_EVENT, FG_DEBUG,
- " Current magvar = " << magvar );
-
- FG_LOG( FG_EVENT, FG_DEBUG,
- " Current lon=0.00 Sidereal Time = " << gst );
- FG_LOG( FG_EVENT, FG_DEBUG,
- " Current LOCAL Sidereal Time = " << lst << " ("
- << sidereal_precise(-(lon * RAD_TO_DEG))
- << ") (diff = " << gst_diff << ")" );
-}
-
-
-/******************************************************************
- * The following are some functions that were included as FGTime
- * members, although they currently don't make use of any of the
- * class's variables. Maybe this'll change in the future
- *****************************************************************/
-
-// Return time_t for Sat Mar 21 12:00:00 GMT
-//
-// On many systems it is ambiguous if mktime() assumes the input is in
-// GMT, or local timezone. To address this, a new function called
-// timegm() is appearing. It works exactly like mktime() but
-// explicitely interprets the input as GMT.
-//
-// timegm() is available and documented under FreeBSD. It is
-// available, but completely undocumented on my current Debian 2.1
-// distribution.
-//
-// In the absence of timegm() we have to guess what mktime() might do.
-//
-// Many older BSD style systems have a mktime() that assumes the input
-// time in GMT. But FreeBSD explicitly states that mktime() assumes
-// local time zone
-//
-// The mktime() on many SYSV style systems (such as Linux) usually
-// returns its result assuming you have specified the input time in
-// your local timezone. Therefore, in the absence if timegm() you
-// have to go to extra trouble to convert back to GMT.
-//
-// If you are having problems with incorrectly positioned astronomical
-// bodies, this is a really good place to start looking.
-
-time_t FGTime::get_gmt(int year, int month, int day, int hour, int min, int sec)
-{
- struct tm mt;
-
- mt.tm_mon = month;
- mt.tm_mday = day;
- mt.tm_year = year;
- mt.tm_hour = hour;
- mt.tm_min = min;
- mt.tm_sec = sec;
- mt.tm_isdst = -1; // let the system determine the proper time zone
-
- // For now we assume that if daylight is not defined in
- // /usr/include/time.h that we have a machine with a mktime() that
- // assumes input is in GMT ... this only matters if we are
- // building on a system that does not have timegm()
-#if !defined(HAVE_DAYLIGHT)
-# define MK_TIME_IS_GMT 1
-#endif
-
-#if defined( HAVE_TIMEGM )
- return ( timegm(&mt) );
-#elif defined( MK_TIME_IS_GMT )
- return ( mktime(&mt) );
-#else // ! defined ( MK_TIME_IS_GMT )
-
- // timezone seems to work as a proper offset for Linux & Solaris
-# if defined( __linux__ ) || defined( __sun__ )
-# define TIMEZONE_OFFSET_WORKS 1
-# endif
-
- long int start = mktime(&mt);
-
- FG_LOG( FG_EVENT, FG_DEBUG, "start1 = " << start );
- // the ctime() call can screw up time progression on some versions
- // of Linux
- // fgPrintf( FG_EVENT, FG_DEBUG, "start2 = %s", ctime(&start));
- FG_LOG( FG_EVENT, FG_DEBUG, "(tm_isdst = " << mt.tm_isdst << ")" );
-
- timezone = fix_up_timezone( timezone );
-
-# if defined( TIMEZONE_OFFSET_WORKS )
- FG_LOG( FG_EVENT, FG_DEBUG,
- "start = " << start << ", timezone = " << timezone );
- return( start - timezone );
-# else // ! defined( TIMEZONE_OFFSET_WORKS )
-
- daylight = mt.tm_isdst;
- if ( daylight > 0 ) {
- daylight = 1;
- } else if ( daylight < 0 ) {
- FG_LOG( FG_EVENT, FG_WARN,
- "OOOPS, problem in fg_time.cxx, no daylight savings info." );
- }
-
- long int offset = -(timezone / 3600 - daylight);
-
- FG_LOG( FG_EVENT, FG_DEBUG, " Raw time zone offset = " << timezone );
- FG_LOG( FG_EVENT, FG_DEBUG, " Daylight Savings = " << daylight );
- FG_LOG( FG_EVENT, FG_DEBUG, " Local hours from GMT = " << offset );
-
- long int start_gmt = start - timezone + (daylight * 3600);
-
- FG_LOG( FG_EVENT, FG_DEBUG, " March 21 noon (CST) = " << start );
-
- return ( start_gmt );
-# endif // ! defined( TIMEZONE_OFFSET_WORKS )
-#endif // ! defined ( MK_TIME_IS_GMT )
-}
-
-// Fix up timezone if using ftime()
-long int FGTime::fix_up_timezone( long int timezone_orig )
-{
-#if !defined( HAVE_GETTIMEOFDAY ) && defined( HAVE_FTIME )
- // ftime() needs a little extra help finding the current timezone
- struct timeb current;
- ftime(¤t);
- return( current.timezone * 60 );
-#else
- return( timezone_orig );
-#endif
-}
-
-
-char* FGTime::format_time( const struct tm* p, char* buf )
-{
- sprintf( buf, "%d/%d/%2d %d:%02d:%02d",
- p->tm_mon, p->tm_mday, p->tm_year,
- p->tm_hour, p->tm_min, p->tm_sec);
- return buf;
-}
-
-
-// Force an update of the sky and lighting parameters
-void FGTime::local_update_sky_and_lighting_params( void ) {
- fgUpdateSunPos();
- fgUpdateMoonPos();
- cur_light_params.Update();
-}
-
-
-FGTime* FGTime::cur_time_params = 0;
+++ /dev/null
-// fg_time.hxx -- data structures and routines for managing time related stuff.
-//
-// Written by Curtis Olson, started August 1997.
-//
-// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
-// $Id$
-
-
-#ifndef _FG_TIME_HXX
-#define _FG_TIME_HXX
-
-
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#ifdef HAVE_WINDOWS_H
-# include <windows.h>
-#endif
-
-#include <GL/glut.h>
-
-#include <simgear/compiler.h>
-
-#ifdef FG_HAVE_STD_INCLUDES
-# include <ctime>
-#else
-# include <time.h>
-#endif
-
-#include <FDM/flight.hxx>
-
-#include "timezone.h"
-#include "lowleveltime.h"
-
-// Define a structure containing global time parameters
-class FGTime {
-
-private:
- // tzContainer stores all the current Timezone control points/
- TimezoneContainer* tzContainer;
-
- //Store the current local timezone name;
- char *zonename;
-
- // Unix "calendar" time in seconds
- time_t cur_time;
-
- // Break down of GMT time
- struct tm *gmt;
-
- // Julian date
- double jd;
-
- // modified Julian date
- double mjd;
-
- double last_mjd, last_dy;
- int last_mn, last_yr;
-
- // side real time at prime meridian
- double gst;
-
- // local sidereal time
- double lst;
-
- // local offset to GMT
- time_t localOffset;
-
- // the difference between the precise sidereal time algorithm
- // result and the course result. course + diff has good accuracy
- // for the short term
- double gst_diff;
-
- // An offset in seconds from the true time. Allows us to adjust
- // the effective time of day.
- long int warp;
-
- // How much to change the value of warp each iteration. Allows us
- // to make time progress faster than normal.
- long int warp_delta;
-
- // Paused?
- bool pause;
-
- // Local magnetic variation and dip in radians
- double magvar;
- double magdip;
-
- void local_update_sky_and_lighting_params( void );
-
-public:
-
- FGTime();
- ~FGTime();
-
- inline double getJD() const { return jd; };
- inline double getMjd() const { return mjd; };
- inline double getLst() const { return lst; };
- inline double getGst() const { return gst; };
- inline time_t get_cur_time() const { return cur_time; };
- inline struct tm* getGmt()const { return gmt; };
- inline bool getPause() const { return pause; };
-
- void adjust_warp(int val) { warp += val; };
- void adjust_warp_delta(int val) { warp_delta += val; };
- void togglePauseMode() { pause = !pause; };
-
- // Initialize the time dependent variables
- void init( double lon, double lat );
-
- // Update the time dependent variables
- void update( double lon, double lat, double alt_m );
- void updateLocal();
-
- void cal_mjd (int mn, double dy, int yr);
- void utc_gst();
- double sidereal_precise (double lng);
- double sidereal_course(double lng);
- static FGTime *cur_time_params;
-
- // Some other stuff which were changed to FGTime members on
- // questionable grounds -:)
- // time_t get_start_gmt(int year);
- time_t get_gmt(int year, int month, int day,
- int hour, int minute, int second);
- time_t get_gmt(struct tm* the_time);
-
- char* format_time( const struct tm* p, char* buf );
- long int fix_up_timezone( long int timezone_orig );
-
- // Return magnetic variations
- double getMagVar() const { return magvar; }
- double getMagDip() const { return magdip; }
-};
-
-
-inline time_t FGTime::get_gmt(struct tm* the_time) // this is just a wrapper
-{
- //printf("Using: %24s as input\n", asctime(the_time));
- return get_gmt(the_time->tm_year,
- the_time->tm_mon,
- the_time->tm_mday,
- the_time->tm_hour,
- the_time->tm_min,
- the_time->tm_sec);
-}
-
-
-#endif // _FG_TIME_HXX
# include <sys/time.h> // for get/setitimer, gettimeofday, struct timeval
#endif
-#include "fg_time.hxx"
+#include <simgear/timing/fg_time.hxx>
+
#include "fg_timer.hxx"
#include "timestamp.hxx"
+++ /dev/null
-/* -*- Mode: C++ -*- *****************************************************
- * geocoord.h
- * Written by Durk Talsma. Started March 1998.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- **************************************************************************/
-
-/*************************************************************************
- *
- * This file defines a small and simple class to store geocentric
- * coordinates. Basically, class GeoCoord is intended as a base class for
- * any kind of of object, that can be categorized according to its
- * location on earth, be it navaids, or aircraft. This class for originally
- * written for FlightGear, in order to store Timezone control points.
- *
- ************************************************************************/
-#include "geocoord.h"
-#include <plib/sg.h>
-
-GeoCoord::GeoCoord(const GeoCoord& other)
-{
- lat = other.lat;
- lon = other.lon;
-}
-
-// double GeoCoord::getAngle(const GeoCoord& other) const
-// {
-// Vector first( getX(), getY(), getZ());
-// Vector secnd(other.getX(), other.getY(), other.getZ());
-// double
-// dot = VecDot(first, secnd),
-// len1 = first.VecLen(),
-// len2 = secnd.VecLen(),
-// len = len1 * len2,
-// angle = 0;
-// //printf ("Dot: %f, len1: %f len2: %f\n", dot, len1, len2);
-// /*Vector pPos = prevPos - Reference->prevPos;
-// Vector pVel = prevVel - Reference->prevVel;*/
-
-
-// if ( ( (dot / len) < 1) && (dot / len > -1) && len )
-// angle = acos(dot / len);
-// return angle;
-// }
-
-// GeoCoord* GeoCoordContainer::getNearest(const GeoCoord& ref) const
-// {
-// float angle, maxAngle = 180;
-
-// GeoCoordVectorConstIterator i, nearest;
-// for (i = data.begin(); i != data.end(); i++)
-// {
-// angle = RAD_TO_DEG * (*i)->getAngle(ref);
-// if (angle < maxAngle)
-// {
-// maxAngle = angle;
-// nearest = i;
-// }
-// }
-// return *nearest;
-// }
-
-
-GeoCoord* GeoCoordContainer::getNearest(const GeoCoord& ref) const
-{
- sgVec3 first, secnd;
- float dist, maxDist=SG_MAX;
- sgSetVec3( first, ref.getX(), ref.getY(), ref.getZ());
- GeoCoordVectorConstIterator i, nearest;
- for (i = data.begin(); i != data.end(); i++)
- {
- sgSetVec3(secnd, (*i)->getX(), (*i)->getY(), (*i)->getZ());
- dist = sgDistanceSquaredVec3(first, secnd);
- if (dist < maxDist)
- {
- maxDist = dist;
- nearest = i;
- }
- }
- return *nearest;
-}
-
-
-GeoCoordContainer::~GeoCoordContainer()
-{
- GeoCoordVectorIterator i = data.begin();
- while (i != data.end())
- delete *i++;
-}
+++ /dev/null
-/* -*- Mode: C++ -*- *****************************************************
- * geocoord.h
- * Written by Durk Talsma. Started July 1999.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- **************************************************************************/
-
-/*************************************************************************
- *
- * This file defines a small and simple class to store geocentric
- * coordinates. Basically, class GeoCoord is intended as a base class for
- * any kind of of object, that can be categorized according to its
- * location on earth, be it navaids, or aircraft. This class for originally
- * written for FlightGear, in order to store Timezone control points.
- *
- ************************************************************************/
-
-
-#ifndef _GEOCOORD_H_
-#define _GEOCOORD_H_
-
-#include <simgear/compiler.h>
-
-
-#include <math.h>
-#include <string>
-#include STL_IOSTREAM
-//#include <streambuf> // looks like streambuf does not exist on linux.
-// But it looks like it isn't used anyways -:)
-#include <vector>
-
-FG_USING_NAMESPACE(std);
-
-#include <simgear/constants.h>
-
-class GeoCoord
-{
-protected:
- float lat;
- float lon;
-
-public:
- GeoCoord() { lat = 0.0; lon = 0.0;};
- GeoCoord(float la, float lo) { lat = la; lon = lo;};
- GeoCoord(const GeoCoord& other);
- virtual ~GeoCoord() {};
-
- void set(float la, float lo) { lat = la; lon = lo; };
- float getLat() const { return lat; };
- float getLon() const { return lon; };
- float getX() const { return cos(DEG_TO_RAD*lat) * cos(DEG_TO_RAD*lon); };
- float getY() const { return cos(DEG_TO_RAD*lat) * sin(DEG_TO_RAD*lon); };
- float getZ() const { return sin(DEG_TO_RAD*lat); };
-
-
- //double getAngle(const GeoCoord& other) const;
- virtual void print() {} ;
- virtual char *getDescription() {return 0;};
-};
-
-typedef vector<GeoCoord*> GeoCoordVector;
-typedef vector<GeoCoord*>::iterator GeoCoordVectorIterator;
-typedef vector<GeoCoord*>::const_iterator GeoCoordVectorConstIterator;
-
-/************************************************************************
- * GeoCoordContainer is a simple container class, that stores objects
- * derived from GeoCoord. Basically, it is a wrapper around an STL vector,
- * with some added functionality
- ***********************************************************************/
-
-class GeoCoordContainer
-{
-protected:
- GeoCoordVector data;
-
-public:
- GeoCoordContainer() {};
- virtual ~GeoCoordContainer();
-
- const GeoCoordVector& getData() const { return data; };
- GeoCoord* getNearest(const GeoCoord& ref) const;
-};
-
-
-#endif // _GEO_COORD_H_
#include <simgear/math/interpolater.hxx>
#include <simgear/math/polar3d.hxx>
#include <simgear/misc/fgpath.hxx>
+#include <simgear/timing/fg_time.hxx>
#include <Aircraft/aircraft.hxx>
#include <Main/options.hxx>
#include <Main/views.hxx>
-#include "fg_time.hxx"
#include "light.hxx"
#include "sunpos.hxx"
+++ /dev/null
-/* -*- Mode: C++ -*- *****************************************************
- * Written by various people (I"ll look up the exact credits later)
- * Modified by Durk Talsma, July 1999 for use in FlightGear
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- **************************************************************************/
-
-/********************************************************************
- * This file redefines some low-level Unix-like time functions for *
- * use with FlightGear. Most notably, localtime() is adapted to use *
- * a custom timezone, in order to get the 'local' time for a given *
- * aircraft's position, and not only for the current location of the*
- * computer running the sim. *
- * *
- * Software adapted from glibc functions, by Durk Talsma. Started *
- * July, 17, 1999. *
- ********************************************************************/
-
-
-#include <time.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <errno.h>
-//#include <libc-lock.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include "lowleveltime.h"
-
-
-/* BIG FAT WARNING: NOTICE THAT I HARDCODED ENDIANNES. PLEASE CHANGE THIS */
-#ifndef BIG_ENDIAN
-#define BIG_ENDIAN 4321
-#endif
-
-#ifndef LITTLE_ENDIAN
-#define LITTLE_ENDIAN 1234
-#endif
-
-#ifndef BYTE_ORDER
-#define BYTE_ORDER LITTLE_ENDIAN
-#endif
-
-
-#ifndef BYTE_ORDER
-#define BYTE_ORDER
-#endif
-
-/* END OF BIG FAT WARNING */
-
-//#include "tzfile.h"
-
-#define min(a, b) ((a) < (b) ? (a) : (b))
-#define max(a, b) ((a) > (b) ? (a) : (b))
-#define sign(x) ((x) < 0 ? -1 : 1)
-
-struct leap
- {
- time_t transition; /* Time the transition takes effect. */
- long int change; /* Seconds of correction to apply. */
- };
-
-/* Header for a list of buffers containing time zone strings. */
-struct tzstring_head
-{
- struct tzstring_head *next;
- /* The buffer itself immediately follows the header.
- The buffer contains zero or more (possibly overlapping) strings.
- The last string is followed by 2 '\0's instead of the usual 1. */
-};
-
-
-/* First in a list of buffers containing time zone strings.
- All the buffers but the last are read-only. */
-static struct
-{
- struct tzstring_head head;
- char data[48];
-} tzstring_list;
-
-/* Size of the last buffer in the list, not counting its header. */
-static size_t tzstring_last_buffer_size = sizeof tzstring_list.data;
-
-
-static char *old_fgtz = NULL;
-static int use_fgtzfile = 1;
-static int fgdaylight;
-static char* fgtzname[2];
-static long int fgtimezone;
-
-
-static size_t num_transitions;
-static time_t *transitions = NULL;
-static unsigned char *type_idxs = NULL;
-static size_t num_types;
-static struct ttinfo *types = NULL;
-static char *zone_names = NULL;
-static size_t num_leaps;
-static struct leap *leaps = NULL;
-
-
-static void fgtzset_internal (int always, const char *tz);
-static int fgtz_compute(time_t timer, const struct tm *tm);
-static int fgcompute_change(fgtz_rule *rule, int year);
-static struct ttinfo *fgfind_transition (time_t timer);
-static void fgcompute_tzname_max (size_t chars);
-static inline int decode (const void *ptr);
-void fgtzfile_read (const char *file);
-static void offtime (const time_t *t, long int offset, struct tm *tp);
-static char *tzstring (const char* string);
-
-/* tz_rules[0] is standard, tz_rules[1] is daylight. */
-static fgtz_rule fgtz_rules[2];
-
-int fgtzfile_compute (time_t timer, int use_localtime,
- long int *leap_correct, int *leap_hit);
-struct ttinfo
- {
- long int offset; /* Seconds east of GMT. */
- unsigned char isdst; /* Used to set tm_isdst. */
- unsigned char idx; /* Index into `zone_names'. */
- unsigned char isstd; /* Transition times are in standard time. */
- unsigned char isgmt; /* Transition times are in GMT. */
- };
-
-
-
-/* How many days come before each month (0-12). */
-const unsigned short int mon_yday[2][13] =
- {
- /* Normal years. */
- { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
- /* Leap years. */
- { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
- };
-
-
-/* The C Standard says that localtime and gmtime return the same pointer. */
-struct tm _fgtmbuf;
-
-
-#ifndef isleap
-/* Nonzero if YEAR is a leap year (every 4 years,
- except every 100th isn't, and every 400th is). */
-# define isleap(year) \
- ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
-#endif
-
-
-
-
-/* Return the `struct tm' representation of *T in local time. */
-struct tm * fgLocaltime (const time_t *t, const char *tzName)
-{
- return fgtz_convert (t, 1, &_fgtmbuf, tzName);
-}
-
-
-/* Return the `struct tm' representation of *TIMER in the local timezone.
- Use local time if USE_LOCALTIME is nonzero, UTC otherwise. */
-struct tm * fgtz_convert (const time_t *timer, int use_localtime, struct tm *tp, const char *tzName)
-{
- long int leap_correction;
- long int offsetCorr; // ADDED TO RESOLVE NON-ANSI FIELDS IN struct tm
- int leap_extra_secs;
-
- if (timer == NULL)
- {
- //set_errno (EINVAL);
- return NULL;
- }
-
- //libc_lock_lock (tzset_lock);
-
- /* Update internal database according to current TZ setting.
- POSIX.1 8.3.7.2 says that localtime_r is not required to set tzname.
- This is a good idea since this allows at least a bit more parallelism.
- By analogy we apply the same rule to gmtime_r. */
- fgtzset_internal (tp == &_fgtmbuf, tzName);
-
- if (use_fgtzfile)
- {
- if (! fgtzfile_compute (*timer, use_localtime,
- &leap_correction, &leap_extra_secs))
- tp = NULL;
- }
- else
- {
- offtime (timer, 0, tp);
- if (! fgtz_compute (*timer, tp))
- tp = NULL;
- leap_correction = 0L;
- leap_extra_secs = 0;
- }
-
- if (tp)
- {
- if (use_localtime)
- {
- tp->tm_isdst = fgdaylight;
- //tp->tm_zone = fgtzname[fgdaylight]; // NON_ANSI
- //tp->tm_gmtoff = -fgtimezone; // NON_ANSI
- offsetCorr = -fgtimezone;
- }
- else
- {
- tp->tm_isdst = 0;
- //tp->tm_zone = "GMT"; // NON_ANSI
- //tp->tm_gmtoff = 0L; // NON_ANSI
- offsetCorr = -fgtimezone;
- }
-
- //offtime (timer, tp->tm_gmtoff - leap_correction, tp);
- offtime (timer, offsetCorr - leap_correction, tp);
- tp->tm_sec += leap_extra_secs;
- }
-
- //libc_lock_unlock (tzset_lock);
-
- return tp;
-}
-
-
-
-/* the following stuff is adapted from the tzCode package */
-
-static size_t longest;
-static char * abbr (struct tm * tmp);
-
-void show(const char *zone, time_t t, int v)
-{
- struct tm * tmp;
-
- (void) printf("%-*s ", (int) longest, zone);
- if (v)
- (void) printf("%.24s UTC = ", asctime(gmtime(&t)));
- tmp = fgLocaltime(&t, zone);
- (void) printf("%.24s", asctime(tmp));
- if (*abbr(tmp) != '\0')
- (void) printf(" %s", abbr(tmp));
- if (v) {
- (void) printf(" isdst=%d", tmp->tm_isdst);
-#ifdef TM_GMTOFF
- (void) printf(" gmtoff=%ld", tmp->TM_GMTOFF);
-#endif /* defined TM_GMTOFF */
- }
- (void) printf("\n");
-}
-
-static char *abbr(struct tm *tmp)
-{
- register char * result;
- static char nada;
-
- if (tmp->tm_isdst != 0 && tmp->tm_isdst != 1)
- return &nada;
- result = fgtzname[tmp->tm_isdst];
- return (result == NULL) ? &nada : result;
-}
-
-
-
-/***********************************************************************/
-
-
-/* Interpret the TZ envariable. */
-static void fgtzset_internal (int always, const char *tz)
-{
- time_t now;
- time(&now);
- static int is_initialized = 0;
- //register const char *tz;
- register size_t l;
- char *tzbuf;
- unsigned short int hh, mm, ss;
- unsigned short int whichrule;
-
- if (is_initialized && !always)
- return;
- is_initialized = 1;
-
- /* Examine the TZ environment variable. */
- //tz = getenv ("TZ");
- if (tz == NULL)
- /* No user specification; use the site-wide default. */
- tz = TZDEFAULT;
- else if (*tz == '\0')
- /* User specified the empty string; use UTC explicitly. */
- tz = "Universal";
-
-#ifdef MACOS
- /* as you well know, mac paths contain leading colon, this code
- messes things up.... */
-#else
- /* A leading colon means "implementation defined syntax".
- We ignore the colon and always use the same algorithm:
- try a data file, and if none exists parse the 1003.1 syntax. */
- if (tz && *tz == ':')
- ++tz;
-#endif
-
- /* Check whether the value changes since the last run. */
- if (old_fgtz != NULL && tz != NULL && strcmp (tz, old_fgtz) == 0)
- /* No change, simply return. */
- return;
-
- fgtz_rules[0].name = NULL;
- fgtz_rules[1].name = NULL;
-
- /* Save the value of `tz'. */
- if (old_fgtz != NULL)
- free (old_fgtz);
- old_fgtz = tz ? strdup (tz) : NULL;
-
- /* Try to read a data file. */
- fgtzfile_read (tz);
- if (use_fgtzfile)
- return;
- // The default behaviour of the originale tzset_internal (int always, char* tz)
- // function is to set up a default timezone, in any casetz file_read() fails
- // Currently this leads to problems, because it modidifies the system timezone
- // and not the local aircraft timezone, contained in FlightGear. I could adapt
- // this in future versions of this code, but doubt whether this is what we really
- // want. So right now, exit when timezone information reading failed.
- // Guess I'll change that to something like 12 * (FG_LON / 180.0)
- //
- // For now, I'll leave it like this.
- else
- {
- printf ("Timezone reading failed\n");
- exit(1);
- }
- // this emacs "comment out" function is cool!
-
-// // /* No data file found. Default to UTC if nothing specified. */
-// // printf ("1. Current local time = %24s", asctime(localtime(&now)));
-// if (tz == NULL || *tz == '\0')
-// {
-// fgtz_rules[0].name = fgtz_rules[1].name = "UTC";
-// fgtz_rules[0].type = fgtz_rules[1].type = fgtz_rule::J0;
-// fgtz_rules[0].m = fgtz_rules[0].n = fgtz_rules[0].d = 0;
-// fgtz_rules[1].m = fgtz_rules[1].n = fgtz_rules[1].d = 0;
-// fgtz_rules[0].secs = fgtz_rules[1].secs = 0;
-// fgtz_rules[0].offset = fgtz_rules[1].offset = 0L;
-// fgtz_rules[0].change = fgtz_rules[1].change = (time_t) -1;
-// fgtz_rules[0].computed_for = fgtz_rules[1].computed_for = 0;
-// return;
-// }
-
-// /* Clear out old state and reset to unnamed UTC. */
-// //printf ("2. Current local time = %24s", asctime(localtime(&now)));
-// memset (fgtz_rules, 0, sizeof fgtz_rules);
-// fgtz_rules[0].name = fgtz_rules[1].name = "";
-
-// /* Get the standard timezone name. */
-// tzbuf = malloc (strlen (tz) + 1);
-// if (! tzbuf)
-// {
-// /* Clear the old tz name so we will try again. */
-// free (old_fgtz);
-// old_fgtz = NULL;
-// return;
-// }
-// //printf ("3. Current local time = %24s", asctime(localtime(&now)));
-// if (sscanf (tz, "%[^0-9,+-]", tzbuf) != 1 ||
-// (l = strlen (tzbuf)) < 3)
-// {
-// free (tzbuf);
-// return;
-// }
-
-// fgtz_rules[0].name = tzstring (tzbuf);
-
-// tz += l;
-// //printf ("4. Current local time = %24s", asctime(localtime(&now)));
-// /* Figure out the standard offset from UTC. */
-// if (*tz == '\0' || (*tz != '+' && *tz != '-' && !isdigit (*tz)))
-// {
-// free (tzbuf);
-// return;
-// }
-// //printf ("5. Current local time = %24s", asctime(localtime(&now)));
-// if (*tz == '-' || *tz == '+')
-// fgtz_rules[0].offset = *tz++ == '-' ? 1L : -1L;
-// else
-// fgtz_rules[0].offset = -1L;
-// switch (sscanf (tz, "%hu:%hu:%hu", &hh, &mm, &ss))
-// {
-// default:
-// free (tzbuf);
-// return;
-// case 1:
-// mm = 0;
-// case 2:
-// ss = 0;
-// case 3:
-// break;
-// }
-// //printf ("6. Current local time = %24s", asctime(localtime(&now)));
-// fgtz_rules[0].offset *= (min (ss, 59) + (min (mm, 59) * 60) +
-// (min (hh, 23) * 60 * 60));
-
-// for (l = 0; l < 3; ++l)
-// {
-// while (isdigit(*tz))
-// ++tz;
-// if (l < 2 && *tz == ':')
-// ++tz;
-// }
-// //printf ("7. Current local time = %24s", asctime(localtime(&now)));
-// /* Get the DST timezone name (if any). */
-// if (*tz != '\0')
-// {
-// char *n = tzbuf + strlen (tzbuf) + 1;
-// if (sscanf (tz, "%[^0-9,+-]", n) != 1 ||
-// (l = strlen (n)) < 3)
-// goto done_names; /* Punt on name, set up the offsets. */
-// //printf ("7.1 Current local time = %24s", asctime(localtime(&now)));
-// fgtz_rules[1].name = tzstring (n);
-
-// tz += l;
-
-// /* Figure out the DST offset from GMT. */
-// if (*tz == '-' || *tz == '+')
-// fgtz_rules[1].offset = *tz++ == '-' ? 1L : -1L;
-// else
-// fgtz_rules[1].offset = -1L;
-// //printf ("7.2 Current local time = %24s", asctime(localtime(&now)));
-// switch (sscanf (tz, "%hu:%hu:%hu", &hh, &mm, &ss))
-// {
-// default:
-// /* Default to one hour later than standard time. */
-// fgtz_rules[1].offset = fgtz_rules[0].offset + (60 * 60);
-// break;
-
-// case 1:
-// mm = 0;
-// case 2:
-// ss = 0;
-// case 3:
-// fgtz_rules[1].offset *= (min (ss, 59) + (min (mm, 59) * 60) +
-// (min (hh, 23) * (60 * 60)));
-// break;
-// }
-// //printf ("7.3 Current local time = %24s", asctime(localtime(&now)));
-// for (l = 0; l < 3; ++l)
-// {
-// while (isdigit (*tz))
-// ++tz;
-// if (l < 2 && *tz == ':')
-// ++tz;
-// }
-// //printf ("7.4 Current local time = %24s", asctime(localtime(&now)));
-// if (*tz == '\0' || (tz[0] == ',' && tz[1] == '\0'))
-// {
-// /* There is no rule. See if there is a default rule file. */
-// //printf ("7.4.1 Current local time = %24s", asctime(localtime(&now)));
-// tzfile_default (fgtz_rules[0].name, fgtz_rules[1].name,
-// fgtz_rules[0].offset, fgtz_rules[1].offset);
-// //printf ("7.4.2 Current local time = %24s", asctime(localtime(&now)));
-// if (use_fgtzfile)
-// {
-// free (old_fgtz);
-// old_fgtz = NULL;
-// free (tzbuf);
-// return;
-// }
-// }
-// }
-// else
-// {
-// /* There is no DST. */
-// fgtz_rules[1].name = fgtz_rules[0].name;
-// free (tzbuf);
-// return;
-// }
-// //printf ("7.5 Current local time = %24s", asctime(localtime(&now)));
-// done_names:
-// //printf ("8. Current local time = %24s", asctime(localtime(&now)));
-// free (tzbuf);
-
-// /* Figure out the standard <-> DST rules. */
-// for (whichrule = 0; whichrule < 2; ++whichrule)
-// {
-// register fgtz_rule *tzr = &fgtz_rules[whichrule];
-
-// /* Ignore comma to support string following the incorrect
-// specification in early POSIX.1 printings. */
-// tz += *tz == ',';
-
-// /* Get the date of the change. */
-// if (*tz == 'J' || isdigit (*tz))
-// {
-// char *end;
-// tzr->type = *tz == 'J' ? fgtz_rule::J1 : fgtz_rule::J0;
-// if (tzr->type == fgtz_rule::J1 && !isdigit (*++tz))
-// return;
-// tzr->d = (unsigned short int) strtoul (tz, &end, 10);
-// if (end == tz || tzr->d > 365)
-// return;
-// else if (tzr->type == fgtz_rule::J1 && tzr->d == 0)
-// return;
-// tz = end;
-// }
-// else if (*tz == 'M')
-// {
-// int n;
-// tzr->type = fgtz_rule::M;
-// if (sscanf (tz, "M%hu.%hu.%hu%n",
-// &tzr->m, &tzr->n, &tzr->d, &n) != 3 ||
-// tzr->m < 1 || tzr->m > 12 ||
-// tzr->n < 1 || tzr->n > 5 || tzr->d > 6)
-// return;
-// tz += n;
-// }
-// else if (*tz == '\0')
-// {
-// /* United States Federal Law, the equivalent of "M4.1.0,M10.5.0". */
-// tzr->type = fgtz_rule::M;
-// if (tzr == &fgtz_rules[0])
-// {
-// tzr->m = 4;
-// tzr->n = 1;
-// tzr->d = 0;
-// }
-// else
-// {
-// tzr->m = 10;
-// tzr->n = 5;
-// tzr->d = 0;
-// }
-// }
-// else
-// return;
-// //printf ("9. Current local time = %24s", asctime(localtime(&now)));
-// if (*tz != '\0' && *tz != '/' && *tz != ',')
-// return;
-// else if (*tz == '/')
-// {
-// /* Get the time of day of the change. */
-// ++tz;
-// if (*tz == '\0')
-// return;
-// switch (sscanf (tz, "%hu:%hu:%hu", &hh, &mm, &ss))
-// {
-// default:
-// hh = 2; /* Default to 2:00 AM. */
-// case 1:
-// mm = 0;
-// case 2:
-// ss = 0;
-// case 3:
-// break;
-// }
-// for (l = 0; l < 3; ++l)
-// {
-// while (isdigit (*tz))
-// ++tz;
-// if (l < 2 && *tz == ':')
-// ++tz;
-// }
-// tzr->secs = (hh * 60 * 60) + (mm * 60) + ss;
-// }
-// else
-// /* Default to 2:00 AM. */
-// tzr->secs = 2 * 60 * 60;
-
-// tzr->computed_for = -1;
-// }
-// // printf ("10. Current local time = %24s", asctime(localtime(&now)));
-//
-}
-
-/************************************************************************/
-
-
-/* Figure out the correct timezone for *TIMER and TM (which must be the same)
- and set `tzname', `timezone', and `daylight' accordingly.
- Return nonzero on success, zero on failure. */
-size_t fgtzname_cur_max;
-
-static int fgtz_compute (time_t timer, const struct tm* tm)
- // time_t timer;
- // const struct tm *tm;
-{
- if (! fgcompute_change (&fgtz_rules[0], 1900 + tm->tm_year) ||
- ! fgcompute_change (&fgtz_rules[1], 1900 + tm->tm_year))
- return 0;
-
- fgdaylight = timer >= fgtz_rules[0].change && timer < fgtz_rules[1].change;
- fgtimezone = -fgtz_rules[fgdaylight].offset;
- fgtzname[0] = (char *) fgtz_rules[0].name;
- fgtzname[1] = (char *) fgtz_rules[1].name;
-
- {
- /* Keep tzname_cur_max up to date. */
- size_t len0 = strlen (fgtzname[0]);
- size_t len1 = strlen (fgtzname[1]);
- if (len0 > fgtzname_cur_max)
- fgtzname_cur_max = len0;
- if (len1 > fgtzname_cur_max)
- fgtzname_cur_max = len1;
- }
-
- return 1;
-}
-
-/**********************************************************************/
-
-/* Figure out the exact time (as a time_t) in YEAR
- when the change described by RULE will occur and
- put it in RULE->change, saving YEAR in RULE->computed_for.
- Return nonzero if successful, zero on failure. */
-static int fgcompute_change (fgtz_rule *rule, int year)
- // tz_rule *rule;
- // int year;
-{
- register time_t t;
- int y;
-
- if (year != -1 && rule->computed_for == year)
- /* Operations on times in 1969 will be slower. Oh well. */
- return 1;
-
- /* First set T to January 1st, 0:00:00 GMT in YEAR. */
- t = 0;
- for (y = 1970; y < year; ++y)
- t += SECSPERDAY * (isleap (y) ? 366 : 365);
-
- switch (rule->type)
- {
- case fgtz_rule::J1:
- /* Jn - Julian day, 1 == January 1, 60 == March 1 even in leap years.
- In non-leap years, or if the day number is 59 or less, just
- add SECSPERDAY times the day number-1 to the time of
- January 1, midnight, to get the day. */
- t += (rule->d - 1) * SECSPERDAY;
- if (rule->d >= 60 && isleap (year))
- t += SECSPERDAY;
- break;
-
- case fgtz_rule::J0:
- /* n - Day of year.
- Just add SECSPERDAY times the day number to the time of Jan 1st. */
- t += rule->d * SECSPERDAY;
- break;
-
- case fgtz_rule::M:
- /* Mm.n.d - Nth "Dth day" of month M. */
- {
- register int i, d, m1, yy0, yy1, yy2, dow;
- register const unsigned short int *myday =
- &mon_yday[isleap (year)][rule->m];
-
- /* First add SECSPERDAY for each day in months before M. */
- t += myday[-1] * SECSPERDAY;
-
- /* Use Zeller's Congruence to get day-of-week of first day of month. */
- m1 = (rule->m + 9) % 12 + 1;
- yy0 = (rule->m <= 2) ? (year - 1) : year;
- yy1 = yy0 / 100;
- yy2 = yy0 % 100;
- dow = ((26 * m1 - 2) / 10 + 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
- if (dow < 0)
- dow += 7;
-
- /* DOW is the day-of-week of the first day of the month. Get the
- day-of-month (zero-origin) of the first DOW day of the month. */
- d = rule->d - dow;
- if (d < 0)
- d += 7;
- for (i = 1; i < rule->n; ++i)
- {
- if (d + 7 >= myday[0] - myday[-1])
- break;
- d += 7;
- }
-
- /* D is the day-of-month (zero-origin) of the day we want. */
- t += d * SECSPERDAY;
- }
- break;
- }
-
- /* T is now the Epoch-relative time of 0:00:00 GMT on the day we want.
- Just add the time of day and local offset from GMT, and we're done. */
-
- rule->change = t - rule->offset + rule->secs;
- rule->computed_for = year;
- return 1;
-}
-
-/*************************************************************************/
-
-int fgtzfile_compute (time_t timer, int use_localtime,
- long int *leap_correct, int *leap_hit)
-{
- register size_t i;
-
- if (use_localtime)
- {
- struct ttinfo *info = fgfind_transition (timer);
- fgdaylight = info->isdst;
- fgtimezone = -info->offset;
- for (i = 0;
- i < num_types && i < sizeof (fgtzname) / sizeof (fgtzname[0]);
- ++i)
- fgtzname[types[i].isdst] = &zone_names[types[i].idx];
- if (info->isdst < sizeof (fgtzname) / sizeof (fgtzname[0]))
- fgtzname[info->isdst] = &zone_names[info->idx];
- }
-
- *leap_correct = 0L;
- *leap_hit = 0;
-
- /* Find the last leap second correction transition time before TIMER. */
- i = num_leaps;
- do
- if (i-- == 0)
- return 1;
- while (timer < leaps[i].transition);
-
- /* Apply its correction. */
- *leap_correct = leaps[i].change;
-
- if (timer == leaps[i].transition && /* Exactly at the transition time. */
- ((i == 0 && leaps[i].change > 0) ||
- leaps[i].change > leaps[i - 1].change))
- {
- *leap_hit = 1;
- while (i > 0 &&
- leaps[i].transition == leaps[i - 1].transition + 1 &&
- leaps[i].change == leaps[i - 1].change + 1)
- {
- ++*leap_hit;
- --i;
- }
- }
-
- return 1;
-}
-
-/**************************************************************************/
-
-static struct ttinfo * fgfind_transition (time_t timer)
-{
- size_t i;
-
- if (num_transitions == 0 || timer < transitions[0])
- {
- /* TIMER is before any transition (or there are no transitions).
- Choose the first non-DST type
- (or the first if they're all DST types). */
- i = 0;
- while (i < num_types && types[i].isdst)
- ++i;
- if (i == num_types)
- i = 0;
- }
- else
- {
- /* Find the first transition after TIMER, and
- then pick the type of the transition before it. */
- for (i = 1; i < num_transitions; ++i)
- if (timer < transitions[i])
- break;
- i = type_idxs[i - 1];
- }
-
- return &types[i];
-}
-
-
-/**************************************************************************/
-void fgtzfile_read (const char *file)
-{
- static const char default_tzdir[] = TZDIR;
- size_t num_isstd, num_isgmt;
- register FILE *f;
- struct tzhead tzhead;
- size_t chars;
- register size_t i;
- struct ttinfo *info;
-
- use_fgtzfile = 0;
-
- if (transitions != NULL)
- free ((void *) transitions);
- transitions = NULL;
- if (type_idxs != NULL)
- free ((void *) type_idxs);
- type_idxs = NULL;
- if (types != NULL)
- free ((void *) types);
- types = NULL;
- if (zone_names != NULL)
- free ((void *) zone_names);
- zone_names = NULL;
- if (leaps != NULL)
- free ((void *) leaps);
- leaps = NULL;
-
- if (file == NULL)
- /* No user specification; use the site-wide default. */
- file = TZDEFAULT;
- else if (*file == '\0')
- /* User specified the empty string; use UTC with no leap seconds. */
- return;
- else
- {
- /* We must not allow to read an arbitrary file in a setuid
- program. So we fail for any file which is not in the
- directory hierachy starting at TZDIR
- and which is not the system wide default TZDEFAULT. */
- //if (libc_enable_secure
- // && ((*file == '/'
- // && memcmp (file, TZDEFAULT, sizeof TZDEFAULT)
- // && memcmp (file, default_tzdir, sizeof (default_tzdir) - 1))
- // || strstr (file, "../") != NULL))
- /* This test is certainly a bit too restrictive but it should
- catch all critical cases. */
- //return;
- }
-
-// if (*file != '/') // if a relative path is used, append what file points to
-// // to the path indicated by TZDIR.
-// {
-// const char *tzdir;
-// unsigned int len, tzdir_len;
-// char *_new;
-
-// tzdir = getenv ("TZDIR");
-// if (tzdir == NULL || *tzdir == '\0')
-// {
-// tzdir = default_tzdir;
-// tzdir_len = sizeof (default_tzdir) - 1;
-// }
-// else
-// tzdir_len = strlen (tzdir);
-// len = strlen (file) + 1;
-// _new = (char *) alloca (tzdir_len + 1 + len);
-// memcpy (_new, tzdir, tzdir_len);
-// _new[tzdir_len] = '/';
-// memcpy (&_new[tzdir_len + 1], file, len);
-// file = _new;
-// }
-
- f = fopen (file, "rb");
- if (f == NULL)
- return;
-
- if (fread ((void *) &tzhead, sizeof (tzhead), 1, f) != 1)
- goto lose;
-
- num_transitions = (size_t) decode (tzhead.tzh_timecnt);
- num_types = (size_t) decode (tzhead.tzh_typecnt);
- chars = (size_t) decode (tzhead.tzh_charcnt);
- num_leaps = (size_t) decode (tzhead.tzh_leapcnt);
- num_isstd = (size_t) decode (tzhead.tzh_ttisstdcnt);
- num_isgmt = (size_t) decode (tzhead.tzh_ttisgmtcnt);
-
- if (num_transitions > 0)
- {
- transitions = (time_t *) malloc (num_transitions * sizeof(time_t));
- if (transitions == NULL)
- goto lose;
- type_idxs = (unsigned char *) malloc (num_transitions);
- if (type_idxs == NULL)
- goto lose;
- }
- if (num_types > 0)
- {
- types = (struct ttinfo *) malloc (num_types * sizeof (struct ttinfo));
- if (types == NULL)
- goto lose;
- }
- if (chars > 0)
- {
- zone_names = (char *) malloc (chars);
- if (zone_names == NULL)
- goto lose;
- }
- if (num_leaps > 0)
- {
- leaps = (struct leap *) malloc (num_leaps * sizeof (struct leap));
- if (leaps == NULL)
- goto lose;
- }
-
- if (sizeof (time_t) < 4)
- abort ();
-
- if (fread(transitions, 4, num_transitions, f) != num_transitions ||
- fread(type_idxs, 1, num_transitions, f) != num_transitions)
- goto lose;
-
- /* Check for bogus indices in the data file, so we can hereafter
- safely use type_idxs[T] as indices into `types' and never crash. */
- for (i = 0; i < num_transitions; ++i)
- if (type_idxs[i] >= num_types)
- goto lose;
-
- if (BYTE_ORDER != BIG_ENDIAN || sizeof (time_t) != 4)
- {
- /* Decode the transition times, stored as 4-byte integers in
- network (big-endian) byte order. We work from the end of
- the array so as not to clobber the next element to be
- processed when sizeof (time_t) > 4. */
- i = num_transitions;
- while (i-- > 0)
- transitions[i] = decode ((char *) transitions + i*4);
- }
-
- for (i = 0; i < num_types; ++i)
- {
- unsigned char x[4];
- if (fread (x, 1, 4, f) != 4 ||
- fread (&types[i].isdst, 1, 1, f) != 1 ||
- fread (&types[i].idx, 1, 1, f) != 1)
- goto lose;
- if (types[i].idx >= chars) /* Bogus index in data file. */
- goto lose;
- types[i].offset = (long int) decode (x);
- }
-
- if (fread (zone_names, 1, chars, f) != chars)
- goto lose;
-
- for (i = 0; i < num_leaps; ++i)
- {
- unsigned char x[4];
- if (fread (x, 1, sizeof (x), f) != sizeof (x))
- goto lose;
- leaps[i].transition = (time_t) decode (x);
- if (fread (x, 1, sizeof (x), f) != sizeof (x))
- goto lose;
- leaps[i].change = (long int) decode (x);
- }
-
- for (i = 0; i < num_isstd; ++i)
- {
- int c = getc (f);
- if (c == EOF)
- goto lose;
- types[i].isstd = c != 0;
- }
- while (i < num_types)
- types[i++].isstd = 0;
-
- for (i = 0; i < num_isgmt; ++i)
- {
- int c = getc (f);
- if (c == EOF)
- goto lose;
- types[i].isgmt = c != 0;
- }
- while (i < num_types)
- types[i++].isgmt = 0;
-
- fclose (f);
-
- info = fgfind_transition (0);
- for (i = 0; i < num_types && i < sizeof (fgtzname) / sizeof (fgtzname[0]);
- ++i)
- fgtzname[types[i].isdst] = tzstring (&zone_names[types[i].idx]);
- if (info->isdst < sizeof (fgtzname) / sizeof (fgtzname[0]))
- fgtzname[info->isdst] = tzstring (&zone_names[info->idx]);
-
- fgcompute_tzname_max (chars);
-
- use_fgtzfile = 1;
- return;
-
- lose:;
- fclose(f);
-}
-
-/****************************************************************************/
-static void fgcompute_tzname_max (size_t chars)
-{
- extern size_t tzname_cur_max; /* Defined in tzset.c. */
-
- const char *p;
-
- p = zone_names;
- do
- {
- const char *start = p;
- while (*p != '\0')
- ++p;
- if ((size_t) (p - start) > fgtzname_cur_max)
- fgtzname_cur_max = p - start;
- } while (++p < &zone_names[chars]);
-}
-
-/**************************************************************************/
-
-//#include <endian.h>
-
-/* Decode the four bytes at PTR as a signed integer in network byte order. */
-static inline int decode (const void *ptr)
-{
- if ((BYTE_ORDER == BIG_ENDIAN) && sizeof (int) == 4)
- return *(const int *) ptr;
- else
- {
- const unsigned char *p = (unsigned char *)ptr;
- int result = *p & (1 << (CHAR_BIT - 1)) ? ~0 : 0;
-
- result = (result << 8) | *p++;
- result = (result << 8) | *p++;
- result = (result << 8) | *p++;
- result = (result << 8) | *p++;
-
- return result;
- }
-}
-
-
-
-#define SECS_PER_HOUR (60 * 60)
-#define SECS_PER_DAY (SECS_PER_HOUR * 24)
-
-/* Compute the `struct tm' representation of *T,
- offset OFFSET seconds east of UTC,
- and store year, yday, mon, mday, wday, hour, min, sec into *TP. */
-
-void offtime (const time_t *t, long int offset, struct tm *tp)
- // const time_t *t;
- // long int offset;
- // struct tm *tp;
-{
- register long int days, rem, y;
- register const unsigned short int *ip;
-
- days = *t / SECS_PER_DAY;
- rem = *t % SECS_PER_DAY;
- rem += offset;
- while (rem < 0)
- {
- rem += SECS_PER_DAY;
- --days;
- }
- while (rem >= SECS_PER_DAY)
- {
- rem -= SECS_PER_DAY;
- ++days;
- }
- tp->tm_hour = rem / SECS_PER_HOUR;
- rem %= SECS_PER_HOUR;
- tp->tm_min = rem / 60;
- tp->tm_sec = rem % 60;
- /* January 1, 1970 was a Thursday. */
- tp->tm_wday = (4 + days) % 7;
- if (tp->tm_wday < 0)
- tp->tm_wday += 7;
- y = 1970;
-
-#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
-
- while (days < 0 || days >= (isleap (y) ? 366 : 365))
- {
- /* Guess a corrected year, assuming 365 days per year. */
- long int yg = y + days / 365 - (days % 365 < 0);
-
- /* Adjust DAYS and Y to match the guessed year. */
- days -= ((yg - y) * 365
- + LEAPS_THRU_END_OF (yg - 1)
- - LEAPS_THRU_END_OF (y - 1));
- y = yg;
- }
- tp->tm_year = y - 1900;
- tp->tm_yday = days;
- ip = mon_yday[isleap(y)];
- for (y = 11; days < ip[y]; --y)
- continue;
- days -= ip[y];
- tp->tm_mon = y;
- tp->tm_mday = days + 1;
-}
-
-/* Allocate a time zone string with given contents.
- The string will never be moved or deallocated.
- However, its contents may be shared with other such strings. */
-char *tzstring (const char* string)
- //const char *string;
-{
- struct tzstring_head *h = &tzstring_list.head;
- size_t needed;
- char *p;
-
- /* Look through time zone string list for a duplicate of this one. */
- for (h = &tzstring_list.head; ; h = h->next)
- {
- for (p = (char *) (h + 1); p[0] | p[1]; ++p)
- if (strcmp (p, string) == 0)
- return p;
- if (! h->next)
- break;
- }
-
- /* No duplicate was found. Copy to the end of this buffer if there's room;
- otherwise, append a large-enough new buffer to the list and use it. */
- ++p;
- needed = strlen (string) + 2; /* Need 2 trailing '\0's after last string. */
-
- if ((size_t) ((char *) (h + 1) + tzstring_last_buffer_size - p) < needed)
- {
- size_t buffer_size = tzstring_last_buffer_size;
- while ((buffer_size *= 2) < needed)
- continue;
- if (! (h = h->next = (struct tzstring_head *)malloc (sizeof *h + buffer_size)))
- return NULL;
- h->next = NULL;
- tzstring_last_buffer_size = buffer_size;
- p = (char *) (h + 1);
- }
-
- return strncpy (p, string, needed);
-}
+++ /dev/null
-/* -*- Mode: C++ -*- *****************************************************
- * lowleveltime.h
- * Written by various people (I"ll look up the exact credits later)
- * Modified by Durk Talsma, July 1999 for use in FlightGear
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- **************************************************************************/
-
-/********************************************************************
- * This file redefines some low-level Unix-like time functions for *
- * use with FlightGear. Most notably, localtime() is adapted to use *
- * a custom timezone, in order to get the 'local' time for a given *
- * aircraft's position, and not only for the current location of the*
- * computer running the sim. *
- * *
- * Software adapted from glibc functions, by Durk Talsma. Started *
- * July, 17, 1999. *
- ********************************************************************/
-
-#ifndef _LOWLEVELTIME_H_
-#define _LOWLEVELTIME_H_
-
-#include <time.h>
-
-/* adapted from zdump.c */
-void show (const char *zone, time_t t, int v);
-
-/* adapted from <time.h> */
-struct tm * fgLocaltime (const time_t *t, const char *tzName);
-
-/* Prototype for the internal function to get information based on TZ. */
-extern struct tm *fgtz_convert (const time_t *t, int use_localtime,
- struct tm *tp, const char *tzName);
-
-/* This structure contains all the information about a
- timezone given in the POSIX standard TZ envariable. */
-typedef struct
- {
- const char *name;
-
- /* When to change. */
- enum { J0, J1, M } type; /* Interpretation of: */
- unsigned short int m, n, d; /* Month, week, day. */
- unsigned int secs; /* Time of day. */
-
- long int offset; /* Seconds east of GMT (west if < 0). */
-
- /* We cache the computed time of change for a
- given year so we don't have to recompute it. */
- time_t change; /* When to change to this zone. */
- int computed_for; /* Year above is computed for. */
- } fgtz_rule;
-
-struct tzhead {
- char tzh_magic[4]; /* TZ_MAGIC */
- char tzh_reserved[16]; /* reserved for future use */
- char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
- char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
- char tzh_leapcnt[4]; /* coded number of leap seconds */
- char tzh_timecnt[4]; /* coded number of transition times */
- char tzh_typecnt[4]; /* coded number of local time types */
- char tzh_charcnt[4]; /* coded number of abbr. chars */
-};
-
-
-/* Defined in mktime.c. */
-extern const unsigned short int mon_yday[2][13];
-
-#ifndef TZDIR
-#define TZDIR "/usr/local/etc/zoneinfo" /* Time zone object file directory */
-#endif /* !defined TZDIR */
-
-
-
-#ifndef TZDEFAULT
-#define TZDEFAULT "localtime"
-#endif /* !defined TZDEFAULT */
-
-#define SECSPERMIN 60
-#define MINSPERHOUR 60
-#define HOURSPERDAY 24
-#define DAYSPERWEEK 7
-#define DAYSPERNYEAR 365
-#define DAYSPERLYEAR 366
-#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
-#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY)
-#define MONSPERYEAR 12
-
-#define TM_SUNDAY 0
-#define TM_MONDAY 1
-#define TM_TUESDAY 2
-#define TM_WEDNESDAY 3
-#define TM_THURSDAY 4
-#define TM_FRIDAY 5
-#define TM_SATURDAY 6
-
-#define TM_JANUARY 0
-#define TM_FEBRUARY 1
-#define TM_MARCH 2
-#define TM_APRIL 3
-#define TM_MAY 4
-#define TM_JUNE 5
-#define TM_JULY 6
-#define TM_AUGUST 7
-#define TM_SEPTEMBER 8
-#define TM_OCTOBER 9
-#define TM_NOVEMBER 10
-#define TM_DECEMBER 11
-
-#define TM_YEAR_BASE 1900
-
-#define EPOCH_YEAR 1970
-#define EPOCH_WDAY TM_THURSDAY
-
-#endif
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
+#include <simgear/ephemeris/ephemeris.hxx>
#include <simgear/math/fg_geodesy.hxx>
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
#include <simgear/math/vector.hxx>
+#include <simgear/timing/fg_time.hxx>
-#include <Ephemeris/ephemeris.hxx>
#include <Main/views.hxx>
#include <Scenery/scenery.hxx>
-#include "fg_time.hxx"
#include "moonpos.hxx"
// extern SolarSystem *solarSystem;
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
+#include <simgear/ephemeris/ephemeris.hxx>
#include <simgear/math/fg_geodesy.hxx>
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
#include <simgear/math/vector.hxx>
+#include <simgear/timing/fg_time.hxx>
-#include <Ephemeris/ephemeris.hxx>
#include <Main/views.hxx>
#include <Scenery/scenery.hxx>
-#include "fg_time.hxx"
#include "sunpos.hxx"
// extern SolarSystem *solarSystem;
+++ /dev/null
-/* -*- Mode: C++ -*- *****************************************************
- * timezone.cc
- * Written by Durk Talsma. Started July 1999.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- **************************************************************************/
-
-/*************************************************************************
- *
- * Timezone is derived from geocoord, and stores the timezone centerpoint,
- * as well as the countrycode and the timezone descriptor. The latter is
- * used in order to get the local time.
- *
- ************************************************************************/
-#include <stdio.h>
-#include "timezone.h"
-
-
-Timezone::Timezone(float la, float lo, char* cc, char* desc) :
- GeoCoord(la, lo)
-{
- countryCode = strdup(cc);
- descriptor = strdup(desc);
-}
-
-/* Build a timezone object from a textline in zone.tab */
-Timezone::Timezone(const char *infoString) :
- GeoCoord()
-{
- int i = 0;
- while (infoString[i] != '\t')
- i++;
- char buffer[128];
- char latlon[128];
- strncpy(buffer, infoString, i);
- buffer[i] = 0;
- countryCode = strdup(buffer);
- i ++;
- int start = i;
- while (infoString[i] != '\t')
- i++;
- int size = i - start;
- strncpy(latlon, (&infoString[start]), size);
- latlon[size] = 0;
- char sign;
- sign = latlon[0];
- strncpy(buffer, &latlon[1], 2);
- lat = atof(buffer);
- strncpy(buffer, &latlon[3], 2);
- lat += (atof(buffer) / 60);
- int nextPos;
- if (strlen(latlon) > 12)
- {
- nextPos = 7;
- strncpy(buffer, &latlon[5], 2);
- lat += (atof(buffer) / 3600.0);
- }
- else
- nextPos = 5;
- if (sign == '-')
- lat = -lat;
-
- sign = latlon[nextPos];
- nextPos++;
- strncpy(buffer, &latlon[nextPos], 3);
- lon = atof(buffer);
- nextPos += 3;
- strncpy(buffer, &latlon[nextPos], 2);
- buffer[2] = 0;
-
- lon += (atof(buffer) / 60);
- if (strlen(latlon) > 12)
- {
- nextPos += 2;
- strncpy(buffer, &latlon[nextPos], 2);
- lon += (atof (buffer) / 3600.00);
- }
- if (sign == '-')
- lon = -lon;
- i ++;
- start = i;
- while (!((infoString[i] == '\t') || (infoString[i] == '\n')))
- i++;
- size = i - start;
- strncpy(buffer, (&infoString[start]), size);
- buffer[size] = 0;
- descriptor = strdup(buffer);
-}
-
-/* the copy constructor */
-Timezone::Timezone(const Timezone& other)
-{
- lat = other.getLat();
- lon = other.getLon();
- countryCode = strdup(other.countryCode);
- descriptor = strdup(other.descriptor);
-}
-
-
-/********* Member functions for TimezoneContainer class ********/
-
-TimezoneContainer::TimezoneContainer(const char *filename)
-{
- char buffer[256];
- FILE* infile = fopen(filename, "r");
- if (!(infile))
- {
- fprintf(stderr, "Unable to open file %s\n", filename);
- exit(1);
- }
- else
- {
-
- while (1)
- {
- fgets(buffer, 256, infile);
- if (feof(infile))
- break;
- for (int i = 0; i < 256; i++)
- {
- if (buffer[i] == '#')
- buffer[i] = 0;
- }
- if (buffer[0])
- {
- data.push_back(new Timezone(buffer));
- }
- }
- }
-}
-
-TimezoneContainer::~TimezoneContainer()
-{
-}
+++ /dev/null
-/* -*- Mode: C++ -*- *****************************************************
- * timezone.h
- * Written by Durk Talsma. Started July 1999.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- **************************************************************************/
-
-/*************************************************************************
- *
- * Timezone is derived from geocoord, and stores the timezone centerpoint,
- * as well as the countrycode and the timezone descriptor. The latter is
- * used in order to get the local time.
- *
- ************************************************************************/
-
-#ifndef _TIMEZONE_H_
-#define _TIMEZONE_H_
-
-#include "geocoord.h"
-#include <stdio.h>
-
-class Timezone : public GeoCoord
-{
-private:
- char* countryCode;
- char* descriptor;
-
-public:
- Timezone() :
- GeoCoord()
- {
- countryCode = 0;
- descriptor = 0;
- };
- Timezone(float la, float lo, char* cc, char* desc);
- Timezone(const char *infoString);
- Timezone(const Timezone &other);
- virtual ~Timezone() { delete [] countryCode; delete [] descriptor; };
-
-
- virtual void print() { printf("%s", descriptor);};
- virtual char * getDescription() { return descriptor; };
-};
-
-/************************************************************************
- * Timezone container is derived from GeoCoordContainer, and has some
- * added functionality.
- ************************************************************************/
-
-class TimezoneContainer : public GeoCoordContainer
-{
- public:
- TimezoneContainer(const char *filename);
- virtual ~TimezoneContainer();
-};
-
-
-
-#endif // _TIMEZONE_H_