New Paste :: Recent Pastes:: No Line Numbers
Timer Code by dranith
1
#ifndef _TIMER_H__ #define _TIMER_H__ /////////////////////////////////////////////////////////////////////// #include <mmsystem.h> /////////////////////////////////////////////////////////////////////// class PTimer { MFLOAT m_FrameInterval; MINT m_LastFps; MINT m_Fps; MINT m_LastTime; MINT m_CurTime; MINT m_FrameTime; public: // ctor PTimer() { m_CurTime = 0; m_Fps = 0; m_LastFps = 0; m_FrameInterval = 0.0f; timeBeginPeriod( 1 ); m_LastTime = timeGetTime(); } // dtor ~PTimer() { // Reset timer resolution timeEndPeriod( 1 ); } // Functions void Update() { m_CurTime = timeGetTime(); m_FrameInterval = static_cast<MFLOAT>((m_CurTime - m_FrameTime) * 0.001f); m_FrameTime = m_CurTime; ++m_Fps; if( (m_CurTime - m_LastTime) > 1000 ) { m_LastTime = m_CurTime; m_LastFps = m_Fps; m_Fps = 0; } } MINT Fps() { return m_LastFps; } MFLOAT FrameInterval() { return m_FrameInterval; } }; /////////////////////////////////////////////////////////////////////// #endif