From 6b5fbca567ffdd33438cd87acf38d709f3e4ff3e Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Sun, 27 Nov 2022 20:29:54 +0100 Subject: [PATCH] early-access version 3161 --- README.md | 2 +- src/input_common/drivers/sdl_driver.cpp | 15 +++++-------- src/input_common/drivers/sdl_driver.h | 3 ++- src/input_common/main.cpp | 10 +++++++++ src/input_common/main.h | 3 +++ src/yuzu/main.cpp | 12 ++++++++++ src/yuzu/main.h | 2 ++ src/yuzu_cmd/default_ini.h | 29 ++++++++++++++++++++++--- 8 files changed, 62 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 45ada3632..8dc11f0cb 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 3160. +This is the source code for early-access 3161. ## Legal Notice diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index 034ee7159..439009b3d 100755 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp @@ -361,6 +361,12 @@ void SDLDriver::CloseJoystick(SDL_Joystick* sdl_joystick) { } } +void SDLDriver::PumpEvents() const { + if (initialized) { + SDL_PumpEvents(); + } +} + void SDLDriver::HandleGameControllerEvent(const SDL_Event& event) { switch (event.type) { case SDL_JOYBUTTONUP: { @@ -451,14 +457,6 @@ SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_en initialized = true; if (start_thread) { - poll_thread = std::thread([this] { - Common::SetCurrentThreadName("SDL_MainLoop"); - using namespace std::chrono_literals; - while (initialized) { - SDL_PumpEvents(); - std::this_thread::sleep_for(1ms); - } - }); vibration_thread = std::thread([this] { Common::SetCurrentThreadName("SDL_Vibration"); using namespace std::chrono_literals; @@ -481,7 +479,6 @@ SDLDriver::~SDLDriver() { initialized = false; if (start_thread) { - poll_thread.join(); vibration_thread.join(); SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER); } diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h index a5f78d3fa..104508520 100755 --- a/src/input_common/drivers/sdl_driver.h +++ b/src/input_common/drivers/sdl_driver.h @@ -36,6 +36,8 @@ public: /// Unregisters SDL device factories and shut them down. ~SDLDriver() override; + void PumpEvents() const; + /// Handle SDL_Events for joysticks from SDL_PollEvent void HandleGameControllerEvent(const SDL_Event& event); @@ -128,7 +130,6 @@ private: bool start_thread = false; std::atomic initialized = false; - std::thread poll_thread; std::thread vibration_thread; }; } // namespace InputCommon diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 1c63d15fd..c4abbfa73 100755 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -334,6 +334,12 @@ struct InputSubsystem::Impl { #endif } + void PumpEvents() const { +#ifdef HAVE_SDL2 + sdl->PumpEvents(); +#endif + } + void RegisterInput(const MappingData& data) { mapping_factory->RegisterInput(data); } @@ -482,6 +488,10 @@ void InputSubsystem::StopMapping() const { impl->mapping_factory->StopMapping(); } +void InputSubsystem::PumpEvents() const { + impl->PumpEvents(); +} + std::string GenerateKeyboardParam(int key_code) { Common::ParamPackage param; param.Set("engine", "keyboard"); diff --git a/src/input_common/main.h b/src/input_common/main.h index 870e196fb..d223257f6 100755 --- a/src/input_common/main.h +++ b/src/input_common/main.h @@ -147,6 +147,9 @@ public: /// Stop polling from all backends. void StopMapping() const; + /// Signals SDL driver for new input events + void PumpEvents() const; + private: struct Impl; std::unique_ptr impl; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index d733bbf75..d87d8309c 100755 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -168,6 +168,7 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; constexpr int default_mouse_hide_timeout = 2500; constexpr int default_mouse_center_timeout = 10; +constexpr int default_input_update_timeout = 1; /** * "Callouts" are one-time instructional messages shown to the user. In the config settings, there @@ -406,6 +407,10 @@ GMainWindow::GMainWindow(std::unique_ptr config_, bool has_broken_vulkan mouse_center_timer.setInterval(default_mouse_center_timeout); connect(&mouse_center_timer, &QTimer::timeout, this, &GMainWindow::CenterMouseCursor); + update_input_timer.setInterval(default_input_update_timeout); + connect(&update_input_timer, &QTimer::timeout, this, &GMainWindow::UpdateInputDrivers); + update_input_timer.start(); + MigrateConfigFiles(); if (has_broken_vulkan) { @@ -3646,6 +3651,13 @@ void GMainWindow::UpdateUISettings() { UISettings::values.first_start = false; } +void GMainWindow::UpdateInputDrivers() { + if (!input_subsystem) { + return; + } + input_subsystem->PumpEvents(); +} + void GMainWindow::HideMouseCursor() { if (emu_thread == nullptr && UISettings::values.hide_mouse) { mouse_hide_timer.stop(); diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 86ccb03cc..ffa052b92 100755 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -353,6 +353,7 @@ private: void UpdateGPUAccuracyButton(); void UpdateStatusButtons(); void UpdateUISettings(); + void UpdateInputDrivers(); void HideMouseCursor(); void ShowMouseCursor(); void CenterMouseCursor(); @@ -404,6 +405,7 @@ private: bool auto_muted = false; QTimer mouse_hide_timer; QTimer mouse_center_timer; + QTimer update_input_timer; QString startup_icon_theme; bool os_dark_mode = false; diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index f6e09c995..26e0e37af 100755 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h @@ -6,16 +6,22 @@ namespace DefaultINI { const char* sdl2_config_file = R"( -[ControlsGeneral] + +[ControlsP0] # The input devices and parameters for each Switch native input +# The config section determines the player number where the config will be applied on. For example "ControlsP0", "ControlsP1", ... # It should be in the format of "engine:[engine_name],[param1]:[value1],[param2]:[value2]..." # Escape characters $0 (for ':'), $1 (for ',') and $2 (for '$') can be used in values +# Indicates if this player should be connected at boot +connected= + # for button input, the following devices are available: # - "keyboard" (default) for keyboard input. Required parameters: # - "code": the code of the key to bind # - "sdl" for joystick input using SDL. Required parameters: -# - "joystick": the index of the joystick to bind +# - "guid": SDL identification GUID of the joystick +# - "port": the index of the joystick to bind # - "button"(optional): the index of the button to bind # - "hat"(optional): the index of the hat to bind as direction buttons # - "axis"(optional): the index of the axis to bind @@ -58,12 +64,29 @@ button_screenshot= # - "modifier_scale": a float number representing the applied modifier scale to the analog input. # Must be in range of 0.0-1.0. Defaults to 0.5 # - "sdl" for joystick input using SDL. Required parameters: -# - "joystick": the index of the joystick to bind +# - "guid": SDL identification GUID of the joystick +# - "port": the index of the joystick to bind # - "axis_x": the index of the axis to bind as x-axis (default to 0) # - "axis_y": the index of the axis to bind as y-axis (default to 1) lstick= rstick= +# for motion input, the following devices are available: +# - "keyboard" (default) for emulating random motion input from buttons. Required parameters: +# - "code": the code of the key to bind +# - "sdl" for motion input using SDL. Required parameters: +# - "guid": SDL identification GUID of the joystick +# - "port": the index of the joystick to bind +# - "motion": the index of the motion sensor to bind +# - "cemuhookudp" for motion input using Cemu Hook protocol. Required parameters: +# - "guid": the IP address of the cemu hook server encoded to a hex string. for example 192.168.0.1 = "c0a80001" +# - "port": the port of the cemu hook server +# - "pad": the index of the joystick +# - "motion": the index of the motion sensor of the joystick to bind +motionleft= +motionright= + +[ControlsGeneral] # To use the debug_pad, prepend `debug_pad_` before each button setting above. # i.e. debug_pad_button_a=