SFML community forums
Help => Window => Topic started by: Jungletoe on August 22, 2013, 08:37:00 pm
-
I was experimenting a bit with SFML 2.1. Capping the framerate worked fine for a while, but it's noticeably starting to increase a lot at random times.
I can provide a minimal example, although I do not know how to reproduce it. I'm running Windows 7 with Intel Chipset Family graphics.
(http://i.imgur.com/udkXZ98.gif)
-
As stated in the tutorial, it's not a reliable method for precise timing. Use another method.
-
As stated in the tutorial, it's not a reliable method for precise timing. Use another method.
What other methods are there? Timing it myself? If I timed it myself using sf::sleep, wouldn't that cause the same problems that are happening right now?
-
VSync; separate graphics and logic updates.
-
As stated in the tutorial, it's not a reliable method for precise timing. Use another method.
What other methods are there? Timing it myself? If I timed it myself using sf::sleep, wouldn't that cause the same problems that are happening right now?
I know sleep's imprecise, but what's wrong with making a clock and using getElapsedTime and/or the return value of restart()?
-
but what's wrong with making a clock and using getElapsedTime and/or the return value of restart()?
What are you doing while the frame time has not elapsed yet? Busy waiting? Then you have your answer ;)
-
Is there a way to have precise timing as well as non-busy waiting? I assumed sf::sleep being imprecise meant you had to choose one or the other.
-
Is there a way to have precise timing as well as non-busy waiting? I assumed sf::sleep being imprecise meant you had to choose one or the other.
Well yeah:
VSync; separate graphics and logic updates.
For instance something like this (http://gafferongames.com/game-physics/fix-your-timestep/). ;)
-
That post is exactly what I thought you were supposed to do before Nexus called it "busy waiting."
Or is using SFML's clock functions (other than sleep) different from what that post describes?
-
Is this an appropraite way to implement frame independant movement?
float missedFrames;
decimalMovement += modf((delta/frameTime), &missedFrames);
if(decimalMovement > 1.0f)
{
decimalMovement -= 1.0f;
missedFrames += 1.0f;
}
for (int i = 0; i < missedFrames; i++)
{
// draw
}
Edit: I'm an idiot. Fixed.
-
Using VSync, you can avoid busy waiting. I don't really like simple games that use a CPU core to capacity for no reason, heating the room and consuming the laptop battery in no time ;)
You can still separate graphics and logic updates. Keep in mind that with enabled VSync, sf::RenderWindow::display() implicitly waits for the next screen refresh.
Jungletoe, I recommend to read the article linked by eXpl0it3r, it explains pretty well how to manage frame rates.
-
Yeah, I already figured a way how to do it by multiplying the change per second by the delta time. Thanks!
-
I already figured a way how to do it by multiplying the change per second by the delta time.
Read further. This approach has its own problems, for logic updates it is recommended to have a fixed time step.