mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-01-19 07:51:03 +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:
parent
f240799e6d
commit
209bd9d529
1 changed files with 14 additions and 19 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue