Skip to main content
gamedev.net
🔒 Locked

Timer help!!

Started by ph0ngwh0ng 0 replies 200+ views
Original Post
ph0ngwh0ng
ph0ngwh0ng
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??
ph0ng^_^wh0ng
ph0ngwh0ng
ph0ngwh0ng
AH! Found the problem. The loop I used to test the timer was too tight, that is not enough time would elapse between the starting time and the end time for the elapsed time to be accumulated.

Thanks anyways all!

ph0ng^_^wh0ng
tanks u
ph0ng^_^wh0ng

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.