Advertisement

FPS calculations always not perfect

Started by April 10, 2001 06:36 AM
-1 comments, last by gimp 23 years, 10 months ago
  
void CEngine::SetFPS(void)
{
	static CTimer Timer;
	static unsigned int	FpsNum;
	static unsigned int	LastFpsNum;
	static unsigned int	NumFrames;

	if(Timer.ElapsedSeconds() >= 1.0f)
	{
		Timer.Reset();
		FpsNum = NumFrames;
		NumFrames = 0;

		if (LastFpsNum != FpsNum)
		{
			//Display FPS

			std::string FPS("FPS : ");
			std::stringstream temp;
			temp << FpsNum;
			FPS += temp.str();
			m_Renderer->Screen.SetCaption(FPS);
			LastFpsNum = FpsNum;
		}
	}
	else
		++NumFrames;
}
  
This code when run with a v-refresh of 60 always seems to report ~62. On other refresh rates it''s ways too high there too. The CTimer is just a wrapper around QueryPerformance counter. The ''second'' calculation is like this: double CTimer::ElapsedSeconds(void) { LARGE_INTEGER Current; QueryPerformanceCounter(&Current); return (double)(Current.QuadPart - m_Start) / s_Frequency; } Hopefully casting to double isn''t too evil in ths case. (I''m not worried if my clock breaks at the year 25000ad ) Any suggestions for why I am seeing too many increments per second? Thanks Chris
Chris Brodie

This topic is closed to new replies.

Advertisement