Jump to content
  • Advertisement
Sign in to follow this  
vertex78

[SDL]high resolution timers?

This topic is 3663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

on this page http://www.libsdl.org/cgi/docwiki.cgi/SDL_GetTicks there is a note that says: NOTE: On platforms with high resolution timers, you can get the number of microseconds. Will add details after further investigations. Does anyone know anything more about this?

Share this post


Link to post
Share on other sites
Advertisement
Use the source!

For example, SDL 1.2 on Windows appears not to use a high resolution timer (due to issues with QueryPerformanceCounter on Win2K apparently).

Share this post


Link to post
Share on other sites
You would have to look through the actual source code, not just the header. Here is a snippet from the win32 timer directory


void SDL_StartTicks(void)
{
/* Set first ticks value */
#ifdef USE_GETTICKCOUNT
start = GetTickCount();
#else
#if 0 /* Apparently there are problems with QPC on Win2K */
if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE)
{
hires_timer_available = TRUE;
QueryPerformanceCounter(&hires_start_ticks);
}
else
#endif
{
hires_timer_available = FALSE;
timeBeginPeriod(1); /* use 1 ms timer precision */
start = timeGetTime();
}
#endif
}

Uint32 SDL_GetTicks(void)
{
DWORD now, ticks;
#ifndef USE_GETTICKCOUNT
LARGE_INTEGER hires_now;
#endif

#ifdef USE_GETTICKCOUNT
now = GetTickCount();
#else
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

if ( now < start ) {
ticks = (TIME_WRAP_VALUE-start) + now;
} else {
ticks = (now - start);
}
return(ticks);
}



As rip-off said, and you can see, they are just using timeGetTime( ) and not the high-res timer. Looking through the unix source, it looks like they try to use clock_gettime, but default to gettimeofday.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!