|
|
b352c10 |
diff -uNrp SimGear-2.0.0.orig/simgear/timing/timestamp.cxx SimGear-2.0.0/simgear/timing/timestamp.cxx
|
|
|
b352c10 |
--- SimGear-2.0.0.orig/simgear/timing/timestamp.cxx 2010-02-17 16:39:22.000000000 +0100
|
|
|
b352c10 |
+++ SimGear-2.0.0/simgear/timing/timestamp.cxx 2010-02-26 23:09:15.826492455 +0100
|
|
|
b352c10 |
@@ -24,83 +24,6 @@
|
|
|
b352c10 |
// $Id$
|
|
|
b352c10 |
|
|
|
b352c10 |
|
|
|
b352c10 |
-#ifdef HAVE_CONFIG_H
|
|
|
b352c10 |
-# include <simgear_config.h>
|
|
|
b352c10 |
-#endif
|
|
|
b352c10 |
-
|
|
|
b352c10 |
-#include <simgear/compiler.h>
|
|
|
b352c10 |
-
|
|
|
b352c10 |
-#include <ctime>
|
|
|
b352c10 |
-
|
|
|
b352c10 |
-#ifdef HAVE_SYS_TIMEB_H
|
|
|
b352c10 |
-# include <sys/timeb.h> // for ftime() and struct timeb
|
|
|
b352c10 |
-#endif
|
|
|
b352c10 |
-#ifdef HAVE_UNISTD_H
|
|
|
b352c10 |
-# include <unistd.h> // for gettimeofday() and the _POSIX_TIMERS define
|
|
|
b352c10 |
-#endif
|
|
|
b352c10 |
-#ifdef HAVE_SYS_TIME_H
|
|
|
b352c10 |
-# include <sys/time.h> // for get/setitimer, gettimeofday, struct timeval
|
|
|
b352c10 |
-#endif
|
|
|
b352c10 |
-
|
|
|
b352c10 |
-#if defined(_POSIX_TIMERS) && (0 < _POSIX_TIMERS)
|
|
|
b352c10 |
-# include <time.h>
|
|
|
b352c10 |
-# include <errno.h>
|
|
|
b352c10 |
-#endif
|
|
|
b352c10 |
-
|
|
|
b352c10 |
-#ifdef WIN32
|
|
|
b352c10 |
-# include <windows.h>
|
|
|
b352c10 |
-# if defined( __CYGWIN__ ) || defined( __CYGWIN32__ )
|
|
|
b352c10 |
-# define NEAR /* */
|
|
|
b352c10 |
-# define FAR /* */
|
|
|
b352c10 |
-# endif
|
|
|
b352c10 |
-# include <mmsystem.h>
|
|
|
b352c10 |
-#endif
|
|
|
b352c10 |
-
|
|
|
b352c10 |
#include "timestamp.hxx"
|
|
|
b352c10 |
|
|
|
b352c10 |
-void SGTimeStamp::stamp() {
|
|
|
b352c10 |
-#ifdef _WIN32
|
|
|
b352c10 |
- unsigned int t;
|
|
|
b352c10 |
- t = timeGetTime();
|
|
|
b352c10 |
- _sec = t / 1000;
|
|
|
b352c10 |
- _nsec = ( t - ( _sec * 1000 ) ) * 1000 * 1000;
|
|
|
b352c10 |
-#elif defined(_POSIX_TIMERS) && (0 < _POSIX_TIMERS)
|
|
|
b352c10 |
- struct timespec ts;
|
|
|
b352c10 |
-#if defined(_POSIX_MONOTONIC_CLOCK)
|
|
|
b352c10 |
- static clockid_t clockid = CLOCK_MONOTONIC;
|
|
|
b352c10 |
- static bool firstTime = true;
|
|
|
b352c10 |
- if (firstTime) {
|
|
|
b352c10 |
- firstTime = false;
|
|
|
b352c10 |
- // For the first time test if the monotonic clock is available.
|
|
|
b352c10 |
- // If so use this if not use the realtime clock.
|
|
|
b352c10 |
- if (-1 == clock_gettime(clockid, &ts) && errno == EINVAL)
|
|
|
b352c10 |
- clockid = CLOCK_REALTIME;
|
|
|
b352c10 |
- }
|
|
|
b352c10 |
- clock_gettime(clockid, &ts);
|
|
|
b352c10 |
-#else
|
|
|
b352c10 |
- clock_gettime(CLOCK_REALTIME, &ts);
|
|
|
b352c10 |
-#endif
|
|
|
b352c10 |
- _sec = ts.tv_sec;
|
|
|
b352c10 |
- _nsec = ts.tv_nsec;
|
|
|
b352c10 |
-#elif defined( HAVE_GETTIMEOFDAY )
|
|
|
b352c10 |
- struct timeval current;
|
|
|
b352c10 |
- struct timezone tz;
|
|
|
b352c10 |
- // sg_timestamp currtime;
|
|
|
b352c10 |
- gettimeofday(¤t, &tz;;
|
|
|
b352c10 |
- _sec = current.tv_sec;
|
|
|
b352c10 |
- _nsec = current.tv_usec * 1000;
|
|
|
b352c10 |
-#elif defined( HAVE_GETLOCALTIME )
|
|
|
b352c10 |
- SYSTEMTIME current;
|
|
|
b352c10 |
- GetLocalTime(¤t;;
|
|
|
b352c10 |
- _sec = current.wSecond;
|
|
|
b352c10 |
- _nsec = current.wMilliseconds * 1000 * 1000;
|
|
|
b352c10 |
-#elif defined( HAVE_FTIME )
|
|
|
b352c10 |
- struct timeb current;
|
|
|
b352c10 |
- ftime(¤t;;
|
|
|
b352c10 |
- _sec = current.time;
|
|
|
b352c10 |
- _nsec = current.millitm * 1000 * 1000;
|
|
|
b352c10 |
-#else
|
|
|
b352c10 |
-# error Port me
|
|
|
b352c10 |
-#endif
|
|
|
b352c10 |
-}
|
|
|
b352c10 |
-
|
|
|
b352c10 |
+// empty, all inline class now.
|
|
|
b352c10 |
diff -uNrp SimGear-2.0.0.orig/simgear/timing/timestamp.hxx SimGear-2.0.0/simgear/timing/timestamp.hxx
|
|
|
b352c10 |
--- SimGear-2.0.0.orig/simgear/timing/timestamp.hxx 2010-02-17 16:39:22.000000000 +0100
|
|
|
b352c10 |
+++ SimGear-2.0.0/simgear/timing/timestamp.hxx 2010-02-26 23:09:23.070286905 +0100
|
|
|
b352c10 |
@@ -32,12 +32,42 @@
|
|
|
b352c10 |
# error This library requires C++
|
|
|
b352c10 |
#endif
|
|
|
b352c10 |
|
|
|
b352c10 |
+#ifdef HAVE_CONFIG_H
|
|
|
b352c10 |
+# include <simgear_config.h>
|
|
|
b352c10 |
+#endif
|
|
|
b352c10 |
+
|
|
|
b352c10 |
#include <iosfwd>
|
|
|
b352c10 |
#include <iomanip>
|
|
|
b352c10 |
#include <sstream>
|
|
|
b352c10 |
#include <simgear/compiler.h>
|
|
|
b352c10 |
#include <simgear/math/SGCMath.hxx>
|
|
|
b352c10 |
|
|
|
b352c10 |
+#include <ctime>
|
|
|
b352c10 |
+
|
|
|
b352c10 |
+#ifdef HAVE_SYS_TIMEB_H
|
|
|
b352c10 |
+# include <sys/timeb.h> // for ftime() and struct timeb
|
|
|
b352c10 |
+#endif
|
|
|
b352c10 |
+#ifdef HAVE_UNISTD_H
|
|
|
b352c10 |
+# include <unistd.h> // for gettimeofday() and the _POSIX_TIMERS define
|
|
|
b352c10 |
+#endif
|
|
|
b352c10 |
+#ifdef HAVE_SYS_TIME_H
|
|
|
b352c10 |
+# include <sys/time.h> // for get/setitimer, gettimeofday, struct timeval
|
|
|
b352c10 |
+#endif
|
|
|
b352c10 |
+
|
|
|
b352c10 |
+#if defined(_POSIX_TIMERS) && (0 < _POSIX_TIMERS)
|
|
|
b352c10 |
+# include <time.h>
|
|
|
b352c10 |
+# include <errno.h>
|
|
|
b352c10 |
+#endif
|
|
|
b352c10 |
+
|
|
|
b352c10 |
+#ifdef WIN32
|
|
|
b352c10 |
+# include <windows.h>
|
|
|
b352c10 |
+# if defined( __CYGWIN__ ) || defined( __CYGWIN32__ )
|
|
|
b352c10 |
+# define NEAR /* */
|
|
|
b352c10 |
+# define FAR /* */
|
|
|
b352c10 |
+# endif
|
|
|
b352c10 |
+# include <mmsystem.h>
|
|
|
b352c10 |
+#endif
|
|
|
b352c10 |
+
|
|
|
b352c10 |
/**
|
|
|
b352c10 |
* The SGTimeStamp class allows you to mark and compare time stamps
|
|
|
b352c10 |
* with nanosecond accuracy (if your system has support for this
|
|
|
b352c10 |
@@ -76,7 +106,51 @@ public:
|
|
|
b352c10 |
// { setTime(sec); }
|
|
|
b352c10 |
|
|
|
b352c10 |
/** Update stored time to current time (seconds and nanoseconds) */
|
|
|
b352c10 |
- void stamp();
|
|
|
b352c10 |
+ void stamp() {
|
|
|
b352c10 |
+#ifdef _WIN32
|
|
|
b352c10 |
+ unsigned int t;
|
|
|
b352c10 |
+ t = timeGetTime();
|
|
|
b352c10 |
+ _sec = t / 1000;
|
|
|
b352c10 |
+ _nsec = ( t - ( _sec * 1000 ) ) * 1000 * 1000;
|
|
|
b352c10 |
+#elif defined(_POSIX_TIMERS) && (0 < _POSIX_TIMERS)
|
|
|
b352c10 |
+ struct timespec ts;
|
|
|
b352c10 |
+#if defined(_POSIX_MONOTONIC_CLOCK)
|
|
|
b352c10 |
+ static clockid_t clockid = CLOCK_MONOTONIC;
|
|
|
b352c10 |
+ static bool firstTime = true;
|
|
|
b352c10 |
+ if (firstTime) {
|
|
|
b352c10 |
+ firstTime = false;
|
|
|
b352c10 |
+ // For the first time test if the monotonic clock is available.
|
|
|
b352c10 |
+ // If so use this if not use the realtime clock.
|
|
|
b352c10 |
+ if (-1 == clock_gettime(clockid, &ts) && errno == EINVAL)
|
|
|
b352c10 |
+ clockid = CLOCK_REALTIME;
|
|
|
b352c10 |
+ }
|
|
|
b352c10 |
+ clock_gettime(clockid, &ts);
|
|
|
b352c10 |
+#else
|
|
|
b352c10 |
+ clock_gettime(CLOCK_REALTIME, &ts);
|
|
|
b352c10 |
+#endif
|
|
|
b352c10 |
+ _sec = ts.tv_sec;
|
|
|
b352c10 |
+ _nsec = ts.tv_nsec;
|
|
|
b352c10 |
+#elif defined( HAVE_GETTIMEOFDAY )
|
|
|
b352c10 |
+ struct timeval current;
|
|
|
b352c10 |
+ struct timezone tz;
|
|
|
b352c10 |
+ // sg_timestamp currtime;
|
|
|
b352c10 |
+ gettimeofday(¤t, &tz;;
|
|
|
b352c10 |
+ _sec = current.tv_sec;
|
|
|
b352c10 |
+ _nsec = current.tv_usec * 1000;
|
|
|
b352c10 |
+#elif defined( HAVE_GETLOCALTIME )
|
|
|
b352c10 |
+ SYSTEMTIME current;
|
|
|
b352c10 |
+ GetLocalTime(¤t;;
|
|
|
b352c10 |
+ _sec = current.wSecond;
|
|
|
b352c10 |
+ _nsec = current.wMilliseconds * 1000 * 1000;
|
|
|
b352c10 |
+#elif defined( HAVE_FTIME )
|
|
|
b352c10 |
+ struct timeb current;
|
|
|
b352c10 |
+ ftime(¤t;;
|
|
|
b352c10 |
+ _sec = current.time;
|
|
|
b352c10 |
+ _nsec = current.millitm * 1000 * 1000;
|
|
|
b352c10 |
+#else
|
|
|
b352c10 |
+# error Port me
|
|
|
b352c10 |
+#endif
|
|
|
b352c10 |
+ }
|
|
|
b352c10 |
|
|
|
b352c10 |
/** Set the time from a double value */
|
|
|
b352c10 |
void setTime(const double& seconds)
|