Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Limit frame rate  (Read 30828 times)

0 Members and 2 Guests are viewing this topic.

Ninjaboi

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • http://www.ninjasoftcorp.webs.com/index.html
Limit frame rate
« on: September 22, 2011, 09:31:39 pm »
Probably a question that's answered somewhere else, but I've been trying to limit the frame rate in an application, and I think I'm having a meltdown with simple math  :oops: .

Code: [Select]
framerate = Window.GetFrameDuration();

if( framerate < (unsigned)( 1 / 60 ) )
{

Window.Wait( ((unsigned)( 1 / 60 ) - framerate) );

}


I'm wanting 60 fps, though I'm not even sure if that is correct to get it. If it is, would changing the value dividing into 1 ( 60 ) to say 30 make the fps 30? I did this fine in SDL ( using a very similar method ) though I'm still new working with SFML. I already saw the tutorial page that talks about handling time.

http://www.sfml-dev.org/tutorials/1.3/window-time.php

Which gave me a way to get the time between frames.

EDIT: I already know about V-Sync, as well as setting the frame limit for a window via SetFramerateLimit(). I'd rather not make the application rely on the refresh rate of the monitor, and I don't want to simply limit what the window displays  8) .

Hope that makes sense  :P .

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Limit frame rate
« Reply #1 on: September 22, 2011, 09:38:23 pm »
This topic has been discussed a lot in this forum, you'll certainly find many posts about it. Words to search for are SetFramerateLimit, Clock and Sleep.

Anyway, sf::Window::SetFramerateLimit() should be exactly what you need. It automatically waits as long as necessary, limiting the frame rate of the whole thread.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ninjaboi

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • http://www.ninjasoftcorp.webs.com/index.html
Limit frame rate
« Reply #2 on: September 22, 2011, 10:07:08 pm »
Thanks for telling me that Nexus, I was under the impression that sf::Window::SetFramerateLimit() only limited the displaying on the window itself. Now I know  :D . I was almost at the point where I was going to use OS specific code for time management just for framerate limiting :twisted: .

 

anything