I know this places a few more static variables, but it would allow for
accuracy past the ms if you wanted (just change the divisor)
//Note that QueryPerformanceCounter loops after the same 49.7 days…
//***********************************************************************
// START
//***********************************************************************
// globals:
static bool ptcAvailable;
static DWORD start; // still remains from b4
static DWORD divisor;
void SDL_StartTicks(void)
{
LARGE_INTEGER ptc, ptf;
ptcAvailable = QueryPerformanceCounter(&ptc) &&
QueryPerformanceFrequency(&ptf);
// value is for PTC ticks / sec… conversion to ms
if (ptcAvailable)
{
divisor = ptf.QuadPart / 1000;
start = ptc.QuadPart / divisor;
}
else
start = GetTickCount();
}
Uint32 SDL_GetTicks()
{
DWORD now, ticks;
if (ptcAvailable)
{
LARGE_INTEGER currentPTC;
QueryPerformanceCounter(¤tPTC);
now = currentPTC.QuadPart / divisor;
}
else
now = GetTickCount();
if ( now < start )
{
ticks = (TIME_WRAP_VALUE-start) + now;
}
else
ticks = (now - start);
return (ticks);
}
//*************************************************
// END
//*************************************************
The code does not include the #ifdef USE_GETTICKCOUNT stuff, but it could
be easily added.
Interesting note:
I retested this code under VC++ 6 (I had used some similarish code B4
under BCB, but used to to make a more accurate TDateTime… anyways). It
turns out this code is actually FASTER than the GetTickCount() version…
especially surprising since Query version gets its start value several
lines b4 the GetTickCount one!!!
I ran 10000 SDL_GetTicks and the Query version usually got it done .1
seconds faster.
Hope this is useful for something.
Joe Tennies--------------------------
A student, working on a rather long math homework assignment, discovered
that one problem fairly easy to solve, except that it required about three
pages of fairly simple proof after the one or two difficult steps. It being
rather late at night, he did the difficult steps and left the proof undone,
along with a note:
This proof is left as an exercise for the grader.
Next week, he received his homework back. He noted that several extra pages
had been stapled to the back of it. Examining the extra pages, he was
surprised to find the entire proof written down step-by step. At the end,
in red pen, the grader had written:
I made a minor math error. Minus 2.