Framerates
Does anyone know how to calculate framerates?
altair
altair734@yahoo.com
crawlegend.iwarp.com
altairaltair734@yahoo.comwww.geocities.com/altair734
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.
//
// 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);
//////////////////////////////////
//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);
//////////////////////////////////
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement