timer: Added SDL_GetTicks64(), for a timer that doesn't wrap every ~49 days.

Note that this removes the timeGetTime() fallback on Windows; it is a
32-bit counter and SDL2 should never choose to use it, as it only is needed
if QueryPerformanceCounter() isn't available, and QPC is _always_ available
on Windows XP and later.

OS/2 has a similar situation, but since it isn't clear to me that similar
promises can be made about DosTmrQueryTime() even in modern times, I decided
to leave the fallback in, with some heroic measures added to try to provide a
true 64-bit tick counter despite the 49-day wraparound. That approach can
migrate to Windows too, if we discover some truly broken install that doesn't
have QPC and still depends on timeGetTime().

Fixes #4870.
This commit is contained in:
Ryan C. Gordon
2021-10-23 15:00:31 -04:00
parent 0d631c741f
commit 99c9727dc0
11 changed files with 128 additions and 97 deletions

View File

@@ -51,24 +51,23 @@ SDL_TicksQuit(void)
ticks_started = SDL_FALSE;
}
Uint32 SDL_GetTicks(void)
Uint64
SDL_GetTicks64(void)
{
struct timeval now;
if (!ticks_started) {
SDL_TicksInit();
}
struct timeval now;
Uint32 ticks;
gettimeofday(&now, NULL);
ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
return(ticks);
return (((Uint64)(now.tv_sec-start.tv_sec)) * 1000) + (((Uint64) (now.tv_usec-start.tv_usec)) / 1000);
}
Uint64
SDL_GetPerformanceCounter(void)
{
return SDL_GetTicks();
return SDL_GetTicks64();
}
Uint64