mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-12-04 03:25:39 +00:00
Merge pull request #1031 from ggrtk/negcon-deadzone
NeGcon: Add steering axis deadzone setting
This commit is contained in:
commit
79aa1cece7
|
@ -216,6 +216,9 @@ Controller::SettingList Controller::GetSettings(ControllerType type)
|
||||||
case ControllerType::NamcoGunCon:
|
case ControllerType::NamcoGunCon:
|
||||||
return NamcoGunCon::StaticGetSettings();
|
return NamcoGunCon::StaticGetSettings();
|
||||||
|
|
||||||
|
case ControllerType::NeGcon:
|
||||||
|
return NeGcon::StaticGetSettings();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,11 @@ void NeGcon::SetAxisState(s32 axis_code, float value)
|
||||||
// Steering Axis: -1..1 -> 0..255
|
// Steering Axis: -1..1 -> 0..255
|
||||||
if (axis_code == static_cast<s32>(Axis::Steering))
|
if (axis_code == static_cast<s32>(Axis::Steering))
|
||||||
{
|
{
|
||||||
const u8 u8_value = static_cast<u8>(std::clamp(((value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f));
|
const float float_value =
|
||||||
|
(std::abs(value) < m_steering_deadzone) ?
|
||||||
|
0.0f :
|
||||||
|
std::copysign((std::abs(value) - m_steering_deadzone) / (1.0f - m_steering_deadzone), value);
|
||||||
|
const u8 u8_value = static_cast<u8>(std::clamp(((float_value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f));
|
||||||
|
|
||||||
SetAxisState(static_cast<Axis>(axis_code), u8_value);
|
SetAxisState(static_cast<Axis>(axis_code), u8_value);
|
||||||
|
|
||||||
|
@ -242,3 +246,18 @@ u32 NeGcon::StaticGetVibrationMotorCount()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Controller::SettingList NeGcon::StaticGetSettings()
|
||||||
|
{
|
||||||
|
static constexpr std::array<SettingInfo, 1> settings = {
|
||||||
|
{SettingInfo::Type::Float, "SteeringDeadzone", TRANSLATABLE("NeGcon", "Steering Axis Deadzone"),
|
||||||
|
TRANSLATABLE("NeGcon", "Sets deadzone size for steering axis."), "0.00f", "0.00f", "0.99f", "0.01f"}};
|
||||||
|
|
||||||
|
return SettingList(settings.begin(), settings.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void NeGcon::LoadSettings(const char* section)
|
||||||
|
{
|
||||||
|
Controller::LoadSettings(section);
|
||||||
|
m_steering_deadzone = g_host_interface->GetFloatSettingValue(section, "SteeringDeadzone", 0.10f);
|
||||||
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
static AxisList StaticGetAxisNames();
|
static AxisList StaticGetAxisNames();
|
||||||
static ButtonList StaticGetButtonNames();
|
static ButtonList StaticGetButtonNames();
|
||||||
static u32 StaticGetVibrationMotorCount();
|
static u32 StaticGetVibrationMotorCount();
|
||||||
|
static SettingList StaticGetSettings();
|
||||||
|
|
||||||
ControllerType GetType() const override;
|
ControllerType GetType() const override;
|
||||||
std::optional<s32> GetAxisCodeByName(std::string_view axis_name) const override;
|
std::optional<s32> GetAxisCodeByName(std::string_view axis_name) const override;
|
||||||
|
@ -56,6 +57,8 @@ public:
|
||||||
void SetAxisState(Axis axis, u8 value);
|
void SetAxisState(Axis axis, u8 value);
|
||||||
void SetButtonState(Button button, bool pressed);
|
void SetButtonState(Button button, bool pressed);
|
||||||
|
|
||||||
|
void LoadSettings(const char* section) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class TransferState : u8
|
enum class TransferState : u8
|
||||||
{
|
{
|
||||||
|
@ -75,4 +78,6 @@ private:
|
||||||
u16 m_button_state = UINT16_C(0xFFFF);
|
u16 m_button_state = UINT16_C(0xFFFF);
|
||||||
|
|
||||||
TransferState m_transfer_state = TransferState::Idle;
|
TransferState m_transfer_state = TransferState::Idle;
|
||||||
|
|
||||||
|
float m_steering_deadzone = 0.00f;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue