Replace RenderWindow with swapchains

This commit is contained in:
SirLynix
2023-01-21 12:02:34 +01:00
committed by Jérôme Leclercq
parent 8db1c04568
commit 18851c9185
66 changed files with 1404 additions and 2048 deletions

View File

@@ -48,10 +48,13 @@ namespace Nz
enum class WindowEventType
{
Created,
Destruction,
GainedFocus,
LostFocus,
KeyPressed,
KeyReleased,
Minimized,
MouseButtonPressed,
MouseButtonReleased,
MouseEntered,
@@ -61,6 +64,7 @@ namespace Nz
Moved,
Quit,
Resized,
Restored,
TextEdited,
TextEntered,

View File

@@ -1,57 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_PLATFORM_EVENTHANDLER_HPP
#define NAZARA_PLATFORM_EVENTHANDLER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/ObjectHandle.hpp>
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Event.hpp>
#include <Nazara/Utils/Signal.hpp>
namespace Nz
{
class EventHandler;
using EventHandlerHandle = ObjectHandle<EventHandler>;
class EventHandler : public HandledObject<EventHandler>
{
public:
EventHandler() = default;
explicit EventHandler(const EventHandler&);
EventHandler(EventHandler&&) noexcept = default;
~EventHandler() = default;
inline void Dispatch(const WindowEvent& event);
EventHandler& operator=(const EventHandler&) = delete;
EventHandler& operator=(EventHandler&&) noexcept = default;
NazaraSignal(OnEvent, const EventHandler* /*eventHandler*/, const WindowEvent& /*event*/);
NazaraSignal(OnGainedFocus, const EventHandler* /*eventHandler*/);
NazaraSignal(OnLostFocus, const EventHandler* /*eventHandler*/);
NazaraSignal(OnKeyPressed, const EventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnKeyReleased, const EventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnMouseButtonPressed, const EventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& /*event*/);
NazaraSignal(OnMouseButtonReleased, const EventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& /*event*/);
NazaraSignal(OnMouseEntered, const EventHandler* /*eventHandler*/);
NazaraSignal(OnMouseLeft, const EventHandler* /*eventHandler*/);
NazaraSignal(OnMouseMoved, const EventHandler* /*eventHandler*/, const WindowEvent::MouseMoveEvent& /*event*/);
NazaraSignal(OnMouseWheelMoved, const EventHandler* /*eventHandler*/, const WindowEvent::MouseWheelEvent& /*event*/);
NazaraSignal(OnMoved, const EventHandler* /*eventHandler*/, const WindowEvent::PositionEvent& /*event*/);
NazaraSignal(OnQuit, const EventHandler* /*eventHandler*/);
NazaraSignal(OnResized, const EventHandler* /*eventHandler*/, const WindowEvent::SizeEvent& /*event*/);
NazaraSignal(OnTextEntered, const EventHandler* /*eventHandler*/, const WindowEvent::TextEvent& /*event*/);
NazaraSignal(OnTextEdited, const EventHandler* /*eventHandler*/, const WindowEvent::EditEvent& /*event*/);
};
}
#include <Nazara/Platform/EventHandler.inl>
#endif // NAZARA_PLATFORM_EVENTHANDLER_HPP

View File

@@ -15,7 +15,7 @@
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/CursorController.hpp>
#include <Nazara/Platform/Enums.hpp>
#include <Nazara/Platform/EventHandler.hpp>
#include <Nazara/Platform/WindowEventHandler.hpp>
#include <Nazara/Platform/Icon.hpp>
#include <Nazara/Platform/VideoMode.hpp>
#include <Nazara/Platform/WindowHandle.hpp>
@@ -38,35 +38,31 @@ namespace Nz
public:
Window();
inline Window(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default);
inline explicit Window(void* handle);
inline explicit Window(WindowHandle handle);
Window(const Window&) = delete;
Window(Window&& window);
virtual ~Window();
Window(Window&& window) noexcept;
~Window();
inline void Close();
bool Create(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default);
bool Create(void* handle);
bool Create(WindowHandle handle);
void Destroy();
inline void EnableCloseOnQuit(bool closeOnQuit);
NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system")
inline void EnableEventPolling(bool enable);
void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable);
inline const std::shared_ptr<Cursor>& GetCursor() const;
inline CursorController& GetCursorController();
inline EventHandler& GetEventHandler();
inline WindowEventHandler& GetEventHandler();
WindowHandle GetHandle() const;
Vector2i GetPosition() const;
Vector2ui GetSize() const;
WindowStyleFlags GetStyle() const;
WindowHandle GetSystemHandle() const;
std::string GetTitle() const;
void HandleEvent(const WindowEvent& event);
bool HasFocus() const;
bool IsMinimized() const;
@@ -75,16 +71,8 @@ namespace Nz
inline bool IsValid() const;
bool IsVisible() const;
NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system")
bool PollEvent(WindowEvent* event);
void PushEvent(const WindowEvent& event);
void ProcessEvents(bool block = false);
void SetCursor(std::shared_ptr<Cursor> cursor);
inline void SetCursor(SystemCursor systemCursor);
void SetEventListener(bool listener);
void SetFocus();
void SetIcon(std::shared_ptr<Icon> icon);
void SetMaximumSize(const Vector2i& maxSize);
@@ -99,20 +87,10 @@ namespace Nz
void SetTitle(const std::string& title);
void SetVisible(bool visible);
NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system")
bool WaitEvent(WindowEvent* event);
Window& operator=(const Window&) = delete;
Window& operator=(Window&& window);
Window& operator=(Window&& window) noexcept;
protected:
void* GetHandle();
virtual bool OnWindowCreated();
virtual void OnWindowDestroy();
virtual void OnWindowResized();
MovablePtr<WindowImpl> m_impl;
static void ProcessEvents();
private:
void ConnectSlots();
@@ -122,26 +100,21 @@ namespace Nz
inline const WindowImpl* GetImpl() const;
void IgnoreNextMouseEvent(int mouseX, int mouseY) const;
void HandleEvent(const WindowEvent& event);
static bool Initialize();
static void Uninitialize();
NazaraSlot(CursorController, OnCursorUpdated, m_cursorUpdateSlot);
std::queue<WindowEvent> m_events;
std::vector<WindowEvent> m_pendingEvents;
std::condition_variable m_eventCondition;
CursorController m_cursorController;
std::shared_ptr<Cursor> m_cursor;
EventHandler m_eventHandler;
std::shared_ptr<Icon> m_icon;
std::mutex m_eventMutex;
std::mutex m_eventConditionMutex;
bool m_asyncWindow;
std::unique_ptr<WindowImpl> m_impl;
CursorController m_cursorController;
Vector2i m_position;
Vector2ui m_size;
WindowEventHandler m_eventHandler;
bool m_closed;
bool m_closeOnQuit;
bool m_eventPolling;
bool m_ownsWindow;
bool m_waitForEvent;
};

