Original Post
Alright, I'm trying to implement my timing routine in my game engine.. however I'm having some difficulties.
I essentially took the code right out of the GameDev tutorial on high resolution timers, here is the entire cTimer class:
The problem seems to be with the do loop in doTimeB, if I don't comment it out then it appears to be looping contiunously because no action occurs in the game. Whats going on?
[edited by - dovyman on March 15, 2003 4:51:03 PM]
class cTiming {
public:
cTiming::cTiming();
cTiming::~cTiming();
double ftime();
void SetFPS(int x);
void doTimeA();
void doTimeB();
INT64 g_frequency;
INT64 g_count;
float framestart,frameend,frametime,fps;
int framespersecond;
};
cTiming::cTiming()
{
// Get the number of counts per second
QueryPerformanceFrequency( (LARGE_INTEGER*)&g_frequency );
// If the frequency is 0 then this system does not have
// high performance timers
if( g_frequency == 0 )
{
OutputDebugString( "The system does not support high resolution timing" );
// cTiming::~cTiming();
}
}
cTiming::~cTiming()
{
}
double cTiming::ftime()
{
QueryPerformanceCounter((LARGE_INTEGER*)&g_count);
return g_count/g_frequency;
}
void cTiming::doTimeA()
{
framestart=ftime(); // get the first time
// char* time;
// itoa(framestart,time,3);
// OutputDebugString(time);
// OutputDebugString("\n");
}
void cTiming::doTimeB()
{
do
{
// get the time till its not equal to start frame time, it
// should never loop at the rate of this timer, but if it
// does then it will cap to the frame rate to the rate of
// this timer which is 1193180 Hz
frameend=ftime(); // get end of frame time
} while(frameend==framestart);
frametime=frameend-framestart; // find difference to get frametime
framestart=frameend; // make the first time be the next time
// the inverse of frame time is the frame rate
fps=1.0/frametime;
}
void cTiming::SetFPS(int x)
{
framespersecond = x;
}