SFML community forums

Help => General => Topic started by: AndrewB on February 05, 2013, 01:19:02 am

Title: sf::Window::setFramerateLimit vs sf::Clock
Post by: AndrewB 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.
Title: Re: sf::Window::setFramerateLimit vs sf::Clock
Post by: FRex 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());
?
Title: Re: sf::Window::setFramerateLimit vs sf::Clock
Post by: Laurent 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.