mirror of
https://github.com/love2d/love.git
synced 2026-08-12 16:40:57 +02:00
Apply patch for increased timer accuracy (issue #303)
This commit is contained in:
@@ -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(µ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
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user