Improved the performances of Window::getSize() (the size is now cached)
This commit is contained in:
parent
7c9f9cc41c
commit
da96ec5811
@ -473,6 +473,7 @@ private:
|
||||
priv::GlContext* m_context; ///< Platform-specific implementation of the OpenGL context
|
||||
Clock m_clock; ///< Clock for measuring the elapsed time between frames
|
||||
Time m_frameTimeLimit; ///< Current framerate limit
|
||||
Vector2u m_size; ///< Current size of the window
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
@ -44,7 +44,8 @@ namespace sf
|
||||
Window::Window() :
|
||||
m_impl (NULL),
|
||||
m_context (NULL),
|
||||
m_frameTimeLimit(Time::Zero)
|
||||
m_frameTimeLimit(Time::Zero),
|
||||
m_size (0, 0)
|
||||
{
|
||||
|
||||
}
|
||||
@ -54,7 +55,8 @@ m_frameTimeLimit(Time::Zero)
|
||||
Window::Window(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings) :
|
||||
m_impl (NULL),
|
||||
m_context (NULL),
|
||||
m_frameTimeLimit(Time::Zero)
|
||||
m_frameTimeLimit(Time::Zero),
|
||||
m_size (0, 0)
|
||||
{
|
||||
create(mode, title, style, settings);
|
||||
}
|
||||
@ -64,7 +66,8 @@ m_frameTimeLimit(Time::Zero)
|
||||
Window::Window(WindowHandle handle, const ContextSettings& settings) :
|
||||
m_impl (NULL),
|
||||
m_context (NULL),
|
||||
m_frameTimeLimit(Time::Zero)
|
||||
m_frameTimeLimit(Time::Zero),
|
||||
m_size (0, 0)
|
||||
{
|
||||
create(handle, settings);
|
||||
}
|
||||
@ -223,7 +226,7 @@ void Window::setPosition(const Vector2i& position)
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2u Window::getSize() const
|
||||
{
|
||||
return m_impl ? m_impl->getSize() : Vector2u();
|
||||
return m_size;
|
||||
}
|
||||
|
||||
|
||||
@ -365,7 +368,14 @@ bool Window::filterEvent(const Event& event)
|
||||
{
|
||||
// Notify resize events to the derived class
|
||||
if (event.type == Event::Resized)
|
||||
{
|
||||
// Cache the new size
|
||||
m_size.x = event.size.width;
|
||||
m_size.y = event.size.height;
|
||||
|
||||
// Notify the derived class
|
||||
onResize();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -380,6 +390,9 @@ void Window::initialize()
|
||||
setVerticalSyncEnabled(false);
|
||||
setKeyRepeatEnabled(true);
|
||||
|
||||
// Get and cache the initial size of the window
|
||||
m_size = m_impl->getSize();
|
||||
|
||||
// Reset frame time
|
||||
m_clock.restart();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user