convenience inline operators.
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 );
status = FG_EVENT_READY;
// calculate duration and stats
- timestamp( ¤t );
- long duration = timediff( &last_run, ¤t );
+ current.stamp();
+ long duration = current - last_run;
cum_time += duration;
}
// determine the next absolute run time
- timesum( &next_run, &last_run, interval );
+ next_run = last_run + interval;
}
// 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");
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;
}
// $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.
//
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
// $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.
//
}
+/*
// Portability wrap to get current time.
void timestamp(fg_timestamp *timestamp) {
#if defined( WIN32 )
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),
// $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.
//
#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>
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(¤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.
-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
// $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.
//
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(¤t);
- interval = timediff(&last, ¤t);
- last.seconds = current.seconds;
- last.millis = current.millis;
+ current.stamp();
+ interval = current - last;
+ last = current;
}
return(interval);
/* $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