Archived

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

elis-cool

Good FPS code...

Recommended Posts

I want my FPS counter to be more accurate, and in most games I see they update the FPS (frames per second, not first person shooter silly ) counter several times per second... how do they do this? averaging ot or something? how would u do this? heres what I am currently using:
  
static DWORD oldTime = 0;
static int FPSnum = 0;
static int fps = 50;

if(timeGetTime() > oldTime)
{	
    fps = FPSnum;
    oldTime = timeGetTime() + 1000;
    FPSnum = 0;
}
else FPSnum++;  
CEO Platoon Studios

Share this post


Link to post
Share on other sites
I THINK that might work. You might want to check out
the article "Frame Rate Independent Movement" under
the game programming section.

http://www.gamedev.net/reference/articles/article1604.asp

Share this post


Link to post
Share on other sites
When you measure the time between two frames (call this delta) you are taking the seconds per frame. Simple maths tells us that if we take the reciprocal (1/x) we''ll get the frames per second.

However if you are doing this when your game is running at 200fps your counter will be jumping all over the place so you will want to average this delta out. The simplest way to do this would be to gather 10 deltas and then find the average delta, 1/x it then display it to the user.

You may find that timeGetTime() doesn''t have a high enough accuracy (you will only get discrete fps values) though so you may want to look into QueryPerformanceCounter() and QueryPerformanceFrequency().

Share this post


Link to post
Share on other sites