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
|
priv::GlContext* m_context; ///< Platform-specific implementation of the OpenGL context
|
||||||
Clock m_clock; ///< Clock for measuring the elapsed time between frames
|
Clock m_clock; ///< Clock for measuring the elapsed time between frames
|
||||||
Time m_frameTimeLimit; ///< Current framerate limit
|
Time m_frameTimeLimit; ///< Current framerate limit
|
||||||
|
Vector2u m_size; ///< Current size of the window
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
@ -44,7 +44,8 @@ namespace sf
|
|||||||
Window::Window() :
|
Window::Window() :
|
||||||
m_impl (NULL),
|
m_impl (NULL),
|
||||||
m_context (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) :
|
Window::Window(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings) :
|
||||||
m_impl (NULL),
|
m_impl (NULL),
|
||||||
m_context (NULL),
|
m_context (NULL),
|
||||||
m_frameTimeLimit(Time::Zero)
|
m_frameTimeLimit(Time::Zero),
|
||||||
|
m_size (0, 0)
|
||||||
{
|
{
|
||||||
create(mode, title, style, settings);
|
create(mode, title, style, settings);
|
||||||
}
|
}
|
||||||
@ -64,7 +66,8 @@ m_frameTimeLimit(Time::Zero)
|
|||||||
Window::Window(WindowHandle handle, const ContextSettings& settings) :
|
Window::Window(WindowHandle handle, const ContextSettings& settings) :
|
||||||
m_impl (NULL),
|
m_impl (NULL),
|
||||||
m_context (NULL),
|
m_context (NULL),
|
||||||
m_frameTimeLimit(Time::Zero)
|
m_frameTimeLimit(Time::Zero),
|
||||||
|
m_size (0, 0)
|
||||||
{
|
{
|
||||||
create(handle, settings);
|
create(handle, settings);
|
||||||
}
|
}
|
||||||
@ -223,7 +226,7 @@ void Window::setPosition(const Vector2i& position)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vector2u Window::getSize() const
|
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
|
// Notify resize events to the derived class
|
||||||
if (event.type == Event::Resized)
|
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();
|
onResize();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -380,6 +390,9 @@ void Window::initialize()
|
|||||||
setVerticalSyncEnabled(false);
|
setVerticalSyncEnabled(false);
|
||||||
setKeyRepeatEnabled(true);
|
setKeyRepeatEnabled(true);
|
||||||
|
|
||||||
|
// Get and cache the initial size of the window
|
||||||
|
m_size = m_impl->getSize();
|
||||||
|
|
||||||
// Reset frame time
|
// Reset frame time
|
||||||
m_clock.restart();
|
m_clock.restart();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user