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

Author Topic: Question about Window::SetFramerateLimit and Window::Display  (Read 3460 times)

0 Members and 1 Guest are viewing this topic.

tester

  • Newbie
  • *
  • Posts: 17
    • View Profile
I looked into the source code to check how the framerate limit works. And I saw that if a framerate is set, the Display function simply calls the Sleep function. And the Sleep function, in Windows, is a wrapper to the WinAPI Sleep function.
Now my question: Isn't that some kind of a hack? I mean, Sleep doesn't just suspend the graphic output inside the window, it suspends the whole application. So, let's say, to demonstrate the case, I program a game with one frame per second: I would expect the gaming screen to update once per second. But I would expect the window itself (resizing, moving, minimizing, closing etc.) to work as usual. But instead, of course, it only works once per second.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Question about Window::SetFramerateLimit and Window::Display
« Reply #1 on: May 03, 2010, 10:35:40 pm »
The framerate limit is not meant to use with such values as 1 frame per second. SFML and all its functions are designed for real-time applications.

You have to use other techniques of your own to achieve what you want.
Laurent Gomila - SFML developer

tester

  • Newbie
  • *
  • Posts: 17
    • View Profile
Question about Window::SetFramerateLimit and Window::Display
« Reply #2 on: May 03, 2010, 11:50:37 pm »
This was just an example. I wanted to illustrate that it's a hack to use Sleep for a framerate limit because Sleep is meant to stop the whole thread. Even if in practice it's just some milliseconds, the GUI and the game screen are logically two different things. And if you want to stop the game screen, you should still not stop the GUI.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Question about Window::SetFramerateLimit and Window::Display
« Reply #3 on: May 04, 2010, 12:36:59 am »
You can't stop one thing and not another if they both are executed in the same thread. There's no magical solution.

And most of the time, the framerate limit is used especially to make the application sleep and save CPU usage. What you have in mind is clearly not what SetFramerateLimit is made for, so just ignore it.
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Question about Window::SetFramerateLimit and Window::Display
« Reply #4 on: May 11, 2010, 01:13:30 pm »
In older games the framerate is synched with the input and you have 'frames of execution' so I don't see how this is different.

If you want the game to animate slower like slow motion and retain the framerate you need to edit your animation code.

petersvp

  • Newbie
  • *
  • Posts: 6
    • View Profile
Question about Window::SetFramerateLimit and Window::Display
« Reply #5 on: June 08, 2010, 09:45:57 pm »
If you want to render a game only on 1 FPS, you can call display every 1 secong, getEvent() otherwise. Use cf::clock

Look at the following code snippet for illustration:

cf::Clock cl1;
float secs=1;

 if(cl1.GetElapsedTime()>=secs)
        {
            render your frame here;
            secs++;
        }
else game_window->GetEvent(e)