From 9e1b0af25907f7a8b960aa5c1e7d931691f40196 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 27 Aug 2020 15:16:47 -0400 Subject: input_common: Eliminate most global state Abstracts most of the input mechanisms under an InputSubsystem class that is managed by the frontends, eliminating any static constructors and destructors. This gets rid of global accessor functions and also allows the frontends to have a more fine-grained control over the lifecycle of the input subsystem. This also makes it explicit which interfaces rely on the input subsystem instead of making it opaque in the interface functions. All that remains to migrate over is the factories, which can be done in a separate change. --- src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/yuzu_cmd/emu_window/emu_window_sdl2.cpp') diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index e5e684206..a804d5185 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp @@ -13,23 +13,25 @@ #include "input_common/sdl/sdl.h" #include "yuzu_cmd/emu_window/emu_window_sdl2.h" -EmuWindow_SDL2::EmuWindow_SDL2(Core::System& system, bool fullscreen) : system{system} { +EmuWindow_SDL2::EmuWindow_SDL2(Core::System& system, bool fullscreen, + InputCommon::InputSubsystem* input_subsystem_) + : system{system}, input_subsystem{input_subsystem_} { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { LOG_CRITICAL(Frontend, "Failed to initialize SDL2! Exiting..."); exit(1); } - InputCommon::Init(); + input_subsystem->Initialize(); SDL_SetMainReady(); } EmuWindow_SDL2::~EmuWindow_SDL2() { - InputCommon::Shutdown(); + input_subsystem->Shutdown(); SDL_Quit(); } void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); - InputCommon::GetMotionEmu()->Tilt(x, y); + input_subsystem->GetMotionEmu()->Tilt(x, y); } void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { @@ -41,9 +43,9 @@ void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { } } else if (button == SDL_BUTTON_RIGHT) { if (state == SDL_PRESSED) { - InputCommon::GetMotionEmu()->BeginTilt(x, y); + input_subsystem->GetMotionEmu()->BeginTilt(x, y); } else { - InputCommon::GetMotionEmu()->EndTilt(); + input_subsystem->GetMotionEmu()->EndTilt(); } } } @@ -79,9 +81,9 @@ void EmuWindow_SDL2::OnFingerUp() { void EmuWindow_SDL2::OnKeyEvent(int key, u8 state) { if (state == SDL_PRESSED) { - InputCommon::GetKeyboard()->PressKey(key); + input_subsystem->GetKeyboard()->PressKey(key); } else if (state == SDL_RELEASED) { - InputCommon::GetKeyboard()->ReleaseKey(key); + input_subsystem->GetKeyboard()->ReleaseKey(key); } } -- cgit v1.2.3