Apply patch for increased timer accuracy (issue #303)

This commit is contained in:
Bart van Strien
2011-10-02 16:11:24 +02:00
parent eb7053b43f
commit 66ecf8aff0
+18 -10
View File
@@ -103,19 +103,27 @@ namespace sdl
double Timer::getMicroTime() const
{
#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(&microTime);
// 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
timeval t;
gettimeofday(&t, NULL);
return t.tv_sec%86400 + t.tv_usec/1000000.0;
return t.tv_sec + t.tv_usec/1000000.0;
#endif
}