diff --git a/pcsx2/PAD/Host/KeyStatus.cpp b/pcsx2/PAD/Host/KeyStatus.cpp index ffb670a1a4..12cc9df1a9 100644 --- a/pcsx2/PAD/Host/KeyStatus.cpp +++ b/pcsx2/PAD/Host/KeyStatus.cpp @@ -55,6 +55,29 @@ void KeyStatus::Init() void KeyStatus::Set(u32 pad, u32 index, float value) { + // Since we reordered the buttons for better UI, we need to remap them here. + static constexpr std::array bitmask_mapping = {{ + 12, // PAD_UP + 13, // PAD_RIGHT + 14, // PAD_DOWN + 15, // PAD_LEFT + 4, // PAD_TRIANGLE + 5, // PAD_CIRCLE + 6, // PAD_CROSS + 7, // PAD_SQUARE + 8, // PAD_SELECT + 11, // PAD_START + 2, // PAD_L1 + 0, // PAD_L2 + 3, // PAD_R1 + 1, // PAD_R2 + 9, // PAD_L3 + 10, // PAD_R3 + 16, // PAD_ANALOG + 17, // PAD_PRESSURE + // remainder are analogs and not used here + }}; + if (IsAnalogKey(index)) { m_button_pressure[pad][index] = static_cast(std::clamp(value * m_axis_scale[pad][1] * 255.0f, 0.0f, 255.0f)); @@ -123,38 +146,24 @@ void KeyStatus::Set(u32 pad, u32 index, float value) } #undef MERGE_F } - + } + else if (IsTriggerKey(index)) + { + const float s_value = std::clamp(value * m_trigger_scale[pad][1], 0.0f, 1.0f); + const float dz_value = (m_axis_scale[pad][0] > 0.0f && s_value < m_axis_scale[pad][0]) ? 0.0f : s_value; + m_button_pressure[pad][index] = static_cast(dz_value * 255.0f); + if (dz_value > 0.0f) + m_button[pad] &= ~(1u << bitmask_mapping[index]); + else + m_button[pad] |= (1u << bitmask_mapping[index]); } else { // Don't affect L2/R2, since they are analog on most pads. - const float pmod = ((m_button[pad] & (1u << PAD_PRESSURE)) == 0 && !IsTriggerKey(index)) ? m_pressure_modifier[pad] : 1.0f; + const float pmod = ((m_button[pad] & (1u << PAD_PRESSURE)) == 0) ? m_pressure_modifier[pad] : 1.0f; const float dz_value = (value < m_button_deadzone[pad]) ? 0.0f : value; m_button_pressure[pad][index] = static_cast(std::clamp(dz_value * pmod * 255.0f, 0.0f, 255.0f)); - // Since we reordered the buttons for better UI, we need to remap them here. - static constexpr std::array bitmask_mapping = {{ - 12, // PAD_UP - 13, // PAD_RIGHT - 14, // PAD_DOWN - 15, // PAD_LEFT - 4, // PAD_TRIANGLE - 5, // PAD_CIRCLE - 6, // PAD_CROSS - 7, // PAD_SQUARE - 8, // PAD_SELECT - 11, // PAD_START - 2, // PAD_L1 - 0, // PAD_L2 - 3, // PAD_R1 - 1, // PAD_R2 - 9, // PAD_L3 - 10, // PAD_R3 - 16, // PAD_ANALOG - 17, // PAD_PRESSURE - // remainder are analogs and not used here - }}; - if (dz_value > 0.0f) m_button[pad] &= ~(1u << bitmask_mapping[index]); else diff --git a/pcsx2/PAD/Host/KeyStatus.h b/pcsx2/PAD/Host/KeyStatus.h index 36547967ab..605e129f4d 100644 --- a/pcsx2/PAD/Host/KeyStatus.h +++ b/pcsx2/PAD/Host/KeyStatus.h @@ -40,6 +40,7 @@ namespace PAD u8 m_button_pressure[NUM_CONTROLLER_PORTS][MAX_KEYS]; PADAnalog m_analog[NUM_CONTROLLER_PORTS]; float m_axis_scale[NUM_CONTROLLER_PORTS][2]; + float m_trigger_scale[NUM_CONTROLLER_PORTS][2]; float m_vibration_scale[NUM_CONTROLLER_PORTS][2]; float m_pressure_modifier[NUM_CONTROLLER_PORTS]; float m_button_deadzone[NUM_CONTROLLER_PORTS]; @@ -66,6 +67,11 @@ namespace PAD m_axis_scale[pad][0] = deadzone; m_axis_scale[pad][1] = scale; } + __fi void SetTriggerScale(u32 pad, float deadzone, float scale) + { + m_trigger_scale[pad][0] = deadzone; + m_trigger_scale[pad][1] = scale; + } __fi float GetVibrationScale(u32 pad, u32 motor) const { return m_vibration_scale[pad][motor]; } __fi void SetVibrationScale(u32 pad, u32 motor, float scale) { m_vibration_scale[pad][motor] = scale; } __fi float GetPressureModifier(u32 pad) const { return m_pressure_modifier[pad]; } diff --git a/pcsx2/PAD/Host/PAD.cpp b/pcsx2/PAD/Host/PAD.cpp index 6300ee4722..8074626893 100644 --- a/pcsx2/PAD/Host/PAD.cpp +++ b/pcsx2/PAD/Host/PAD.cpp @@ -217,8 +217,11 @@ void PAD::LoadConfig(const SettingsInterface& si) const float axis_deadzone = si.GetFloatValue(section.c_str(), "Deadzone", DEFAULT_STICK_DEADZONE); const float axis_scale = si.GetFloatValue(section.c_str(), "AxisScale", DEFAULT_STICK_SCALE); + const float trigger_deadzone = si.GetFloatValue(section.c_str(), "TriggerDeadzone", DEFAULT_TRIGGER_DEADZONE); + const float trigger_scale = si.GetFloatValue(section.c_str(), "TriggerDeadzone", DEFAULT_TRIGGER_SCALE); const float button_deadzone = si.GetFloatValue(section.c_str(), "ButtonDeadzone", DEFAULT_BUTTON_DEADZONE); g_key_status.SetAxisScale(i, axis_deadzone, axis_scale); + g_key_status.SetTriggerScale(i, trigger_deadzone, trigger_scale); g_key_status.SetButtonDeadzone(i, button_deadzone); if (ci->vibration_caps != VibrationCapabilities::NoVibration) @@ -415,6 +418,12 @@ static const SettingInfo s_dualshock2_settings[] = { "Sets the analog stick axis scaling factor. A value between 130% and 140% is recommended when using recent " "controllers, e.g. DualShock 4, Xbox One Controller.", "1.33", "0.01", "2.00", "0.01", "%.0f%%", nullptr, nullptr, 100.0f}, + {SettingInfo::Type::Float, "TriggerDeadzone", "Trigger Deadzone", + "Sets the analog stick deadzone, i.e. the fraction of the stick movement which will be ignored.", + "0.00", "0.00", "1.00", "0.01", "%.0f%%", nullptr, nullptr, 100.0f}, + {SettingInfo::Type::Float, "TriggerScale", "Trigger Sensitivity", + "Sets the trigger scaling factor.", + "1.00", "0.01", "2.00", "0.01", "%.0f%%", nullptr, nullptr, 100.0f}, {SettingInfo::Type::Float, "LargeMotorScale", "Large Motor Vibration Scale", "Increases or decreases the intensity of low frequency vibration sent by the game.", "1.00", "0.00", "2.00", "0.01", "%.0f%%", nullptr, nullptr, 100.0f}, @@ -564,14 +573,6 @@ void PAD::CopyConfiguration(SettingsInterface* dest_si, const SettingsInterface& if (copy_pad_config) { - dest_si->CopyFloatValue(src_si, section.c_str(), "AxisScale"); - - if (info->vibration_caps != VibrationCapabilities::NoVibration) - { - dest_si->CopyFloatValue(src_si, section.c_str(), "LargeMotorScale"); - dest_si->CopyFloatValue(src_si, section.c_str(), "SmallMotorScale"); - } - for (u32 i = 0; i < info->num_settings; i++) { const SettingInfo& csi = info->settings[i]; diff --git a/pcsx2/PAD/Host/PAD.h b/pcsx2/PAD/Host/PAD.h index f2a87250e5..d5b4feb0ac 100644 --- a/pcsx2/PAD/Host/PAD.h +++ b/pcsx2/PAD/Host/PAD.h @@ -76,6 +76,8 @@ namespace PAD /// Default stick deadzone/sensitivity. static constexpr float DEFAULT_STICK_DEADZONE = 0.0f; static constexpr float DEFAULT_STICK_SCALE = 1.33f; + static constexpr float DEFAULT_TRIGGER_DEADZONE = 0.0f; + static constexpr float DEFAULT_TRIGGER_SCALE = 1.0f; static constexpr float DEFAULT_MOTOR_SCALE = 1.0f; static constexpr float DEFAULT_PRESSURE_MODIFIER = 0.5f; static constexpr float DEFAULT_BUTTON_DEADZONE = 0.0f;