Jump to content
  • Advertisement
Sign in to follow this  
Progames25

[solved]Frames Per Second

This topic is 3561 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

Hello, Im using C++ and Direct3D, and am wondering whats the best way to set up the FramesPerSecond for an RPG? Thanks, Progames25 [Edited by - Progames25 on October 26, 2008 7:10:30 PM]

Share this post


Link to post
Share on other sites
Advertisement
Count the number of frames per second. [smile] Or, get the inverse of the time it took to perform a game step and render a frame.

More specifically:
Set up a timer, then start counting frames. When the timer reaches 1.0 second, display how many frames were rendered then reset the counter and the timer.

Share this post


Link to post
Share on other sites
So something like this in Winmain():
DWORD timerstart = GetTickCount();
// PeekMessage
while ((GetTickCount() - timerstart) < 60/*60fps?*/)
{
//show graphics and all that here?
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Progames25
So something like this in Winmain():
DWORD timerstart = GetTickCount();
// PeekMessage
while ((GetTickCount() - timerstart) < 60/*60fps?*/)
{
//show graphics and all that here?
}
Nope, GetTickCount() isn't accurate enough (It's accurate to about 20ms or so), 60ms isn't 60 frames per second, 60FPS would be 1000 / 60 milliseconds (1/60 seconds).

You want something like this (psuedocode):

float FPS = 0;
while(running)
{
float start_time = getTime();
renderFrame();
float end_time = getTime();
FPS = 1.0 / (end_time - start_time);
}

In reality you'd want to averag the results a bit so that little blips in the frame time don't affect your frame rate too much.

Another thing you could do would be:

float FPS = 0;
while(running)
{
int frames = 0;
float start_time = getTime();
do {
renderFrame();
frame++;
} while(getTime() - start_time < 1000); // Loop for 1 second (1000ms)

FPS = frames / (getTime() - start_time);
}


That'll only update the FPS every second, but will smooth out the bumps a lot more. Likewise, change the while() condition to something like 100 to update every 100ms.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!