|
@@ -103,19 +103,27 @@ namespace sdl
|
|
double Timer::getMicroTime() const
|
|
double Timer::getMicroTime() const
|
|
{
|
|
{
|
|
#ifdef LOVE_WINDOWS
|
|
#ifdef LOVE_WINDOWS
|
|
- __int64 ticks, freq;
|
|
|
|
- LARGE_INTEGER temp;
|
|
|
|
- QueryPerformanceCounter(&temp);
|
|
|
|
- ticks = temp.QuadPart;
|
|
|
|
- QueryPerformanceFrequency(&temp);
|
|
|
|
- freq = temp.QuadPart;
|
|
|
|
- __int64 secs = ticks/freq;
|
|
|
|
- __int64 usecs = static_cast<__int64>((ticks%freq)/(freq/1000000.0));
|
|
|
|
- return secs%86400 + usecs/1000000.0;
|
|
|
|
|
|
+ static __int64 freq = 0;
|
|
|
|
+
|
|
|
|
+ if (!freq)
|
|
|
|
+ {
|
|
|
|
+ LARGE_INTEGER temp;
|
|
|
|
+ QueryPerformanceFrequency(&temp);
|
|
|
|
+
|
|
|
|
+ freq = (__int64) temp.QuadPart;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ LARGE_INTEGER microTime;
|
|
|
|
+ QueryPerformanceCounter(µTime);
|
|
|
|
+
|
|
|
|
+ // The 64 to 32 bit integer conversion, assuming the fraction part down
|
|
|
|
+ // to microseconds takes 20 bits, should not be a problem unless the
|
|
|
|
+ // system has an uptime of a few decades.
|
|
|
|
+ return (double) microTime.QuadPart / (double) freq;
|
|
#else
|
|
#else
|
|
timeval t;
|
|
timeval t;
|
|
gettimeofday(&t, NULL);
|
|
gettimeofday(&t, NULL);
|
|
- return t.tv_sec%86400 + t.tv_usec/1000000.0;
|
|
|
|
|
|
+ return t.tv_sec + t.tv_usec/1000000.0;
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
|
|
|