#### Archived

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

# Good FPS code...

This topic is 5900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
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

##### 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().

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 33
• ### Forum Statistics

• Total Topics
632633
• Total Posts
3007543
• ### Who's Online (See full list)

There are no registered users currently online

×