Skip to content
Permalink
Browse files

ControllerEmu: Clamp results of trigger/slider states to prevent inte…

…ger overflow later on.
  • Loading branch information...
jordan-woyak committed Oct 15, 2019
1 parent 4425d05 commit b120b0872658335e1f23422e61b2e2b16f1aaab6
@@ -48,7 +48,7 @@ void MixedTriggers::GetState(u16* const digital, const u16* bitmasks, ControlSta
{
const ControlState button_value = ApplyDeadzone(controls[i]->control_ref->State(), deadzone);
ControlState analog_value =
ApplyDeadzone(controls[trigger_count + i]->control_ref->State(), deadzone);
std::min(ApplyDeadzone(controls[trigger_count + i]->control_ref->State(), deadzone), 1.0);

// Apply threshold:
if (button_value > threshold)
@@ -34,6 +34,6 @@ Slider::StateData Slider::GetState()
const ControlState deadzone = m_deadzone_setting.GetValue() / 100;
const ControlState state = controls[1]->control_ref->State() - controls[0]->control_ref->State();

return {ApplyDeadzone(state, deadzone)};
return {std::clamp(ApplyDeadzone(state, deadzone), -1.0, 1.0)};
}
} // namespace ControllerEmu
@@ -28,7 +28,7 @@ Triggers::StateData Triggers::GetState()

StateData result(trigger_count);
for (size_t i = 0; i < trigger_count; ++i)
result.data[i] = ApplyDeadzone(controls[i]->control_ref->State(), deadzone);
result.data[i] = std::min(ApplyDeadzone(controls[i]->control_ref->State(), deadzone), 1.0);

return result;
}

0 comments on commit b120b08

Please sign in to comment.
You can’t perform that action at this time.