Added Holger Schemel's fix for SDL_GetTicks() on W2K
This adds QueryPerformanceCounter() support, which is probably a good thing. --HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%4090
This commit is contained in:
parent
96c6144609
commit
ec76bd6aef
1 changed files with 39 additions and 3 deletions
|
@ -39,28 +39,64 @@ static char rcsid =
|
||||||
|
|
||||||
#define TIME_WRAP_VALUE (~(DWORD)0)
|
#define TIME_WRAP_VALUE (~(DWORD)0)
|
||||||
|
|
||||||
/* The first ticks value of the application */
|
/* The first (low-resolution) ticks value of the application */
|
||||||
static DWORD start;
|
static DWORD start;
|
||||||
|
|
||||||
|
#ifndef USE_GETTICKCOUNT
|
||||||
|
/* Store if a high-resolution performance counter exists on the system */
|
||||||
|
static BOOL hires_timer_available;
|
||||||
|
/* The first high-resolution ticks value of the application */
|
||||||
|
static LARGE_INTEGER hires_start_ticks;
|
||||||
|
/* The number of ticks per second of the high-resolution performance counter */
|
||||||
|
static LARGE_INTEGER hires_ticks_per_second;
|
||||||
|
#endif
|
||||||
|
|
||||||
void SDL_StartTicks(void)
|
void SDL_StartTicks(void)
|
||||||
{
|
{
|
||||||
/* Set first ticks value */
|
/* Set first ticks value */
|
||||||
#ifdef USE_GETTICKCOUNT
|
#ifdef USE_GETTICKCOUNT
|
||||||
start = GetTickCount();
|
start = GetTickCount();
|
||||||
#else
|
#else
|
||||||
start = timeGetTime();
|
if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE)
|
||||||
|
{
|
||||||
|
hires_timer_available = TRUE;
|
||||||
|
QueryPerformanceCounter(&hires_start_ticks);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hires_timer_available = FALSE;
|
||||||
|
timeBeginPeriod(1); /* use 1 ms timer precision */
|
||||||
|
start = timeGetTime();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 SDL_GetTicks(void)
|
Uint32 SDL_GetTicks(void)
|
||||||
{
|
{
|
||||||
DWORD now, ticks;
|
DWORD now, ticks;
|
||||||
|
#ifndef USE_GETTICKCOUNT
|
||||||
|
LARGE_INTEGER hires_now;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_GETTICKCOUNT
|
#ifdef USE_GETTICKCOUNT
|
||||||
now = GetTickCount();
|
now = GetTickCount();
|
||||||
#else
|
#else
|
||||||
now = timeGetTime();
|
if (hires_timer_available)
|
||||||
|
{
|
||||||
|
QueryPerformanceCounter(&hires_now);
|
||||||
|
|
||||||
|
hires_now.QuadPart -= hires_start_ticks.QuadPart;
|
||||||
|
hires_now.QuadPart *= 1000;
|
||||||
|
hires_now.QuadPart /= hires_ticks_per_second.QuadPart;
|
||||||
|
|
||||||
|
return (DWORD)hires_now.QuadPart;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
now = timeGetTime();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( now < start ) {
|
if ( now < start ) {
|
||||||
ticks = (TIME_WRAP_VALUE-start) + now;
|
ticks = (TIME_WRAP_VALUE-start) + now;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue