SFML community forums
Help => Window => Topic started by: tester on May 03, 2010, 10:19:27 pm
-
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.
-
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.
-
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.
-
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.
-
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.
-
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)