Utility/Window: Replace NAZARA_UTILITY_THREADED_WINDOW by a runtime flag (WIP)
This commit is contained in:
@@ -38,9 +38,6 @@
|
||||
// Lors du parsage d'une ressource, déclenche un avertissement si une erreur non-critique est repérée dans une ressource (Plus lent)
|
||||
#define NAZARA_UTILITY_STRICT_RESOURCE_PARSING 1
|
||||
|
||||
// Fait tourner chaque fenêtre dans un thread séparé si le système le supporte
|
||||
#define NAZARA_UTILITY_THREADED_WINDOW 0
|
||||
|
||||
// Protège les classes des accès concurrentiels
|
||||
//#define NAZARA_UTILITY_THREADSAFE 1
|
||||
|
||||
|
||||
@@ -432,12 +432,14 @@ namespace Nz
|
||||
|
||||
enum WindowStyleFlags
|
||||
{
|
||||
WindowStyle_None = 0x0,
|
||||
WindowStyle_Fullscreen = 0x1,
|
||||
WindowStyle_None = 0x0, ///< Window has no border nor titlebar.
|
||||
WindowStyle_Fullscreen = 0x1, ///< At the window creation, the OS tries to set it in fullscreen.
|
||||
|
||||
WindowStyle_Closable = 0x2,
|
||||
WindowStyle_Resizable = 0x4,
|
||||
WindowStyle_Titlebar = 0x8,
|
||||
WindowStyle_Closable = 0x2, ///< Allows the window to be closed by a button in the titlebar, generating a Quit event.
|
||||
WindowStyle_Resizable = 0x4, ///< Allows the window to be resized by dragging its corners or by a button of the titlebar.
|
||||
WindowStyle_Titlebar = 0x8, ///< Adds a titlebar to the window, this option is automatically enabled if buttons of the titlebar are enabled.
|
||||
|
||||
WindowStyle_Threaded = 0x10, ///< Runs the window into a thread, allowing the application to keep updating while resizing/dragging the window.
|
||||
|
||||
WindowStyle_Default = WindowStyle_Closable | WindowStyle_Resizable | WindowStyle_Titlebar,
|
||||
WindowStyle_Max = WindowStyle_Titlebar*2-1
|
||||
|
||||
@@ -24,6 +24,9 @@ namespace Nz
|
||||
|
||||
inline void Dispatch(const WindowEvent& event);
|
||||
|
||||
EventHandler& operator=(const EventHandler&) = delete;
|
||||
EventHandler& operator=(EventHandler&&) = default;
|
||||
|
||||
NazaraSignal(OnEvent, const EventHandler* /*eventHandler*/, const WindowEvent& /*event*/);
|
||||
NazaraSignal(OnGainedFocus, const EventHandler* /*eventHandler*/);
|
||||
NazaraSignal(OnLostFocus, const EventHandler* /*eventHandler*/);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#define NAZARA_WINDOW_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ConditionVariable.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
@@ -19,11 +21,6 @@
|
||||
#include <Nazara/Utility/WindowHandle.hpp>
|
||||
#include <queue>
|
||||
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
#include <Nazara/Core/ConditionVariable.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Cursor;
|
||||
@@ -114,23 +111,24 @@ namespace Nz
|
||||
|
||||
private:
|
||||
void IgnoreNextMouseEvent(int mouseX, int mouseY) const;
|
||||
inline void HandleEvent(const WindowEvent& event);
|
||||
inline void PushEvent(const WindowEvent& event);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
std::queue<WindowEvent> m_events;
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
std::vector<WindowEvent> m_pendingEvents;
|
||||
ConditionVariable m_eventCondition;
|
||||
EventHandler m_eventHandler;
|
||||
Mutex m_eventMutex;
|
||||
Mutex m_eventConditionMutex;
|
||||
bool m_waitForEvent;
|
||||
#endif
|
||||
EventHandler m_eventHandler;
|
||||
bool m_asyncWindow;
|
||||
bool m_closed;
|
||||
bool m_closeOnQuit;
|
||||
bool m_eventPolling;
|
||||
bool m_ownsWindow;
|
||||
bool m_waitForEvent;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Core/LockGuard.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
@@ -13,11 +14,10 @@ namespace Nz
|
||||
*/
|
||||
inline Window::Window() :
|
||||
m_impl(nullptr),
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
m_waitForEvent(false),
|
||||
#endif
|
||||
m_asyncWindow(false),
|
||||
m_closeOnQuit(true),
|
||||
m_eventPolling(false)
|
||||
m_eventPolling(false),
|
||||
m_waitForEvent(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -41,16 +41,16 @@ namespace Nz
|
||||
inline Window::Window(Window&& window) noexcept :
|
||||
m_impl(window.m_impl),
|
||||
m_events(std::move(window.m_events)),
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
m_pendingEvents(std::move(window.m_pendingEvents)),
|
||||
m_eventCondition(std::move(window.m_eventCondition)),
|
||||
m_eventHandler(std::move(window.m_eventHandler)),
|
||||
m_eventMutex(std::move(window.m_eventMutex)),
|
||||
m_eventConditionMutex(std::move(window.m_eventConditionMutex)),
|
||||
m_waitForEvent(window.m_waitForEvent),
|
||||
#endif
|
||||
m_closed(window.m_closed),
|
||||
m_closeOnQuit(window.m_closeOnQuit),
|
||||
m_eventPolling(window.m_eventPolling),
|
||||
m_ownsWindow(window.m_ownsWindow)
|
||||
m_ownsWindow(window.m_ownsWindow),
|
||||
m_waitForEvent(window.m_waitForEvent)
|
||||
{
|
||||
window.m_impl = nullptr;
|
||||
}
|
||||
@@ -104,12 +104,8 @@ namespace Nz
|
||||
return m_impl != nullptr;
|
||||
}
|
||||
|
||||
inline void Window::PushEvent(const WindowEvent& event)
|
||||
inline void Window::HandleEvent(const WindowEvent& event)
|
||||
{
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
m_eventMutex.Lock();
|
||||
#endif
|
||||
|
||||
if (m_eventPolling)
|
||||
m_events.push(event);
|
||||
|
||||
@@ -120,17 +116,27 @@ namespace Nz
|
||||
|
||||
if (event.type == WindowEventType_Quit && m_closeOnQuit)
|
||||
Close();
|
||||
}
|
||||
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
m_eventMutex.Unlock();
|
||||
|
||||
if (m_waitForEvent)
|
||||
inline void Window::PushEvent(const WindowEvent& event)
|
||||
{
|
||||
if (!m_asyncWindow)
|
||||
HandleEvent(event);
|
||||
else
|
||||
{
|
||||
m_eventConditionMutex.Lock();
|
||||
m_eventCondition.Signal();
|
||||
m_eventConditionMutex.Unlock();
|
||||
{
|
||||
LockGuard eventLock(m_eventMutex);
|
||||
|
||||
m_pendingEvents.push_back(event);
|
||||
}
|
||||
|
||||
if (m_waitForEvent)
|
||||
{
|
||||
m_eventConditionMutex.Lock();
|
||||
m_eventCondition.Signal();
|
||||
m_eventConditionMutex.Unlock();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -141,22 +147,21 @@ namespace Nz
|
||||
{
|
||||
Destroy();
|
||||
|
||||
m_closed = window.m_closed;
|
||||
m_closeOnQuit = window.m_closeOnQuit;
|
||||
m_eventPolling = window.m_eventPolling;
|
||||
m_impl = window.m_impl;
|
||||
m_events = std::move(window.m_events);
|
||||
m_ownsWindow = window.m_ownsWindow;
|
||||
m_closed = window.m_closed;
|
||||
m_closeOnQuit = window.m_closeOnQuit;
|
||||
m_eventCondition = std::move(window.m_eventCondition);
|
||||
m_eventConditionMutex = std::move(window.m_eventConditionMutex);
|
||||
m_eventHandler = std::move(window.m_eventHandler);
|
||||
m_eventMutex = std::move(window.m_eventMutex);
|
||||
m_eventPolling = window.m_eventPolling;
|
||||
m_impl = window.m_impl;
|
||||
m_events = std::move(window.m_events);
|
||||
m_pendingEvents = std::move(window.m_pendingEvents);
|
||||
m_ownsWindow = window.m_ownsWindow;
|
||||
m_waitForEvent = window.m_waitForEvent;
|
||||
|
||||
window.m_impl = nullptr;
|
||||
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
m_eventCondition = std::move(window.m_eventCondition);
|
||||
m_eventMutex = std::move(window.m_eventMutex);
|
||||
m_eventConditionMutex = std::move(window.m_eventConditionMutex);
|
||||
m_waitForEvent = window.m_waitForEvent;
|
||||
#endif
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user