performance counter giving unexpected results
below is my fps code. When get fps from GetFPS(float* fps)
the float output is a intger numbers -4543543 +523454 ets
CFrameTimer::CFrameTimer(void)
{
m_lastUpdate = 0;
m_fpsUpdateInterval = 0.5f;
m_numFrames = 0;
m_fps = 0;
// We need to know how often the clock is updated
if( !QueryPerformanceFrequency((LARGE_INTEGER *)&m_ticksPerSecond) )
m_ticksPerSecond = 1000;
// If timeAtGameStart is 0 then we get the time since
// the start of the computer when we call GetGameTime()
m_timeAtGameStart = 0;
m_timeAtGameStart = GetGameTime();
}
// Called every time you need the current game time
float CFrameTimer::GetGameTime()
{
UINT64 ticks;
float time;
// This is the number of clock ticks since start
if( !QueryPerformanceCounter((LARGE_INTEGER *)&ticks) )
ticks = (UINT64)timeGetTime();
// Divide by frequency to get the time in seconds
time = (float)(__int64)ticks/(float)(__int64)m_ticksPerSecond;
// Subtract the time at game start to get
// the time since the game started
time -= m_timeAtGameStart;
return time;
}
// Called once for every frame
void CFrameTimer::UpdateFPS()
{
m_numFrames++;
float currentUpdate = GetGameTime();
if( currentUpdate - m_lastUpdate > m_fpsUpdateInterval )
{
m_fps = m_numFrames / (currentUpdate - m_lastUpdate);
m_lastUpdate = currentUpdate;
m_numFrames = 0;
}
}
void CFrameTimer::GetFPS(float* fps)
{
*fps = m_fps;
}
Instead of using INT64 and __int64, and casting to LARGE_INTEGER, just declare your variables of type LARGE_INTEGER. When you need to set it directly, set var.quadPart.
~BenDilts( void );
~BenDilts( void );
thanx for sugestion. however i did a stupid mistake i was outputing a float val using %d into char buffer. my mistake.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement