diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 846479fd7..a2256b001 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -82,6 +82,9 @@ void Config::ReadValues() { // System Region Settings::values.region_value = glfw_config->GetInteger("System Region", "region_value", 1); + // Input Backend + Settings::values.input_backend = glfw_config->GetInteger("Input Backend", "input_backend", 0); + // Miscellaneous Settings::values.log_filter = glfw_config->Get("Miscellaneous", "log_filter", "*:Info"); } diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h index fd5a90d56..5129e613d 100644 --- a/src/citra/default_ini.h +++ b/src/citra/default_ini.h @@ -62,6 +62,11 @@ use_virtual_sd = # 0: Japan, 1: USA (default), 2: Europe, 3: Australia, 4: China, 5: Korea, 6: Taiwan region_value = +[Input Backend] +# Input system Citra will use during emulation +# 0: Keyboard (default), 1: SDL2 (gamepad) +input_backend = + [Miscellaneous] # A filter which removes logs below a certain logging level. # Examples: *:Debug Kernel.SVC:Trace Service.*:Critical diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp index 1dbd1a00d..900e1cfc3 100644 --- a/src/citra/emu_window/emu_window_glfw.cpp +++ b/src/citra/emu_window/emu_window_glfw.cpp @@ -127,7 +127,7 @@ void EmuWindow_GLFW::SwapBuffers() { /// Polls window events void EmuWindow_GLFW::PollEvents() { glfwPollEvents(); - InputCommon::g_user_input->Poll(); + if(InputCommon::g_user_input) InputCommon::g_user_input->Poll(); } /// Makes the GLFW OpenGL context current for the caller thread diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 998cb1b18..bfd82c6e0 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -161,7 +161,7 @@ void GRenderWindow::DoneCurrent() } void GRenderWindow::PollEvents() { - InputCommon::g_user_input->Poll(); + if(InputCommon::g_user_input) InputCommon::g_user_input->Poll(); } // On Qt 5.0+, this correctly gets the size of the framebuffer (pixels). diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index 460f4ec07..5f3be1210 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -69,6 +69,10 @@ void Config::ReadValues() { Settings::values.region_value = qt_config->value("region_value", 1).toInt(); qt_config->endGroup(); + qt_config->beginGroup("Input Backend"); + Settings::values.input_backend = qt_config->value("input_backend", 0).toInt(); + qt_config->endGroup(); + qt_config->beginGroup("Miscellaneous"); Settings::values.log_filter = qt_config->value("log_filter", "*:Info").toString().toStdString(); qt_config->endGroup(); @@ -123,6 +127,10 @@ void Config::SaveValues() { qt_config->setValue("region_value", Settings::values.region_value); qt_config->endGroup(); + qt_config->beginGroup("Input Backend"); + qt_config->setValue("input_backend", Settings::values.input_backend); + qt_config->endGroup(); + qt_config->beginGroup("Miscellaneous"); qt_config->setValue("log_filter", QString::fromStdString(Settings::values.log_filter)); qt_config->endGroup(); diff --git a/src/core/settings.h b/src/core/settings.h index 54c1023b8..8f65a5cc4 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -51,6 +51,9 @@ struct Values { float bg_green; float bg_blue; + // Input backend + int input_backend; + std::string log_filter; } extern values; diff --git a/src/core/system.cpp b/src/core/system.cpp index 50ef00e84..4b0209896 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -24,7 +24,7 @@ void Init(EmuWindow* emu_window) { Kernel::Init(); HLE::Init(); VideoCore::Init(emu_window); - InputCommon::Init(InputCommon::InputBackends::SDL2); + InputCommon::Init(); } void Shutdown() { diff --git a/src/input_common/input_common.cpp b/src/input_common/input_common.cpp index 47df0babf..3520a7c83 100644 --- a/src/input_common/input_common.cpp +++ b/src/input_common/input_common.cpp @@ -8,6 +8,8 @@ #include "input_common/sdl_input/sdl_input.h" #endif +#include "core/settings.h" + namespace InputCommon { // User input system @@ -21,8 +23,13 @@ const Service::HID::PadState& InputBase::GetPadState() const { return controller.pad_state; } -void Init(InputBackends backend) { - switch (backend) { +void Init() { + // Initialize backend based on configuration settings + // Convert int into a strongly typed enum first + + std::cout<<"Setting -> " << Settings::values.input_backend << "\n"; + + switch (static_cast(Settings::values.input_backend)) { #ifdef HAS_SDL // SDL2 backend selected case InputBackends::SDL2: @@ -41,10 +48,7 @@ void Init(InputBackends backend) { } // Shutdown immediately if backend failed to initialize - if (!g_user_input && !g_user_input->activated) { - Shutdown(); - return; - } + if (!g_user_input) Shutdown(); } void Shutdown() { diff --git a/src/input_common/input_common.h b/src/input_common/input_common.h index ea8f40a7c..c15665623 100644 --- a/src/input_common/input_common.h +++ b/src/input_common/input_common.h @@ -11,8 +11,8 @@ namespace InputCommon { /// Enum defining available backends enum class InputBackends { - NONE, - SDL2 + NONE = 0, + SDL2 = 1 }; class InputBase : NonCopyable { @@ -44,9 +44,6 @@ public: */ const Service::HID::PadState& GetPadState() const; - /// Current input system activation status - bool activated; - protected: /// Internal name of currently selected device std::string device_name; @@ -55,11 +52,8 @@ protected: ControllerState controller; }; -/** - * Initializes the user input system - * @param backend Enumeration of the backend to use - */ -void Init(InputBackends backend); +/// Initialize the user input system +void Init(); /// Deactive the user input system void Shutdown(); diff --git a/src/input_common/sdl_input/sdl_input.cpp b/src/input_common/sdl_input/sdl_input.cpp index 1b18ce0ad..9a6422be6 100644 --- a/src/input_common/sdl_input/sdl_input.cpp +++ b/src/input_common/sdl_input/sdl_input.cpp @@ -18,7 +18,7 @@ SDLController::SDLController() { controller.touch_screen_x = 0; controller.touch_screen_y = 0; - activated = Init(); + Init(); } SDLController::~SDLController() { @@ -127,6 +127,10 @@ void SDLController::ProcessInput() { pad_id = 300; pad_id += input_event.jhat.hat * 4; + // It is physically impossible for a hat/"dpad" to have certain inputs activated + // That is to say when "left" is activated, "right" must be deactivated + // All of these activate/deactivate combos must be accounted for hat input + // For hats, pad_ids are L/R/U/D, e.g. L = pad_id, R = pad_id + 1, and so on switch (input_event.jhat.value) { case SDL_HAT_CENTERED: controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex;