Jump to content
  • Advertisement
Sign in to follow this  
kelcharge

Limiting Frames Per Second?

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

In my game engine, I would like it to run at a smooth 60 frames per second, but it always seems to be higher than this. How would I limit the number of FPS? I am using Dev-C++ and Allegro.

Share this post


Link to post
Share on other sites
Advertisement
Quote:

...thou shalt not limit your frame rate.
...thou shalt use time based updates.


found carved on stone plaques in during a cave excavation, heed the wisdom of ancient cultures and listen to the message.

Share this post


Link to post
Share on other sites
Quote:
Original post by skittleo
I recommend limiting your framerate, and you will find many games do. They do this because as framerates increases, movement distance decreases per frame and eventually you'll run into floating point errors and things happening that wouldn't normally happen at 60fps.


This is basicly a fallacy. Most games don't and the problems that you mention are easily remedied by using a 'scrap' counter and for physics using a fixed timestep (something you probably want todo anyhow). With that out of the way you can use the extra framerate to react faster to user input handle networking and do loads of stuff that's far better than sitting in a busy wait loop.

Share this post


Link to post
Share on other sites
Agreed, if you really want a fixed framerate, then for heavens sake, don't use a busy idle loop. Either use Sleep(), so other apps can use the leftover CPU time, oro do something with it yourself. You might be able to process input or physics or networking or other stuff while waiting for the next frame (or as DigitalDelusion says,just use a fixed timestep, and the entire game can run at the faster framerate, which will be a lot easier for you to manage)

Share this post


Link to post
Share on other sites
Quote:
Original post by skittleo
Ps: Sorry DigitalDelusion, but I had to disagree. I never used to cap my framerate until I started experiencing precision problems, and then I realized that capping the framerate is pretty common in games.


The inprecision arise because you're taking varied timesteps and will often cause very strange things indeed (like jump distance dependant on framerate etc) so you've correctly identified one problem (varied timesteps) but your solution is to be blunt, crap!

What you really ought todo, and what I've been trying to say all along is that you problaby want something like

delta = scrap + TimeSinceLastFrame();
//handle physics
for(; delta >= timestep; delta -= timestep)
StepPhysics( timestep);
scrap = delta;//save scrap time
//handle input and non time dependant stuff here


this way you keep your physics chugging along nicely and keep it quite deteremnistic while not busy waiting and spending the extra cycles doing real work (like responding to player input)

Share this post


Link to post
Share on other sites
I've been seeing a post about FPS limit at least once a week for some time now.

Try to recycle.
Answered here.

Share this post


Link to post
Share on other sites
Quote:
Original post by skittleo
I already acknowledged that fixed timesteps are a better solution. And it's good that you for providing some sample code to kelcharge. I have used both in my applications, and if you did not provide an example for fixed timesteps, I would have.

That said, my solution is not "blunt crap." I am sorry you became offended when I pushed for a very simple solution. Take it with a grain of salt next time. But it's better than no limit at all.


My main objection is that the solution is hiding a problem instead of solving it, correctly identifying what goes wrong and handling the cause is in my oppinion much more valuble than providing a quick fix in many circumstances.

Maybe my reply was overly rethoric but at a grander scale it did help foster a more throug discussion providing a more solid (although perhaps not as clear cut) answer to the original post.

Share this post


Link to post
Share on other sites
xor, you were extremely helpful in pointing me to that other topic. I can finally get it to stay at 60 FPS.

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!