mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +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::WindowImpl* myImpl; ///< Platform-specific implementation of the window
|
||||||
priv::GlContext* myContext; ///< Platform-specific implementation of the OpenGL context
|
priv::GlContext* myContext; ///< Platform-specific implementation of the OpenGL context
|
||||||
Clock myClock; ///< Clock for measuring the elapsed time between frames
|
Clock myClock; ///< Clock for measuring the elapsed time between frames
|
||||||
unsigned int myFramerateLimit; ///< Current framerate limit
|
Time myFrameTimeLimit; ///< Current framerate limit
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
@ -44,7 +44,7 @@ namespace sf
|
|||||||
Window::Window() :
|
Window::Window() :
|
||||||
myImpl (NULL),
|
myImpl (NULL),
|
||||||
myContext (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) :
|
Window::Window(VideoMode mode, const std::string& title, Uint32 style, const ContextSettings& settings) :
|
||||||
myImpl (NULL),
|
myImpl (NULL),
|
||||||
myContext (NULL),
|
myContext (NULL),
|
||||||
myFramerateLimit(0)
|
myFrameTimeLimit(Time::Zero)
|
||||||
{
|
{
|
||||||
Create(mode, title, style, settings);
|
Create(mode, title, style, settings);
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ myFramerateLimit(0)
|
|||||||
Window::Window(WindowHandle handle, const ContextSettings& settings) :
|
Window::Window(WindowHandle handle, const ContextSettings& settings) :
|
||||||
myImpl (NULL),
|
myImpl (NULL),
|
||||||
myContext (NULL),
|
myContext (NULL),
|
||||||
myFramerateLimit(0)
|
myFrameTimeLimit(Time::Zero)
|
||||||
{
|
{
|
||||||
Create(handle, settings);
|
Create(handle, settings);
|
||||||
}
|
}
|
||||||
@ -308,23 +308,26 @@ bool Window::SetActive(bool active) const
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void Window::Display()
|
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
|
// Display the backbuffer on screen
|
||||||
if (SetActive())
|
if (SetActive())
|
||||||
myContext->Display();
|
myContext->Display();
|
||||||
|
|
||||||
|
// Limit the framerate if needed
|
||||||
|
if (myFrameTimeLimit != Time::Zero)
|
||||||
|
{
|
||||||
|
Sleep(myFrameTimeLimit - myClock.GetElapsedTime());
|
||||||
|
myClock.Restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void Window::SetFramerateLimit(unsigned int limit)
|
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