SFML community forums

Help => Window => Topic started by: Jungletoe on August 22, 2013, 08:37:00 pm

Title: Are there still limitFramesPerSecond() isssues in 2.1?
Post 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)
Title: Re: Are there still limitFramesPerSecond() isssues in 2.1?
Post by: Laurent on August 22, 2013, 09:14:34 pm
As stated in the tutorial, it's not a reliable method for precise timing. Use another method.
Title: Re: Are there still limitFramesPerSecond() isssues in 2.1?
Post by: Jungletoe on August 22, 2013, 11:03:43 pm
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?
Title: Re: Are there still limitFramesPerSecond() isssues in 2.1?
Post by: Nexus on August 22, 2013, 11:06:57 pm
VSync; separate graphics and logic updates.
Title: Re: Are there still limitFramesPerSecond() isssues in 2.1?
Post by: Ixrec on August 22, 2013, 11:08:48 pm
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()?
Title: Re: Are there still limitFramesPerSecond() isssues in 2.1?
Post by: Nexus on August 22, 2013, 11:15:05 pm
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 ;)
Title: Re: Are there still limitFramesPerSecond() isssues in 2.1?
Post by: Ixrec on August 22, 2013, 11:31:36 pm
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.
Title: Re: Are there still limitFramesPerSecond() isssues in 2.1?
Post by: eXpl0it3r on August 23, 2013, 01:01:59 am
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/). ;)
Title: Re: Are there still limitFramesPerSecond() isssues in 2.1?
Post by: Ixrec on August 23, 2013, 01:44:40 am
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?
Title: Re: Are there still limitFramesPerSecond() isssues in 2.1?
Post by: Jungletoe on August 23, 2013, 02:22:21 am
Is this an appropraite way to implement frame independant movement?

Code: [Select]
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.
Title: Re: Are there still limitFramesPerSecond() isssues in 2.1?
Post by: Nexus on August 23, 2013, 10:55:31 am
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.
Title: Re: Are there still limitFramesPerSecond() isssues in 2.1?
Post by: Jungletoe on August 23, 2013, 03:15:11 pm
Yeah, I already figured a way how to do it by multiplying the change per second by the delta time. Thanks!
Title: Re: Are there still limitFramesPerSecond() isssues in 2.1?
Post by: Nexus on August 23, 2013, 03:33:26 pm
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.