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.
This commit is contained in:
phosit 2025-04-18 11:03:34 +02:00
parent f6cd1be604
commit f52429c996
No known key found for this signature in database
GPG key ID: C9430B600671C268
3 changed files with 12 additions and 15 deletions

View file

@ -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<ICameraController> CameraController;
struct InputHandler
{
CGameViewImpl& gameView;
Input::Reaction operator()(const SDL_Event& ev);
};
Input::Handler<InputHandler> 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);
}

View file

@ -19,7 +19,6 @@
#define INCLUDED_GAMEVIEW
#include "lib/code_annotation.h"
#include "ps/Input.h"
#include "renderer/backend/IDeviceCommandContext.h"
#include "renderer/Scene.h"
#include "simulation2/system/Entity.h"
@ -59,8 +58,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;
@ -99,6 +96,4 @@ private:
CGameViewImpl* m;
};
Input::Reaction game_view_handler(const SDL_Event& ev);
#endif // INCLUDED_GAMEVIEW

View file

@ -258,7 +258,6 @@ static void InitPs(bool setup_gui, const CStrW& gui_page, ScriptInterface* srcSc
g_Joystick.Initialise();
std::unique_ptr<InputHandlers> handlers{std::make_unique<InputHandlers>()};
handlers->emplace(g_VideoMode.m_InputManager, Input::Slot::GAME_VIEW, game_view_handler);
handlers->emplace(g_VideoMode.m_InputManager, Input::Slot::HOTKEY_INPUT, HotkeyInputActualHandler);