Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


[SDL] Frame Limiting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 _Zac_   Members   -  Reputation: 138

Like
0Likes
Like

Posted 04 January 2012 - 01:33 AM

Alright, I know Frame Limiting is something that's brought up a lot, but my question is how do I do it accurately.

I've noticed that my display surface somehow never gets double-buffered, so I'm trying to find another way. Considering that 1000/60 is a decimal while SDL_GetTicks() is an integer, it's extremely hard to get an accurate 60 FPS.

So far I've tried waiting for 16ms one frame, then 17ms the next two and just repeating this cycle (updating the average every 3 frames of course). (16+17+17)/3=16.666... but my FPS calculator keeps detecting 60.049 FPS this way.

I've also tried creating a float and after waiting the desired amount of milliseconds doing while((Uint32)NextTick<=SDL_GetTicks())NextTick+=1000.0f/60.0f; Usually with the same results but with a less stable framerate.

So either my FPS counter is wrong and I'm getting 60 FPS (sometimes dipping) or I can't really get more accurate than 60.049 FPS +or-0.1

What would be the most accurate way to achieve 60 FPS without double buffering?

Sponsor:

#2 Deprecated   Members   -  Reputation: 107

Like
0Likes
Like

Posted 04 January 2012 - 10:29 AM

I asked about the same question yesterday, you can find the answer I got here (http://www.gamedev.net/topic/617960-how-to-handle-update-rate/page__view__findpost__p__4899430).

But to be honest, you're trying to get 60 FPS and you've got it already. You will never get exactly 60 FPS (unless casting to int) for 2 reasons.

1) (I'm assuming) you're not in total control of the system you're running on. Your application probably wont get 100% of the CPU time, at the very least the OS will keep some to render your desktop, move your mouse etc.

2) You're not in total control of the code. What if SDL_GetTicks() takes about 1 ms to generate the answer? As SDL_GetTicks() is part of your frame limiting you'll always be a little off. Same goes for variable assignment, addition, division, increment, if/loop -statements.
Those who can do, do; those who can't do, do teach.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS