🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Framerates

Started by
2 comments, last by altair734 24 years, 5 months ago
Does anyone know how to calculate framerates? altair altair734@yahoo.com crawlegend.iwarp.com
altairaltair734@yahoo.comwww.geocities.com/altair734
Advertisement
I created this class to handle fps for debug purposes:

//
// This class is for timeing the game and calculate framrate
//

class CLTIMER {

private:
float timeoffset;
DWORD currenttime, lasttime;
float updatefps;
int fps;
int frames ;

public:
CLTIMER :: CLTIMER() {
updatefps = 0.0f;
fps = 0;
frames = 0;
}

CLTIMER :: ~CLTIMER() {

}

void CLTIMER :: GetTimePassed() {
// if the game just started, set lasttime to the
// current time this prevents the game from
// thinking that several hours have passed from
// the last frame.
if (lasttime == 0) lasttime = timeGetTime();

// get the current time
currenttime = timeGetTime();

// calculate the offset
timeoffset = ((float(currenttime) - lasttime) / 1000);


updatefps += timeoffset;
frames += 1;

if (updatefps >= 0.2f) {
fps = (int)(frames / updatefps);
frames = 0;
updatefps = 0.0f;
}

// put the current time in the lasttime variable
lasttime = currenttime;

}

float CLTIMER :: TimePassed () {
return timeoffset;
}

int CLTIMER :: FrameRate() {
return (int)(fps);
}

};

CLTIMER timer;


Call timer.GetTimePassed() once every frame and when you want the fps just call timer.FrameRate()



The dictionary is the only place where success comes before work.
Death is lifes way saying your fired.
I use this. I got it from realtime strategy game programming book. then use a function for putting text on the screen to view it. The framerate is in the variabel buff.

//FPS/////////////////////////////
static int time = 0;
static int frame = 0;
static int count = 0;
static int timelast = 0;
time = timeGetTime();
count++;
if(time-timelast >= 1000)
{
frame = count;
timelast = time;
count = 0;
}
char buff[40];
itoa(frame, buff,10);
//////////////////////////////////
timeGetTime has very high overheads..bad..

Look up the PerformanceCounter in the MSDN docs.

This topic is closed to new replies.

Advertisement