mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-26 23:55:40 +00:00
ControllerInterface: Implement axis scaling for axis-to-axis mappings
This feature allows us to work around analog stick range issues at the intercardinal directions in certain titles (e.g. Rockman DASH 2) caused by modern controllers having a tighter logical range of reporting than PS1 analog controllers.
This commit is contained in:
parent
840a80670f
commit
6b7c068f83
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<AxisCallback, MAX_NUM_AXISES> axis_mapping;
|
||||
std::array<ButtonCallback, MAX_NUM_BUTTONS> button_mapping;
|
||||
std::array<std::array<ButtonCallback, 2>, MAX_NUM_AXISES> axis_button_mapping;
|
||||
|
|
Loading…
Reference in a new issue