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

Author Topic: Are there still limitFramesPerSecond() isssues in 2.1?  (Read 4566 times)

0 Members and 1 Guest are viewing this topic.

Jungletoe

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Are there still limitFramesPerSecond() isssues in 2.1?
« 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.


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Are there still limitFramesPerSecond() isssues in 2.1?
« Reply #1 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.
Laurent Gomila - SFML developer

Jungletoe

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Re: Are there still limitFramesPerSecond() isssues in 2.1?
« Reply #2 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?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Are there still limitFramesPerSecond() isssues in 2.1?
« Reply #3 on: August 22, 2013, 11:06:57 pm »
VSync; separate graphics and logic updates.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Are there still limitFramesPerSecond() isssues in 2.1?
« Reply #4 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()?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Are there still limitFramesPerSecond() isssues in 2.1?
« Reply #5 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 ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Are there still limitFramesPerSecond() isssues in 2.1?
« Reply #6 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: Are there still limitFramesPerSecond() isssues in 2.1?
« Reply #7 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Are there still limitFramesPerSecond() isssues in 2.1?
« Reply #8 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?

Jungletoe

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Re: Are there still limitFramesPerSecond() isssues in 2.1?
« Reply #9 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.
« Last Edit: August 23, 2013, 05:35:12 am by Jungletoe »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Are there still limitFramesPerSecond() isssues in 2.1?
« Reply #10 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jungletoe

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Re: Are there still limitFramesPerSecond() isssues in 2.1?
« Reply #11 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!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Are there still limitFramesPerSecond() isssues in 2.1?
« Reply #12 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything