Input: Add simple stick multipliers

This commit is contained in:
Megamouse 2019-05-16 21:14:33 +02:00
parent 34964e0e4f
commit 3a5d1c6b15
6 changed files with 23 additions and 19 deletions

View file

@ -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
// 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)
{
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)
{
@ -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)
{
return static_cast<u16>(ScaleStickInput(raw_value, 0, thumb_max));
return static_cast<u16>(ScaleStickInput(scaled_value, 0, thumb_max));
}
else
{
return NormalizeDirectedInput(raw_value, threshold, thumb_max);
return NormalizeDirectedInput(scaled_value, threshold, thumb_max);
}
}

View file

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <cmath>
#include <vector>
@ -346,6 +346,8 @@ struct pad_config final : cfg::node
cfg::string l2 { this, "L2", "" };
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> rstickdeadzone{ this, "Right Stick Deadzone", 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
// 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%
// X and Y is expected to be in (-255) to 255 range, deadzone should be in terms of thumb stick range

View file

@ -1,4 +1,4 @@
#include "ds4_pad_handler.h"
#include "ds4_pad_handler.h"
#include <thread>
@ -340,14 +340,14 @@ void ds4_pad_handler::TranslateButtonPress(u64 keyCode, bool& pressed, u16& val,
case DS4KeyCodes::LSYNeg:
case DS4KeyCodes::LSYPos:
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;
case DS4KeyCodes::RSXNeg:
case DS4KeyCodes::RSXPos:
case DS4KeyCodes::RSYNeg:
case DS4KeyCodes::RSYPos:
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;
default: // normal button (should in theory also support sensitive buttons)
pressed = val > 0;

View file

@ -525,12 +525,12 @@ void evdev_joystick_handler::TranslateButtonPress(u64 keyCode, bool& pressed, u1
else if (checkButtons(m_dev.axis_left))
{
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))
{
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)
{

View file

@ -1,4 +1,4 @@
#ifdef _WIN32
#ifdef _WIN32
#include "mm_joystick_handler.h"
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())
{
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())
{
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)
{

View file

@ -1,4 +1,4 @@

#ifdef _WIN32
#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::LSYNeg:
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;
case XInputKeyCodes::RSXNeg:
case XInputKeyCodes::RSXPos:
case XInputKeyCodes::RSYPos:
case XInputKeyCodes::RSYNeg:
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;
default: // normal button (should in theory also support sensitive buttons)
pressed = val > 0;