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

Author Topic: sf::Window::setFramerateLimit vs sf::Clock  (Read 2064 times)

0 Members and 1 Guest are viewing this topic.

AndrewB

  • Newbie
  • *
  • Posts: 33
    • View Profile
sf::Window::setFramerateLimit vs sf::Clock
« on: February 05, 2013, 01:19:02 am »
Is there any difference in precision using sf::Window::setFrameLimit compared to using my own sf::clock to limit the frame rate?

Thanks, Andrew.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: sf::Window::setFramerateLimit vs sf::Clock
« Reply #1 on: February 05, 2013, 01:22:17 am »
void Window::display()
{
    // Display the backbuffer on screen
    if (setActive())
        m_context->display();

    // Limit the framerate if needed
    if (m_frameTimeLimit != Time::Zero)
    {
        sleep(m_frameTimeLimit - m_clock.getElapsedTime());
        m_clock.restart();
    }
}


void Window::setFramerateLimit(unsigned int limit)
{
    if (limit > 0)
        m_frameTimeLimit = seconds(1.f / limit);
    else
        m_frameTimeLimit = Time::Zero;

 
No.
Actually, Laurent, why isn't it
sleep(m_frameTimeLimit - m_clock.restart());
?
« Last Edit: February 05, 2013, 01:31:49 am by FRex »
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Window::setFramerateLimit vs sf::Clock
« Reply #2 on: February 05, 2013, 08:10:18 am »
Because it would restart before sleeping, and incorrectly add a little from the previous frame to the next frame time.
Laurent Gomila - SFML developer