Sign in to follow this  
Progames25

[solved]Frames Per Second

Recommended Posts

Progames25    100
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
fastcall22    10838
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
Progames25    100
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
Evil Steve    2017
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this