More SGTime clean ups.

This commit is contained in:
curt 2000-07-07 14:59:04 +00:00
parent 8159b749f4
commit 1a6e2509c7
5 changed files with 56 additions and 75 deletions

View File

@ -6,7 +6,7 @@ dnl $Id$
AC_INIT(simgear/bucket/newbucket.cxx)
dnl Initialize the automake stuff
AM_INIT_AUTOMAKE(SimGear, 0.0.11)
AM_INIT_AUTOMAKE(SimGear, 0.0.12)
dnl Checks for programs.
AC_PROG_MAKE_SET

View File

@ -50,9 +50,6 @@
/* Define if you have zlib installed system wide. */
#undef HAVE_ZLIB
/* Define to package name */
#undef PACKAGE
/* Define as the return type of signal handlers (int or void). */
#undef RETSIGTYPE
@ -68,9 +65,6 @@
/* Define if your <sys/time.h> declares struct tm. */
#undef TM_IN_SYS_TIME
/* Define to version number */
#undef VERSION
/* Define if compiling on a Winbloze (95, NT, etc.) platform */
#undef WIN32
@ -205,3 +199,10 @@
/* Define if you have the socket library (-lsocket). */
#undef HAVE_LIBSOCKET
/* Name of package */
#undef PACKAGE
/* Version number of package */
#undef VERSION

View File

@ -4,12 +4,13 @@ lib_LIBRARIES = libsgtiming.a
include_HEADERS = \
geocoord.h \
lowleveltime.h \
sg_time.hxx \
timezone.h
libsgtiming_a_SOURCES = \
geocoord.cxx \
lowleveltime.cxx lowleveltime.h \
lowleveltime.cxx \
sg_time.cxx \
timezone.cxx \
# event.cxx event.hxx \

View File

