Original Post
I implemented a timer for frame limiting, movement and refresh rate synchronization. Problem is when i test it( i display elapsing seconds ), seconds seem to last 2-3 seconds..
I implemented it using QueryPerformanceCounter and QueryPerformanceFrequency:
Initializing the timer:
if( QueryPerformanceFrequency( (LARGE_INTEGER*)(&m_llPerfFreq) ) )
{
// Performance counter available
m_bQPC = true;
m_dFreqFactor = 1.f/m_llPerfFreq;
QueryPerformanceCounter( (LARGE_INTEGER*)(&m_llStart) );
}
else
{
// Performance counter unavailable, use timeGetTime()
m_bQPC = false;
m_dFreqFactor = 0.001f;
m_llStart = timeGetTime();
}
Starting:
void start_timer()
{
if( m_bQPC )
QueryPerformanceCounter( (LARGE_INTEGER*)(&m_llStart) );
else
m_llStart = timeGetTime();
}
Accumulating:
void accumulate()
{
if( m_bQPC )
QueryPerformanceCounter( (LARGE_INTEGER*)(&m_llEnd) );
else
m_llEnd = timeGetTime();
m_dElapsed += (m_llEnd-m_llStart)*m_dFreqFactor;
m_iCounter++;
}
Hungarian notation is used. Some help would be appreciated. Also, I''d like to know of a way to sync frame drawing and scene movement to the monitor''s refresh rate??