afTime.cpp
资源名称:AirForce.rar [点击查看]
上传用户:kaiguan
上传日期:2007-10-28
资源大小:1074k
文件大小:1k
源码类别:
其他游戏
开发平台:
Visual C++
- #include "afTime.h"
- float afTime::lastFrameTime = 0.0f;
- float afTime::totalFrameTime=0.0f;
- int afTime::NumOfFrames=0;
- float afTime::fps = 0.0f;
- bool afTime::firstUpdate = true;
- LARGE_INTEGER afTime::time0={0,0};
- LARGE_INTEGER afTime::time1={0,0};
- LARGE_INTEGER afTime::freq={0,0};
- void afTime::update()
- {
- lastFrameTime = 0.0f;
- fps = 0.0f;
- QueryPerformanceCounter(&time1);
- if(firstUpdate)
- {
- firstUpdate = false;
- QueryPerformanceFrequency(&freq);
- time0 = time1;
- }
- if(freq.QuadPart!=0)
- lastFrameTime = (float)(time1.QuadPart-time0.QuadPart) / (float)(freq.QuadPart);
- if(lastFrameTime>0.0f)
- {
- fps = 1.0f / lastFrameTime;
- NumOfFrames++;
- totalFrameTime+=lastFrameTime;
- }
- time0 = time1;
- }
- float afTime::getLastFrameTime()
- {
- return lastFrameTime;
- }
- float afTime::getFPS()
- {
- return fps;
- }
- float afTime::getAverageFPS()
- {
- return NumOfFrames/totalFrameTime;
- }
- afTimeInstance afTime::getCurrentTime()
- {
- LARGE_INTEGER time;
- QueryPerformanceCounter(&time);
- return afTimeInstance(time);
- }
- float afTime::getTimeSince(const afTimeInstance& nInst)
- {
- LARGE_INTEGER time;
- QueryPerformanceCounter(&time);
- if(freq.LowPart!=0)
- return (float)(time.QuadPart-nInst.getQuadPart()) / (float)(freq.QuadPart);
- return 0.0f;
- }