mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-26 23:55:40 +00:00
ControllerInterface: Move axis scaling into AnalogController class
This commit is contained in:
parent
ca14e53c4a
commit
d87ab23fec
|
@ -82,7 +82,8 @@ void AnalogController::SetAxisState(s32 axis_code, float value)
|
|||
return;
|
||||
|
||||
// -1..1 -> 0..255
|
||||
const u8 u8_value = static_cast<u8>(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<u8>(std::clamp(((scaled_value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f));
|
||||
|
||||
SetAxisState(static_cast<Axis>(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<u8>(std::min<u32>(g_host_interface->GetIntSettingValue(section, "VibrationBias", 8), 255));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<AxisCallback, MAX_NUM_AXISES> axis_mapping;
|
||||
|
|
|
@ -229,8 +229,7 @@ bool XInputControllerInterface::HandleAxisEvent(u32 index, Axis axis, s32 value)
|
|||
const AxisCallback& cb = m_controllers[index].axis_mapping[static_cast<u32>(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<u32>(controller_index), &vib);
|
||||
}
|
||||
|
||||
bool XInputControllerInterface::SetControllerAxisScale(int controller_index, float scale /* = 1.00f */)
|
||||
{
|
||||
if (static_cast<u32>(controller_index) >= XUSER_MAX_COUNT || !m_controllers[controller_index].connected)
|
||||
return false;
|
||||
|
||||
m_controllers[static_cast<u32>(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<u32>(controller_index)].axis_scale);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool XInputControllerInterface::SetControllerDeadzone(int controller_index, float size /* = 0.25f */)
|
||||
{
|
||||
if (static_cast<u32>(controller_index) >= XUSER_MAX_COUNT || !m_controllers[controller_index].connected)
|
||||
|
|
|
@ -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<AxisCallback, MAX_NUM_AXISES> axis_mapping;
|
||||
|
|
Loading…
Reference in a new issue