Hello smart beings from GameDev.net.
I need some assistance in solving my problem.
I am making an engine, though I call it more of a framework rather than an engine because most of the things in it are just wrappers and no major subsystem existing yet. Anyway, I'm at this point of making an FPS (frame rate) counter. This one seems to be odd because I keep on getting 41FPS on my counter and not 60! Note that I have a 3.0Ghz (OC'ed) core2duo system, and I am just rendering four simple lines forming a crosshair at the center and nothing else! So, I'm doubting that my FPS computation is wrong since if I set my m_FPSControl (my delay rate for busy-waiting loop) to 75, I get an FPS of 60 and above. Is there something wrong on my code?
InterfaceGame methods:
U32 InterfaceGame::GetFPS()
{
return m_FPS;
}
U32 InterfaceGame::GetFPSCount()
{
return m_FPSCount;
}
U32 InterfaceGame::GetMsPF()
{
return m_MsPF;
}
inline void InterfaceGame::SetFPS( U32 p_MyFPS )
{
m_FPS = p_MyFPS;
m_FPSControl = 1000 / m_FPS; // looks right to me
}
void InterfaceGame::GameSyncStart()
{
m_TimeStart = App::GetTick();
}
void InterfaceGame::GameSyncFinish()
{
while( ( App::GetTick() - m_TimeStart ) < m_FPSControl );
m_MsPF = App::GetTick() - m_TimeStart;
++m_FPSFrames;
m_FPSTickAccumulator += m_MsPF;
if( m_FPSTickAccumulator > 1000 )
{
m_FPSCount = m_FPSFrames;
m_FPSFrames = 0;
m_FPSTickAccumulator = 0;
}
}
Before game loop:
g_pGame->SetFPS( 60 );
My main game loop somewhere:
{
g_pGame->GameSyncStart();
...
g_pGame->GameSyncFinish();
SwapBuffers( g_App.AppDeviceContext );
if( App::IsFPSDisplayOn() && !App::IsFullscreen() )
{
std::string StringTemp = App::GetGameName( TRUE );
StringTemp += " - ";
StringTemp += ToString( g_pGame->GetFPSCount() );
StringTemp += "/";
StringTemp += ToString( g_pGame->GetFPS() );
StringTemp += " FPS; ";
StringTemp += ToString( g_pGame->GetMsPF() );
StringTemp += " MsPF";
SetWindowText( g_App.AppWindow, StringTemp.c_str() );
}
}
Anyone?
-edit-
corrected a code to prevent confusion.
[Edited by - AndreiVictor on May 26, 2007 12:29:32 PM]