SFML community forums

Help => Window => Topic started by: panithadrum on November 04, 2009, 10:48:18 pm

Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: panithadrum 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?
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: Nexus on November 04, 2009, 11:19:06 pm
When do you set the framerate limit? Inside the loop?

Could you post some code?
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: Laurent on November 04, 2009, 11:22:24 pm
Are you on Windows?
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: panithadrum 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
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: Laurent on November 05, 2009, 12:00:45 am
Does v-sync (without framerate limit) give a better result?
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: OniLinkPlus 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.
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: panithadrum 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!
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: Laurent 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?
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: panithadrum 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.
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: Laurent 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.
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: panithadrum 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?
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: Laurent 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)
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: panithadrum 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?
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: Laurent 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?
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: panithadrum 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!
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: Laurent on November 07, 2009, 01:46:50 pm
Quote
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.

This function has a very low resolution, so it's not very surprising.

Quote
Think that Ogre's implementation works fine?

That's what people say, at least. They also say that it's not a perfect workaround, but it seems to be enough. This workaround was implemented a long time ago and not modified since then, so I guess it's robust enough :)
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: panithadrum on November 07, 2009, 03:09:12 pm
Great then. You are doing a pretty nice work.

Do you have some kind of blog or site with personal info? I would like to know who you are :-)
Title: Strange behavior using sf::RenderWindow::SetFramerateLimit()
Post by: Laurent on November 07, 2009, 03:32:08 pm
Quote
Do you have some kind of blog or site with personal info? I would like to know who you are

No. I you Google me you'll only find a few old, crappy websites ;)