Replace GetSystemTimeAsFileTime() with GetPerformanceCounter().

GetSystemTimeAsFileTime() is okay as long as the game runs fullscreen.
For some reasons it's resolution degraded to ~16ms as soon as the game
runs widowed... Better use GetPerformanceCounter(), its more reliable
and the recommended API for timecounters.
This commit is contained in:
Yamagi Burmeister 2019-04-01 19:29:08 +02:00
parent f240799e6d
commit 209bd9d529

View file

@ -261,29 +261,24 @@ Sys_ConsoleOutput(char *string)
long long
Sys_Microseconds(void)
{
long long microseconds;
static long long uSecbase;
static LARGE_INTEGER freq = { 0 };
static LARGE_INTEGER base = { 0 };
FILETIME ft;
unsigned long long tmpres = 0;
GetSystemTimeAsFileTime(&ft);
tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;
tmpres /= 10; // Convert to microseconds.
tmpres -= 11644473600000000ULL; // ...and to unix epoch.
microseconds = tmpres;
if (!uSecbase)
if (!freq.QuadPart)
{
uSecbase = microseconds - 1001ll;
QueryPerformanceFrequency(&freq);
}
return microseconds - uSecbase;
if (!base.QuadPart)
{
QueryPerformanceCounter(&base);
base.QuadPart -= 1001;
}
LARGE_INTEGER cur;
QueryPerformanceCounter(&cur);
return (cur.QuadPart - base.QuadPart) * 1000000 / freq.QuadPart;
}
int