More SGTime clean ups.
This commit is contained in:
+1
-1
@@ -6,7 +6,7 @@ dnl $Id$
|
|||||||
AC_INIT(simgear/bucket/newbucket.cxx)
|
AC_INIT(simgear/bucket/newbucket.cxx)
|
||||||
|
|
||||||
dnl Initialize the automake stuff
|
dnl Initialize the automake stuff
|
||||||
AM_INIT_AUTOMAKE(SimGear, 0.0.11)
|
AM_INIT_AUTOMAKE(SimGear, 0.0.12)
|
||||||
|
|
||||||
dnl Checks for programs.
|
dnl Checks for programs.
|
||||||
AC_PROG_MAKE_SET
|
AC_PROG_MAKE_SET
|
||||||
|
|||||||
+7
-6
@@ -50,9 +50,6 @@
|
|||||||
/* Define if you have zlib installed system wide. */
|
/* Define if you have zlib installed system wide. */
|
||||||
#undef HAVE_ZLIB
|
#undef HAVE_ZLIB
|
||||||
|
|
||||||
/* Define to package name */
|
|
||||||
#undef PACKAGE
|
|
||||||
|
|
||||||
/* Define as the return type of signal handlers (int or void). */
|
/* Define as the return type of signal handlers (int or void). */
|
||||||
#undef RETSIGTYPE
|
#undef RETSIGTYPE
|
||||||
|
|
||||||
@@ -68,9 +65,6 @@
|
|||||||
/* Define if your <sys/time.h> declares struct tm. */
|
/* Define if your <sys/time.h> declares struct tm. */
|
||||||
#undef TM_IN_SYS_TIME
|
#undef TM_IN_SYS_TIME
|
||||||
|
|
||||||
/* Define to version number */
|
|
||||||
#undef VERSION
|
|
||||||
|
|
||||||
/* Define if compiling on a Winbloze (95, NT, etc.) platform */
|
/* Define if compiling on a Winbloze (95, NT, etc.) platform */
|
||||||
#undef WIN32
|
#undef WIN32
|
||||||
|
|
||||||
@@ -205,3 +199,10 @@
|
|||||||
|
|
||||||
/* Define if you have the socket library (-lsocket). */
|
/* Define if you have the socket library (-lsocket). */
|
||||||
#undef HAVE_LIBSOCKET
|
#undef HAVE_LIBSOCKET
|
||||||
|
|
||||||
|
/* Name of package */
|
||||||
|
#undef PACKAGE
|
||||||
|
|
||||||
|
/* Version number of package */
|
||||||
|
#undef VERSION
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ lib_LIBRARIES = libsgtiming.a
|
|||||||
|
|
||||||
include_HEADERS = \
|
include_HEADERS = \
|
||||||
geocoord.h \
|
geocoord.h \
|
||||||
|
lowleveltime.h \
|
||||||
sg_time.hxx \
|
sg_time.hxx \
|
||||||
timezone.h
|
timezone.h
|
||||||
|
|
||||||
libsgtiming_a_SOURCES = \
|
libsgtiming_a_SOURCES = \
|
||||||
geocoord.cxx \
|
geocoord.cxx \
|
||||||
lowleveltime.cxx lowleveltime.h \
|
lowleveltime.cxx \
|
||||||
sg_time.cxx \
|
sg_time.cxx \
|
||||||
timezone.cxx \
|
timezone.cxx \
|
||||||
# event.cxx event.hxx \
|
# event.cxx event.hxx \
|
||||||
|
|||||||
+27
-43
@@ -51,28 +51,17 @@
|
|||||||
|
|
||||||
#include <simgear/constants.h>
|
#include <simgear/constants.h>
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
// #include <simgear/magvar/magvar.hxx>
|
|
||||||
#include <simgear/misc/fgpath.hxx>
|
#include <simgear/misc/fgpath.hxx>
|
||||||
|
|
||||||
// #include <FDM/flight.hxx>
|
|
||||||
// #include <Main/options.hxx>
|
|
||||||
// #include <Time/light.hxx>
|
|
||||||
|
|
||||||
#include "sg_time.hxx"
|
#include "sg_time.hxx"
|
||||||
#include "timezone.h"
|
#include "timezone.h"
|
||||||
#include "lowleveltime.h"
|
#include "lowleveltime.h"
|
||||||
// #include "moonpos.hxx"
|
|
||||||
// #include "sunpos.hxx"
|
|
||||||
|
|
||||||
|
|
||||||
#define DEGHR(x) ((x)/15.)
|
#define DEGHR(x) ((x)/15.)
|
||||||
#define RADHR(x) DEGHR(x*RAD_TO_DEG)
|
#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 )
|
SGTime::SGTime( const string& root )
|
||||||
{
|
{
|
||||||
if (cur_time_params) {
|
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() );
|
FG_LOG( FG_EVENT, FG_INFO, "Reading timezone info from: " << zone.str() );
|
||||||
tzContainer = new TimezoneContainer( zone.c_str() );
|
tzContainer = new TimezoneContainer( zone.c_str() );
|
||||||
warp=0;
|
// warp=0;
|
||||||
warp_delta=0;
|
// warp_delta=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -115,22 +104,18 @@ void SGTime::updateLocal( double lon, double lat, const string& root )
|
|||||||
zonename = strdup( zone.c_str() );
|
zonename = strdup( zone.c_str() );
|
||||||
currGMT = get_gmt( gmtime(&cur_time) );
|
currGMT = get_gmt( gmtime(&cur_time) );
|
||||||
aircraftLocalTime = get_gmt( (fgLocaltime(&cur_time, zone.c_str())) );
|
aircraftLocalTime = get_gmt( (fgLocaltime(&cur_time, zone.c_str())) );
|
||||||
localOffset = aircraftLocalTime - currGMT;
|
local_offset = aircraftLocalTime - currGMT;
|
||||||
// cerr << "Using " << localOffset << " as local time offset Timezone is "
|
cout << "Using " << local_offset << " as local time offset Timezone is "
|
||||||
// << zonename << endl;
|
<< zonename << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the time dependent variables (maybe I'll put this in the
|
// Initialize the time dependent variables (maybe I'll put this in the
|
||||||
// constructor later)
|
// constructor later)
|
||||||
void SGTime::init( double lon, double lat, const string& root,
|
void SGTime::init( double lon, double lat, const string& root )
|
||||||
time_t timeOffset, sgTimingOffsetType offsetType )
|
// time_t timeOffset, sgTimingOffsetType offsetType )
|
||||||
{
|
{
|
||||||
FG_LOG( FG_EVENT, FG_INFO, "Initializing Time" );
|
FG_LOG( FG_EVENT, FG_INFO, "Initializing Time" );
|
||||||
gst_diff = -9999.0;
|
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 currGMT;
|
||||||
time_t systemLocalTime;
|
time_t systemLocalTime;
|
||||||
@@ -152,13 +137,18 @@ void SGTime::init( double lon, double lat, const string& root,
|
|||||||
zone.append( "Timezone" );
|
zone.append( "Timezone" );
|
||||||
zone.append( nearestTz->getDescription() );
|
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() );
|
zonename = strdup( zone.c_str() );
|
||||||
|
cout << "zonename = " << zonename << endl;
|
||||||
//show( buffer.c_str(), cur_time, 1);
|
//show( buffer.c_str(), cur_time, 1);
|
||||||
//printf ("Current greenwich mean time = %24s", asctime(gmtime(&cur_time)));
|
//printf ("Current greenwich mean time = %24s", asctime(gmtime(&cur_time)));
|
||||||
//printf ("Current local time = %24s", asctime(localtime(&cur_time)));
|
//printf ("Current local time = %24s", asctime(localtime(&cur_time)));
|
||||||
currGMT = get_gmt( gmtime(&cur_time) );
|
currGMT = get_gmt( gmtime(&cur_time) );
|
||||||
|
cout << "currGMT = " << currGMT << endl;
|
||||||
|
|
||||||
systemLocalTime = get_gmt( localtime(&cur_time) );
|
systemLocalTime = get_gmt( localtime(&cur_time) );
|
||||||
|
cout << "systemLocalTime = " << systemLocalTime << endl;
|
||||||
|
|
||||||
aircraftLocalTime = get_gmt( fgLocaltime(&cur_time, zone.c_str()) );
|
aircraftLocalTime = get_gmt( fgLocaltime(&cur_time, zone.c_str()) );
|
||||||
//printf ("Current greenwich mean time = %24s", asctime(gmtime(&cur_time)));
|
//printf ("Current greenwich mean time = %24s", asctime(gmtime(&cur_time)));
|
||||||
//printf ("Current local time = %24s", asctime(localtime(&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, SLT = %d, (difference = %d)\n", currGMT, systemLocalTime, (currGMT - systemLocalTime));
|
||||||
// printf("Gmt = %d, ALT = %d, (difference = %d)\n", currGMT, aircraftLocalTime, (currGMT - aircraftLocalTime));
|
// printf("Gmt = %d, ALT = %d, (difference = %d)\n", currGMT, aircraftLocalTime, (currGMT - aircraftLocalTime));
|
||||||
// exit(1);
|
// exit(1);
|
||||||
|
|
||||||
|
#if 0
|
||||||
// Okay, we now have six possible scenarios
|
// Okay, we now have six possible scenarios
|
||||||
switch (offsetType)
|
switch (offsetType)
|
||||||
{
|
{
|
||||||
@@ -201,6 +193,8 @@ void SGTime::init( double lon, double lat, const string& root,
|
|||||||
|
|
||||||
warp_delta = 0;
|
warp_delta = 0;
|
||||||
// pause = current_options.get_pause();
|
// 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) {
|
if (mn == last_mn && yr == last_yr && dy == last_dy) {
|
||||||
mjd = last_mjd;
|
mjd = last_mjd;
|
||||||
//return(mjd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m = mn;
|
m = mn;
|
||||||
@@ -250,8 +243,6 @@ void SGTime::cal_mjd (int mn, double dy, int yr)
|
|||||||
last_dy = dy;
|
last_dy = dy;
|
||||||
last_yr = yr;
|
last_yr = yr;
|
||||||
last_mjd = mjd;
|
last_mjd = mjd;
|
||||||
|
|
||||||
//return(mjd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -267,7 +258,7 @@ void SGTime::utc_gst ()
|
|||||||
x /= 3600.0;
|
x /= 3600.0;
|
||||||
gst = (1.0/SIDRATE)*hr + x;
|
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
|
// 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;
|
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)
|
// get current Unix calendar time (in seconds)
|
||||||
warp += warp_delta;
|
// warp += warp_delta;
|
||||||
cur_time = time(NULL) + warp;
|
cur_time = time(NULL) + warp;
|
||||||
FG_LOG( FG_EVENT, FG_DEBUG,
|
FG_LOG( FG_EVENT, FG_INFO,
|
||||||
" Current Unix calendar time = " << cur_time
|
" Current Unix calendar time = " << cur_time
|
||||||
<< " warp = " << warp << " delta = " << warp_delta );
|
<< " warp = " << warp );
|
||||||
|
|
||||||
#if 0
|
|
||||||
if ( warp_delta ) {
|
|
||||||
// time is changing so force an update
|
|
||||||
local_update_sky_and_lighting_params();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// get GMT break down for current time
|
// get GMT break down for current time
|
||||||
gmt = gmtime(&cur_time);
|
gmt = gmtime(&cur_time);
|
||||||
FG_LOG( FG_EVENT, FG_DEBUG,
|
FG_LOG( FG_EVENT, FG_INFO,
|
||||||
" Current GMT = " << gmt->tm_mon+1 << "/"
|
" Current GMT = " << gmt->tm_mon+1 << "/"
|
||||||
<< gmt->tm_mday << "/" << gmt->tm_year << " "
|
<< gmt->tm_mday << "/" << gmt->tm_year << " "
|
||||||
<< gmt->tm_hour << ":" << gmt->tm_min << ":"
|
<< 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)
|
// convert "back" to Julian date + partial day (as a fraction of one)
|
||||||
jd = mjd + MJD0;
|
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);
|
// 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;
|
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 );
|
" Current lon=0.00 Sidereal Time = " << gst );
|
||||||
FG_LOG( FG_EVENT, FG_DEBUG,
|
FG_LOG( FG_EVENT, FG_INFO,
|
||||||
" Current LOCAL Sidereal Time = " << lst << " ("
|
" Current LOCAL Sidereal Time = " << lst << " ("
|
||||||
<< sidereal_precise(-(lon * RAD_TO_DEG))
|
<< sidereal_precise(-(lon * RAD_TO_DEG))
|
||||||
<< ") (diff = " << gst_diff << ")" );
|
<< ") (diff = " << gst_diff << ")" );
|
||||||
|
|||||||
+18
-23
@@ -71,45 +71,38 @@ private:
|
|||||||
// tzContainer stores all the current Timezone control points/
|
// tzContainer stores all the current Timezone control points/
|
||||||
TimezoneContainer* tzContainer;
|
TimezoneContainer* tzContainer;
|
||||||
|
|
||||||
//Store the current local timezone name;
|
// Points to the current local timezone name;
|
||||||
char *zonename;
|
char *zonename;
|
||||||
|
|
||||||
// Unix "calendar" time in seconds
|
// Unix "calendar" time in seconds
|
||||||
time_t cur_time;
|
time_t cur_time;
|
||||||
|
|
||||||
// Break down of GMT time
|
// Break down of equivalent GMT time
|
||||||
struct tm *gmt;
|
struct tm *gmt;
|
||||||
|
|
||||||
|
// offset of local time relative to GMT
|
||||||
|
time_t local_offset;
|
||||||
|
|
||||||
// Julian date
|
// Julian date
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
// modified Julian date
|
// modified Julian date
|
||||||
double mjd;
|
double mjd;
|
||||||
|
|
||||||
double last_mjd, last_dy;
|
|
||||||
int last_mn, last_yr;
|
|
||||||
|
|
||||||
// side real time at prime meridian
|
// side real time at prime meridian
|
||||||
double gst;
|
double gst;
|
||||||
|
|
||||||
// local sidereal time
|
// local sidereal time
|
||||||
double lst;
|
double lst;
|
||||||
|
|
||||||
// local offset to GMT
|
|
||||||
time_t localOffset;
|
|
||||||
|
|
||||||
// the difference between the precise sidereal time algorithm
|
// the difference between the precise sidereal time algorithm
|
||||||
// result and the course result. course + diff has good accuracy
|
// result and the course result. course_gst + diff has good
|
||||||
// for the short term
|
// accuracy for the short term
|
||||||
double gst_diff;
|
double gst_diff;
|
||||||
|
|
||||||
// An offset in seconds from the true time. Allows us to adjust
|
// internal book keeping data
|
||||||
// the effective time of day.
|
double last_mjd, last_dy;
|
||||||
long int warp;
|
int last_mn, last_yr;
|
||||||
|
|
||||||
// How much to change the value of warp each iteration. Allows us
|
|
||||||
// to make time progress faster than normal.
|
|
||||||
long int warp_delta;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -123,15 +116,15 @@ public:
|
|||||||
inline time_t get_cur_time() const { return cur_time; };
|
inline time_t get_cur_time() const { return cur_time; };
|
||||||
inline struct tm* getGmt()const { return gmt; };
|
inline struct tm* getGmt()const { return gmt; };
|
||||||
|
|
||||||
void adjust_warp(int val) { warp += val; };
|
// void adjust_warp(int val) { warp += val; };
|
||||||
void adjust_warp_delta(int val) { warp_delta += val; };
|
// void adjust_warp_delta(int val) { warp_delta += val; };
|
||||||
|
|
||||||
// Initialize the time dependent variables
|
// Initialize the time dependent variables
|
||||||
void init( double lon, double lat, const string& root,
|
void init( double lon, double lat, const string& root );
|
||||||
time_t timeOffset, sgTimingOffsetType offsetType );
|
// time_t timeOffset, sgTimingOffsetType offsetType );
|
||||||
|
|
||||||
// Update the time dependent variables
|
// 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 updateLocal( double lon, double lat, const string& root );
|
||||||
|
|
||||||
void cal_mjd (int mn, double dy, int yr);
|
void cal_mjd (int mn, double dy, int yr);
|
||||||
@@ -147,10 +140,12 @@ public:
|
|||||||
int hour, int minute, int second);
|
int hour, int minute, int second);
|
||||||
time_t get_gmt(struct tm* the_time);
|
time_t get_gmt(struct tm* the_time);
|
||||||
|
|
||||||
|
inline char* get_zonename() const { return zonename; }
|
||||||
|
|
||||||
char* format_time( const struct tm* p, char* buf );
|
char* format_time( const struct tm* p, char* buf );
|
||||||
long int fix_up_timezone( long int timezone_orig );
|
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; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user