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.
This commit is contained in:
parent
3db9a25977
commit
9e1b0af259
25 changed files with 397 additions and 243 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,14 @@ namespace Core {
|
|||
class System;
|
||||
}
|
||||
|
||||
namespace InputCommon {
|
||||
class InputSubsystem;
|
||||
}
|
||||
|
||||
class EmuWindow_SDL2 : public Core::Frontend::EmuWindow {
|
||||
public:
|
||||
explicit EmuWindow_SDL2(Core::System& system, bool fullscreen);
|
||||
explicit EmuWindow_SDL2(Core::System& system, bool fullscreen,
|
||||
InputCommon::InputSubsystem* input_subsystem);
|
||||
~EmuWindow_SDL2();
|
||||
|
||||
/// Polls window events
|
||||
|
@ -76,4 +81,7 @@ protected:
|
|||
|
||||
/// Keeps track of how often to update the title bar during gameplay
|
||||
u32 last_time = 0;
|
||||
|
||||
/// Input subsystem to use with this window.
|
||||
InputCommon::InputSubsystem* input_subsystem;
|
||||
};
|
||||
|
|
|
@ -87,8 +87,9 @@ bool EmuWindow_SDL2_GL::SupportsRequiredGLExtensions() {
|
|||
return unsupported_ext.empty();
|
||||
}
|
||||
|
||||
EmuWindow_SDL2_GL::EmuWindow_SDL2_GL(Core::System& system, bool fullscreen)
|
||||
: EmuWindow_SDL2{system, fullscreen} {
|
||||
EmuWindow_SDL2_GL::EmuWindow_SDL2_GL(Core::System& system, bool fullscreen,
|
||||
InputCommon::InputSubsystem* input_subsystem)
|
||||
: EmuWindow_SDL2{system, fullscreen, input_subsystem} {
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
|
||||
|
|
|
@ -8,9 +8,14 @@
|
|||
#include "core/frontend/emu_window.h"
|
||||
#include "yuzu_cmd/emu_window/emu_window_sdl2.h"
|
||||
|
||||
namespace InputCommon {
|
||||
class InputSubsystem;
|
||||
}
|
||||
|
||||
class EmuWindow_SDL2_GL final : public EmuWindow_SDL2 {
|
||||
public:
|
||||
explicit EmuWindow_SDL2_GL(Core::System& system, bool fullscreen);
|
||||
explicit EmuWindow_SDL2_GL(Core::System& system, bool fullscreen,
|
||||
InputCommon::InputSubsystem* input_subsystem);
|
||||
~EmuWindow_SDL2_GL();
|
||||
|
||||
void Present() override;
|
||||
|
|
|
@ -19,8 +19,9 @@
|
|||
#include <SDL.h>
|
||||
#include <SDL_syswm.h>
|
||||
|
||||
EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(Core::System& system, bool fullscreen)
|
||||
: EmuWindow_SDL2{system, fullscreen} {
|
||||
EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(Core::System& system, bool fullscreen,
|
||||
InputCommon::InputSubsystem* input_subsystem)
|
||||
: EmuWindow_SDL2{system, fullscreen, input_subsystem} {
|
||||
const std::string window_title = fmt::format("yuzu {} | {}-{} (Vulkan)", Common::g_build_name,
|
||||
Common::g_scm_branch, Common::g_scm_desc);
|
||||
render_window =
|
||||
|
|
|
@ -13,9 +13,14 @@ namespace Core {
|
|||
class System;
|
||||
}
|
||||
|
||||
namespace InputCommon {
|
||||
class InputSubsystem;
|
||||
}
|
||||
|
||||
class EmuWindow_SDL2_VK final : public EmuWindow_SDL2 {
|
||||
public:
|
||||
explicit EmuWindow_SDL2_VK(Core::System& system, bool fullscreen);
|
||||
explicit EmuWindow_SDL2_VK(Core::System& system, bool fullscreen,
|
||||
InputCommon::InputSubsystem* input_subsystem);
|
||||
~EmuWindow_SDL2_VK();
|
||||
|
||||
void Present() override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue