timer.cpp
来自「wince 3d tutorial, it has various exampl」· C++ 代码 · 共 42 行
CPP
42 行
#include "timer.h"
Timer::Timer()
{
//we must initialize all our variables
m_diffTime = 0;
m_accumTime = 0;
m_fps = 0;
m_lastTime = 0;
m_frameTime = 0;
}
//-----------------------------------------------------
void Timer::UpdateTimer()
{
long currentTime;
static long framesPerSecond = 0;
static bool sw = false;
static unsigned long firstTime = 0;
if(!sw)
{
firstTime = GetTickCount();
sw = true;
}
currentTime = GetTickCount() - firstTime; //compute time elapsed since the first UpdateTimer call
m_diffTime = currentTime - m_frameTime; //compute time elapsed since the last frame
m_accumTime += m_diffTime; //compute accumulated time
m_frameTime = currentTime;
//compute frames per second
framesPerSecond++;
if(currentTime - m_lastTime > 1000 )
{
m_lastTime = currentTime;
m_fps = framesPerSecond;
framesPerSecond = 0;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?