ControllerEmu: Clamp results of trigger/slider states to prevent integer overflow later on.

This commit is contained in:
Jordan Woyak 2019-10-15 15:35:07 -05:00
parent 4425d05c4a
commit b120b08726
3 changed files with 3 additions and 3 deletions

View File

@ -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)

View File

@ -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

View File

@ -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;
}