mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-04 05:51:27 +12:00
Input: Add simple stick multipliers
This commit is contained in:
parent
34964e0e4f
commit
3a5d1c6b15
6 changed files with 23 additions and 19 deletions
|
@ -130,14 +130,14 @@ u16 PadHandlerBase::NormalizeTriggerInput(u16 value, int threshold)
|
||||||
|
|
||||||
// normalizes a directed input, meaning it will correspond to a single "button" and not an axis with two directions
|
// normalizes a directed input, meaning it will correspond to a single "button" and not an axis with two directions
|
||||||
// the input values must lie in 0+
|
// the input values must lie in 0+
|
||||||
u16 PadHandlerBase::NormalizeDirectedInput(u16 raw_value, s32 threshold, s32 maximum)
|
u16 PadHandlerBase::NormalizeDirectedInput(s32 raw_value, s32 threshold, s32 maximum)
|
||||||
{
|
{
|
||||||
if (threshold >= maximum || maximum <= 0)
|
if (threshold >= maximum || maximum <= 0)
|
||||||
{
|
{
|
||||||
return static_cast<u16>(0);
|
return static_cast<u16>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
float val = float(std::clamp(static_cast<s32>(raw_value), 0, maximum)) / float(maximum); // value based on max range converted to [0, 1]
|
float val = float(std::clamp(raw_value, 0, maximum)) / float(maximum); // value based on max range converted to [0, 1]
|
||||||
|
|
||||||
if (threshold <= 0)
|
if (threshold <= 0)
|
||||||
{
|
{
|
||||||
|
@ -150,15 +150,17 @@ u16 PadHandlerBase::NormalizeDirectedInput(u16 raw_value, s32 threshold, s32 max
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 PadHandlerBase::NormalizeStickInput(u16 raw_value, int threshold, bool ignore_threshold)
|
u16 PadHandlerBase::NormalizeStickInput(u16 raw_value, int threshold, int multiplier, bool ignore_threshold)
|
||||||
{
|
{
|
||||||
|
const s32 scaled_value = (multiplier * raw_value) / 100;
|
||||||
|
|
||||||
if (ignore_threshold)
|
if (ignore_threshold)
|
||||||
{
|
{
|
||||||
return static_cast<u16>(ScaleStickInput(raw_value, 0, thumb_max));
|
return static_cast<u16>(ScaleStickInput(scaled_value, 0, thumb_max));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return NormalizeDirectedInput(raw_value, threshold, thumb_max);
|
return NormalizeDirectedInput(scaled_value, threshold, thumb_max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -346,6 +346,8 @@ struct pad_config final : cfg::node
|
||||||
cfg::string l2 { this, "L2", "" };
|
cfg::string l2 { this, "L2", "" };
|
||||||
cfg::string l3 { this, "L3", "" };
|
cfg::string l3 { this, "L3", "" };
|
||||||
|
|
||||||
|
cfg::_int<0, 200> lstickmultiplier{this, "Left Stick Multiplier", 100};
|
||||||
|
cfg::_int<0, 200> rstickmultiplier{this, "Right Stick Multiplier", 100};
|
||||||
cfg::_int<0, 1000000> lstickdeadzone{ this, "Left Stick Deadzone", 0 };
|
cfg::_int<0, 1000000> lstickdeadzone{ this, "Left Stick Deadzone", 0 };
|
||||||
cfg::_int<0, 1000000> rstickdeadzone{ this, "Right Stick Deadzone", 0 };
|
cfg::_int<0, 1000000> rstickdeadzone{ this, "Right Stick Deadzone", 0 };
|
||||||
cfg::_int<0, 1000000> ltriggerthreshold{ this, "Left Trigger Threshold", 0 };
|
cfg::_int<0, 1000000> ltriggerthreshold{ this, "Left Trigger Threshold", 0 };
|
||||||
|
@ -437,9 +439,9 @@ protected:
|
||||||
|
|
||||||
// normalizes a directed input, meaning it will correspond to a single "button" and not an axis with two directions
|
// normalizes a directed input, meaning it will correspond to a single "button" and not an axis with two directions
|
||||||
// the input values must lie in 0+
|
// the input values must lie in 0+
|
||||||
u16 NormalizeDirectedInput(u16 raw_value, s32 threshold, s32 maximum);
|
u16 NormalizeDirectedInput(s32 raw_value, s32 threshold, s32 maximum);
|
||||||
|
|
||||||
u16 NormalizeStickInput(u16 raw_value, int threshold, bool ignore_threshold = false);
|
u16 NormalizeStickInput(u16 raw_value, int threshold, int multiplier, bool ignore_threshold = false);
|
||||||
|
|
||||||
// This function normalizes stick deadzone based on the DS3's deadzone, which is ~13%
|
// This function normalizes stick deadzone based on the DS3's deadzone, which is ~13%
|
||||||
// X and Y is expected to be in (-255) to 255 range, deadzone should be in terms of thumb stick range
|
// X and Y is expected to be in (-255) to 255 range, deadzone should be in terms of thumb stick range
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "ds4_pad_handler.h"
|
#include "ds4_pad_handler.h"
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
@ -340,14 +340,14 @@ void ds4_pad_handler::TranslateButtonPress(u64 keyCode, bool& pressed, u16& val,
|
||||||
case DS4KeyCodes::LSYNeg:
|
case DS4KeyCodes::LSYNeg:
|
||||||
case DS4KeyCodes::LSYPos:
|
case DS4KeyCodes::LSYPos:
|
||||||
pressed = val > (ignore_threshold ? 0 : p_profile->lstickdeadzone);
|
pressed = val > (ignore_threshold ? 0 : p_profile->lstickdeadzone);
|
||||||
val = pressed ? NormalizeStickInput(val, p_profile->lstickdeadzone, ignore_threshold) : 0;
|
val = pressed ? NormalizeStickInput(val, p_profile->lstickdeadzone, p_profile->lstickmultiplier, ignore_threshold) : 0;
|
||||||
break;
|
break;
|
||||||
case DS4KeyCodes::RSXNeg:
|
case DS4KeyCodes::RSXNeg:
|
||||||
case DS4KeyCodes::RSXPos:
|
case DS4KeyCodes::RSXPos:
|
||||||
case DS4KeyCodes::RSYNeg:
|
case DS4KeyCodes::RSYNeg:
|
||||||
case DS4KeyCodes::RSYPos:
|
case DS4KeyCodes::RSYPos:
|
||||||
pressed = val > (ignore_threshold ? 0 : p_profile->rstickdeadzone);
|
pressed = val > (ignore_threshold ? 0 : p_profile->rstickdeadzone);
|
||||||
val = pressed ? NormalizeStickInput(val, p_profile->rstickdeadzone, ignore_threshold) : 0;
|
val = pressed ? NormalizeStickInput(val, p_profile->rstickdeadzone, p_profile->rstickmultiplier, ignore_threshold) : 0;
|
||||||
break;
|
break;
|
||||||
default: // normal button (should in theory also support sensitive buttons)
|
default: // normal button (should in theory also support sensitive buttons)
|
||||||
pressed = val > 0;
|
pressed = val > 0;
|
||||||
|
|
|
@ -525,12 +525,12 @@ void evdev_joystick_handler::TranslateButtonPress(u64 keyCode, bool& pressed, u1
|
||||||
else if (checkButtons(m_dev.axis_left))
|
else if (checkButtons(m_dev.axis_left))
|
||||||
{
|
{
|
||||||
pressed = value > (ignore_threshold ? 0 : profile->lstickdeadzone);
|
pressed = value > (ignore_threshold ? 0 : profile->lstickdeadzone);
|
||||||
value = pressed ? NormalizeStickInput(value, profile->lstickdeadzone, ignore_threshold) : 0;
|
value = pressed ? NormalizeStickInput(value, profile->lstickdeadzone, profile->lstickmultiplier, ignore_threshold) : 0;
|
||||||
}
|
}
|
||||||
else if (checkButtons(m_dev.axis_right))
|
else if (checkButtons(m_dev.axis_right))
|
||||||
{
|
{
|
||||||
pressed = value > (ignore_threshold ? 0 : profile->rstickdeadzone);
|
pressed = value > (ignore_threshold ? 0 : profile->rstickdeadzone);
|
||||||
value = pressed ? NormalizeStickInput(value, profile->rstickdeadzone, ignore_threshold) : 0;
|
value = pressed ? NormalizeStickInput(value, profile->rstickdeadzone, profile->rstickmultiplier, ignore_threshold) : 0;
|
||||||
}
|
}
|
||||||
else // normal button (should in theory also support sensitive buttons)
|
else // normal button (should in theory also support sensitive buttons)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "mm_joystick_handler.h"
|
#include "mm_joystick_handler.h"
|
||||||
|
|
||||||
mm_joystick_handler::mm_joystick_handler() : PadHandlerBase(pad_handler::mm)
|
mm_joystick_handler::mm_joystick_handler() : PadHandlerBase(pad_handler::mm)
|
||||||
|
@ -448,12 +448,12 @@ void mm_joystick_handler::TranslateButtonPress(u64 keyCode, bool& pressed, u16&
|
||||||
else if (std::find(m_dev->axis_left.begin(), m_dev->axis_left.end(), keyCode) != m_dev->axis_left.end())
|
else if (std::find(m_dev->axis_left.begin(), m_dev->axis_left.end(), keyCode) != m_dev->axis_left.end())
|
||||||
{
|
{
|
||||||
pressed = val > (ignore_threshold ? 0 : p_profile->lstickdeadzone);
|
pressed = val > (ignore_threshold ? 0 : p_profile->lstickdeadzone);
|
||||||
val = pressed ? NormalizeStickInput(val, p_profile->lstickdeadzone, ignore_threshold) : 0;
|
val = pressed ? NormalizeStickInput(val, p_profile->lstickdeadzone, p_profile->lstickmultiplier, ignore_threshold) : 0;
|
||||||
}
|
}
|
||||||
else if (std::find(m_dev->axis_right.begin(), m_dev->axis_right.end(), keyCode) != m_dev->axis_right.end())
|
else if (std::find(m_dev->axis_right.begin(), m_dev->axis_right.end(), keyCode) != m_dev->axis_right.end())
|
||||||
{
|
{
|
||||||
pressed = val > (ignore_threshold ? 0 : p_profile->rstickdeadzone);
|
pressed = val > (ignore_threshold ? 0 : p_profile->rstickdeadzone);
|
||||||
val = pressed ? NormalizeStickInput(val, p_profile->rstickdeadzone, ignore_threshold) : 0;
|
val = pressed ? NormalizeStickInput(val, p_profile->rstickdeadzone, p_profile->rstickmultiplier, ignore_threshold) : 0;
|
||||||
}
|
}
|
||||||
else // normal button (should in theory also support sensitive buttons)
|
else // normal button (should in theory also support sensitive buttons)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "xinput_pad_handler.h"
|
#include "xinput_pad_handler.h"
|
||||||
|
|
||||||
|
@ -172,14 +172,14 @@ void xinput_pad_handler::TranslateButtonPress(u64 keyCode, bool& pressed, u16& v
|
||||||
case XInputKeyCodes::LSYPos:
|
case XInputKeyCodes::LSYPos:
|
||||||
case XInputKeyCodes::LSYNeg:
|
case XInputKeyCodes::LSYNeg:
|
||||||
pressed = val > (ignore_threshold ? 0 : p_profile->lstickdeadzone);
|
pressed = val > (ignore_threshold ? 0 : p_profile->lstickdeadzone);
|
||||||
val = pressed ? NormalizeStickInput(val, p_profile->lstickdeadzone, ignore_threshold) : 0;
|
val = pressed ? NormalizeStickInput(val, p_profile->lstickdeadzone, p_profile->lstickmultiplier, ignore_threshold) : 0;
|
||||||
break;
|
break;
|
||||||
case XInputKeyCodes::RSXNeg:
|
case XInputKeyCodes::RSXNeg:
|
||||||
case XInputKeyCodes::RSXPos:
|
case XInputKeyCodes::RSXPos:
|
||||||
case XInputKeyCodes::RSYPos:
|
case XInputKeyCodes::RSYPos:
|
||||||
case XInputKeyCodes::RSYNeg:
|
case XInputKeyCodes::RSYNeg:
|
||||||
pressed = val > (ignore_threshold ? 0 : p_profile->rstickdeadzone);
|
pressed = val > (ignore_threshold ? 0 : p_profile->rstickdeadzone);
|
||||||
val = pressed ? NormalizeStickInput(val, p_profile->rstickdeadzone, ignore_threshold) : 0;
|
val = pressed ? NormalizeStickInput(val, p_profile->rstickdeadzone, p_profile->rstickmultiplier, ignore_threshold) : 0;
|
||||||
break;
|
break;
|
||||||
default: // normal button (should in theory also support sensitive buttons)
|
default: // normal button (should in theory also support sensitive buttons)
|
||||||
pressed = val > 0;
|
pressed = val > 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue