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

Author Topic: SetFramerateLimit() problem and custom FPS regulation  (Read 2732 times)

0 Members and 1 Guest are viewing this topic.

Protomancer

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
SetFramerateLimit() problem and custom FPS regulation
« on: July 16, 2012, 05:04:04 pm »
Hello,

I've just recently come across a problem when using the the setFramerateLimit() function. It doesn't set the maximum framerate to the specified value, but rather to the nearest multiple of 50. Other times it sets it to a steady 66 or 57 when given a value of 60. Using vertical sync fixes the issue after 10 seconds of running, but this disables the option of using a custom framerate. I've seen another post where someone has encountered the same problem:
http://en.sfml-dev.org/forums/index.php?topic=8015.msg53582#msg53582
As a solution wasn't found, I made this post to ask about possible fixes. I measured the framerates with 1.0f / App.GetFrameTime(), and double checked with fraps. I really doubt hardware limitations have anything to do with it.
Some additional information: I'm using Visual C++ 2008 Express Edition with SFML 1.6, but the person in the other post was using SFMl 2.0 RC so I don't think the version is at fault. My graphics card is an nvidia Geforce GT 540m, I can provide other specs too if needed. Any input on the topic would be highly appreciated.

However, this is not the main reason I've made this post. As I couldn't realiably use SetFramerateLimit() to manage my fps, I've set up a custom system to manage the FPS of my program:
int main()  {

//Setting up rendering, input management, level manager etc.

sf::Clock RegulatorClock;

float FPSLimit = 60;
float FPSRegulator = FPSLimit;
float Offset = 0.02;

//main game loop
while (App.IsOpened())
{

if(RegulatorClock.GetElapsedTime() > (1.0f / FPSRegulator))
{
                        if ( 1.0 /App.GetFrameTime() < FPSLimit)
                                FPSRegulator += Offset;
                        if ( 1.0 /App.GetFrameTime() > FPSLimit)
                                FPSRegulator -= Offset;

//Everything else in here: Managing input, drawing, displaying, switching levels etc.


RegulatorClock.Reset();
}

}

return EXIT_SUCCES;
}

This method basically just checks every iteration where the current FPS rating is, and modifies it to keep it around FPSLimit.
My questions are these: are there any dangers using this method? Will there be any performance issues because of this? How reliable could it possibly be in the long run? Are there any problems with sf::Clock that would make this function incorrectly?

As i said above, any input would be highly appreciated.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10837
    • View Profile
    • development blog
    • Email
Re: SetFramerateLimit() problem and custom FPS regulation
« Reply #1 on: July 16, 2012, 05:27:40 pm »
It' a known problem but not really a bug. The origin of the problem comes from the limitation of the individual implementaion of the OS sleep function or it's underlying hardware. The sleep functions are only as precicse as 10ms or more, and since the setFramerateLimit only invokes that function nothing much can be done on SFML side.
Nexus has also encountered other 'strange' behaviour when running inside and when running outside of VS:  http://en.sfml-dev.org/forums/index.php?topic=7750.msg52226#msg52226
As he suggests one could try to messure the offset on it's own and increase/decrese the sleep time (which implies having to implement it's own frameeate limiter).

What you're trying to achive in your code puzzels me a bit. If you really just increase the value that gets passed to the update functions then this won't help you at all but only make it worse. E.g. someone runs your game on an old PC and really only gets 25 fps, now you just pretend everything runs at 60 fps which will totally screw up the gameplay because everything would move too fast...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Protomancer

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: SetFramerateLimit() problem and custom FPS regulation
« Reply #2 on: July 16, 2012, 06:05:59 pm »
Thanks for the quick response!
I didn't consider all the possible scenarios with this method. It works perfectly fine if your machine is powerful enough to run at FPSLimit all the time, but as you pointed out, on older machines that can't run at max speed all the time, it'd cause a whole lot of problems.
Thanks again for the input, I'll modify my program to take into account being run on older machines too.

HemoGoblin

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: SetFramerateLimit() problem and custom FPS regulation
« Reply #3 on: July 17, 2012, 06:31:10 pm »
I'm having similar problem but my framerate (set with setFramerateLimit(60U)) is sometimes ~40 FPS while other games are running smoothly. Also, i tried using clock for custom framerate regulation but i had the same problem. Also when i was moving with mouse the framerate was bigger (with unlimited framerate), what can cause this? I tried everything, even without any drawing or updating game state the framerate was still low.
« Last Edit: July 17, 2012, 06:33:04 pm by HemoGoblin »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10837
    • View Profile
    • development blog
    • Email
Re: SetFramerateLimit() problem and custom FPS regulation
« Reply #4 on: July 17, 2012, 06:38:41 pm »
Have read my answer like at all? ::)
It's the same problem.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

HemoGoblin

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: SetFramerateLimit() problem and custom FPS regulation
« Reply #5 on: July 17, 2012, 06:40:47 pm »
Have read my answer like at all? ::)
It's the same problem.
Of course i did.
« Last Edit: July 17, 2012, 06:45:30 pm by HemoGoblin »

 

anything