SFML community forums
Help => Window => Topic started 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?
-
When do you set the framerate limit? Inside the loop?
Could you post some code?
-
Are you on Windows?
-
I am on Windows 7.
I set framelimit just after create my window. Here my code (nothing special):
///////////////////////
// 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
-
Does v-sync (without framerate limit) give a better result?
-
I am on Windows 7.
I set framelimit just after create my window. Here my code (nothing special):
///////////////////////
// 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.
-
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!
-
Does v-sync (without framerate limit) give a better result?
Nope...
Really? What results did you get exactly?
-
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:
//////////////////////////////////////////////
// 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.
-
Are you sure that your FPS class has no bug? :P
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.
-
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?
-
What do you mean by a simple modification?
In the Platform::GetSystemTime() function (src/System/Win32/Platform.cpp), change that
if (UseHighPerformanceTimer)
to that
if (!UseHighPerformanceTimer)
-
OK. I did.
With
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?
-
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?
-
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!
-
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.
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 :)
-
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 :-)
-
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 ;)