Skip to main content
gamedev.net
🔒 Locked

Good FPS code...

Started by elis-cool Jul 30, 2002 at 5:09 AM 2 replies 350+ views
Original Post
elis-cool
elis-cool
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
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
vrihai
vrihai
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
elis-cool
elis-cool
i know all about frame rate intependent movement and everything, but the code I have only updates it once per second, and so is not very accurate...

CEO Platoon Studios
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
Kazan
Kazan
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().

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.