Jump to content
  • Advertisement


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.

If you intended to correct an error in the post then please contact us.

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.


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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!