[SDL]high resolution timers?

Started by
2 comments, last by Simian Man 15 years, 10 months ago
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?
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).
well i did look through the header file SDL_timer.h but I did not find anything that talked about it.
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.

This topic is closed to new replies.

Advertisement