1
0
Fork 0

Converted "struct fg_timestamp" to "class fgTIMESTAMP" and added some

convenience inline operators.
This commit is contained in:
curt 1998-12-04 01:32:46 +00:00
parent 554768199d
commit 59b20e610c
5 changed files with 143 additions and 28 deletions

View file

@ -101,7 +101,7 @@ fgEVENT::run()
FG_LOG(FG_EVENT, FG_INFO, "Running " << description );
// record starting time
timestamp( &last_run );
last_run.stamp();
// run the event
event_cb->call( (void**)NULL );
@ -113,8 +113,8 @@ fgEVENT::run()
status = FG_EVENT_READY;
// calculate duration and stats
timestamp( &current );
long duration = timediff( &last_run, &current );
current.stamp();
long duration = current - last_run;
cum_time += duration;
@ -127,7 +127,7 @@ fgEVENT::run()
}
// 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
void fgEVENT_MGR::Process( void ) {
fgEVENT *e_ptr;
fg_timestamp cur_time;
fgTIMESTAMP cur_time;
unsigned int i, size;
FG_LOG( FG_EVENT, FG_DEBUG, "Processing events" );
// get the current time
timestamp(&cur_time);
cur_time.stamp();
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");
@ -239,9 +239,9 @@ void fgEVENT_MGR::Process( void ) {
e_ptr = &event_table[i];
if ( e_ptr->status == fgEVENT::FG_EVENT_READY ) {
FG_LOG( FG_EVENT, FG_DEBUG,
" Item " << i << " current " << cur_time.seconds
<< " next run @ " << e_ptr->next_run.seconds );
if ( timediff(&cur_time, &(e_ptr->next_run)) <= 0) {
" Item " << i << " current " << cur_time.get_seconds()
<< " next run @ " << e_ptr->next_run.get_seconds() );
if ( ( e_ptr->next_run - cur_time ) <= 0 ) {
run_queue.push_back(e_ptr);
e_ptr->status = fgEVENT::FG_EVENT_QUEUED;
}
@ -265,6 +265,10 @@ fgEVENT_MGR::~fgEVENT_MGR( void ) {
// $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
// Borland portability tweaks.
//

View file

@ -97,9 +97,9 @@ public:
long interval; // interval in ms between each iteration of this event
fg_timestamp last_run;
fg_timestamp current;
fg_timestamp next_run;
fgTIMESTAMP last_run;
fgTIMESTAMP current;
fgTIMESTAMP next_run;
long cum_time; // cumulative processor time of this event
long min_time; // time of quickest execution
@ -169,6 +169,10 @@ extern fgEVENT_MGR global_events;
// $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
// Converted to Point3D class.
//

View file

@ -97,6 +97,7 @@ void fgTimeInit(fgTIME *t) {
}
/*
// Portability wrap to get current time.
void timestamp(fg_timestamp *timestamp) {
#if defined( WIN32 )
@ -149,7 +150,7 @@ void timesum(fg_timestamp *res, fg_timestamp *start, long millis) {
res->millis = ( start->millis + millis ) % 1000;
#endif
}
*/
// given a date in months, mn, days, dy, years, yr, return the
// modified Julian date (number of days elapsed since 1900 jan 0.5),
@ -452,6 +453,10 @@ void fgTimeUpdate(fgFLIGHT *f, fgTIME *t) {
// $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
// Converted fgFLIGHT to a class.
//

View file

@ -43,6 +43,16 @@
#include <GL/glut.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>
@ -87,22 +97,107 @@ typedef struct {
extern fgTIME cur_time_params;
typedef struct {
class fgTIMESTAMP {
private:
long seconds;
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(&current, &tz);
seconds = current.tv_sec;
millis = current.tv_usec / 1000;
#elif defined( HAVE_GETLOCALTIME )
SYSTEMTIME current;
GetLocalTime(&current);
seconds = current.wSecond;
millis = current.wMilliseconds;
#elif defined( HAVE_FTIME )
struct timeb current;
ftime(&current);
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.
void timestamp(fg_timestamp *timestamp);
// void timestamp(fg_timestamp *timestamp);
// 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
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
@ -117,6 +212,10 @@ void fgTimeUpdate(fgFLIGHT *f, fgTIME *t);
// $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
// C++-ifying.
//

View file

@ -102,18 +102,17 @@ void fgTimerInit(float dt, void (*f)( int )) {
int fgGetTimeInterval( void ) {
int interval;
static int inited = 0;
static fg_timestamp last;
fg_timestamp current;
static fgTIMESTAMP last;
fgTIMESTAMP current;
if ( ! inited ) {
inited = 1;
timestamp(&last);
last.stamp();
interval = 0;
} else {
timestamp(&current);
interval = timediff(&last, &current);
last.seconds = current.seconds;
last.millis = current.millis;
current.stamp();
interval = current - last;
last = current;
}
return(interval);
@ -121,9 +120,13 @@ int fgGetTimeInterval( void ) {
/* $Log$
/* Revision 1.3 1998/04/28 01:22:18 curt
/* Type-ified fgTIME and fgVIEW.
/* Revision 1.4 1998/12/04 01:32:51 curt
/* 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
* Cleaned up initialization sequence to eliminate interdependencies
* between sun position, lighting, and view position. This creates a