mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 15:51:04 +08:00
Fixed Window::SetFramerateLimit
This commit is contained in:
parent
feae26e15b
commit
84d75ed487
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user