@ -51,28 +51,17 @@
#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 "sg_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
SGTime::SGTime( const string& root )
{
if (cur_time_params) {
@ -89,8 +78,8 @@ SGTime::SGTime( const string& root )
FG_LOG( FG_EVENT, FG_INFO, "Reading timezone info from: " << zone.str() );
tzContainer = new TimezoneContainer( zone.c_str() );
warp=0;
warp_delta=0;
// warp=0;
// warp_delta=0;
}
@ -115,22 +104,18 @@ void SGTime::updateLocal( double lon, double lat, const string& root )
zonename = strdup( zone.c_str() );
currGMT = get_gmt( gmtime(&cur_time) );
aircraftLocalTime = get_gmt( (fgLocaltime(&cur_time, zone.c_str())) );
localOffset = aircraftLocalTime - currGMT;
// cerr << "Using " << localOffset << " as local time offset Timezone is "
// << zonename << endl;
local_offset = aircraftLocalTime - currGMT;
cout << "Using " << local_offset << " as local time offset Timezone is "
<< zonename << endl;
}
// Initialize the time dependent variables (maybe I'll put this in the
// constructor later)
void SGTime::init( double lon, double lat, const string& root,
time_t timeOffset, sgTimingOffsetType offsetType )
void SGTime::init( double lon, double lat, const string& root )
// time_t timeOffset, sgTimingOffsetType offsetType )
{
FG_LOG( FG_EVENT, FG_INFO, "Initializing Time" );
gst_diff = -9999.0;
FG_LOG( FG_EVENT, FG_DEBUG,
"time offset = " << timeOffset );
// time_t timeOffset = current_options.get_time_offset();
// int offsetType = current_options.get_time_offset_type();
time_t currGMT;
time_t systemLocalTime;
@ -152,13 +137,18 @@ void SGTime::init( double lon, double lat, const string& root,
zone.append( "Timezone" );
zone.append( nearestTz->getDescription() );
// printf("Using %s for timezone information\n", buffer);
cout << "Using " << zone.str() << " for timezone information" << endl;
zonename = strdup( zone.c_str() );
cout << "zonename = " << zonename << endl;
//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) );
cout << "currGMT = " << currGMT << endl;
systemLocalTime = get_gmt( localtime(&cur_time) );
cout << "systemLocalTime = " << systemLocalTime << endl;
aircraftLocalTime = get_gmt( fgLocaltime(&cur_time, zone.c_str()) );
//printf ("Current greenwich mean time = %24s", asctime(gmtime(&cur_time)));
//printf ("Current local time = %24s", asctime(localtime(&cur_time)));
@ -169,6 +159,8 @@ void SGTime::init( double lon, double lat, const string& root,
// 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);
#if 0
// Okay, we now have six possible scenarios
switch (offsetType)
{
@ -201,6 +193,8 @@ void SGTime::init( double lon, double lat, const string& root,
warp_delta = 0;
// pause = current_options.get_pause();
#endif
}
@ -218,7 +212,6 @@ void SGTime::cal_mjd (int mn, double dy, int yr)
if (mn == last_mn && yr == last_yr && dy == last_dy) {
mjd = last_mjd;
//return(mjd);
}
m = mn;
@ -250,8 +243,6 @@ void SGTime::cal_mjd (int mn, double dy, int yr)
last_dy = dy;
last_yr = yr;
last_mjd = mjd;
//return(mjd);
}
@ -267,7 +258,7 @@ void SGTime::utc_gst ()
x /= 3600.0;
gst = (1.0/SIDRATE)*hr + x;
FG_LOG( FG_EVENT, FG_DEBUG, " gst => " << gst );
FG_LOG( FG_EVENT, FG_INFO, " gst => " << gst );
}
@ -338,28 +329,21 @@ double SGTime::sidereal_course(double lng)
// Update time variables such as gmt, julian date, and sidereal time
void SGTime::update( double lon, double lat, double alt_m ) {
void SGTime::update( double lon, double lat, double alt_m, long int warp ) {
double gst_precise, gst_course;
FG_LOG( FG_EVENT, FG_DEBUG, "Updating time" );
FG_LOG( FG_EVENT, FG_INFO, "Updating time" );
// get current Unix calendar time (in seconds)
warp += warp_delta;
// warp += warp_delta;
cur_time = time(NULL) + warp;
FG_LOG( FG_EVENT, FG_DEBUG,
FG_LOG( FG_EVENT, FG_INFO,
" Current Unix calendar time = " << cur_time
<< " warp = " << warp << " delta = " << warp_delta );
#if 0
if ( warp_delta ) {
// time is changing so force an update
local_update_sky_and_lighting_params();
}
#endif
<< " warp = " << warp );
// get GMT break down for current time
gmt = gmtime(&cur_time);
FG_LOG( FG_EVENT, FG_DEBUG,
FG_LOG( FG_EVENT, FG_INFO,
" Current GMT = " << gmt->tm_mon+1 << "/"
<< gmt->tm_mday << "/" << gmt->tm_year << " "
<< gmt->tm_hour << ":" << gmt->tm_min << ":"
@ -377,7 +361,7 @@ void SGTime::update( double lon, double lat, double alt_m ) {
// 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 );
FG_LOG( FG_EVENT, FG_INFO, " Current Julian Date = " << jd );
// printf(" Current Longitude = %.3f\n", FG_Longitude * RAD_TO_DEG);
@ -398,9 +382,9 @@ void SGTime::update( double lon, double lat, double alt_m ) {
lst = sidereal_course( -(lon * RAD_TO_DEG)) + gst_diff;
}
FG_LOG( FG_EVENT, FG_DEBUG,
FG_LOG( FG_EVENT, FG_INFO,
" Current lon=0.00 Sidereal Time = " << gst );
FG_LOG( FG_EVENT, FG_DEBUG,
FG_LOG( FG_EVENT, FG_INFO,
" Current LOCAL Sidereal Time = " << lst << " ("
<< sidereal_precise(-(lon * RAD_TO_DEG))
<< ") (diff = " << gst_diff << ")" );

View File

@ -71,45 +71,38 @@ private:
// tzContainer stores all the current Timezone control points/
TimezoneContainer* tzContainer;
//Store the current local timezone name;
// Points to the current local timezone name;
char *zonename;
// Unix "calendar" time in seconds
time_t cur_time;
// Break down of GMT time
// Break down of equivalent GMT time
struct tm *gmt;
// offset of local time relative to GMT
time_t local_offset;
// 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
// result and the course result. course_gst + 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;
// internal book keeping data
double last_mjd, last_dy;
int last_mn, last_yr;
public:
@ -123,15 +116,15 @@ public:
inline time_t get_cur_time() const { return cur_time; };
inline struct tm* getGmt()const { return gmt; };
void adjust_warp(int val) { warp += val; };
void adjust_warp_delta(int val) { warp_delta += val; };
// void adjust_warp(int val) { warp += val; };
// void adjust_warp_delta(int val) { warp_delta += val; };
// Initialize the time dependent variables
void init( double lon, double lat, const string& root,
time_t timeOffset, sgTimingOffsetType offsetType );
void init( double lon, double lat, const string& root );
// time_t timeOffset, sgTimingOffsetType offsetType );
// Update the time dependent variables
void update( double lon, double lat, double alt_m );
void update( double lon, double lat, double alt_m, long int warp );
void updateLocal( double lon, double lat, const string& root );
void cal_mjd (int mn, double dy, int yr);
@ -146,11 +139,13 @@ public:
time_t get_gmt(int year, int month, int day,
int hour, int minute, int second);
time_t get_gmt(struct tm* the_time);
inline char* get_zonename() const { return zonename; }
char* format_time( const struct tm* p, char* buf );
long int fix_up_timezone( long int timezone_orig );
inline int get_warp_delta() const { return warp_delta; }
// inline int get_warp_delta() const { return warp_delta; }
};