From 481347899d4e7bc375d4c7464dc026beb23d4886 Mon Sep 17 00:00:00 2001 From: zhangdoa Date: Sat, 9 Dec 2023 12:24:56 +0100 Subject: [PATCH] Sanitate the names of the window and event system members. Wrap the event system implementation to a class. --- Source/Client/LogicClient/Player.inl | 40 +-- Source/Client/LogicClient/World.inl | 10 +- .../DefaultRenderingClientImpl.inl | 12 +- .../Client/RenderingClient/GIResolvePass.cpp | 2 +- Source/Editor/viewport.cpp | 16 +- Source/Engine/Engine/Engine.cpp | 8 +- Source/Engine/Engine/Engine.h | 2 +- Source/Engine/Interface/IEngine.h | 2 +- Source/Engine/Interface/IEventSystem.h | 16 +- Source/Engine/Interface/IWindowSystem.h | 10 +- .../LinuxWindow/LinuxWindowSystem.cpp | 24 +- .../Platform/LinuxWindow/LinuxWindowSystem.h | 8 +- .../Platform/MacWindow/MacWindowSystem.cpp | 22 +- .../Platform/MacWindow/MacWindowSystem.h | 8 +- .../DXWindowSurface/WinDXWindowSurface.cpp | 26 +- .../GLWindowSurface/WinGLWindowSurface.cpp | 28 +- .../VKWindowSurface/WinVKWindowSurface.cpp | 30 +-- .../Platform/WinWindow/WinWindowSystem.cpp | 146 +++++------ .../Platform/WinWindow/WinWindowSystem.h | 16 +- Source/Engine/RenderingFrontend/GUISystem.cpp | 2 +- .../DX11/DX11RenderingServer.cpp | 2 +- .../DX12/DX12RenderingServer.cpp | 2 +- .../RenderingServer/VK/VKRenderingServer.cpp | 2 +- Source/Engine/SubSystem/EventSystem.cpp | 248 +++++++++--------- Source/Engine/SubSystem/EventSystem.h | 20 +- .../ImGuiWrapper/ImGuiWindowWin.cpp | 6 +- .../ThirdParty/PhysXWrapper/PhysXWrapper.cpp | 2 +- 27 files changed, 349 insertions(+), 361 deletions(-) diff --git a/Source/Client/LogicClient/Player.inl b/Source/Client/LogicClient/Player.inl index 265262b9..3d33d88d 100644 --- a/Source/Client/LogicClient/Player.inl +++ b/Source/Client/LogicClient/Player.inl @@ -216,32 +216,32 @@ namespace Inno static_cast(g_Engine->getComponentManager()->GetComponentSystem())->SetActiveCamera(m_activeCameraComponent); }; - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_W, true }, ButtonEvent{ EventLifeTime::Continuous, &f_moveForward }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_S, true }, ButtonEvent{ EventLifeTime::Continuous, &f_moveBackward }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_A, true }, ButtonEvent{ EventLifeTime::Continuous, &f_moveLeft }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_D, true }, ButtonEvent{ EventLifeTime::Continuous, &f_moveRight }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_W, true }, ButtonEvent{ EventLifeTime::Continuous, &f_moveForward }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_S, true }, ButtonEvent{ EventLifeTime::Continuous, &f_moveBackward }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_A, true }, ButtonEvent{ EventLifeTime::Continuous, &f_moveLeft }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_D, true }, ButtonEvent{ EventLifeTime::Continuous, &f_moveRight }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_W, true }, ButtonEvent{ EventLifeTime::OneShot, &f_move }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_S, true }, ButtonEvent{ EventLifeTime::OneShot, &f_move }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_A, true }, ButtonEvent{ EventLifeTime::OneShot, &f_move }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_D, true }, ButtonEvent{ EventLifeTime::OneShot, &f_move }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_W, true }, ButtonEvent{ EventLifeTime::OneShot, &f_move }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_S, true }, ButtonEvent{ EventLifeTime::OneShot, &f_move }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_A, true }, ButtonEvent{ EventLifeTime::OneShot, &f_move }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_D, true }, ButtonEvent{ EventLifeTime::OneShot, &f_move }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_W, false }, ButtonEvent{ EventLifeTime::OneShot, &f_stop }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_S, false }, ButtonEvent{ EventLifeTime::OneShot, &f_stop }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_A, false }, ButtonEvent{ EventLifeTime::OneShot, &f_stop }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_D, false }, ButtonEvent{ EventLifeTime::OneShot, &f_stop }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_W, false }, ButtonEvent{ EventLifeTime::OneShot, &f_stop }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_S, false }, ButtonEvent{ EventLifeTime::OneShot, &f_stop }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_A, false }, ButtonEvent{ EventLifeTime::OneShot, &f_stop }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_D, false }, ButtonEvent{ EventLifeTime::OneShot, &f_stop }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_E, true }, ButtonEvent{ EventLifeTime::OneShot, &f_addForce }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_E, true }, ButtonEvent{ EventLifeTime::OneShot, &f_addForce }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_SPACE, true }, ButtonEvent{ EventLifeTime::Continuous, &f_speedUp }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_SPACE, false }, ButtonEvent{ EventLifeTime::Continuous, &f_speedDown }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_SPACE, true }, ButtonEvent{ EventLifeTime::Continuous, &f_speedUp }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_SPACE, false }, ButtonEvent{ EventLifeTime::Continuous, &f_speedDown }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_MOUSE_BUTTON_RIGHT, true }, ButtonEvent{ EventLifeTime::Continuous, &f_allowMove }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_MOUSE_BUTTON_RIGHT, false }, ButtonEvent{ EventLifeTime::Continuous, &f_forbidMove }); - g_Engine->getEventSystem()->addMouseMovementCallback(MouseMovementAxis::Horizontal, MouseMovementEvent{ EventLifeTime::OneShot, &f_rotateAroundPositiveYAxis }); - g_Engine->getEventSystem()->addMouseMovementCallback(MouseMovementAxis::Vertical, MouseMovementEvent{ EventLifeTime::OneShot, &f_rotateAroundRightAxis }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_MOUSE_BUTTON_RIGHT, true }, ButtonEvent{ EventLifeTime::Continuous, &f_allowMove }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_MOUSE_BUTTON_RIGHT, false }, ButtonEvent{ EventLifeTime::Continuous, &f_forbidMove }); + g_Engine->getEventSystem()->AddMouseMovementCallback(MouseMovementAxis::Horizontal, MouseMovementEvent{ EventLifeTime::OneShot, &f_rotateAroundPositiveYAxis }); + g_Engine->getEventSystem()->AddMouseMovementCallback(MouseMovementAxis::Vertical, MouseMovementEvent{ EventLifeTime::OneShot, &f_rotateAroundRightAxis }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_O, true }, ButtonEvent{ EventLifeTime::OneShot, &f_switchCamera }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_O, true }, ButtonEvent{ EventLifeTime::OneShot, &f_switchCamera }); m_isEventsRegistered = true; diff --git a/Source/Client/LogicClient/World.inl b/Source/Client/LogicClient/World.inl index 7461df87..6958ca19 100644 --- a/Source/Client/LogicClient/World.inl +++ b/Source/Client/LogicClient/World.inl @@ -434,8 +434,8 @@ namespace Inno f_runRayTracing = [&]() { g_Engine->getRenderingFrontend()->RunRayTracing(); }; f_pauseGame = [&]() { allowUpdate = !allowUpdate; }; - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_N, true }, ButtonEvent{ EventLifeTime::OneShot, &f_runRayTracing }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_F, true }, ButtonEvent{ EventLifeTime::OneShot, &f_pauseGame }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_N, true }, ButtonEvent{ EventLifeTime::OneShot, &f_runRayTracing }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_F, true }, ButtonEvent{ EventLifeTime::OneShot, &f_pauseGame }); f_sceneLoadingFinishCallback = [&]() { if (!m_player) @@ -484,8 +484,8 @@ namespace Inno g_Engine->getAssetSystem()->ConvertModel("..//Res//Models//Wolf//Wolf.fbx", "..//Res//ConvertedAssets//"); }; - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_R, true }, ButtonEvent{ EventLifeTime::OneShot, &f_loadTestScene }); - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_Y, true }, ButtonEvent{ EventLifeTime::OneShot, &f_convertModel }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_R, true }, ButtonEvent{ EventLifeTime::OneShot, &f_loadTestScene }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_Y, true }, ButtonEvent{ EventLifeTime::OneShot, &f_convertModel }); return true; } @@ -563,7 +563,7 @@ namespace Inno Vec4 WorldSystem::getMousePositionInWorldSpace() { auto l_screenResolution = g_Engine->getRenderingFrontend()->GetScreenResolution(); - auto l_mousePositionSS = g_Engine->getEventSystem()->getMousePosition(); + auto l_mousePositionSS = g_Engine->getEventSystem()->GetMousePosition(); auto l_x = 2.0f * l_mousePositionSS.x / l_screenResolution.x - 1.0f; auto l_y = 1.0f - 2.0f * l_mousePositionSS.y / l_screenResolution.y; diff --git a/Source/Client/RenderingClient/DefaultRenderingClientImpl.inl b/Source/Client/RenderingClient/DefaultRenderingClientImpl.inl index 33aeaa3a..8ba1a0be 100644 --- a/Source/Client/RenderingClient/DefaultRenderingClientImpl.inl +++ b/Source/Client/RenderingClient/DefaultRenderingClientImpl.inl @@ -80,22 +80,22 @@ namespace Inno bool DefaultRenderingClientImpl::Setup(ISystemConfig* systemConfig) { f_showLightHeatmap = [&]() { m_showLightHeatmap = !m_showLightHeatmap; }; - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_H, true }, ButtonEvent{ EventLifeTime::OneShot, &f_showLightHeatmap }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_H, true }, ButtonEvent{ EventLifeTime::OneShot, &f_showLightHeatmap }); f_showProbe = [&]() { m_showProbe = !m_showProbe; }; - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_G, true }, ButtonEvent{ EventLifeTime::OneShot, &f_showProbe }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_G, true }, ButtonEvent{ EventLifeTime::OneShot, &f_showProbe }); f_showVoxel = [&]() { m_showVoxel = !m_showVoxel; }; - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_V, true }, ButtonEvent{ EventLifeTime::OneShot, &f_showVoxel }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_V, true }, ButtonEvent{ EventLifeTime::OneShot, &f_showVoxel }); f_showTransparent = [&]() { m_showTransparent = !m_showTransparent; }; - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_T, true }, ButtonEvent{ EventLifeTime::OneShot, &f_showTransparent }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_T, true }, ButtonEvent{ EventLifeTime::OneShot, &f_showTransparent }); f_showVolumetric = [&]() { m_showVolumetric = !m_showVolumetric; }; - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_J, true }, ButtonEvent{ EventLifeTime::OneShot, &f_showVolumetric }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_J, true }, ButtonEvent{ EventLifeTime::OneShot, &f_showVolumetric }); f_saveScreenCapture = [&]() { m_saveScreenCapture = !m_saveScreenCapture; }; - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_C, true }, ButtonEvent{ EventLifeTime::OneShot, &f_saveScreenCapture }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_C, true }, ButtonEvent{ EventLifeTime::OneShot, &f_saveScreenCapture }); f_SetupJob = [&]() { DefaultGPUBuffers::Setup(); diff --git a/Source/Client/RenderingClient/GIResolvePass.cpp b/Source/Client/RenderingClient/GIResolvePass.cpp index e151e23c..6f35b1b7 100644 --- a/Source/Client/RenderingClient/GIResolvePass.cpp +++ b/Source/Client/RenderingClient/GIResolvePass.cpp @@ -310,7 +310,7 @@ bool GIResolvePass::Setup() auto l_renderingServer = g_Engine->getRenderingServer(); f_reloadGIData = [&]() { m_needToReloadGIData = true; }; - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_B, true }, ButtonEvent{ EventLifeTime::OneShot, &f_reloadGIData }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_B, true }, ButtonEvent{ EventLifeTime::OneShot, &f_reloadGIData }); setupSky(); setupSurfels(); diff --git a/Source/Editor/viewport.cpp b/Source/Editor/viewport.cpp index 6870468b..92d3c7a1 100644 --- a/Source/Editor/viewport.cpp +++ b/Source/Editor/viewport.cpp @@ -35,7 +35,7 @@ Viewport::Viewport(QWidget *parent) Viewport::~Viewport() { - g_Engine->getWindowSystem()->sendEvent(WM_DESTROY, WM_DESTROY, 0); + g_Engine->getWindowSystem()->SendEvent(WM_DESTROY, WM_DESTROY, 0); } void Viewport::initialize() @@ -90,7 +90,7 @@ bool ViewportEventFilter::eventFilter(QObject *obj, QEvent *event) auto l_key = reinterpret_cast(event); if(l_key->key() < Qt::Key_Escape) { - g_Engine->getWindowSystem()->sendEvent(WM_KEYDOWN, l_key->key(), 0); + g_Engine->getWindowSystem()->SendEvent(WM_KEYDOWN, l_key->key(), 0); } } @@ -99,7 +99,7 @@ bool ViewportEventFilter::eventFilter(QObject *obj, QEvent *event) auto l_key = reinterpret_cast(event); if(l_key->key() < Qt::Key_Escape) { - g_Engine->getWindowSystem()->sendEvent(WM_KEYUP, l_key->key(), 0); + g_Engine->getWindowSystem()->SendEvent(WM_KEYUP, l_key->key(), 0); } } if (l_eventType == QEvent::MouseButtonPress) @@ -108,10 +108,10 @@ bool ViewportEventFilter::eventFilter(QObject *obj, QEvent *event) switch (l_key->button()) { case Qt::MouseButton::LeftButton: - g_Engine->getWindowSystem()->sendEvent(WM_LBUTTONDOWN, WM_LBUTTONDOWN, 0); + g_Engine->getWindowSystem()->SendEvent(WM_LBUTTONDOWN, WM_LBUTTONDOWN, 0); break; case Qt::MouseButton::RightButton: - g_Engine->getWindowSystem()->sendEvent(WM_RBUTTONDOWN, WM_RBUTTONDOWN, 0); + g_Engine->getWindowSystem()->SendEvent(WM_RBUTTONDOWN, WM_RBUTTONDOWN, 0); break; default: break; @@ -123,10 +123,10 @@ bool ViewportEventFilter::eventFilter(QObject *obj, QEvent *event) switch (l_mouseButton->button()) { case Qt::MouseButton::LeftButton: - g_Engine->getWindowSystem()->sendEvent(WM_LBUTTONUP, WM_LBUTTONUP, 0); + g_Engine->getWindowSystem()->SendEvent(WM_LBUTTONUP, WM_LBUTTONUP, 0); break; case Qt::MouseButton::RightButton: - g_Engine->getWindowSystem()->sendEvent(WM_RBUTTONUP, WM_RBUTTONUP, 0); + g_Engine->getWindowSystem()->SendEvent(WM_RBUTTONUP, WM_RBUTTONUP, 0); break; default: break; @@ -138,7 +138,7 @@ bool ViewportEventFilter::eventFilter(QObject *obj, QEvent *event) auto l_x = l_mouseMovement->pos().x() * MOUSE_SENSITIVITY; auto l_y = l_mouseMovement->pos().y() * MOUSE_SENSITIVITY; auto l_lparm = MAKELONG(l_x, l_y); - g_Engine->getWindowSystem()->sendEvent(WM_MOUSEMOVE, WM_MOUSEMOVE, l_lparm); + g_Engine->getWindowSystem()->SendEvent(WM_MOUSEMOVE, WM_MOUSEMOVE, l_lparm); } return false; } diff --git a/Source/Engine/Engine/Engine.cpp b/Source/Engine/Engine/Engine.cpp index 35de0f83..0f5eb4b9 100644 --- a/Source/Engine/Engine/Engine.cpp +++ b/Source/Engine/Engine/Engine.cpp @@ -432,7 +432,8 @@ bool EngineNS::Setup(void* appHook, void* extraHook, char* pScmdline, IRendering SystemSetup(TaskSystem); SystemSetup(TestSystem); - + SystemSetup(EventSystem); + IWindowSystemConfig l_windowSystemConfig; l_windowSystemConfig.m_AppHook = appHook; l_windowSystemConfig.m_ExtraHook = extraHook; @@ -458,7 +459,6 @@ bool EngineNS::Setup(void* appHook, void* extraHook, char* pScmdline, IRendering SystemSetup(SceneSystem); SystemSetup(PhysicsSystem); - SystemSetup(EventSystem); IRenderingFrontendConfig l_renderingFrontendConfig; l_renderingFrontendConfig.m_RenderingServer = m_RenderingServer.get(); @@ -509,7 +509,7 @@ bool EngineNS::Setup(void* appHook, void* extraHook, char* pScmdline, IRendering m_RenderingServer->Present(); - m_WindowSystem->getWindowSurface()->swapBuffer(); + m_WindowSystem->GetWindowSurface()->swapBuffer(); auto l_tickEndTime = m_TimeSystem->getCurrentTimeFromEpoch(); @@ -767,7 +767,7 @@ float Engine::getTickTime() return m_tickTime; } -const FixedSizeString<128>& Engine::getApplicationName() +const FixedSizeString<128>& Engine::GetApplicationName() { return m_applicationName; } diff --git a/Source/Engine/Engine/Engine.h b/Source/Engine/Engine/Engine.h index 2e09d0d3..53db239d 100644 --- a/Source/Engine/Engine/Engine.h +++ b/Source/Engine/Engine/Engine.h @@ -36,6 +36,6 @@ namespace Inno InitConfig getInitConfig() override; float getTickTime() override; - const FixedSizeString<128>& getApplicationName() override; + const FixedSizeString<128>& GetApplicationName() override; }; } \ No newline at end of file diff --git a/Source/Engine/Interface/IEngine.h b/Source/Engine/Interface/IEngine.h index 6a6cf857..d1872912 100644 --- a/Source/Engine/Interface/IEngine.h +++ b/Source/Engine/Interface/IEngine.h @@ -70,6 +70,6 @@ namespace Inno INNO_ENGINE_API virtual float getTickTime() = 0; - INNO_ENGINE_API virtual const FixedSizeString<128>& getApplicationName() = 0; + INNO_ENGINE_API virtual const FixedSizeString<128>& GetApplicationName() = 0; }; } diff --git a/Source/Engine/Interface/IEventSystem.h b/Source/Engine/Interface/IEventSystem.h index 0cd388c3..f4a569de 100644 --- a/Source/Engine/Interface/IEventSystem.h +++ b/Source/Engine/Interface/IEventSystem.h @@ -40,16 +40,16 @@ namespace Inno public: INNO_CLASS_INTERFACE_NON_COPYABLE(IEventSystem); - virtual InputConfig getInputConfig() = 0; + virtual InputConfig GetInputConfig() = 0; - virtual void addButtonStateCallback(ButtonState buttonState, ButtonEvent buttonEvent) = 0; - virtual void addMouseMovementCallback(MouseMovementAxis mouseMovementAxis, MouseMovementEvent mouseMovementEvent) = 0; + virtual void AddButtonStateCallback(ButtonState buttonState, ButtonEvent buttonEvent) = 0; + virtual void AddMouseMovementCallback(MouseMovementAxis mouseMovementAxis, MouseMovementEvent mouseMovementEvent) = 0; - virtual void buttonStateCallback(ButtonState buttonState) = 0; - virtual void windowSizeCallback(int32_t width, int32_t height) = 0; - virtual void mouseMovementCallback(float mouseXPos, float mouseYPos) = 0; - virtual void scrollCallback(float xoffset, float yoffset) = 0; + virtual void ButtonStateCallback(ButtonState buttonState) = 0; + virtual void WindowResizeCallback(int32_t width, int32_t height) = 0; + virtual void MouseMovementCallback(float mouseXPos, float mouseYPos) = 0; + virtual void ScrollCallback(float xOffset, float yOffset) = 0; - virtual Vec2 getMousePosition() = 0; + virtual Vec2 GetMousePosition() = 0; }; } \ No newline at end of file diff --git a/Source/Engine/Interface/IWindowSystem.h b/Source/Engine/Interface/IWindowSystem.h index 355688ce..d140345a 100644 --- a/Source/Engine/Interface/IWindowSystem.h +++ b/Source/Engine/Interface/IWindowSystem.h @@ -4,7 +4,7 @@ namespace Inno { - using WindowEventCallbackFunctor = std::function; + using WindowEventCallback = std::function; class IWindowSystemConfig : public ISystemConfig { @@ -18,11 +18,11 @@ namespace Inno public: INNO_CLASS_INTERFACE_NON_COPYABLE(IWindowSystem); - virtual IWindowSurface* getWindowSurface() = 0; - virtual const std::vector& getButtonState() = 0; + virtual IWindowSurface* GetWindowSurface() = 0; + virtual const std::vector& GetButtonState() = 0; // Editor only - virtual bool sendEvent(uint32_t umsg, uint32_t WParam, int32_t LParam) = 0; - virtual bool addEventCallback(WindowEventCallbackFunctor* functor) = 0; + virtual bool SendEvent(uint32_t uMsg, uint32_t wParam, int32_t lParam) = 0; + virtual bool AddEventCallback(WindowEventCallback* callback) = 0; }; } \ No newline at end of file diff --git a/Source/Engine/Platform/LinuxWindow/LinuxWindowSystem.cpp b/Source/Engine/Platform/LinuxWindow/LinuxWindowSystem.cpp index e7cce659..fd7cd2e0 100644 --- a/Source/Engine/Platform/LinuxWindow/LinuxWindowSystem.cpp +++ b/Source/Engine/Platform/LinuxWindow/LinuxWindowSystem.cpp @@ -21,11 +21,11 @@ namespace LinuxWindowSystemNS bool Update(); bool Terminate(); - IWindowSurface* m_windowSurface; + IWindowSurface* m_WindowSurface; ObjectStatus m_ObjectStatus = ObjectStatus::Terminated; - InitConfig m_initConfig; - std::vector m_buttonState; - std::set m_windowEventCallbackFunctor; + InitConfig m_InitConfig; + std::vector m_ButtonStates; + std::set m_WindowEventCallbacks; Display* m_display; Window m_window; @@ -68,7 +68,7 @@ bool LinuxWindowSystemNS::Setup(ISystemConfig* systemConfig) /* Show_the_window --------------- */ - auto l_windowName = g_Engine->getApplicationName(); + auto l_windowName = g_Engine->GetApplicationName(); XStoreName(m_display, m_window, l_windowName.c_str()); XSelectInput(m_display, m_window, ExposureMask | StructureNotifyMask); @@ -177,24 +177,24 @@ ObjectStatus LinuxWindowSystem::GetStatus() return LinuxWindowSystemNS::m_ObjectStatus; } -IWindowSurface* LinuxWindowSystem::getWindowSurface() +IWindowSurface* LinuxWindowSystem::GetWindowSurface() { - return LinuxWindowSystemNS::m_windowSurface; + return LinuxWindowSystemNS::m_WindowSurface; } -const std::vector& LinuxWindowSystem::getButtonState() +const std::vector& LinuxWindowSystem::GetButtonState() { - return LinuxWindowSystemNS::m_buttonState; + return LinuxWindowSystemNS::m_ButtonStates; } -bool LinuxWindowSystem::sendEvent(uint32_t umsg, uint32_t WParam, int32_t LParam) +bool LinuxWindowSystem::SendEvent(uint32_t uMsg, uint32_t wParam, int32_t lParam) { return true; } -bool LinuxWindowSystem::addEventCallback(WindowEventCallbackFunctor* functor) +bool LinuxWindowSystem::AddEventCallback(WindowEventCallback* callback) { - LinuxWindowSystemNS::m_windowEventCallbackFunctor.emplace(functor); + LinuxWindowSystemNS::m_WindowEventCallbacks.emplace(functor); return true; } diff --git a/Source/Engine/Platform/LinuxWindow/LinuxWindowSystem.h b/Source/Engine/Platform/LinuxWindow/LinuxWindowSystem.h index 76a5383c..3352d45c 100644 --- a/Source/Engine/Platform/LinuxWindow/LinuxWindowSystem.h +++ b/Source/Engine/Platform/LinuxWindow/LinuxWindowSystem.h @@ -15,10 +15,10 @@ namespace Inno ObjectStatus GetStatus() override; - IWindowSurface* getWindowSurface() override; - const std::vector& getButtonState() override; + IWindowSurface* GetWindowSurface() override; + const std::vector& GetButtonState() override; - bool sendEvent(uint32_t umsg, uint32_t WParam, int32_t LParam) override; - bool addEventCallback(WindowEventCallbackFunctor* functor) override; + bool SendEvent(uint32_t uMsg, uint32_t wParam, int32_t lParam) override; + bool AddEventCallback(WindowEventCallback* callback) override; }; } diff --git a/Source/Engine/Platform/MacWindow/MacWindowSystem.cpp b/Source/Engine/Platform/MacWindow/MacWindowSystem.cpp index c98b3e42..afe22197 100644 --- a/Source/Engine/Platform/MacWindow/MacWindowSystem.cpp +++ b/Source/Engine/Platform/MacWindow/MacWindowSystem.cpp @@ -7,11 +7,11 @@ extern IEngine* g_Engine; namespace MacWindowSystemNS { - IWindowSurface* m_windowSurface; + IWindowSurface* m_WindowSurface; ObjectStatus m_ObjectStatus = ObjectStatus::Terminated; - InitConfig m_initConfig; - std::vector m_buttonState; - std::set m_windowEventCallbackFunctor; + InitConfig m_InitConfig; + std::vector m_ButtonStates; + std::set m_WindowEventCallbacks; MacWindowSystemBridge* m_bridge; } @@ -55,24 +55,24 @@ ObjectStatus MacWindowSystem::GetStatus() return MacWindowSystemNS::m_ObjectStatus; } -IWindowSurface* MacWindowSystem::getWindowSurface() +IWindowSurface* MacWindowSystem::GetWindowSurface() { - return MacWindowSystemNS::m_windowSurface; + return MacWindowSystemNS::m_WindowSurface; } -const std::vector& MacWindowSystem::getButtonState() +const std::vector& MacWindowSystem::GetButtonState() { - return MacWindowSystemNS::m_buttonState; + return MacWindowSystemNS::m_ButtonStates; } -bool MacWindowSystem::sendEvent(uint32_t umsg, uint32_t WParam, int32_t LParam) +bool MacWindowSystem::SendEvent(uint32_t uMsg, uint32_t wParam, int32_t lParam) { return true; } -bool MacWindowSystem::addEventCallback(WindowEventCallbackFunctor* functor) +bool MacWindowSystem::AddEventCallback(WindowEventCallback* callback) { - MacWindowSystemNS::m_windowEventCallbackFunctor.emplace(functor); + MacWindowSystemNS::m_WindowEventCallbacks.emplace(functor); return true; } diff --git a/Source/Engine/Platform/MacWindow/MacWindowSystem.h b/Source/Engine/Platform/MacWindow/MacWindowSystem.h index 23ffb249..cb2a20bb 100644 --- a/Source/Engine/Platform/MacWindow/MacWindowSystem.h +++ b/Source/Engine/Platform/MacWindow/MacWindowSystem.h @@ -16,11 +16,11 @@ namespace Inno ObjectStatus GetStatus() override; - IWindowSurface* getWindowSurface() override; - const std::vector& getButtonState() override; + IWindowSurface* GetWindowSurface() override; + const std::vector& GetButtonState() override; - bool sendEvent(uint32_t umsg, uint32_t WParam, int32_t LParam) override; - bool addEventCallback(WindowEventCallbackFunctor* functor) override; + bool SendEvent(uint32_t uMsg, uint32_t wParam, int32_t lParam) override; + bool AddEventCallback(WindowEventCallback* callback) override; void setBridge(MacWindowSystemBridge* bridge); }; diff --git a/Source/Engine/Platform/WinWindow/DXWindowSurface/WinDXWindowSurface.cpp b/Source/Engine/Platform/WinWindow/DXWindowSurface/WinDXWindowSurface.cpp index 2f2ba984..b5f92924 100644 --- a/Source/Engine/Platform/WinWindow/DXWindowSurface/WinDXWindowSurface.cpp +++ b/Source/Engine/Platform/WinWindow/DXWindowSurface/WinDXWindowSurface.cpp @@ -14,28 +14,28 @@ namespace WinDXWindowSurfaceNS bool Terminate(); ObjectStatus m_ObjectStatus = ObjectStatus::Terminated; - InitConfig m_initConfig; + InitConfig m_InitConfig; } bool WinDXWindowSurfaceNS::Setup(ISystemConfig* systemConfig) { auto l_windowSurfaceConfig = reinterpret_cast(systemConfig); - m_initConfig = g_Engine->getInitConfig(); + m_InitConfig = g_Engine->getInitConfig(); - if (m_initConfig.engineMode == EngineMode::Host) + if (m_InitConfig.engineMode == EngineMode::Host) { // Setup the windows class with default settings. - auto l_windowName = g_Engine->getApplicationName(); + auto l_windowName = g_Engine->GetApplicationName(); WNDCLASSEX wcex; ZeroMemory(&wcex, sizeof(wcex)); wcex.cbSize = sizeof(wcex); wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wcex.lpfnWndProc = (WNDPROC)l_windowSurfaceConfig->WindowProc; - wcex.hInstance = reinterpret_cast(g_Engine->getWindowSystem())->getHInstance(); + wcex.hInstance = reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationInstance(); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.lpszClassName = reinterpret_cast(g_Engine->getWindowSystem())->getApplicationName(); + wcex.lpszClassName = reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationName(); auto l_windowClass = MAKEINTATOM(RegisterClassEx(&wcex)); @@ -52,14 +52,14 @@ bool WinDXWindowSurfaceNS::Setup(ISystemConfig* systemConfig) // create a new window and context auto l_hwnd = CreateWindow( - l_windowClass, reinterpret_cast(g_Engine->getWindowSystem())->getApplicationName(), // class name, window name + l_windowClass, reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationName(), // class name, window name WS_OVERLAPPEDWINDOW, // styles l_rect.right, l_rect.bottom, // posx, posy. If x is set to CW_USEDEFAULT y is ignored l_screenWidth, l_screenHeight, // width, height NULL, NULL, // parent window, menu - reinterpret_cast(g_Engine->getWindowSystem())->getHInstance(), NULL); // instance, param + reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationInstance(), NULL); // instance, param - reinterpret_cast(g_Engine->getWindowSystem())->setHwnd(l_hwnd); + reinterpret_cast(g_Engine->getWindowSystem())->SetWindowHandle(l_hwnd); } m_ObjectStatus = ObjectStatus::Activated; @@ -70,12 +70,12 @@ bool WinDXWindowSurfaceNS::Setup(ISystemConfig* systemConfig) bool WinDXWindowSurfaceNS::Initialize() { - if (m_initConfig.engineMode == EngineMode::Host) + if (m_InitConfig.engineMode == EngineMode::Host) { // Bring the window up on the screen and set it as main focus. - ShowWindow(reinterpret_cast(g_Engine->getWindowSystem())->getHwnd(), true); - SetForegroundWindow(reinterpret_cast(g_Engine->getWindowSystem())->getHwnd()); - SetFocus(reinterpret_cast(g_Engine->getWindowSystem())->getHwnd()); + ShowWindow(reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle(), true); + SetForegroundWindow(reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle()); + SetFocus(reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle()); } Logger::Log(LogLevel::Success, "WinDXWindowSurface has been initialized."); diff --git a/Source/Engine/Platform/WinWindow/GLWindowSurface/WinGLWindowSurface.cpp b/Source/Engine/Platform/WinWindow/GLWindowSurface/WinGLWindowSurface.cpp index a9cda035..dae8ce43 100644 --- a/Source/Engine/Platform/WinWindow/GLWindowSurface/WinGLWindowSurface.cpp +++ b/Source/Engine/Platform/WinWindow/GLWindowSurface/WinGLWindowSurface.cpp @@ -21,23 +21,23 @@ namespace WinGLWindowSurfaceNS HDC m_HDC; HGLRC m_HGLRC; ObjectStatus m_ObjectStatus = ObjectStatus::Terminated; - InitConfig m_initConfig; + InitConfig m_InitConfig; } bool WinGLWindowSurfaceNS::Setup(ISystemConfig* systemConfig) { auto l_windowSurfaceConfig = reinterpret_cast(systemConfig); - m_initConfig = g_Engine->getInitConfig(); + m_InitConfig = g_Engine->getInitConfig(); WNDCLASSEX wcex; ZeroMemory(&wcex, sizeof(wcex)); wcex.cbSize = sizeof(wcex); wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wcex.lpfnWndProc = (WNDPROC)l_windowSurfaceConfig->WindowProc; - wcex.hInstance = reinterpret_cast(g_Engine->getWindowSystem())->getHInstance(); + wcex.hInstance = reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationInstance(); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.lpszClassName = reinterpret_cast(g_Engine->getWindowSystem())->getApplicationName(); + wcex.lpszClassName = reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationName(); auto l_windowClass = MAKEINTATOM(RegisterClassEx(&wcex)); @@ -49,7 +49,7 @@ bool WinGLWindowSurfaceNS::Setup(ISystemConfig* systemConfig) 0, 0, // position x, y 1, 1, // width, height NULL, NULL, // parent window, menu - reinterpret_cast(g_Engine->getWindowSystem())->getHInstance(), NULL); // instance, param + reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationInstance(), NULL); // instance, param HDC fakeDC = GetDC(fakeWND); // Device Context @@ -115,7 +115,7 @@ bool WinGLWindowSurfaceNS::Setup(ISystemConfig* systemConfig) return false; } - if (m_initConfig.engineMode == EngineMode::Host) + if (m_InitConfig.engineMode == EngineMode::Host) { // Determine the resolution of the clients desktop screen. auto l_screenResolution = g_Engine->getRenderingFrontend()->GetScreenResolution(); @@ -130,19 +130,19 @@ bool WinGLWindowSurfaceNS::Setup(ISystemConfig* systemConfig) // create a new window and context auto l_hwnd = CreateWindow( - l_windowClass, reinterpret_cast(g_Engine->getWindowSystem())->getApplicationName(), // class name, window name + l_windowClass, reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationName(), // class name, window name WS_OVERLAPPEDWINDOW, // styles l_rect.right, l_rect.bottom, // posx, posy. If x is set to CW_USEDEFAULT y is ignored l_screenWidth, l_screenHeight, // width, height NULL, NULL, // parent window, menu - reinterpret_cast(g_Engine->getWindowSystem())->getHInstance(), NULL); // instance, param + reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationInstance(), NULL); // instance, param - reinterpret_cast(g_Engine->getWindowSystem())->setHwnd(l_hwnd); + reinterpret_cast(g_Engine->getWindowSystem())->SetWindowHandle(l_hwnd); } auto f_CreateGLContextTask = [&]() { - m_HDC = GetDC(reinterpret_cast(g_Engine->getWindowSystem())->getHwnd()); + m_HDC = GetDC(reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle()); const int32_t pixelAttribs[] = { WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, @@ -240,11 +240,11 @@ bool WinGLWindowSurfaceNS::Setup(ISystemConfig* systemConfig) auto l_ActivateGLContextTask = g_Engine->getTaskSystem()->Submit("ActivateGLContextTask", 2, nullptr, f_ActivateGLContextTask); l_ActivateGLContextTask.m_Future->Get(); - if (m_initConfig.engineMode == EngineMode::Host) + if (m_InitConfig.engineMode == EngineMode::Host) { - ShowWindow(reinterpret_cast(g_Engine->getWindowSystem())->getHwnd(), true); - SetForegroundWindow(reinterpret_cast(g_Engine->getWindowSystem())->getHwnd()); - SetFocus(reinterpret_cast(g_Engine->getWindowSystem())->getHwnd()); + ShowWindow(reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle(), true); + SetForegroundWindow(reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle()); + SetFocus(reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle()); } m_ObjectStatus = ObjectStatus::Activated; diff --git a/Source/Engine/Platform/WinWindow/VKWindowSurface/WinVKWindowSurface.cpp b/Source/Engine/Platform/WinWindow/VKWindowSurface/WinVKWindowSurface.cpp index 2afaf009..78ee17f4 100644 --- a/Source/Engine/Platform/WinWindow/VKWindowSurface/WinVKWindowSurface.cpp +++ b/Source/Engine/Platform/WinWindow/VKWindowSurface/WinVKWindowSurface.cpp @@ -18,28 +18,28 @@ namespace WinVKWindowSurfaceNS bool Terminate(); ObjectStatus m_ObjectStatus = ObjectStatus::Terminated; - InitConfig m_initConfig; + InitConfig m_InitConfig; } bool WinVKWindowSurfaceNS::Setup(ISystemConfig* systemConfig) { auto l_windowSurfaceConfig = reinterpret_cast(systemConfig); - m_initConfig = g_Engine->getInitConfig(); + m_InitConfig = g_Engine->getInitConfig(); - if (m_initConfig.engineMode == EngineMode::Host) + if (m_InitConfig.engineMode == EngineMode::Host) { // Setup the windows class with default settings. - auto l_windowName = g_Engine->getApplicationName(); + auto l_windowName = g_Engine->GetApplicationName(); WNDCLASSEX wcex; ZeroMemory(&wcex, sizeof(wcex)); wcex.cbSize = sizeof(wcex); wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wcex.lpfnWndProc = (WNDPROC)l_windowSurfaceConfig->WindowProc; - wcex.hInstance = reinterpret_cast(g_Engine->getWindowSystem())->getHInstance(); + wcex.hInstance = reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationInstance(); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.lpszClassName = reinterpret_cast(g_Engine->getWindowSystem())->getApplicationName(); + wcex.lpszClassName = reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationName(); auto l_windowClass = MAKEINTATOM(RegisterClassEx(&wcex)); @@ -54,14 +54,14 @@ bool WinVKWindowSurfaceNS::Setup(ISystemConfig* systemConfig) // create a new window and context auto l_hwnd = CreateWindow( - l_windowClass, reinterpret_cast(g_Engine->getWindowSystem())->getApplicationName(), // class name, window name + l_windowClass, reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationName(), // class name, window name WS_OVERLAPPEDWINDOW, // styles l_rect.right, l_rect.bottom, // posx, posy. If x is set to CW_USEDEFAULT y is ignored l_screenWidth, l_screenHeight, // width, height NULL, NULL, // parent window, menu - reinterpret_cast(g_Engine->getWindowSystem())->getHInstance(), NULL); // instance, param + reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationInstance(), NULL); // instance, param - reinterpret_cast(g_Engine->getWindowSystem())->setHwnd(l_hwnd); + reinterpret_cast(g_Engine->getWindowSystem())->SetWindowHandle(l_hwnd); } m_ObjectStatus = ObjectStatus::Activated; @@ -75,8 +75,8 @@ bool WinVKWindowSurfaceNS::Initialize() VkWin32SurfaceCreateInfoKHR l_createInfo = {}; l_createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; l_createInfo.pNext = NULL; - l_createInfo.hinstance = reinterpret_cast(g_Engine->getWindowSystem())->getHInstance(); - l_createInfo.hwnd = reinterpret_cast(g_Engine->getWindowSystem())->getHwnd(); + l_createInfo.hinstance = reinterpret_cast(g_Engine->getWindowSystem())->GetApplicationInstance(); + l_createInfo.hwnd = reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle(); auto l_renderingServer = reinterpret_cast(g_Engine->getRenderingServer()); auto l_VkInstance = reinterpret_cast(l_renderingServer->GetVkInstance()); @@ -89,12 +89,12 @@ bool WinVKWindowSurfaceNS::Initialize() return false; } - if (m_initConfig.engineMode == EngineMode::Host) + if (m_InitConfig.engineMode == EngineMode::Host) { // Bring the window up on the screen and set it as main focus. - ShowWindow(reinterpret_cast(g_Engine->getWindowSystem())->getHwnd(), true); - SetForegroundWindow(reinterpret_cast(g_Engine->getWindowSystem())->getHwnd()); - SetFocus(reinterpret_cast(g_Engine->getWindowSystem())->getHwnd()); + ShowWindow(reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle(), true); + SetForegroundWindow(reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle()); + SetFocus(reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle()); } Logger::Log(LogLevel::Success, "WinVKWindowSurface has been initialized."); diff --git a/Source/Engine/Platform/WinWindow/WinWindowSystem.cpp b/Source/Engine/Platform/WinWindow/WinWindowSystem.cpp index 5154ccd0..c78dbfbd 100644 --- a/Source/Engine/Platform/WinWindow/WinWindowSystem.cpp +++ b/Source/Engine/Platform/WinWindow/WinWindowSystem.cpp @@ -10,123 +10,116 @@ using namespace Inno; extern IEngine* g_Engine; -LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); - namespace WinWindowSystemNS { - LRESULT CALLBACK MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam); + LRESULT CALLBACK ProcessEvent(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); - IWindowSurface* m_windowSurface; + IWindowSurface* m_WindowSurface; ObjectStatus m_ObjectStatus = ObjectStatus::Terminated; - InitConfig m_initConfig; + InitConfig m_InitConfig; - std::vector m_buttonState; - std::set m_windowEventCallbackFunctor; + std::vector m_ButtonStates; + std::set m_WindowEventCallbacks; - HINSTANCE m_hInstance; - LPCSTR m_applicationName; - HWND m_hwnd; + HINSTANCE m_ApplicationInstance; + LPCSTR m_ApplicationName; + HWND m_WindowHandle; }; using namespace WinWindowSystemNS; -LRESULT WinWindowSystemNS::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam) +LRESULT WinWindowSystemNS::ProcessEvent(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - for (auto i : m_windowEventCallbackFunctor) + for (auto i : m_WindowEventCallbacks) { - (*i)(hwnd, umsg, (uint64_t)wparam, (int64_t)lparam); + (*i)(hwnd, uMsg, (uint64_t)wParam, (int64_t)lParam); } - switch (umsg) + switch (uMsg) { case WM_KEYDOWN: { - m_buttonState[(uint64_t)wparam].m_isPressed = true; + m_ButtonStates[(uint64_t)wParam].m_isPressed = true; return 0; } case WM_KEYUP: { - m_buttonState[(uint64_t)wparam].m_isPressed = false; + m_ButtonStates[(uint64_t)wParam].m_isPressed = false; return 0; } case WM_LBUTTONDOWN: { - m_buttonState[INNO_MOUSE_BUTTON_LEFT].m_isPressed = true; + m_ButtonStates[INNO_MOUSE_BUTTON_LEFT].m_isPressed = true; return 0; } case WM_LBUTTONUP: { - m_buttonState[INNO_MOUSE_BUTTON_LEFT].m_isPressed = false; + m_ButtonStates[INNO_MOUSE_BUTTON_LEFT].m_isPressed = false; return 0; } case WM_RBUTTONDOWN: { - m_buttonState[INNO_MOUSE_BUTTON_RIGHT].m_isPressed = true; + m_ButtonStates[INNO_MOUSE_BUTTON_RIGHT].m_isPressed = true; return 0; } case WM_RBUTTONUP: { - m_buttonState[INNO_MOUSE_BUTTON_RIGHT].m_isPressed = false; + m_ButtonStates[INNO_MOUSE_BUTTON_RIGHT].m_isPressed = false; return 0; } case WM_MOUSEMOVE: { - auto l_mouseCurrentX = GET_X_LPARAM(lparam); - auto l_mouseCurrentY = GET_Y_LPARAM(lparam); - g_Engine->getEventSystem()->mouseMovementCallback((float)l_mouseCurrentX, (float)l_mouseCurrentY); + auto l_mouseCurrentX = GET_X_LPARAM(lParam); + auto l_mouseCurrentY = GET_Y_LPARAM(lParam); + g_Engine->getEventSystem()->MouseMovementCallback((float)l_mouseCurrentX, (float)l_mouseCurrentY); return 0; } // Any other messages send to the default message handler as our application won't make use of them. default: { - return DefWindowProc(hwnd, umsg, wparam, lparam); + return DefWindowProc(hwnd, uMsg, wParam, lParam); } } } bool WinWindowSystem::Setup(ISystemConfig* systemConfig) { - auto l_systemConfig = reinterpret_cast(systemConfig); - - m_buttonState.resize(g_Engine->getEventSystem()->getInputConfig().totalKeyCodes); - - for (size_t i = 0; i < m_buttonState.size(); i++) + m_ButtonStates.resize(g_Engine->getEventSystem()->GetInputConfig().totalKeyCodes); + for (size_t i = 0; i < m_ButtonStates.size(); i++) { - m_buttonState[i].m_code = (uint32_t)i; + m_ButtonStates[i].m_code = (uint32_t)i; } - m_hInstance = static_cast(l_systemConfig->m_AppHook); - + auto l_systemConfig = reinterpret_cast(systemConfig); + m_ApplicationInstance = static_cast(l_systemConfig->m_AppHook); if (l_systemConfig->m_ExtraHook) { - m_hwnd = *reinterpret_cast(l_systemConfig->m_ExtraHook); + m_WindowHandle = *reinterpret_cast(l_systemConfig->m_ExtraHook); } - m_applicationName = g_Engine->getApplicationName().c_str(); - - // create window surface for different rendering backend - WinWindowSystemNS::m_initConfig = g_Engine->getInitConfig(); - - switch (WinWindowSystemNS::m_initConfig.renderingServer) + m_ApplicationName = g_Engine->GetApplicationName().c_str(); + WinWindowSystemNS::m_InitConfig = g_Engine->getInitConfig(); + switch (WinWindowSystemNS::m_InitConfig.renderingServer) { case RenderingServer::GL: - WinWindowSystemNS::m_windowSurface = new WinGLWindowSurface(); + WinWindowSystemNS::m_WindowSurface = new WinGLWindowSurface(); break; case RenderingServer::DX11: #if defined INNO_PLATFORM_WIN - WinWindowSystemNS::m_windowSurface = new WinDXWindowSurface(); + WinWindowSystemNS::m_WindowSurface = new WinDXWindowSurface(); #endif break; case RenderingServer::DX12: #if defined INNO_PLATFORM_WIN - WinWindowSystemNS::m_windowSurface = new WinDXWindowSurface(); + WinWindowSystemNS::m_WindowSurface = new WinDXWindowSurface(); #endif break; case RenderingServer::VK: #if defined INNO_RENDERER_VULKAN - WinWindowSystemNS::m_windowSurface = new WinVKWindowSurface(); + WinWindowSystemNS::m_WindowSurface = new WinVKWindowSurface(); #endif break; default: @@ -134,11 +127,11 @@ bool WinWindowSystem::Setup(ISystemConfig* systemConfig) } IWindowSurfaceConfig l_surfaceConfig; - l_surfaceConfig.hInstance = m_hInstance; - l_surfaceConfig.hwnd = m_hwnd; - l_surfaceConfig.WindowProc = WindowProc; + l_surfaceConfig.hInstance = m_ApplicationInstance; + l_surfaceConfig.hwnd = m_WindowHandle; + l_surfaceConfig.WindowProc = WinWindowSystemNS::WindowProcedure; - WinWindowSystemNS::m_windowSurface->Setup(&l_surfaceConfig); + WinWindowSystemNS::m_WindowSurface->Setup(&l_surfaceConfig); WinWindowSystemNS::m_ObjectStatus = ObjectStatus::Activated; Logger::Log(LogLevel::Success, "WinWindowSystem Setup finished."); @@ -148,16 +141,15 @@ bool WinWindowSystem::Setup(ISystemConfig* systemConfig) bool WinWindowSystem::Initialize() { - WinWindowSystemNS::m_windowSurface->Initialize(); + WinWindowSystemNS::m_WindowSurface->Initialize(); Logger::Log(LogLevel::Success, "WinWindowSystem has been initialized."); return true; } bool WinWindowSystem::Update() { - if (WinWindowSystemNS::m_initConfig.engineMode == EngineMode::Host) + if (WinWindowSystemNS::m_InitConfig.engineMode == EngineMode::Host) { - //Update window MSG msg; // Initialize the message structure. @@ -176,22 +168,22 @@ bool WinWindowSystem::Update() bool WinWindowSystem::Terminate() { - WinWindowSystemNS::m_windowSurface->Terminate(); + WinWindowSystemNS::m_WindowSurface->Terminate(); - if (WinWindowSystemNS::m_initConfig.engineMode == EngineMode::Host) + if (WinWindowSystemNS::m_InitConfig.engineMode == EngineMode::Host) { // Show the mouse cursor. ShowCursor(true); // Remove the window. - DestroyWindow(m_hwnd); - m_hwnd = NULL; + DestroyWindow(m_WindowHandle); + m_WindowHandle = NULL; Logger::Log(LogLevel::Warning, "WinWindowSystem: Window closed."); // Remove the application instance. - UnregisterClass(m_applicationName, m_hInstance); - m_hInstance = NULL; + UnregisterClass(m_ApplicationName, m_ApplicationInstance); + m_ApplicationInstance = NULL; } PostQuitMessage(0); @@ -206,56 +198,54 @@ ObjectStatus WinWindowSystem::GetStatus() return WinWindowSystemNS::m_ObjectStatus; } -IWindowSurface* WinWindowSystem::getWindowSurface() +IWindowSurface* WinWindowSystem::GetWindowSurface() { - return WinWindowSystemNS::m_windowSurface; + return WinWindowSystemNS::m_WindowSurface; } -const std::vector& WinWindowSystem::getButtonState() +const std::vector& WinWindowSystem::GetButtonState() { - return m_buttonState; + return m_ButtonStates; } -bool WinWindowSystem::sendEvent(uint32_t umsg, uint32_t WParam, int32_t LParam) +bool WinWindowSystem::SendEvent(uint32_t uMsg, uint32_t wParam, int32_t lParam) { - WindowProc(m_hwnd, umsg, WParam, LParam); + WinWindowSystemNS::WindowProcedure(m_WindowHandle, uMsg, wParam, lParam); return true; } -bool WinWindowSystem::addEventCallback(WindowEventCallbackFunctor* functor) +bool WinWindowSystem::AddEventCallback(WindowEventCallback* callback) { - m_windowEventCallbackFunctor.emplace(functor); + m_WindowEventCallbacks.emplace(callback); return true; } -LPCSTR WinWindowSystem::getApplicationName() +LPCSTR WinWindowSystem::GetApplicationName() { - return m_applicationName; + return m_ApplicationName; } -HINSTANCE WinWindowSystem::getHInstance() +HINSTANCE WinWindowSystem::GetApplicationInstance() { - return m_hInstance; + return m_ApplicationInstance; } -HWND WinWindowSystem::getHwnd() +HWND WinWindowSystem::GetWindowHandle() { - return m_hwnd; + return m_WindowHandle; } -bool WinWindowSystem::setHwnd(HWND rhs) +bool WinWindowSystem::SetWindowHandle(HWND hwnd) { - m_hwnd = rhs; + m_WindowHandle = hwnd; return true; } -LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK WinWindowSystemNS::WindowProcedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // For to eliminate fake OpenGL window handle event - if (hwnd != m_hwnd) - { - return MessageHandler(hwnd, uMsg, wParam, lParam); - } + if (hwnd != m_WindowHandle) + return ProcessEvent(hwnd, uMsg, wParam, lParam); switch (uMsg) { @@ -285,7 +275,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) } default: { - return MessageHandler(hwnd, uMsg, wParam, lParam); + return ProcessEvent(hwnd, uMsg, wParam, lParam); } } } \ No newline at end of file diff --git a/Source/Engine/Platform/WinWindow/WinWindowSystem.h b/Source/Engine/Platform/WinWindow/WinWindowSystem.h index 44fec854..b7bd9629 100644 --- a/Source/Engine/Platform/WinWindow/WinWindowSystem.h +++ b/Source/Engine/Platform/WinWindow/WinWindowSystem.h @@ -18,15 +18,15 @@ namespace Inno ObjectStatus GetStatus() override; - IWindowSurface* getWindowSurface() override; - const std::vector& getButtonState() override; + IWindowSurface* GetWindowSurface() override; + const std::vector& GetButtonState() override; - bool sendEvent(uint32_t umsg, uint32_t WParam, int32_t LParam) override; - bool addEventCallback(WindowEventCallbackFunctor* functor) override; + bool SendEvent(uint32_t uMsg, uint32_t wParam, int32_t lParam) override; + bool AddEventCallback(WindowEventCallback* callback) override; - LPCSTR getApplicationName(); - HINSTANCE getHInstance(); - HWND getHwnd(); - bool setHwnd(HWND rhs); + LPCSTR GetApplicationName(); + HINSTANCE GetApplicationInstance(); + HWND GetWindowHandle(); + bool SetWindowHandle(HWND hwnd); }; } \ No newline at end of file diff --git a/Source/Engine/RenderingFrontend/GUISystem.cpp b/Source/Engine/RenderingFrontend/GUISystem.cpp index 6ae45cb4..9bcaa041 100644 --- a/Source/Engine/RenderingFrontend/GUISystem.cpp +++ b/Source/Engine/RenderingFrontend/GUISystem.cpp @@ -18,7 +18,7 @@ bool GUISystem::Setup(ISystemConfig* systemConfig) f_toggleshowImGui = [&]() { m_showImGui = !m_showImGui; }; - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_I, true }, ButtonEvent{ EventLifeTime::OneShot, &f_toggleshowImGui }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_I, true }, ButtonEvent{ EventLifeTime::OneShot, &f_toggleshowImGui }); return ImGuiWrapper::Get().Setup(); } diff --git a/Source/Engine/RenderingServer/DX11/DX11RenderingServer.cpp b/Source/Engine/RenderingServer/DX11/DX11RenderingServer.cpp index a806261b..fc20744e 100644 --- a/Source/Engine/RenderingServer/DX11/DX11RenderingServer.cpp +++ b/Source/Engine/RenderingServer/DX11/DX11RenderingServer.cpp @@ -220,7 +220,7 @@ bool DX11RenderingServer::Setup(ISystemConfig* systemConfig) m_swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // Set the handle for the window to render to. - m_swapChainDesc.OutputWindow = reinterpret_cast(g_Engine->getWindowSystem())->getHwnd(); + m_swapChainDesc.OutputWindow = reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle(); // Turn multisampling off. m_swapChainDesc.SampleDesc.Count = 1; diff --git a/Source/Engine/RenderingServer/DX12/DX12RenderingServer.cpp b/Source/Engine/RenderingServer/DX12/DX12RenderingServer.cpp index 5d791097..158fe1a3 100644 --- a/Source/Engine/RenderingServer/DX12/DX12RenderingServer.cpp +++ b/Source/Engine/RenderingServer/DX12/DX12RenderingServer.cpp @@ -700,7 +700,7 @@ bool DX12RenderingServerNS::CreateSwapChain() IDXGISwapChain1 *l_swapChain1; auto l_hResult = m_factory->CreateSwapChainForHwnd( m_directCommandQueue.Get(), - reinterpret_cast(g_Engine->getWindowSystem())->getHwnd(), + reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle(), &m_swapChainDesc, nullptr, nullptr, diff --git a/Source/Engine/RenderingServer/VK/VKRenderingServer.cpp b/Source/Engine/RenderingServer/VK/VKRenderingServer.cpp index 1111c4d8..db954622 100644 --- a/Source/Engine/RenderingServer/VK/VKRenderingServer.cpp +++ b/Source/Engine/RenderingServer/VK/VKRenderingServer.cpp @@ -161,7 +161,7 @@ bool VKRenderingServerNS::CreateVkInstance() // set Vulkan app info VkApplicationInfo l_appInfo = {}; l_appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; - l_appInfo.pApplicationName = g_Engine->getApplicationName().c_str(); + l_appInfo.pApplicationName = g_Engine->GetApplicationName().c_str(); l_appInfo.applicationVersion = VK_MAKE_VERSION(0, 0, 9); l_appInfo.pEngineName = "cence Engine"; l_appInfo.engineVersion = VK_MAKE_VERSION(0, 0, 9); diff --git a/Source/Engine/SubSystem/EventSystem.cpp b/Source/Engine/SubSystem/EventSystem.cpp index 6fb48206..caf2d382 100644 --- a/Source/Engine/SubSystem/EventSystem.cpp +++ b/Source/Engine/SubSystem/EventSystem.cpp @@ -8,49 +8,55 @@ extern IEngine* g_Engine; using ButtonEventMap = std::unordered_multimap; using MouseMovementEventMap = std::unordered_map>; -namespace EventSystemNS +namespace Inno { - bool Setup(); - bool Initialize(); - bool Update(); - bool Terminate(); + class EventSystemImpl + { + public: + bool Setup(); + bool Initialize(); + bool Update(); + bool Terminate(); + + bool AddButtonStateCallback(ButtonState buttonState, ButtonEvent buttonEvent); + bool AddMouseMovementCallback(MouseMovementAxis mouseMovementAxis, MouseMovementEvent mouseMovementEvent); - bool addButtonStateCallback(ButtonState buttonState, ButtonEvent buttonEvent); - bool addMouseMovementCallback(MouseMovementAxis mouseMovementAxis, MouseMovementEvent mouseMovementEvent); + Vec2 GetMousePosition(); - Vec2 getMousePosition(); + void ButtonStateCallback(ButtonState buttonState); + void WindowResizeCallback(int32_t width, int32_t height); + void MouseMovementCallback(float mouseXPos, float mouseYPos); + void MouseScrollCallback(float xOffset, float yOffset); - void buttonStateCallback(ButtonState buttonState); - void windowSizeCallback(int32_t width, int32_t height); - void mouseMovementCallback(float mouseXPos, float mouseYPos); - void scrollCallback(float xoffset, float yoffset); + void ExecuteEvent(const ButtonEvent& buttonEvent); - ObjectStatus m_ObjectStatus = ObjectStatus::Terminated; + ObjectStatus m_ObjectStatus = ObjectStatus::Terminated; - const InputConfig m_inputConfig = { 256, 5 }; + const InputConfig m_InputConfig = { 256, 5 }; - std::vector m_previousFrameButtonStates; + std::vector m_PreviousFrameButtonStates; - ButtonEventMap m_buttonEvents; - MouseMovementEventMap m_mouseMovementEvents; + ButtonEventMap m_ButtonEvents; + MouseMovementEventMap m_MouseMovementEvents; - float m_mouseXOffset; - float m_mouseYOffset; - float m_mouseLastX; - float m_mouseLastY; + float m_MouseXOffset; + float m_MouseYOffset; + float m_MouseLastX; + float m_MouseLastY; - Vec4 m_mousePositionInWorldSpace; -}; + Vec4 m_MousePositionInWorldSpace; + }; +} -bool EventSystemNS::Setup() +bool EventSystemImpl::Setup() { - EventSystemNS::m_ObjectStatus = ObjectStatus::Created; + m_ObjectStatus = ObjectStatus::Created; return true; } -bool EventSystemNS::Initialize() +bool EventSystemImpl::Initialize() { - if (EventSystemNS::m_ObjectStatus == ObjectStatus::Created) + if (m_ObjectStatus == ObjectStatus::Created) { m_ObjectStatus = ObjectStatus::Activated; Logger::Log(LogLevel::Success, "EventSystem has been initialized."); @@ -64,54 +70,49 @@ bool EventSystemNS::Initialize() } } -bool EventSystemNS::Update() +bool EventSystemImpl::Update() { - if (EventSystemNS::m_ObjectStatus == ObjectStatus::Activated) + if (EventSystemImpl::m_ObjectStatus != ObjectStatus::Activated) { - auto l_buttonStates = g_Engine->getWindowSystem()->getButtonState(); + EventSystemImpl::m_ObjectStatus = ObjectStatus::Suspended; + return false; + } - for (auto& i : l_buttonStates) - { - buttonStateCallback(i); - } + auto l_buttonStates = g_Engine->getWindowSystem()->GetButtonState(); + for (auto& i : l_buttonStates) + { + ButtonStateCallback(i); + } - if (m_mouseMovementEvents.size() != 0) + if (m_MouseMovementEvents.size() != 0) + { + if (m_MouseXOffset != 0) { - if (m_mouseXOffset != 0) + for (auto& j : m_MouseMovementEvents.find(MouseMovementAxis::Horizontal)->second) { - for (auto& j : m_mouseMovementEvents.find(MouseMovementAxis::Horizontal)->second) - { - (*j.m_eventHandle)(m_mouseXOffset); - }; + (*j.m_eventHandle)(m_MouseXOffset); } - if (m_mouseYOffset != 0) - { - for (auto& j : m_mouseMovementEvents.find(MouseMovementAxis::Vertical)->second) - { - (*j.m_eventHandle)(m_mouseYOffset); - }; - } - if (m_mouseXOffset != 0 || m_mouseYOffset != 0) + } + if (m_MouseYOffset != 0) + { + for (auto& j : m_MouseMovementEvents.find(MouseMovementAxis::Vertical)->second) { - m_mouseXOffset = 0; - m_mouseYOffset = 0; + (*j.m_eventHandle)(m_MouseYOffset); } } - - m_previousFrameButtonStates = l_buttonStates; - - return true; - } - else - { - EventSystemNS::m_ObjectStatus = ObjectStatus::Suspended; - return false; + if (m_MouseXOffset != 0 || m_MouseYOffset != 0) + { + m_MouseXOffset = 0; + m_MouseYOffset = 0; + } } + m_PreviousFrameButtonStates = l_buttonStates; + return true; } -bool EventSystemNS::Terminate() +bool EventSystemImpl::Terminate() { m_ObjectStatus = ObjectStatus::Terminated; Logger::Log(LogLevel::Success, "EventSystem has been terminated."); @@ -119,150 +120,143 @@ bool EventSystemNS::Terminate() return true; } -bool EventSystemNS::addButtonStateCallback(ButtonState buttonState, ButtonEvent buttonEvent) +bool EventSystemImpl::AddButtonStateCallback(ButtonState buttonState, ButtonEvent buttonEvent) { - m_buttonEvents.emplace(buttonState, buttonEvent); + m_ButtonEvents.emplace(buttonState, buttonEvent); return true; } -bool EventSystemNS::addMouseMovementCallback(MouseMovementAxis mouseMovementAxis, MouseMovementEvent mouseMovementEvent) +bool EventSystemImpl::AddMouseMovementCallback(MouseMovementAxis mouseMovementAxis, MouseMovementEvent mouseMovementEvent) { - auto l_result = m_mouseMovementEvents.find(mouseMovementAxis); - if (l_result != m_mouseMovementEvents.end()) - { + auto l_result = m_MouseMovementEvents.find(mouseMovementAxis); + if (l_result != m_MouseMovementEvents.end()) l_result->second.emplace(mouseMovementEvent); - } else - { - m_mouseMovementEvents.emplace(mouseMovementAxis, std::set{ mouseMovementEvent }); - } + m_MouseMovementEvents.emplace(mouseMovementAxis, std::set{ mouseMovementEvent }); return true; } -Vec2 EventSystemNS::getMousePosition() +Vec2 EventSystemImpl::GetMousePosition() { - return Vec2(m_mouseLastX, m_mouseLastY); + return Vec2(m_MouseLastX, m_MouseLastY); } -void EventSystemNS::buttonStateCallback(ButtonState buttonState) +void EventSystemImpl::ButtonStateCallback(ButtonState buttonState) { - auto l_buttonEvents = m_buttonEvents.equal_range(buttonState); + auto l_buttonEvents = m_ButtonEvents.equal_range(buttonState); auto l_resultCount = std::distance(l_buttonEvents.first, l_buttonEvents.second); + if (!l_resultCount) + return; - if (l_resultCount) + for (auto it = l_buttonEvents.first; it != l_buttonEvents.second; it++) { - for (auto it = l_buttonEvents.first; it != l_buttonEvents.second; it++) + if (it->second.m_eventLifeTime == EventLifeTime::Continuous && it->second.m_eventHandle) + ExecuteEvent(it->second); + else if (m_PreviousFrameButtonStates.size()) { - if (it->second.m_eventLifeTime == EventLifeTime::Continuous) - { - if (it->second.m_eventHandle) - { - auto l_event = reinterpret_cast*>(it->second.m_eventHandle); - (*l_event)(); - } - } - else - { - if (m_previousFrameButtonStates.size()) - { - auto l_previousFrameButtonState = m_previousFrameButtonStates[it->first.m_code]; - if (l_previousFrameButtonState.m_isPressed != it->first.m_isPressed) - { - if (it->second.m_eventHandle) - { - auto l_event = reinterpret_cast*>(it->second.m_eventHandle); - (*l_event)(); - } - } - } - } + auto l_previousFrameButtonState = m_PreviousFrameButtonStates[it->first.m_code]; + if (l_previousFrameButtonState.m_isPressed != it->first.m_isPressed && it->second.m_eventHandle) + ExecuteEvent(it->second); } } } -void EventSystemNS::windowSizeCallback(int32_t width, int32_t height) +void EventSystemImpl::WindowResizeCallback(int32_t width, int32_t height) { TVec2 l_newScreenResolution = TVec2(width, height); g_Engine->getRenderingFrontend()->SetScreenResolution(l_newScreenResolution); g_Engine->getRenderingServer()->Resize(); } -void EventSystemNS::mouseMovementCallback(float mouseXPos, float mouseYPos) +void EventSystemImpl::MouseMovementCallback(float mouseXPos, float mouseYPos) { - m_mouseXOffset = mouseXPos - m_mouseLastX; - m_mouseYOffset = m_mouseLastY - mouseYPos; + m_MouseXOffset = mouseXPos - m_MouseLastX; + m_MouseYOffset = m_MouseLastY - mouseYPos; - m_mouseLastX = mouseXPos; - m_mouseLastY = mouseYPos; + m_MouseLastX = mouseXPos; + m_MouseLastY = mouseYPos; +} + +void EventSystemImpl::MouseScrollCallback(float xOffset, float yOffset) +{ } -void EventSystemNS::scrollCallback(float xoffset, float yoffset) +void EventSystemImpl::ExecuteEvent(const ButtonEvent& buttonEvent) { + auto l_event = reinterpret_cast*>(buttonEvent.m_eventHandle); + (*l_event)(); } bool EventSystem::Setup(ISystemConfig* systemConfig) { - return EventSystemNS::Setup(); + m_Impl = new EventSystemImpl(); + return m_Impl->Setup(); } bool EventSystem::Initialize() { - return EventSystemNS::Initialize(); + return m_Impl->Initialize(); } bool EventSystem::Update() { - return EventSystemNS::Update(); + return m_Impl->Update(); } bool EventSystem::Terminate() { - return EventSystemNS::Terminate(); + if (m_Impl->Terminate()) + { + delete m_Impl; + return true; + } + + return false; } -InputConfig EventSystem::getInputConfig() +InputConfig EventSystem::GetInputConfig() { - return EventSystemNS::m_inputConfig; + return m_Impl->m_InputConfig; } -void EventSystem::addButtonStateCallback(ButtonState buttonState, ButtonEvent buttonEvent) +void EventSystem::AddButtonStateCallback(ButtonState buttonState, ButtonEvent buttonEvent) { - EventSystemNS::addButtonStateCallback(buttonState, buttonEvent); + m_Impl->AddButtonStateCallback(buttonState, buttonEvent); } -void EventSystem::addMouseMovementCallback(MouseMovementAxis mouseMovementAxis, MouseMovementEvent mouseMovementEvent) +void EventSystem::AddMouseMovementCallback(MouseMovementAxis mouseMovementAxis, MouseMovementEvent mouseMovementEvent) { - EventSystemNS::addMouseMovementCallback(mouseMovementAxis, mouseMovementEvent); + m_Impl->AddMouseMovementCallback(mouseMovementAxis, mouseMovementEvent); } -void EventSystem::buttonStateCallback(ButtonState buttonState) +void EventSystem::ButtonStateCallback(ButtonState buttonState) { - EventSystemNS::buttonStateCallback(buttonState); + m_Impl->ButtonStateCallback(buttonState); } -void EventSystem::windowSizeCallback(int32_t width, int32_t height) +void EventSystem::WindowResizeCallback(int32_t width, int32_t height) { - EventSystemNS::windowSizeCallback(width, height); + m_Impl->WindowResizeCallback(width, height); } -void EventSystem::mouseMovementCallback(float mouseXPos, float mouseYPos) +void EventSystem::MouseMovementCallback(float mouseXPos, float mouseYPos) { - EventSystemNS::mouseMovementCallback(mouseXPos, mouseYPos); + m_Impl->MouseMovementCallback(mouseXPos, mouseYPos); } -void EventSystem::scrollCallback(float xoffset, float yoffset) +void EventSystem::ScrollCallback(float xOffset, float yOffset) { - EventSystemNS::scrollCallback(xoffset, yoffset); + m_Impl->MouseScrollCallback(xOffset, yOffset); } -Vec2 EventSystem::getMousePosition() +Vec2 EventSystem::GetMousePosition() { - return EventSystemNS::getMousePosition(); + return m_Impl->GetMousePosition(); } ObjectStatus EventSystem::GetStatus() { - return EventSystemNS::m_ObjectStatus; + return m_Impl->m_ObjectStatus; } \ No newline at end of file diff --git a/Source/Engine/SubSystem/EventSystem.h b/Source/Engine/SubSystem/EventSystem.h index 836f973a..2f5daabb 100644 --- a/Source/Engine/SubSystem/EventSystem.h +++ b/Source/Engine/SubSystem/EventSystem.h @@ -3,6 +3,7 @@ namespace Inno { + class EventSystemImpl; class EventSystem : public IEventSystem { public: @@ -15,16 +16,19 @@ namespace Inno ObjectStatus GetStatus() override; - InputConfig getInputConfig() override; + InputConfig GetInputConfig() override; - void addButtonStateCallback(ButtonState buttonState, ButtonEvent buttonEvent) override; - void addMouseMovementCallback(MouseMovementAxis mouseMovementAxis, MouseMovementEvent mouseMovementEvent) override; + void AddButtonStateCallback(ButtonState buttonState, ButtonEvent buttonEvent) override; + void AddMouseMovementCallback(MouseMovementAxis mouseMovementAxis, MouseMovementEvent mouseMovementEvent) override; - void buttonStateCallback(ButtonState buttonState) override; - void windowSizeCallback(int32_t width, int32_t height) override; - void mouseMovementCallback(float mouseXPos, float mouseYPos) override; - void scrollCallback(float xoffset, float yoffset) override; + void ButtonStateCallback(ButtonState buttonState) override; + void WindowResizeCallback(int32_t width, int32_t height) override; + void MouseMovementCallback(float mouseXPos, float mouseYPos) override; + void ScrollCallback(float xOffset, float yOffset) override; - Vec2 getMousePosition() override; + Vec2 GetMousePosition() override; + + private: + EventSystemImpl* m_Impl; }; } \ No newline at end of file diff --git a/Source/Engine/ThirdParty/ImGuiWrapper/ImGuiWindowWin.cpp b/Source/Engine/ThirdParty/ImGuiWrapper/ImGuiWindowWin.cpp index 9a2490a2..3e73be4e 100644 --- a/Source/Engine/ThirdParty/ImGuiWrapper/ImGuiWindowWin.cpp +++ b/Source/Engine/ThirdParty/ImGuiWrapper/ImGuiWindowWin.cpp @@ -10,7 +10,7 @@ extern IEngine* g_Engine; namespace ImGuiWindowWinNS { - WindowEventCallbackFunctor m_windowEventCallbackFunctor; + WindowEventCallback m_windowEventCallbackFunctor; ObjectStatus m_ObjectStatus = ObjectStatus::Terminated; } @@ -24,7 +24,7 @@ bool ImGuiWindowWin::Setup(ISystemConfig* systemConfig) ImGuiWindowWinNS::m_windowEventCallbackFunctor = [](void* hWnd, uint32_t msg, uint64_t wParam, int64_t lParam) { ImGui_ImplWin32_WndProcHandler((HWND)hWnd, msg, wParam, lParam); }; - g_Engine->getWindowSystem()->addEventCallback(&ImGuiWindowWinNS::m_windowEventCallbackFunctor); + g_Engine->getWindowSystem()->AddEventCallback(&ImGuiWindowWinNS::m_windowEventCallbackFunctor); m_ObjectStatus = ObjectStatus::Created; @@ -35,7 +35,7 @@ bool ImGuiWindowWin::Setup(ISystemConfig* systemConfig) bool ImGuiWindowWin::Initialize() { - ImGui_ImplWin32_Init(reinterpret_cast(g_Engine->getWindowSystem())->getHwnd()); + ImGui_ImplWin32_Init(reinterpret_cast(g_Engine->getWindowSystem())->GetWindowHandle()); m_ObjectStatus = ObjectStatus::Activated; diff --git a/Source/Engine/ThirdParty/PhysXWrapper/PhysXWrapper.cpp b/Source/Engine/ThirdParty/PhysXWrapper/PhysXWrapper.cpp index d02e61bf..ca5cf07e 100644 --- a/Source/Engine/ThirdParty/PhysXWrapper/PhysXWrapper.cpp +++ b/Source/Engine/ThirdParty/PhysXWrapper/PhysXWrapper.cpp @@ -133,7 +133,7 @@ bool PhysXWrapperNS::Setup() f_pauseSimulate = [&]() { m_needSimulate = !m_needSimulate; }; - g_Engine->getEventSystem()->addButtonStateCallback(ButtonState{ INNO_KEY_P, true }, ButtonEvent{ EventLifeTime::OneShot, &f_pauseSimulate }); + g_Engine->getEventSystem()->AddButtonStateCallback(ButtonState{ INNO_KEY_P, true }, ButtonEvent{ EventLifeTime::OneShot, &f_pauseSimulate }); return true; }