View File

@@ -19,7 +19,7 @@ namespace Nz
Create(mode, title, style);
}
inline Window::Window(void* handle) :
inline Window::Window(WindowHandle handle) :
Window()
{
ErrorFlags flags(ErrorMode::ThrowException, true);
@@ -36,16 +36,6 @@ namespace Nz
m_closeOnQuit = closeOnQuit;
}
inline void Window::EnableEventPolling(bool enable)
{
m_eventPolling = enable;
if (!m_eventPolling)
{
while (!m_events.empty())
m_events.pop();
}
}
inline const std::shared_ptr<Cursor>& Window::GetCursor() const
{
return m_cursor;
@@ -56,7 +46,7 @@ namespace Nz
return m_cursorController;
}
inline EventHandler& Nz::Window::GetEventHandler()
inline WindowEventHandler& Nz::Window::GetEventHandler()
{
return m_eventHandler;
}
@@ -90,34 +80,14 @@ namespace Nz
SetCursor(Cursor::Get(systemCursor));
}
inline void Window::PushEvent(const WindowEvent& event)
{
if (!m_asyncWindow)
HandleEvent(event);
else
{
{
std::lock_guard<std::mutex> eventLock(m_eventMutex);
m_pendingEvents.push_back(event);
}
if (m_waitForEvent)
{
std::lock_guard<std::mutex> lock(m_eventConditionMutex);
m_eventCondition.notify_all();
}
}
}
inline WindowImpl* Window::GetImpl()
{
return m_impl;
return m_impl.get();
}
inline const WindowImpl* Window::GetImpl() const
{
return m_impl;
return m_impl.get();
}
}

