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

Author Topic: Framerate Limit not working properly on OSX  (Read 3518 times)

0 Members and 1 Guest are viewing this topic.

posva

  • Full Member
  • ***
  • Posts: 118
  • Feed me pls
    • View Profile
    • Posva Dev Blog
Framerate Limit not working properly on OSX
« on: July 22, 2013, 12:55:30 pm »
Testing the same piece of code on Windows, Linux (ubuntu) and OS X (10.8.4) doesn't have the right FPS on OSX.
Here is the code sample (from base project)

#include <SFML/Graphics.hpp>

// Here is a small helper for you ! Have a look.
#include "ResourcePath.hpp"
#include "FPS.hpp"

int main(int, char const**)
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
    window.setFramerateLimit(60);

    sf::Texture texture;
    if (!texture.loadFromFile(resourcePath() + "cute_image.jpg")) {
        return EXIT_FAILURE;
    }
    sf::Sprite sprite(texture);

    sf::Font font;
    font.loadFromFile(resourcePath()+"sansation.ttf");

    FPS fps(font);
    fps.setColor(sf::Color::Black);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed || (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape))
                window.close();
        }

        window.clear();
        window.draw(sprite);

        fps.step();
        window.draw(fps);

        window.display();
    }

    return EXIT_SUCCESS;
}

This gives a framerate of 57 while it should be 60



The FPS.hpp can be found here
https://gist.github.com/posva/6052868

I created a (rejected) issue here: https://github.com/SFML/SFML/issues/433

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Framerate Limit not working properly on OSX
« Reply #1 on: July 22, 2013, 01:06:59 pm »
window.setFramerateLimit(30); // call it once, after creating the window
Unlike setVerticalSyncEnabled, this feature is implemented by SFML itself, using a combination of sf::Clock and sf::sleep. An important consequence is that it is not 100% reliable, especially for high framerates: sf::sleep's resolution depends on the underlying OS, and can be as high as 10 or 15 milliseconds. Don't rely on this feature to implement precise timing.

sf::sleep can be quite inaccurate. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

posva

  • Full Member
  • ***
  • Posts: 118
  • Feed me pls
    • View Profile
    • Posva Dev Blog
Re: Framerate Limit not working properly on OSX
« Reply #2 on: July 22, 2013, 01:17:39 pm »
Yeah, I know that, I actually tried to hard-code the way SFML2 does the framerate limit to find a workaround.
Still, it's quite annoying having this kind of difference between 2 OS
But thank you for the answer.

Dynamic framerate gives me headache >.<

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Framerate Limit not working properly on OSX
« Reply #3 on: July 22, 2013, 01:44:45 pm »
Quote
Still, it's quite annoying having this kind of difference between 2 OS
You're not using the right tools.

If you want a fixed timestep, read articles about it, there are well known implementations.

If you want a "good" framerate, to avoid huge or tiny update times, and thus potential graphical artifacts, enable vertical synchronization.

In any case, if your code is broken because of +-2 FPS, then it's badly written.
Laurent Gomila - SFML developer

posva

  • Full Member
  • ***
  • Posts: 118
  • Feed me pls
    • View Profile
    • Posva Dev Blog
Re: Framerate Limit not working properly on OSX
« Reply #4 on: July 22, 2013, 02:08:31 pm »
If you want a fixed timestep, read articles about it, there are well known implementations.

Didn't know about that, thank you, I'll search a bit.

If you want a "good" framerate, to avoid huge or tiny update times, and thus potential graphical artifacts, enable vertical synchronization.
That's actually what I do :p But I remeber there were still some OS strange behaviour, I'll recheck this

In any case, if your code is broken because of +-2 FPS, then it's badly written.
No, it's not broken :P
The +-2FPS really change the game when it's FPS fixed :P And dynamic FPS make it even worse

 

anything