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

Author Topic: Strange behavior using sf::RenderWindow::SetFramerateLimit()  (Read 6213 times)

0 Members and 1 Guest are viewing this topic.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« on: November 04, 2009, 10:48:18 pm »
I noticed time ago that sf::RenderWindow::SetFramerateLimit() doesn't work at all. If you put a value of 30, the frame limit goes to 27. If you put 300, it goes to 360 or something.

Also, and that's what I want you to know, my frame rate changes while I move the mouse. When no move is going on, the framerate stays at a number.

It's only me?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6259
  • Thor Developer
    • View Profile
    • Bromeon
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #1 on: November 04, 2009, 11:19:06 pm »
When do you set the framerate limit? Inside the loop?

Could you post some code?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: first SFML book

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32502
    • View Profile
    • SFML's website
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #2 on: November 04, 2009, 11:22:24 pm »
Are you on Windows?
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #3 on: November 04, 2009, 11:57:06 pm »
I am on Windows 7.
I set framelimit just after create my window. Here my code (nothing special):
Code: [Select]
///////////////////////
// Window
///////////////////////
// sf::RenderWindow
sf::RenderWindow sf_window;
// Set window name
{
std::stringstream name;
name << "The dead walk v" << GAME_VERSION_MAJOR << "." << GAME_VERSION_MINOR;
sf_window.Create(sf::VideoMode(320, 240, 16), name.str(), sf::Style::Close);
}
// Some properties
sf_window.UseVerticalSync(true);
sf_window.SetFramerateLimit(60);
sf_window.EnableKeyRepeat(false);


BTW, SetFramelimitRate works the same with/without VSync

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32502
    • View Profile
    • SFML's website
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #4 on: November 05, 2009, 12:00:45 am »
Does v-sync (without framerate limit) give a better result?
Laurent Gomila - SFML developer

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #5 on: November 05, 2009, 12:01:21 am »
Quote from: "panithadrum"
I am on Windows 7.
I set framelimit just after create my window. Here my code (nothing special):
Code: [Select]
///////////////////////
// Window
///////////////////////
// sf::RenderWindow
sf::RenderWindow sf_window;
// Set window name
{
std::stringstream name;
name << "The dead walk v" << GAME_VERSION_MAJOR << "." << GAME_VERSION_MINOR;
sf_window.Create(sf::VideoMode(320, 240, 16), name.str(), sf::Style::Close);
}
// Some properties
sf_window.UseVerticalSync(true);
sf_window.SetFramerateLimit(60);
sf_window.EnableKeyRepeat(false);

BTW, SetFramelimitRate works the same with/without VSync
please post a complete and minimal example showing the error.
I use the latest build of SFML2

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #6 on: November 05, 2009, 12:06:24 am »
Quote from: "Laurent"
Does v-sync (without framerate limit) give a better result?

Nope...

@OniLink10:
I will post the code minimal code tomorrow, I'm going to the bed now :-)

Good night!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32502
    • View Profile
    • SFML's website
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #7 on: November 05, 2009, 12:18:23 am »
Quote from: "panithadrum"
Quote from: "Laurent"
Does v-sync (without framerate limit) give a better result?

Nope...

Really? What results did you get exactly?
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #8 on: November 05, 2009, 11:53:20 am »
Seems that VSync doesn't work for my computer. It is pretty old, a portable Sony Vaio. I can't use PostFX too.

So SetFramerateLimit still doesn't work... here is the minimal code:
Code: [Select]
//////////////////////////////////////////////
// Include
//////////////////////////////////////////////
#include <sfml/graphics.hpp>
#include <sstream>
#include "fps.h" // This is from the FPS example in the wiki

