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] 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;