Pad: Add GetEffectiveInput()

Returns the value, incorporating any deadzone.
This commit is contained in:
Stenzek 2024-01-16 21:39:57 +10:00 committed by Connor McLaughlin
parent c0d86c3852
commit 6f34b7ba99
9 changed files with 56 additions and 0 deletions

View File

@ -47,6 +47,7 @@ public: // Public members
virtual void SetButtonDeadzone(float deadzone) = 0;
virtual void SetAnalogInvertL(bool x, bool y) = 0;
virtual void SetAnalogInvertR(bool x, bool y) = 0;
virtual u8 GetEffectiveInput(u32 index) const = 0;
virtual u8 GetRawInput(u32 index) const = 0;
virtual std::tuple<u8, u8> GetRawLeftAnalog() const = 0;
virtual std::tuple<u8, u8> GetRawRightAnalog() const = 0;

View File

@ -785,6 +785,42 @@ void PadDualshock2::SetAnalogInvertR(bool x, bool y)
this->analogs.ryInvert = y;
}
u8 PadDualshock2::GetEffectiveInput(u32 index) const
{
if (!IsAnalogKey(index))
return GetRawInput(index);
switch (index)
{
case Inputs::PAD_L_LEFT:
return (analogs.lx > 0 && analogs.lx < 127) ? analogs.lx : 0;
case Inputs::PAD_L_RIGHT:
return (analogs.lx >= 128) ? analogs.lx : 0;
case Inputs::PAD_L_UP:
return (analogs.ly > 0 && analogs.ly < 127) ? analogs.ly : 0;
case Inputs::PAD_L_DOWN:
return (analogs.ly >= 128) ? analogs.ly : 0;
case Inputs::PAD_R_LEFT:
return (analogs.rx > 0 && analogs.rx < 127) ? analogs.rx : 0;
case Inputs::PAD_R_RIGHT:
return (analogs.rx >= 128) ? analogs.rx : 0;
case Inputs::PAD_R_UP:
return (analogs.ry > 0 && analogs.ry < 127) ? analogs.ry : 0;
case Inputs::PAD_R_DOWN:
return (analogs.ry >= 128) ? analogs.ry : 0;
default:
return 0;
}
}
u8 PadDualshock2::GetRawInput(u32 index) const
{
return rawInputs[index];

View File

@ -125,6 +125,7 @@ public:
void SetButtonDeadzone(float deadzone) override;
void SetAnalogInvertL(bool x, bool y) override;
void SetAnalogInvertR(bool x, bool y) override;
u8 GetEffectiveInput(u32 index) const override;
u8 GetRawInput(u32 index) const override;
std::tuple<u8, u8> GetRawLeftAnalog() const override;
std::tuple<u8, u8> GetRawRightAnalog() const override;

View File

@ -355,6 +355,11 @@ void PadGuitar::SetAnalogInvertR(bool x, bool y)
{
}
u8 PadGuitar::GetEffectiveInput(u32 index) const
{
return GetRawInput(index);
}
u8 PadGuitar::GetRawInput(u32 index) const
{
return rawInputs[index];

View File

@ -66,6 +66,7 @@ public:
void SetButtonDeadzone(float deadzone) override;
void SetAnalogInvertL(bool x, bool y) override;
void SetAnalogInvertR(bool x, bool y) override;
u8 GetEffectiveInput(u32 index) const override;
u8 GetRawInput(u32 index) const override;
std::tuple<u8, u8> GetRawLeftAnalog() const override;
std::tuple<u8, u8> GetRawRightAnalog() const override;

View File

@ -76,6 +76,11 @@ void PadNotConnected::SetAnalogInvertR(bool x, bool y)
}
u8 PadNotConnected::GetEffectiveInput(u32 index) const
{
return 0;
}
u8 PadNotConnected::GetRawInput(u32 index) const
{
return 0;

View File

@ -23,6 +23,7 @@ public:
void SetButtonDeadzone(float deadzone) override;
void SetAnalogInvertL(bool x, bool y) override;
void SetAnalogInvertR(bool x, bool y) override;
u8 GetEffectiveInput(u32 index) const override;
u8 GetRawInput(u32 index) const override;
std::tuple<u8, u8> GetRawLeftAnalog() const override;
std::tuple<u8, u8> GetRawRightAnalog() const override;

View File

@ -441,6 +441,11 @@ void PadPopn::SetAnalogInvertR(bool x, bool y)
{
}
u8 PadPopn::GetEffectiveInput(u32 index) const
{
return GetRawInput(index);
}
u8 PadPopn::GetRawInput(u32 index) const
{
return rawInputs[index];

View File

@ -89,6 +89,7 @@ public:
void SetButtonDeadzone(float deadzone) override;
void SetAnalogInvertL(bool x, bool y) override;
void SetAnalogInvertR(bool x, bool y) override;
u8 GetEffectiveInput(u32 index) const override;
u8 GetRawInput(u32 index) const override;
std::tuple<u8, u8> GetRawLeftAnalog() const override;
std::tuple<u8, u8> GetRawRightAnalog() const override;