Advertisement

timer

Started by March 04, 2002 04:00 AM
-1 comments, last by foonk 22 years, 11 months ago
hey i have a timer class highly bassed on the timer from neehes tutorials, and to find out how often a frame is being drawn i get the time of the last time and - it from the current time, and divide it by 1000 which should give how many seconds have passed since the last draw, i get around 0.000561, so that means its redrawing 1782.531195 times a second, that seem waaaay too high, what the heck am i doing wrong? the timer code as i said is pretty much the timer form nehes tuts, its
  
CTimer::CTimer()
{
	// Check To See If A Performance Counter Is Available

	if (!QueryPerformanceFrequency((LARGE_INTEGER *) &frequency))
	{
		// No Performace Counter Available

		performance_timer	= FALSE;
		timer_start = timeGetTime();
		resolution = 1.0f/1000.0f;
		frequency = 1000;
		timer_elapsed = timer_start;
	}
	else
	{
		// Performance Counter Is Available

		QueryPerformanceCounter((LARGE_INTEGER *) &timer_start);
		performance_timer	= TRUE;
		// Calculate The Timer Resolution Using The Timer Frequency

		resolution = float( double(1.0f)/double(frequency));
		// Set The Elapsed Time To The Current Time

		timer_elapsed = timer_start;
	}
}

float CTimer::GetTime()
{
	__int64 time;

	if (performance_timer)
	{
		QueryPerformanceCounter((LARGE_INTEGER *) &time);
		// Return The Current Time Minus The Start Time Multiplied By The Resolution And 1000 (To Get MS)

		return float(( time - timer_start) * resolution)*1000.0f;
	}
	else
	{
		// Return The Current Time Minus The Start Time Multiplied By The Resolution And 1000 (To Get MS)

		return float(( timeGetTime() - timer_start) * resolution)*1000.0f;
	}
}
  
thanks for any advice,

This topic is closed to new replies.

Advertisement