//////////////////////////////////////////////
// Main
//////////////////////////////////////////////
int main()
{
///////////////////////
// Window
///////////////////////
// sf::RenderWindow
sf::RenderWindow sf_window;
sf_window.Create(sf::VideoMode(320, 240, 16), "Caca", sf::Style::Close);
// Some properties
sf_window.UseVerticalSync(true);// Doesn't work for my computer...
sf_window.SetFramerateLimit(20);
// FPS
FPS fps;
///////////////////////
// Loop
///////////////////////
bool game_close = false;
while(!game_close)
{
///////////////////////
// Events
///////////////////////
{
sf::Event sf_event;
while(sf_window.GetEvent(sf_event))
{
// Window close event
if (sf_event.Type == sf::Event::Closed)
game_close = true;
}
}

///////////////////////
// Update
///////////////////////
fps.Update();

///////////////////////
// Clear
///////////////////////
sf_window.Clear();

///////////////////////
// Draw
///////////////////////
// FPS
{
// std::stringstream
std::stringstream stringstream;
                        // Two ways to get current FPS
stringstream << static_cast<int>(1/sf_window.GetFrameTime());
//stringstream << fps.GetFPS();
// sf::String
sf::String sf_string(stringstream.str());
sf_string.SetPosition(100, 5);
sf_string.SetSize(20);
sf_string.SetColor(sf::Color::White);
// Draw sf::String
sf_window.Draw(sf_string);
}

///////////////////////
// Display
///////////////////////
sf_window.Display();
}
}


FPS changes a little when I move my mouse lol
Maybe it's my old computers fault!

Anyway, SetFramerateLimit doesn't work properly in any of my computers. I think I saw something related in this forums already.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32502
    • View Profile
    • SFML's website
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #9 on: November 05, 2009, 02:27:29 pm »
Are you sure that your FPS class has no bug? :P

Quote
Anyway, SetFramerateLimit doesn't work properly in any of my computers. I think I saw something related in this forums already.

Yup. The timing function on Windows might be broken sometimes; in one of the topics related to this I asked people having this problem to try a simple modification, but never got feedback.
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #10 on: November 06, 2009, 05:55:25 pm »
Hmm I tried to get the current FPS using 1/sf::Window::GetElapsedTime() and using the wiki FPS class. It's almost the same, lol.

Maybe it's Windows fault... What do you mean by a simple modification?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32502
    • View Profile
    • SFML's website
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #11 on: November 06, 2009, 06:47:20 pm »
Quote
What do you mean by a simple modification?

In the Platform::GetSystemTime() function (src/System/Win32/Platform.cpp), change that
Code: [Select]
if (UseHighPerformanceTimer)
to that
Code: [Select]
if (!UseHighPerformanceTimer)
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #12 on: November 06, 2009, 07:37:58 pm »
OK. I did.

With
Code: [Select]
if (!UseHighPerformanceTimer)
FPS stays in place, even if I move my mouse.

Anyway, the FPS I get is slightly different from the value I put in sf::Window::SetFramerateLimit(). Windows OS fault too?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32502
    • View Profile
    • SFML's website
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #13 on: November 06, 2009, 08:01:30 pm »
Quote
Anyway, the FPS I get is slightly different from the value I put in sf::Window::SetFramerateLimit(). Windows OS fault too?

The other timing function is less accurate, so I guess it's normal. What difference did you get?
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Strange behavior using sf::RenderWindow::SetFramerateLimit()
« Reply #14 on: November 07, 2009, 01:41:14 pm »
I got this using the less accurate timing function as you told me (without VSync).

If SetFramerateLimit(20), then FPS = 19.
(19/20 = 0,95)
If SetFramerateLimit(30), then FPS = 25.
(25/30 = 0,8333333333333333)
If SetFramerateLimit(60), then FPS = 50.
(50/60 = 0,8333333333333333)
If SetFramerateLimit(100), then FPS = 100.
(100/100 = 1)
If SetFramerateLimit(130), then FPS = 100.
(100/130 = 0,7692307692307692)
If SetFramerateLimit(150), then FPS = 100.
(100/150 = 0,6666666666666667)
If SetFramerateLimit(200), then FPS = 100.
(100/200 = 0,5)

...

Hmm, I can't see any pattern here. It just gets stuck at 100 FPS. If I don't put any SetFramerateLimit my FPS goes to 250 more or less.

Think that Ogre's implementation works fine? I never tried it!

 

anything