0
0
Fork 0
mirror of https://github.com/yquake2/yquake2remaster.git synced 2025-03-02 15:32:13 +00:00

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 long long
Sys_Microseconds(void) Sys_Microseconds(void)
{ {
long long microseconds; static LARGE_INTEGER freq = { 0 };
static long long uSecbase; static LARGE_INTEGER base = { 0 };
FILETIME ft; if (!freq.QuadPart)
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)
{ {
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 int