From 84d75ed487ff4021b61b21e6a14c05180eee820a Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Tue, 31 Jan 2012 07:53:02 +0100 Subject: [PATCH] Fixed Window::SetFramerateLimit --- include/SFML/Window/Window.hpp | 2 +- src/SFML/Window/Window.cpp | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/SFML/Window/Window.hpp b/include/SFML/Window/Window.hpp index 4272d6f4..573e289f 100644 --- a/include/SFML/Window/Window.hpp +++ b/include/SFML/Window/Window.hpp @@ -462,7 +462,7 @@ private : priv::WindowImpl* myImpl; ///< Platform-specific implementation of the window priv::GlContext* myContext; ///< Platform-specific implementation of the OpenGL context Clock myClock; ///< Clock for measuring the elapsed time between frames - unsigned int myFramerateLimit; ///< Current framerate limit + Time myFrameTimeLimit; ///< Current framerate limit }; } // namespace sf diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 5c9eb00a..741dd964 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -44,7 +44,7 @@ namespace sf Window::Window() : myImpl (NULL), myContext (NULL), -myFramerateLimit(0) +myFrameTimeLimit(Time::Zero) { } @@ -54,7 +54,7 @@ myFramerateLimit(0) Window::Window(VideoMode mode, const std::string& title, Uint32 style, const ContextSettings& settings) : myImpl (NULL), myContext (NULL), -myFramerateLimit(0) +myFrameTimeLimit(Time::Zero) { Create(mode, title, style, settings); } @@ -64,7 +64,7 @@ myFramerateLimit(0) Window::Window(WindowHandle handle, const ContextSettings& settings) : myImpl (NULL), myContext (NULL), -myFramerateLimit(0) +myFrameTimeLimit(Time::Zero) { Create(handle, settings); } @@ -308,23 +308,26 @@ bool Window::SetActive(bool active) const //////////////////////////////////////////////////////////// void Window::Display() { - // Limit the framerate if needed - if (myFramerateLimit > 0) - { - Time remainingTime = Seconds(1.f / myFramerateLimit) - myClock.Restart(); - Sleep(remainingTime); - } - // Display the backbuffer on screen if (SetActive()) myContext->Display(); + + // Limit the framerate if needed + if (myFrameTimeLimit != Time::Zero) + { + Sleep(myFrameTimeLimit - myClock.GetElapsedTime()); + myClock.Restart(); + } } //////////////////////////////////////////////////////////// void Window::SetFramerateLimit(unsigned int limit) { - myFramerateLimit = limit; + if (limit > 0) + myFrameTimeLimit = Seconds(1.f / limit); + else + myFrameTimeLimit = Time::Zero; }