diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index e627cf209..dd3db4507 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -1030,6 +1030,9 @@ void CommonHostInterface::UpdateControllerInputMap(SettingsInterface& si) for (const std::string& binding : bindings) AddRumbleToInputMap(binding, controller_index, num_motors); } + + const float axis_scale = si.GetFloatValue(category, "AxisScale", 1.00f); + m_controller_interface->SetControllerAxisScale(controller_index, axis_scale); } } diff --git a/src/frontend-common/controller_interface.h b/src/frontend-common/controller_interface.h index ed35e6108..c8f3f14de 100644 --- a/src/frontend-common/controller_interface.h +++ b/src/frontend-common/controller_interface.h @@ -43,6 +43,9 @@ 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; + // Input monitoring for external access. struct Hook { diff --git a/src/frontend-common/sdl_controller_interface.cpp b/src/frontend-common/sdl_controller_interface.cpp index 53af1b297..098f74cf1 100644 --- a/src/frontend-common/sdl_controller_interface.cpp +++ b/src/frontend-common/sdl_controller_interface.cpp @@ -289,7 +289,8 @@ bool SDLControllerInterface::HandleControllerAxisEvent(const SDL_Event* ev) const AxisCallback& cb = it->axis_mapping[ev->caxis.axis]; if (cb) { - cb(value); + // Apply axis scaling only when controller axis is mapped to an axis + cb(std::clamp(it->axis_scale * value, -1.0f, 1.0f)); return true; } @@ -386,3 +387,14 @@ void SDLControllerInterface::SetControllerRumbleStrength(int controller_index, c SDL_HapticRumbleStop(haptic); } } + +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; +} diff --git a/src/frontend-common/sdl_controller_interface.h b/src/frontend-common/sdl_controller_interface.h index 6293b7268..69e8270c5 100644 --- a/src/frontend-common/sdl_controller_interface.h +++ b/src/frontend-common/sdl_controller_interface.h @@ -29,6 +29,9 @@ 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; + void PollEvents() override; bool ProcessSDLEvent(const SDL_Event* event); @@ -42,6 +45,9 @@ 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; + std::array axis_mapping; std::array button_mapping; std::array, MAX_NUM_AXISES> axis_button_mapping;