From d87ab23fec749d03df0808db36fc3a8013b2d1cf Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Wed, 11 Nov 2020 23:55:23 -0800 Subject: [PATCH 1/3] ControllerInterface: Move axis scaling into AnalogController class --- src/core/analog_controller.cpp | 5 ++++- src/core/analog_controller.h | 1 + src/frontend-common/common_host_interface.cpp | 4 ---- src/frontend-common/controller_interface.h | 3 --- src/frontend-common/sdl_controller_interface.cpp | 14 +------------- src/frontend-common/sdl_controller_interface.h | 5 ----- .../xinput_controller_interface.cpp | 14 +------------- src/frontend-common/xinput_controller_interface.h | 5 ----- 8 files changed, 7 insertions(+), 44 deletions(-) diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index c1de2a51c..32c468009 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -82,7 +82,8 @@ void AnalogController::SetAxisState(s32 axis_code, float value) return; // -1..1 -> 0..255 - const u8 u8_value = static_cast(std::clamp(((value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f)); + const float scaled_value = std::clamp(value * m_axis_scale, -1.0f, 1.0f); + const u8 u8_value = static_cast(std::clamp(((scaled_value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f)); SetAxisState(static_cast(axis_code), u8_value); } @@ -567,6 +568,8 @@ void AnalogController::LoadSettings(const char* section) Controller::LoadSettings(section); m_auto_enable_analog = g_host_interface->GetBoolSettingValue(section, "AutoEnableAnalog", false); m_analog_dpad_in_digital_mode = g_host_interface->GetBoolSettingValue(section, "AnalogDPadInDigitalMode", false); + m_axis_scale = + std::clamp(std::abs(g_host_interface->GetFloatSettingValue(section, "AxisScale", 1.00f)), 0.01f, 1.50f); m_rumble_bias = static_cast(std::min(g_host_interface->GetIntSettingValue(section, "VibrationBias", 8), 255)); } diff --git a/src/core/analog_controller.h b/src/core/analog_controller.h index eb6fbd6b5..2cf96fae1 100644 --- a/src/core/analog_controller.h +++ b/src/core/analog_controller.h @@ -137,6 +137,7 @@ private: bool m_auto_enable_analog = false; bool m_analog_dpad_in_digital_mode = false; + float m_axis_scale = 1.00f; u8 m_rumble_bias = 8; bool m_analog_mode = false; diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 188f2f12d..75c130c40 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -1145,10 +1145,6 @@ void CommonHostInterface::UpdateControllerInputMap(SettingsInterface& si) if (m_controller_interface) { - const float axis_scale = si.GetFloatValue(category, "AxisScale", 1.00f); - m_controller_interface->SetControllerAxisScale(controller_index, - (ctype == ControllerType::AnalogController) ? axis_scale : 1.00f); - const float deadzone_size = si.GetFloatValue(category, "Deadzone", 0.25f); m_controller_interface->SetControllerDeadzone(controller_index, deadzone_size); } diff --git a/src/frontend-common/controller_interface.h b/src/frontend-common/controller_interface.h index 60e287f11..952f6a2b6 100644 --- a/src/frontend-common/controller_interface.h +++ b/src/frontend-common/controller_interface.h @@ -62,9 +62,6 @@ public: virtual u32 GetControllerRumbleMotorCount(int controller_index) = 0; virtual void SetControllerRumbleStrength(int controller_index, const float* strengths, u32 num_motors) = 0; - // Set scaling that will be applied on axis-to-axis mappings - virtual bool SetControllerAxisScale(int controller_index, float scale) = 0; - // Set deadzone that will be applied on axis-to-button mappings virtual bool SetControllerDeadzone(int controller_index, float size) = 0; diff --git a/src/frontend-common/sdl_controller_interface.cpp b/src/frontend-common/sdl_controller_interface.cpp index 191c75f5e..d9852841c 100644 --- a/src/frontend-common/sdl_controller_interface.cpp +++ b/src/frontend-common/sdl_controller_interface.cpp @@ -320,8 +320,7 @@ bool SDLControllerInterface::HandleControllerAxisEvent(const SDL_Event* ev) const AxisCallback& cb = it->axis_mapping[ev->caxis.axis]; if (cb) { - // Apply axis scaling only when controller axis is mapped to an axis - cb(std::clamp(it->axis_scale * value, -1.0f, 1.0f)); + cb(value); return true; } @@ -427,17 +426,6 @@ void SDLControllerInterface::SetControllerRumbleStrength(int controller_index, c } } -bool SDLControllerInterface::SetControllerAxisScale(int controller_index, float scale /* = 1.00f */) -{ - auto it = GetControllerDataForPlayerId(controller_index); - if (it == m_controllers.end()) - return false; - - it->axis_scale = std::clamp(std::abs(scale), 0.01f, 1.50f); - Log_InfoPrintf("Controller %d axis scale set to %f", controller_index, it->axis_scale); - return true; -} - bool SDLControllerInterface::SetControllerDeadzone(int controller_index, float size /* = 0.25f */) { auto it = GetControllerDataForPlayerId(controller_index); diff --git a/src/frontend-common/sdl_controller_interface.h b/src/frontend-common/sdl_controller_interface.h index d839b73a0..8f5dbc212 100644 --- a/src/frontend-common/sdl_controller_interface.h +++ b/src/frontend-common/sdl_controller_interface.h @@ -35,9 +35,6 @@ public: u32 GetControllerRumbleMotorCount(int controller_index) override; void SetControllerRumbleStrength(int controller_index, const float* strengths, u32 num_motors) override; - // Set scaling that will be applied on axis-to-axis mappings - bool SetControllerAxisScale(int controller_index, float scale = 1.00f) override; - // Set deadzone that will be applied on axis-to-button mappings bool SetControllerDeadzone(int controller_index, float size = 0.25f) override; @@ -54,8 +51,6 @@ private: int joystick_id; int player_id; - // Scaling value of 1.30f to 1.40f recommended when using recent controllers - float axis_scale = 1.00f; float deadzone = 0.25f; std::array axis_mapping; diff --git a/src/frontend-common/xinput_controller_interface.cpp b/src/frontend-common/xinput_controller_interface.cpp index cb1e59264..575e18361 100644 --- a/src/frontend-common/xinput_controller_interface.cpp +++ b/src/frontend-common/xinput_controller_interface.cpp @@ -229,8 +229,7 @@ bool XInputControllerInterface::HandleAxisEvent(u32 index, Axis axis, s32 value) const AxisCallback& cb = m_controllers[index].axis_mapping[static_cast(axis)]; if (cb) { - // Apply axis scaling only when controller axis is mapped to an axis - cb(std::clamp(m_controllers[index].axis_scale * f_value, -1.0f, 1.0f)); + cb(f_value); return true; } @@ -302,17 +301,6 @@ void XInputControllerInterface::SetControllerRumbleStrength(int controller_index m_xinput_set_state(static_cast(controller_index), &vib); } -bool XInputControllerInterface::SetControllerAxisScale(int controller_index, float scale /* = 1.00f */) -{ - if (static_cast(controller_index) >= XUSER_MAX_COUNT || !m_controllers[controller_index].connected) - return false; - - m_controllers[static_cast(controller_index)].axis_scale = std::clamp(std::abs(scale), 0.01f, 1.50f); - Log_InfoPrintf("Controller %d axis scale set to %f", controller_index, - m_controllers[static_cast(controller_index)].axis_scale); - return true; -} - bool XInputControllerInterface::SetControllerDeadzone(int controller_index, float size /* = 0.25f */) { if (static_cast(controller_index) >= XUSER_MAX_COUNT || !m_controllers[controller_index].connected) diff --git a/src/frontend-common/xinput_controller_interface.h b/src/frontend-common/xinput_controller_interface.h index 21802ff40..3c1996f84 100644 --- a/src/frontend-common/xinput_controller_interface.h +++ b/src/frontend-common/xinput_controller_interface.h @@ -32,9 +32,6 @@ public: u32 GetControllerRumbleMotorCount(int controller_index) override; void SetControllerRumbleStrength(int controller_index, const float* strengths, u32 num_motors) override; - // Set scaling that will be applied on axis-to-axis mappings - bool SetControllerAxisScale(int controller_index, float scale = 1.00f) override; - // Set deadzone that will be applied on axis-to-button mappings bool SetControllerDeadzone(int controller_index, float size = 0.25f) override; @@ -62,8 +59,6 @@ private: XINPUT_STATE last_state = {}; bool connected = false; - // Scaling value of 1.30f to 1.40f recommended when using recent controllers - float axis_scale = 1.00f; float deadzone = 0.25f; std::array axis_mapping; From ca8fe279540ccfb22031e92b17c0456c627a0fd4 Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Thu, 12 Nov 2020 04:16:04 -0800 Subject: [PATCH 2/3] libretro: Add analog axis scale toggle --- .../libretro_host_interface.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/duckstation-libretro/libretro_host_interface.cpp b/src/duckstation-libretro/libretro_host_interface.cpp index d47f7981b..ffb65c747 100644 --- a/src/duckstation-libretro/libretro_host_interface.cpp +++ b/src/duckstation-libretro/libretro_host_interface.cpp @@ -457,7 +457,7 @@ void LibretroHostInterface::OnSystemDestroyed() m_using_hardware_renderer = false; } -static std::array s_option_definitions = {{ +static std::array s_option_definitions = {{ {"duckstation_Console.Region", "Console Region", "Determines which region/hardware to emulate. Auto-Detect will use the region of the disc inserted.", @@ -723,6 +723,12 @@ static std::array s_option_definitions = {{ "Allows you to use the analog sticks to control the d-pad in digital mode, as well as the buttons.", {{"true", "Enabled"}, {"false", "Disabled"}}, "false"}, + {"duckstation_Controller1.AxisScale", + "Controller 1 Analog Axis Scale", + "Sets the analog stick axis scaling factor.", + {{"1.00f", "1.00"}, {"1.40f", "1.40"}}, + "1.00f" + }, {"duckstation_Controller2.Type", "Controller 2 Type", "Sets the type of controller for Slot 2.", @@ -743,6 +749,12 @@ static std::array s_option_definitions = {{ "Allows you to use the analog sticks to control the d-pad in digital mode, as well as the buttons.", {{"true", "Enabled"}, {"false", "Disabled"}}, "false"}, + {"duckstation_Controller2.AxisScale", + "Controller 2 Analog Axis Scale", + "Sets the analog stick axis scaling factor.", + {{"1.00f", "1.00"}, {"1.40f", "1.40"}}, + "1.00f" + }, {"duckstation_Display.ShowOSDMessages", "Display OSD Messages", "Shows on-screen messages generated by the core.", From 3eeab81063f598955702aef5f1b113e81f2f9507 Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Fri, 13 Nov 2020 01:42:31 -0800 Subject: [PATCH 3/3] PlayStationMouse: Fix returning incorrect controller type --- src/core/playstation_mouse.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/playstation_mouse.cpp b/src/core/playstation_mouse.cpp index 0c69d92ac..7541fc1bd 100644 --- a/src/core/playstation_mouse.cpp +++ b/src/core/playstation_mouse.cpp @@ -19,7 +19,7 @@ PlayStationMouse::~PlayStationMouse() = default; ControllerType PlayStationMouse::GetType() const { - return ControllerType::NamcoGunCon; + return ControllerType::PlayStationMouse; } std::optional PlayStationMouse::GetAxisCodeByName(std::string_view axis_name) const