View File

@@ -9,11 +9,10 @@
#ifndef NAZARA_PLATFORM_EVENT_HPP
#define NAZARA_PLATFORM_EVENT_HPP
#include <array>
#include <Nazara/Platform/Enums.hpp>
#include <Nazara/Platform/Keyboard.hpp>
#include <Nazara/Platform/Mouse.hpp>
#include <array>
namespace Nz
{

View File

@@ -0,0 +1,61 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_PLATFORM_EVENTHANDLER_HPP
#define NAZARA_PLATFORM_EVENTHANDLER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/ObjectHandle.hpp>
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/WindowEvent.hpp>
#include <Nazara/Utils/Signal.hpp>
namespace Nz
{
class WindowEventHandler;
using EventHandlerHandle = ObjectHandle<WindowEventHandler>;
class WindowEventHandler : public HandledObject<WindowEventHandler>
{
public:
WindowEventHandler() = default;
explicit WindowEventHandler(const WindowEventHandler&);
WindowEventHandler(WindowEventHandler&&) noexcept = default;
~WindowEventHandler() = default;
inline void Dispatch(const WindowEvent& event);
WindowEventHandler& operator=(const WindowEventHandler&) = delete;
WindowEventHandler& operator=(WindowEventHandler&&) noexcept = default;
NazaraSignal(OnCreated, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnDestruction, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnEvent, const WindowEventHandler* /*eventHandler*/, const WindowEvent& /*event*/);
NazaraSignal(OnGainedFocus, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnLostFocus, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnKeyPressed, const WindowEventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnKeyReleased, const WindowEventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnMinimized, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnMouseButtonPressed, const WindowEventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& /*event*/);
NazaraSignal(OnMouseButtonReleased, const WindowEventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& /*event*/);
NazaraSignal(OnMouseEntered, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnMouseLeft, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnMouseMoved, const WindowEventHandler* /*eventHandler*/, const WindowEvent::MouseMoveEvent& /*event*/);
NazaraSignal(OnMouseWheelMoved, const WindowEventHandler* /*eventHandler*/, const WindowEvent::MouseWheelEvent& /*event*/);
NazaraSignal(OnMoved, const WindowEventHandler* /*eventHandler*/, const WindowEvent::PositionEvent& /*event*/);
NazaraSignal(OnQuit, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnResized, const WindowEventHandler* /*eventHandler*/, const WindowEvent::SizeEvent& /*event*/);
NazaraSignal(OnRestored, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnTextEntered, const WindowEventHandler* /*eventHandler*/, const WindowEvent::TextEvent& /*event*/);
NazaraSignal(OnTextEdited, const WindowEventHandler* /*eventHandler*/, const WindowEvent::EditEvent& /*event*/);
};
}
#include <Nazara/Platform/WindowEventHandler.inl>
#endif // NAZARA_PLATFORM_EVENTHANDLER_HPP

View File

@@ -2,23 +2,31 @@
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Platform/EventHandler.hpp>
#include <Nazara/Platform/WindowEventHandler.hpp>
#include <memory>
#include <Nazara/Platform/Debug.hpp>
namespace Nz
{
inline EventHandler::EventHandler(const EventHandler& other) :
inline WindowEventHandler::WindowEventHandler(const WindowEventHandler& other) :
HandledObject(other)
{
}
inline void EventHandler::Dispatch(const WindowEvent& event)
inline void WindowEventHandler::Dispatch(const WindowEvent& event)
{
OnEvent(this, event);
switch (event.type)
{
case WindowEventType::Created:
OnCreated(this);
break;
case WindowEventType::Destruction:
OnDestruction(this);
break;
case WindowEventType::GainedFocus:
OnGainedFocus(this);
break;
@@ -35,6 +43,10 @@ namespace Nz
OnLostFocus(this);
break;
case WindowEventType::Minimized:
OnMinimized(this);
break;
case WindowEventType::MouseButtonPressed:
OnMouseButtonPressed(this, event.mouseButton);
break;
@@ -71,6 +83,10 @@ namespace Nz
OnResized(this, event.size);
break;
case WindowEventType::Restored:
OnRestored(this);
break;
case WindowEventType::TextEntered:
OnTextEntered(this, event.text);
break;