Utility/Window: Replace NAZARA_UTILITY_THREADED_WINDOW by a runtime flag (WIP)

This commit is contained in:
Jérôme Leclercq
2016-11-07 02:01:09 +01:00
parent 2f11529669
commit cf2bf52701
10 changed files with 176 additions and 186 deletions

View File

@@ -66,6 +66,8 @@ namespace Nz
else if (style & WindowStyle_Closable || style & WindowStyle_Resizable)
style |= WindowStyle_Titlebar;
m_asyncWindow = (style & WindowStyle_Threaded) != 0;
std::unique_ptr<WindowImpl> impl = std::make_unique<WindowImpl>(this);
if (!impl->Create(mode, title, style))
{
@@ -313,11 +315,8 @@ namespace Nz
}
#endif
#if NAZARA_UTILITY_THREADED_WINDOW
LockGuard lock(m_eventMutex);
#else
m_impl->ProcessEvents(false);
#endif
if (!m_asyncWindow)
m_impl->ProcessEvents(false);
if (!m_events.empty())
{
@@ -337,9 +336,17 @@ namespace Nz
NazaraAssert(m_impl, "Window not created");
NazaraUnused(block);
#if !NAZARA_UTILITY_THREADED_WINDOW
m_impl->ProcessEvents(block);
#endif
if (!m_asyncWindow)
m_impl->ProcessEvents(block);
else
{
LockGuard eventLock(m_eventMutex);
for (const WindowEvent& event : m_pendingEvents)
PushEvent(event);
m_pendingEvents.clear();
}
}
void Window::SetCursor(WindowCursor cursor)
@@ -384,25 +391,14 @@ namespace Nz
}
#endif
#if NAZARA_UTILITY_THREADED_WINDOW
m_impl->SetEventListener(listener);
if (!listener)
{
// On vide la pile des évènements
// Empty the event queue
LockGuard lock(m_eventMutex);
while (!m_events.empty())
m_events.pop();
}
#else
if (m_ownsWindow)
{
// Inutile de transmettre l'ordre dans ce cas-là
if (!listener)
NazaraError("A non-threaded window needs to listen to events");
}
else
m_impl->SetEventListener(listener);
#endif
}
void Window::SetFocus()
@@ -590,22 +586,11 @@ namespace Nz
}
#endif
#if NAZARA_UTILITY_THREADED_WINDOW
LockGuard lock(m_eventMutex);
if (m_events.empty())
if (!m_asyncWindow)
{
m_waitForEvent = true;
m_eventConditionMutex.Lock();
m_eventMutex.Unlock();
m_eventCondition.Wait(&m_eventConditionMutex);
m_eventMutex.Lock();
m_eventConditionMutex.Unlock();
m_waitForEvent = false;
}
while (m_events.empty())
m_impl->ProcessEvents(true);
if (!m_events.empty())
{
if (event)
*event = m_events.front();
@@ -613,19 +598,33 @@ namespace Nz
return true;
}
else
{
LockGuard lock(m_eventMutex);
return false;
#else
while (m_events.empty())
m_impl->ProcessEvents(true);
if (m_events.empty())
{
m_waitForEvent = true;
m_eventConditionMutex.Lock();
m_eventMutex.Unlock();
m_eventCondition.Wait(&m_eventConditionMutex);
m_eventMutex.Lock();
m_eventConditionMutex.Unlock();
m_waitForEvent = false;
}
if (event)
*event = m_events.front();
if (!m_events.empty())
{
if (event)
*event = m_events.front();
m_events.pop();
m_events.pop();
return true;
#endif
return true;
}
return false;
}
}
bool Window::OnWindowCreated()