Big f***ing cleanup part 1

This commit is contained in:
Lynix
2020-02-23 00:42:22 +01:00
parent 67d0e0a689
commit 3d22321109
178 changed files with 2190 additions and 5113 deletions

View File

@@ -5,10 +5,7 @@
// Un grand merci à Laurent Gomila pour la SFML qui m'aura bien aidé à réaliser cette implémentation
#include <Nazara/Platform/Win32/WindowImpl.hpp>
#include <Nazara/Core/ConditionVariable.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/Thread.hpp>
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/Icon.hpp>
@@ -130,15 +127,15 @@ namespace Nz
if (async)
{
Mutex mutex;
ConditionVariable condition;
std::mutex mutex;
std::condition_variable condition;
m_threadActive = true;
// On attend que la fenêtre soit créée
mutex.Lock();
m_thread = Thread(WindowThread, &m_handle, win32StyleEx, title, win32Style, fullscreen, Rectui(x, y, width, height), this, &mutex, &condition);
condition.Wait(&mutex);
mutex.Unlock();
std::unique_lock<std::mutex> lock(mutex);
m_thread = std::thread(WindowThread, std::ref(m_handle), win32StyleEx, title, win32Style, fullscreen, Rectui(x, y, width, height), this, std::ref(mutex), std::ref(condition));
condition.wait(lock);
}
else
m_handle = CreateWindowExW(win32StyleEx, className, title.GetWideString().data(), win32Style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), this);
@@ -186,12 +183,12 @@ namespace Nz
{
if (m_style & WindowStyle_Threaded)
{
if (m_thread.IsJoinable())
if (m_thread.joinable())
{
m_threadActive = false;
PostMessageW(m_handle, WM_NULL, 0, 0); // Wake up our thread
m_thread.Join();
m_thread.join();
}
}
else
@@ -1151,24 +1148,24 @@ namespace Nz
return style;
}
void WindowImpl::WindowThread(HWND* handle, DWORD styleEx, const String& title, DWORD style, bool fullscreen, const Rectui& dimensions, WindowImpl* window, Mutex* mutex, ConditionVariable* condition)
void WindowImpl::WindowThread(HWND& handle, DWORD styleEx, const String& title, DWORD style, bool fullscreen, const Rectui& dimensions, WindowImpl* window, std::mutex& mutex, std::condition_variable& condition)
{
HWND& winHandle = *handle;
winHandle = CreateWindowExW(styleEx, className, title.GetWideString().data(), style, dimensions.x, dimensions.y, dimensions.width, dimensions.height, nullptr, nullptr, GetModuleHandle(nullptr), window);
handle = CreateWindowExW(styleEx, className, title.GetWideString().data(), style, dimensions.x, dimensions.y, dimensions.width, dimensions.height, nullptr, nullptr, GetModuleHandle(nullptr), window);
if (winHandle)
if (handle)
window->PrepareWindow(fullscreen);
mutex->Lock();
condition->Signal();
mutex->Unlock(); // mutex and condition may be destroyed after this line
{
std::lock_guard<std::mutex> lock(mutex);
condition.notify_all();
}
if (!winHandle)
if (!handle)
return;
while (window->m_threadActive)
window->ProcessEvents(true);
DestroyWindow(winHandle);
DestroyWindow(handle);
}
}

View File

@@ -11,7 +11,6 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/Thread.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Platform/Config.hpp>
@@ -19,12 +18,13 @@
#include <Nazara/Platform/Mouse.hpp>
#include <Nazara/Platform/VideoMode.hpp>
#include <Nazara/Platform/Window.hpp>
#include <condition_variable>
#include <mutex>
#include <thread>
#include <windows.h>
namespace Nz
{
class ConditionVariable;
class Mutex;
class Window;
#undef IsMinimized // Conflits with windows.h redefinition
@@ -87,7 +87,7 @@ namespace Nz
static Keyboard::Key ConvertVirtualKey(WPARAM key, LPARAM flags);
static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
static UInt32 RetrieveStyle(HWND window);
static void WindowThread(HWND* handle, DWORD styleEx, const String& title, DWORD style, bool fullscreen, const Rectui& dimensions, WindowImpl* window, Mutex* mutex, ConditionVariable* condition);
static void WindowThread(HWND& handle, DWORD styleEx, const String& title, DWORD style, bool fullscreen, const Rectui& dimensions, WindowImpl* window, std::mutex& mutex, std::condition_variable& condition);
HCURSOR m_cursor;
HWND m_handle;
@@ -98,7 +98,7 @@ namespace Nz
Vector2i m_mousePos;
Vector2i m_position;
Vector2ui m_size;
Thread m_thread;
std::thread m_thread;
Window* m_parent;
bool m_eventListener;
bool m_keyRepeat;

View File

@@ -5,7 +5,6 @@
#include <Nazara/Platform/Window.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/LockGuard.hpp>
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/Icon.hpp>
@@ -39,13 +38,10 @@ namespace Nz
Window::Window(Window&& window) :
m_events(std::move(window.m_events)),
m_pendingEvents(std::move(window.m_pendingEvents)),
m_eventCondition(std::move(window.m_eventCondition)),
m_cursorController(std::move(window.m_cursorController)),
m_cursor(std::move(window.m_cursor)),
m_eventHandler(std::move(window.m_eventHandler)),
m_icon(std::move(window.m_icon)),
m_eventMutex(std::move(window.m_eventMutex)),
m_eventConditionMutex(std::move(window.m_eventConditionMutex)),
m_asyncWindow(window.m_asyncWindow),
m_closed(window.m_asyncWindow),
m_closeOnQuit(window.m_closeOnQuit),
@@ -344,7 +340,7 @@ namespace Nz
m_impl->ProcessEvents(block);
else
{
LockGuard eventLock(m_eventMutex);
std::lock_guard<std::mutex> eventLock(m_eventMutex);
for (const WindowEvent& event : m_pendingEvents)
HandleEvent(event);
@@ -570,16 +566,19 @@ namespace Nz
}
else
{
LockGuard lock(m_eventMutex);
std::lock_guard<std::mutex> lock(m_eventMutex);
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_eventMutex.unlock();
std::unique_lock<std::mutex> eventConditionLock(m_eventConditionMutex);
m_eventCondition.wait(eventConditionLock);
m_eventMutex.lock();
}
m_waitForEvent = false;
}
@@ -601,13 +600,10 @@ namespace Nz
{
m_events = std::move(window.m_events);
m_pendingEvents = std::move(window.m_pendingEvents);
m_eventCondition = std::move(window.m_eventCondition);
m_cursorController = std::move(window.m_cursorController);
m_cursor = std::move(window.m_cursor);
m_eventHandler = std::move(window.m_eventHandler);
m_icon = std::move(window.m_icon);
m_eventMutex = std::move(window.m_eventMutex);
m_eventConditionMutex = std::move(window.m_eventConditionMutex);
m_asyncWindow = window.m_asyncWindow;
m_closed = window.m_asyncWindow;
m_closeOnQuit = window.m_closeOnQuit;