From 364d50e1849a3d6479f3cc1d60c7e99f2f2d55be Mon Sep 17 00:00:00 2001 From: phosit Date: Fri, 18 Apr 2025 11:03:34 +0200 Subject: [PATCH] Move the gameView input handler to CGameView `game_view_handler` isn't global anymore. That makes the interface simpler and might make the compilation and the runtime faster. --- source/graphics/GameView.cpp | 21 ++++++++++++--------- source/graphics/GameView.h | 5 ----- source/ps/GameSetup/GameSetup.cpp | 1 - 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index a163a913f2..c1a0f8d327 100644 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -46,9 +46,11 @@ #include "ps/Game.h" #include "ps/Globals.h" #include "ps/Hotkey.h" +#include "ps/Input.h" #include "ps/Loader.h" #include "ps/Profile.h" #include "ps/TouchInput.h" +#include "ps/VideoMode.h" #include "ps/World.h" #include "renderer/Renderer.h" #include "renderer/SceneRenderer.h" @@ -129,6 +131,14 @@ public: * on the fly replacement. It's guaranteed that the pointer is never nulllptr. */ std::unique_ptr CameraController; + + struct InputHandler + { + CGameViewImpl& gameView; + Input::Reaction operator()(const SDL_Event& ev); + }; + Input::Handler m_InputHandler{g_VideoMode.m_InputManager, Input::Slot::GAME_VIEW, + {*this}}; }; #define IMPLEMENT_BOOLEAN_SETTING(NAME) \ @@ -353,19 +363,12 @@ entity_id_t CGameView::GetFollowedEntity() return m->CameraController->GetFollowedEntity(); } -Input::Reaction game_view_handler(const SDL_Event& ev) +Input::Reaction CGameViewImpl::InputHandler::operator()(const SDL_Event& ev) { // put any events that must be processed even if inactive here if (!g_app_has_focus || !g_Game || !g_Game->IsGameStarted() || g_Game->GetView()->GetCinema()->IsPlaying()) return Input::Reaction::PASS; - CGameView *pView=g_Game->GetView(); - - return pView->HandleEvent(ev); -} - -Input::Reaction CGameView::HandleEvent(const SDL_Event& ev) -{ switch(ev.type) { case SDL_HOTKEYPRESS: @@ -402,5 +405,5 @@ Input::Reaction CGameView::HandleEvent(const SDL_Event& ev) } } - return m->CameraController->HandleEvent(ev); + return gameView.CameraController->HandleEvent(ev); } diff --git a/source/graphics/GameView.h b/source/graphics/GameView.h index 58e2ff6c22..8376fe1793 100644 --- a/source/graphics/GameView.h +++ b/source/graphics/GameView.h @@ -19,7 +19,6 @@ #define INCLUDED_GAMEVIEW #include "lib/code_annotation.h" -#include "ps/Input.h" #include "renderer/Scene.h" #include "simulation2/system/Entity.h" @@ -58,8 +57,6 @@ public: void Render(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); void RenderOverlays(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); - Input::Reaction HandleEvent(const SDL_Event& ev); - CVector3D GetCameraPivot() const; CVector3D GetCameraPosition() const; CVector3D GetCameraRotation() const; @@ -98,6 +95,4 @@ private: CGameViewImpl* m; }; -Input::Reaction game_view_handler(const SDL_Event& ev); - #endif // INCLUDED_GAMEVIEW diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 4da2802d02..8f97edea79 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -258,7 +258,6 @@ static void InitPs(bool setup_gui, const CStrW& gui_page, ScriptInterface* srcSc g_Joystick.Initialise(); std::unique_ptr handlers{std::make_unique()}; - handlers->emplace(g_VideoMode.m_InputManager, Input::Slot::GAME_VIEW, game_view_handler); handlers->emplace(g_VideoMode.m_InputManager, Input::Slot::HOTKEY_INPUT, HotkeyInputActualHandler);