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
![](smile.gif)
)
Any suggestions for why I am seeing too many increments per second?
Thanks
Chris