Sign in to follow this  

SDL: Jumping fps

This topic is 3858 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. Wasn't really sure where to put this, but I think my problem has more to do with SDL than programming in general. When I run my application on my slow computer, the frame rate keeps jumping between 71.4 fps and 83.3 fps. Always those two frame rates, and never the same frame rate two frames in a row. When I run the same application on a faster computer, the frame rate jumps between 250.0 fps and 500.0 fps. Some code:
void Timer::resetTimer()
{
    startTime = SDL_GetTicks();
}

Uint32 Timer::getTime()
{
    return(SDL_GetTicks() - startTime);
}
Each frame I call the functions getTime() and resetTimer() and use the time from getTime() to calculate the frame rate. I know it's normal for the frame rate to change from frame to frame, but when it changes like this I get the feeling something's wrong. Do you have any idea what could cause this? Thanks in advance.

Share this post


Link to post
Share on other sites
How are you calculating your fps? My guess is that it's in the floating point arithmetic. I.e 1000.0f/ticksElapsed if this is how you calculate your fps then the result fps will jump noticably when there's a slight change in ticksElapsed.

Example: ticksElapsed = 10 ==> 100 fps
ticksElapsed = 20 ==> 50 fps

As for more accurate calculation, you can look for higher precision timer.

Share this post


Link to post
Share on other sites

This topic is 3858 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.

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