From 2b5709f63aa6b10447f3b29703efc93cc1086073 Mon Sep 17 00:00:00 2001 From: Mike Goslin Date: Tue, 20 Feb 2001 23:25:55 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/express/clockObject.cxx | 17 +++++++++++++++++ panda/src/express/clockObject.h | 12 ++++++++++++ panda/src/express/trueClock.cxx | 29 +++++++++++++++++++++++++++++ panda/src/express/trueClock.h | 3 +++ 4 files changed, 61 insertions(+) diff --git a/panda/src/express/clockObject.cxx b/panda/src/express/clockObject.cxx index f3b0facfb7..48a3cfcf8c 100644 --- a/panda/src/express/clockObject.cxx +++ b/panda/src/express/clockObject.cxx @@ -52,3 +52,20 @@ tick() { _frame_count++; } + +//////////////////////////////////////////////////////////////////// +// Function: TimeVal::contructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +TimeVal:: +TimeVal(void) { +} + +//////////////////////////////////////////////////////////////////// +// Function: get_time_of_day +// Description: +//////////////////////////////////////////////////////////////////// +void get_time_of_day(TimeVal &tv) { + get_true_time_of_day(tv.tv[0], tv.tv[1]); +} diff --git a/panda/src/express/clockObject.h b/panda/src/express/clockObject.h index 3f2f8c0d0e..7d3d8f3da3 100644 --- a/panda/src/express/clockObject.h +++ b/panda/src/express/clockObject.h @@ -11,6 +11,18 @@ #include "trueClock.h" #include "config_express.h" +class EXPCL_PANDAEXPRESS TimeVal { +PUBLISHED: + TimeVal(); + ulong tv[2]; +}; + +BEGIN_PUBLISH + +EXPCL_PANDAEXPRESS void get_time_of_day(TimeVal &tv); + +END_PUBLISH + //////////////////////////////////////////////////////////////////// // Class : ClockObject // Description : A ClockObject keeps track of elapsed real time and diff --git a/panda/src/express/trueClock.cxx b/panda/src/express/trueClock.cxx index 825ccfea88..7275777ed9 100644 --- a/panda/src/express/trueClock.cxx +++ b/panda/src/express/trueClock.cxx @@ -29,6 +29,12 @@ static PN_int64 _frequency; static PN_int64 _init_count; static long _init_sec; +void get_true_time_of_day(ulong &sec, ulong &usec) { + struct timeb tb; + ftime(&tb); + sec = tb.time; + usec = (ulong)(tb.millitm * 1000.0); +} double TrueClock:: get_real_time() const { @@ -105,6 +111,10 @@ timer_handler(int) { return -1; } +void get_true_time_of_day(ulong &sec, ulong &msec) { + cerr << "get_true_time_of_day() not implemented!" << endl; +} + double TrueClock:: get_real_time() const { return (double) _sec + ((double) _msec / 1000.0); @@ -146,6 +156,25 @@ TrueClock() { static long _init_sec; +void get_true_time_of_day(ulong &sec, ulong &msec) { + struct timeval tv; + int result; + +#ifdef GETTIMEOFDAY_ONE_PARAM + result = gettimeofday(&tv); +#else + result = gettimeofday(&tv, (struct timezone *)NULL); +#endif + + if (result < 0) { + sec = 0; + msec = 0; + // Error in gettimeofday(). + return; + } + sec = tv.tv_sec; + msec = tv.tv_usec; +} double TrueClock:: get_real_time() const { diff --git a/panda/src/express/trueClock.h b/panda/src/express/trueClock.h index 0db2d6d346..8280c9b10e 100644 --- a/panda/src/express/trueClock.h +++ b/panda/src/express/trueClock.h @@ -7,6 +7,7 @@ #define TRUECLOCK_H #include +#include "typedef.h" //////////////////////////////////////////////////////////////////// // Class : TrueClock @@ -34,6 +35,8 @@ protected: static TrueClock *_global_ptr; }; +void get_true_time_of_day(ulong &sec, ulong &usec); + #include "trueClock.I" #endif