mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-14 00:58:51 +02:00
ControllerEmu: Add new "input override" system
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@ -63,6 +64,53 @@ void MixedTriggers::GetState(u16* const digital, const u16* bitmasks, ControlSta
|
||||
}
|
||||
}
|
||||
|
||||
void MixedTriggers::GetState(u16* digital, const u16* bitmasks, ControlState* analog,
|
||||
const InputOverrideFunction& override_func, bool adjusted) const
|
||||
{
|
||||
if (!override_func)
|
||||
return GetState(digital, bitmasks, analog, adjusted);
|
||||
|
||||
const ControlState threshold = GetThreshold();
|
||||
ControlState deadzone = GetDeadzone();
|
||||
|
||||
// Return raw values. (used in UI)
|
||||
if (!adjusted)
|
||||
{
|
||||
deadzone = 0.0;
|
||||
}
|
||||
|
||||
const int trigger_count = int(controls.size() / 2);
|
||||
for (int i = 0; i != trigger_count; ++i)
|
||||
{
|
||||
bool button_bool = false;
|
||||
const ControlState button_value = ApplyDeadzone(controls[i]->GetState(), deadzone);
|
||||
ControlState analog_value = ApplyDeadzone(controls[trigger_count + i]->GetState(), deadzone);
|
||||
|
||||
// Apply threshold:
|
||||
if (button_value > threshold)
|
||||
{
|
||||
analog_value = 1.0;
|
||||
button_bool = true;
|
||||
}
|
||||
|
||||
if (const std::optional<ControlState> button_override =
|
||||
override_func(name, controls[i]->name, static_cast<ControlState>(button_bool)))
|
||||
{
|
||||
button_bool = std::lround(*button_override) > 0;
|
||||
}
|
||||
|
||||
if (const std::optional<ControlState> analog_override =
|
||||
override_func(name, controls[trigger_count + i]->name, analog_value))
|
||||
{
|
||||
analog_value = *analog_override;
|
||||
}
|
||||
|
||||
if (button_bool)
|
||||
*digital |= bitmasks[i];
|
||||
analog[i] = std::min(analog_value, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
ControlState MixedTriggers::GetDeadzone() const
|
||||
{
|
||||
return m_deadzone_setting.GetValue() / 100;
|
||||
|
Reference in New Issue
Block a user