Converted "struct fg_timestamp" to "class fgTIMESTAMP" and added some
convenience inline operators.
This commit is contained in:
parent
554768199d
commit
59b20e610c
5 changed files with 143 additions and 28 deletions
|
@ -101,7 +101,7 @@ fgEVENT::run()
|
||||||
FG_LOG(FG_EVENT, FG_INFO, "Running " << description );
|
FG_LOG(FG_EVENT, FG_INFO, "Running " << description );
|
||||||
|
|
||||||
// record starting time
|
// record starting time
|
||||||
timestamp( &last_run );
|
last_run.stamp();
|
||||||
|
|
||||||
// run the event
|
// run the event
|
||||||
event_cb->call( (void**)NULL );
|
event_cb->call( (void**)NULL );
|
||||||
|
@ -113,8 +113,8 @@ fgEVENT::run()
|
||||||
status = FG_EVENT_READY;
|
status = FG_EVENT_READY;
|
||||||
|
|
||||||
// calculate duration and stats
|
// calculate duration and stats
|
||||||
timestamp( ¤t );
|
current.stamp();
|
||||||
long duration = timediff( &last_run, ¤t );
|
long duration = current - last_run;
|
||||||
|
|
||||||
cum_time += duration;
|
cum_time += duration;
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ fgEVENT::run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine the next absolute run time
|
// determine the next absolute run time
|
||||||
timesum( &next_run, &last_run, interval );
|
next_run = last_run + interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -218,16 +218,16 @@ fgEVENT_MGR::PrintStats()
|
||||||
// the queue
|
// the queue
|
||||||
void fgEVENT_MGR::Process( void ) {
|
void fgEVENT_MGR::Process( void ) {
|
||||||
fgEVENT *e_ptr;
|
fgEVENT *e_ptr;
|
||||||
fg_timestamp cur_time;
|
fgTIMESTAMP cur_time;
|
||||||
unsigned int i, size;
|
unsigned int i, size;
|
||||||
|
|
||||||
FG_LOG( FG_EVENT, FG_DEBUG, "Processing events" );
|
FG_LOG( FG_EVENT, FG_DEBUG, "Processing events" );
|
||||||
|
|
||||||
// get the current time
|
// get the current time
|
||||||
timestamp(&cur_time);
|
cur_time.stamp();
|
||||||
|
|
||||||
FG_LOG( FG_EVENT, FG_DEBUG,
|
FG_LOG( FG_EVENT, FG_DEBUG,
|
||||||
" Current timestamp = " << cur_time.seconds );
|
" Current timestamp = " << cur_time.get_seconds() );
|
||||||
|
|
||||||
// printf("Checking if anything is ready to move to the run queue\n");
|
// printf("Checking if anything is ready to move to the run queue\n");
|
||||||
|
|
||||||
|
@ -239,9 +239,9 @@ void fgEVENT_MGR::Process( void ) {
|
||||||
e_ptr = &event_table[i];
|
e_ptr = &event_table[i];
|
||||||
if ( e_ptr->status == fgEVENT::FG_EVENT_READY ) {
|
if ( e_ptr->status == fgEVENT::FG_EVENT_READY ) {
|
||||||
FG_LOG( FG_EVENT, FG_DEBUG,
|
FG_LOG( FG_EVENT, FG_DEBUG,
|
||||||
" Item " << i << " current " << cur_time.seconds
|
" Item " << i << " current " << cur_time.get_seconds()
|
||||||
<< " next run @ " << e_ptr->next_run.seconds );
|
<< " next run @ " << e_ptr->next_run.get_seconds() );
|
||||||
if ( timediff(&cur_time, &(e_ptr->next_run)) <= 0) {
|
if ( ( e_ptr->next_run - cur_time ) <= 0 ) {
|
||||||
run_queue.push_back(e_ptr);
|
run_queue.push_back(e_ptr);
|
||||||
e_ptr->status = fgEVENT::FG_EVENT_QUEUED;
|
e_ptr->status = fgEVENT::FG_EVENT_QUEUED;
|
||||||
}
|
}
|
||||||
|
@ -265,6 +265,10 @@ fgEVENT_MGR::~fgEVENT_MGR( void ) {
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.13 1998/12/04 01:32:46 curt
|
||||||
|
// Converted "struct fg_timestamp" to "class fgTIMESTAMP" and added some
|
||||||
|
// convenience inline operators.
|
||||||
|
//
|
||||||
// Revision 1.12 1998/11/23 21:49:07 curt
|
// Revision 1.12 1998/11/23 21:49:07 curt
|
||||||
// Borland portability tweaks.
|
// Borland portability tweaks.
|
||||||
//
|
//
|
||||||
|
|
|
@ -97,9 +97,9 @@ public:
|
||||||
|
|
||||||
long interval; // interval in ms between each iteration of this event
|
long interval; // interval in ms between each iteration of this event
|
||||||
|
|
||||||
fg_timestamp last_run;
|
fgTIMESTAMP last_run;
|
||||||
fg_timestamp current;
|
fgTIMESTAMP current;
|
||||||
fg_timestamp next_run;
|
fgTIMESTAMP next_run;
|
||||||
|
|
||||||
long cum_time; // cumulative processor time of this event
|
long cum_time; // cumulative processor time of this event
|
||||||
long min_time; // time of quickest execution
|
long min_time; // time of quickest execution
|
||||||
|
@ -169,6 +169,10 @@ extern fgEVENT_MGR global_events;
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.13 1998/12/04 01:32:47 curt
|
||||||
|
// Converted "struct fg_timestamp" to "class fgTIMESTAMP" and added some
|
||||||
|
// convenience inline operators.
|
||||||
|
//
|
||||||
// Revision 1.12 1998/10/16 00:56:08 curt
|
// Revision 1.12 1998/10/16 00:56:08 curt
|
||||||
// Converted to Point3D class.
|
// Converted to Point3D class.
|
||||||
//
|
//
|
||||||
|
|
|
@ -97,6 +97,7 @@ void fgTimeInit(fgTIME *t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
// Portability wrap to get current time.
|
// Portability wrap to get current time.
|
||||||
void timestamp(fg_timestamp *timestamp) {
|
void timestamp(fg_timestamp *timestamp) {
|
||||||
#if defined( WIN32 )
|
#if defined( WIN32 )
|
||||||
|
@ -149,7 +150,7 @@ void timesum(fg_timestamp *res, fg_timestamp *start, long millis) {
|
||||||
res->millis = ( start->millis + millis ) % 1000;
|
res->millis = ( start->millis + millis ) % 1000;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// given a date in months, mn, days, dy, years, yr, return the
|
// given a date in months, mn, days, dy, years, yr, return the
|
||||||
// modified Julian date (number of days elapsed since 1900 jan 0.5),
|
// modified Julian date (number of days elapsed since 1900 jan 0.5),
|
||||||
|
@ -452,6 +453,10 @@ void fgTimeUpdate(fgFLIGHT *f, fgTIME *t) {
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.24 1998/12/04 01:32:49 curt
|
||||||
|
// Converted "struct fg_timestamp" to "class fgTIMESTAMP" and added some
|
||||||
|
// convenience inline operators.
|
||||||
|
//
|
||||||
// Revision 1.23 1998/12/03 01:18:40 curt
|
// Revision 1.23 1998/12/03 01:18:40 curt
|
||||||
// Converted fgFLIGHT to a class.
|
// Converted fgFLIGHT to a class.
|
||||||
//
|
//
|
||||||
|
|
109
Time/fg_time.hxx
109
Time/fg_time.hxx
|
@ -43,6 +43,16 @@
|
||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#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 <Flight/flight.hxx>
|
#include <Flight/flight.hxx>
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,22 +97,107 @@ typedef struct {
|
||||||
extern fgTIME cur_time_params;
|
extern fgTIME cur_time_params;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
class fgTIMESTAMP {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
long seconds;
|
long seconds;
|
||||||
long millis;
|
long millis;
|
||||||
} fg_timestamp;
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
fgTIMESTAMP();
|
||||||
|
fgTIMESTAMP( const long s, const long m );
|
||||||
|
~fgTIMESTAMP();
|
||||||
|
|
||||||
|
// Set time to current time
|
||||||
|
void stamp();
|
||||||
|
|
||||||
|
fgTIMESTAMP& operator = ( const fgTIMESTAMP& t );
|
||||||
|
|
||||||
|
friend fgTIMESTAMP operator + (const fgTIMESTAMP& t, const long& m);
|
||||||
|
friend long operator - (const fgTIMESTAMP& a, const fgTIMESTAMP& b);
|
||||||
|
|
||||||
|
inline long get_seconds() const { return seconds; }
|
||||||
|
inline long get_millis() const { return millis; }
|
||||||
|
};
|
||||||
|
|
||||||
|
inline fgTIMESTAMP::fgTIMESTAMP() {
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fgTIMESTAMP::fgTIMESTAMP( const long s, const long m ) {
|
||||||
|
seconds = s;
|
||||||
|
millis = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fgTIMESTAMP::~fgTIMESTAMP() {
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fgTIMESTAMP& fgTIMESTAMP::operator = (const fgTIMESTAMP& t)
|
||||||
|
{
|
||||||
|
seconds = t.seconds;
|
||||||
|
millis = t.millis;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void fgTIMESTAMP::stamp() {
|
||||||
|
#if defined( WIN32 )
|
||||||
|
unsigned int t;
|
||||||
|
t = timeGetTime();
|
||||||
|
seconds = 0;
|
||||||
|
millis = t;
|
||||||
|
#elif defined( HAVE_GETTIMEOFDAY )
|
||||||
|
struct timeval current;
|
||||||
|
struct timezone tz;
|
||||||
|
// fg_timestamp currtime;
|
||||||
|
gettimeofday(¤t, &tz);
|
||||||
|
seconds = current.tv_sec;
|
||||||
|
millis = current.tv_usec / 1000;
|
||||||
|
#elif defined( HAVE_GETLOCALTIME )
|
||||||
|
SYSTEMTIME current;
|
||||||
|
GetLocalTime(¤t);
|
||||||
|
seconds = current.wSecond;
|
||||||
|
millis = current.wMilliseconds;
|
||||||
|
#elif defined( HAVE_FTIME )
|
||||||
|
struct timeb current;
|
||||||
|
ftime(¤t);
|
||||||
|
seconds = current.time;
|
||||||
|
millis = current.millitm;
|
||||||
|
#else
|
||||||
|
# error Port me
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// difference between time stamps in milliseconds
|
||||||
|
inline fgTIMESTAMP operator + (const fgTIMESTAMP& t, const long& m) {
|
||||||
|
#ifdef WIN32
|
||||||
|
return fgTIMESTAMP( 0, t.millis + m );
|
||||||
|
#else
|
||||||
|
return fgTIMESTAMP( t.seconds + ( t.millis + m ) / 1000,
|
||||||
|
( t.millis + m ) % 1000 );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// difference between time stamps in milliseconds
|
||||||
|
inline long operator - (const fgTIMESTAMP& a, const fgTIMESTAMP& b)
|
||||||
|
{
|
||||||
|
#if defined( WIN32 )
|
||||||
|
return a.millis - b.millis;
|
||||||
|
#else
|
||||||
|
return 1000 * (a.seconds - b.seconds) + (a.millis - b.millis);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Portability wrap to get current time.
|
// Portability wrap to get current time.
|
||||||
void timestamp(fg_timestamp *timestamp);
|
// void timestamp(fg_timestamp *timestamp);
|
||||||
|
|
||||||
|
|
||||||
// Return duration in millis from first to last
|
// Return duration in millis from first to last
|
||||||
long timediff(fg_timestamp *first, fg_timestamp *last);
|
// long timediff(fg_timestamp *first, fg_timestamp *last);
|
||||||
|
|
||||||
|
|
||||||
// Return new timestamp given a time stamp and an interval to add in
|
// Return new timestamp given a time stamp and an interval to add in
|
||||||
void timesum(fg_timestamp *res, fg_timestamp *start, long millis);
|
// void timesum(fg_timestamp *res, fg_timestamp *start, long millis);
|
||||||
|
|
||||||
|
|
||||||
// Update time variables such as gmt, julian date, and sidereal time
|
// Update time variables such as gmt, julian date, and sidereal time
|
||||||
|
@ -117,6 +212,10 @@ void fgTimeUpdate(fgFLIGHT *f, fgTIME *t);
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.9 1998/12/04 01:32:50 curt
|
||||||
|
// Converted "struct fg_timestamp" to "class fgTIMESTAMP" and added some
|
||||||
|
// convenience inline operators.
|
||||||
|
//
|
||||||
// Revision 1.8 1998/10/16 23:28:00 curt
|
// Revision 1.8 1998/10/16 23:28:00 curt
|
||||||
// C++-ifying.
|
// C++-ifying.
|
||||||
//
|
//
|
||||||
|
|
|
@ -102,18 +102,17 @@ void fgTimerInit(float dt, void (*f)( int )) {
|
||||||
int fgGetTimeInterval( void ) {
|
int fgGetTimeInterval( void ) {
|
||||||
int interval;
|
int interval;
|
||||||
static int inited = 0;
|
static int inited = 0;
|
||||||
static fg_timestamp last;
|
static fgTIMESTAMP last;
|
||||||
fg_timestamp current;
|
fgTIMESTAMP current;
|
||||||
|
|
||||||
if ( ! inited ) {
|
if ( ! inited ) {
|
||||||
inited = 1;
|
inited = 1;
|
||||||
timestamp(&last);
|
last.stamp();
|
||||||
interval = 0;
|
interval = 0;
|
||||||
} else {
|
} else {
|
||||||
timestamp(¤t);
|
current.stamp();
|
||||||
interval = timediff(&last, ¤t);
|
interval = current - last;
|
||||||
last.seconds = current.seconds;
|
last = current;
|
||||||
last.millis = current.millis;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(interval);
|
return(interval);
|
||||||
|
@ -121,9 +120,13 @@ int fgGetTimeInterval( void ) {
|
||||||
|
|
||||||
|
|
||||||
/* $Log$
|
/* $Log$
|
||||||
/* Revision 1.3 1998/04/28 01:22:18 curt
|
/* Revision 1.4 1998/12/04 01:32:51 curt
|
||||||
/* Type-ified fgTIME and fgVIEW.
|
/* Converted "struct fg_timestamp" to "class fgTIMESTAMP" and added some
|
||||||
|
/* convenience inline operators.
|
||||||
/*
|
/*
|
||||||
|
* Revision 1.3 1998/04/28 01:22:18 curt
|
||||||
|
* Type-ified fgTIME and fgVIEW.
|
||||||
|
*
|
||||||
* Revision 1.2 1998/04/25 20:24:03 curt
|
* Revision 1.2 1998/04/25 20:24:03 curt
|
||||||
* Cleaned up initialization sequence to eliminate interdependencies
|
* Cleaned up initialization sequence to eliminate interdependencies
|
||||||
* between sun position, lighting, and view position. This creates a
|
* between sun position, lighting, and view position. This creates a
|
||||||
|
|
Loading…
Reference in a new issue