Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Timer.cpp

Go to the documentation of this file.
00001 
00007 #include "Timer.h"
00008 
00009 void Timer::init() {
00010         __int64 rate;
00011 
00012         QueryPerformanceFrequency((LARGE_INTEGER*)&rate);
00013 
00014         frequency = 1.0/(double)rate;
00015 
00016         QueryPerformanceCounter((LARGE_INTEGER*)&startClock);
00017 
00018         frameTime       = 0.0f;
00019         frameStart      = (float)getTime();
00020         frameEnd        = 0.0f;
00021         fpsLimiter      = 0.0f;
00022         fps                     = 0;
00023         frameCount      = 0;
00024 }
00025 
00026 void Timer::update() {
00027         static float t_fps[15];
00028         static int currPos = 0;
00029 
00030         do {
00031                 frameEnd = (float)getTime();
00032         } while (frameEnd == frameStart);
00033 
00034         frameTime = frameEnd - frameStart;
00035         frameStart = frameEnd;
00036 
00046         ++frameCount;
00047 
00048         fpsLimiter += frameTime;
00049         if (fpsLimiter > 1.0f) {
00050                 fps = frameCount;
00051                 fpsLimiter = 0.0f;
00052                 frameCount = 0;
00053         }
00054 }
00055 
00056 double Timer::getTime() {
00057         __int64 endClock;
00058         QueryPerformanceCounter((LARGE_INTEGER*)&endClock);
00059         return (double)(endClock-startClock)*frequency;
00060 }
00061 
00062 float Timer::getFrameTime() {
00063         return frameTime;
00064 }
00065 
00066 int Timer::getFPS() {
00067         return fps;
00068 }
00069 
00070 double Timer::getFrequency() {
00071         return frequency;
00072 }

Generated on Sun Jun 5 15:47:05 2005 for Defacto by  doxygen 1.4.3