Jump to content
  • Advertisement
Sign in to follow this  
n99b

SDL: Jumping fps

This topic is 4073 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
Advertisement
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
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!