Archived

This topic is now archived and is closed to further replies.

Benzy54

help with framerate

Recommended Posts

Framerate is the number of frames rendered per unit of time. Every time you draw a frame, you increment a count of the number of frames drawn. Then you let some new quantity equal the number of frames drawn divided by how long the program has been running for.

However, if you do it that way, you only get the average framerate over the entire run of the program, which means it is generally slower than the instantaneous framerate because it includes the time spent loading resources. For a more practical way to determine framerate, you should reset your counters every three seconds or so. That way, you can get information about framerate drops or increases when they actually happen.

Here''s an example with C++ code:


// Updates the timer.

void UpdateTimer(void)
{
static DWORD previousTime = GetTickCount();
static DWORD recentTime = 0.0;
static int recentFrames = 0;

elapsedTime = GetTickCount() - previousTime;
timeRatio = Ratio((float)elapsedTime, timeRate);
previousTime = GetTickCount();
recentTime += (double)elapsedTime;
totalTime += (elapsedTime / 1000.0);

// Reset the frames-per-second display every three seconds.

if(recentTime > 3000.0)
{
currentFPS = recentFrames / (recentTime / 1000.0);
recentTime = 0.0;
recentFrames = 0.0;
}

recentFrames++;
totalFrames++;
}


"Last time, I asked: ''What does mathematics mean to you?'' And some people answered: ''The manipulation of numbers, the manipulation of structures.'' And if I had asked what music means to you, would you have answered: ''The manipulation of notes?''" - S. Lang

Share this post


Link to post
Share on other sites