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

Author Topic: [SOLVED] This concept dosent make sense for me  (Read 1870 times)

0 Members and 1 Guest are viewing this topic.

Nanobyte7

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
[SOLVED] This concept dosent make sense for me
« on: July 01, 2014, 02:37:17 am »
In the SFML 2.0 development book code, I saw this:
Quote
const sf::Time Game::TimePerFrame = sf::seconds(1.f/60.f);

    [...]

    sf::Clock clock;
    sf::Time timeSinceLastUpdate = sf::Time::Zero;
    while (mWindow.isOpen())
    {
        sf::Time elapsedTime = clock.restart();
        timeSinceLastUpdate += elapsedTime;
        while (timeSinceLastUpdate > TimePerFrame)
        {
            timeSinceLastUpdate -= TimePerFrame;

            processEvents();
            update(TimePerFrame);

        }

        updateStatistics(elapsedTime);
        render();
    }

Why would there be a fixed time-step but unlimited fps? When execute my program using this same concept my computer starts making a noise from buffering or displaying everything too fast. Wouldn't it make more sense to just put render in the while loop after update?
« Last Edit: July 02, 2014, 12:29:01 am by Nanobyte7 »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: This concept dosent make sense for me
« Reply #1 on: July 01, 2014, 04:51:24 am »
Rendering once per cycle ensures that the display is only updated with the latest state. The fixed-step loop is to give the program chance to catch up if it's behind.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: This concept dosent make sense for me
« Reply #2 on: July 01, 2014, 07:55:36 am »
The goal of the fixed time step is not to limit the frame rate or has essentially nothing to do with rendering at all. The fixed time step is to get an consistent logic steps. The logic is thus independent from the rendering. If your PC only manages to render with 20 fps, the position calculation won't be effected by that, it will still move the same pixels per second.

Of course running the rendering as fast as possible isn't good, thus you can still use VSync or frame rate limit and since the logic doesn't depend on the FPS anymore, it doesn't matter if it hovers around 60 or so instead of being exactly 60.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nanobyte7

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: This concept dosent make sense for me
« Reply #3 on: July 02, 2014, 12:28:12 am »
Thank you for the explanation! Ill just use .setVerticalSyncEnabled and .setFramerateLimit to not kill my CPU :D

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: [SOLVED] This concept dosent make sense for me
« Reply #4 on: July 02, 2014, 01:51:08 am »
No, not a combination of the two, just one (preferably setVerticalSyncEnabled).