mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-16 12:58:33 +02:00
ControllerEmu: Implement dead zone setting for triggers.
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@ -21,23 +22,53 @@ MixedTriggers::MixedTriggers(const std::string& name_)
|
||||
: ControlGroup(name_, GroupType::MixedTriggers)
|
||||
{
|
||||
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.9));
|
||||
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0.0, 0, 25));
|
||||
}
|
||||
|
||||
void MixedTriggers::GetState(u16* const digital, const u16* bitmasks, ControlState* analog)
|
||||
void MixedTriggers::GetState(u16* const digital, const u16* bitmasks, ControlState* analog,
|
||||
bool adjusted)
|
||||
{
|
||||
const size_t trigger_count = controls.size() / 2;
|
||||
const ControlState threshold = numeric_settings[SETTING_THRESHOLD]->GetValue();
|
||||
ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue();
|
||||
|
||||
for (size_t i = 0; i < trigger_count; ++i, ++bitmasks, ++analog)
|
||||
// Return raw values. (used in UI)
|
||||
if (!adjusted)
|
||||
{
|
||||
if (controls[i]->control_ref->State() > numeric_settings[0]->GetValue()) // threshold
|
||||
deadzone = 0.0;
|
||||
}
|
||||
|
||||
const int trigger_count = int(controls.size() / 2);
|
||||
for (int i = 0; i != trigger_count; ++i)
|
||||
{
|
||||
ControlState button_value = controls[i]->control_ref->State();
|
||||
ControlState analog_value = controls[trigger_count + i]->control_ref->State();
|
||||
|
||||
// Apply deadzone:
|
||||
analog_value = std::max(0.0, analog_value - deadzone) / (1.0 - deadzone);
|
||||
button_value = std::max(0.0, button_value - deadzone) / (1.0 - deadzone);
|
||||
|
||||
// Apply threshold:
|
||||
if (button_value > threshold)
|
||||
{
|
||||
*analog = 1.0;
|
||||
*digital |= *bitmasks;
|
||||
}
|
||||
else
|
||||
{
|
||||
*analog = controls[i + trigger_count]->control_ref->State();
|
||||
// Fully activate analog:
|
||||
analog_value = 1.0;
|
||||
|
||||
// Activate button:
|
||||
*digital |= bitmasks[i];
|
||||
}
|
||||
|
||||
analog[i] = analog_value;
|
||||
}
|
||||
}
|
||||
|
||||
ControlState MixedTriggers::GetDeadzone() const
|
||||
{
|
||||
return numeric_settings[SETTING_DEADZONE]->GetValue();
|
||||
}
|
||||
|
||||
ControlState MixedTriggers::GetThreshold() const
|
||||
{
|
||||
return numeric_settings[SETTING_THRESHOLD]->GetValue();
|
||||
}
|
||||
|
||||
} // namespace ControllerEmu
|
||||
|
Reference in New Issue
Block a user