Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 b120b08
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Expand Up @@ -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); const ControlState button_value = ApplyDeadzone(controls[i]->control_ref->State(), deadzone);
ControlState analog_value = 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: // Apply threshold:
if (button_value > threshold) if (button_value > threshold)
Expand Down
Expand Up @@ -34,6 +34,6 @@ Slider::StateData Slider::GetState()
const ControlState deadzone = m_deadzone_setting.GetValue() / 100; const ControlState deadzone = m_deadzone_setting.GetValue() / 100;
const ControlState state = controls[1]->control_ref->State() - controls[0]->control_ref->State(); 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 } // namespace ControllerEmu
Expand Up @@ -28,7 +28,7 @@ Triggers::StateData Triggers::GetState()


StateData result(trigger_count); StateData result(trigger_count);
for (size_t i = 0; i < trigger_count; ++i) 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; return result;
} }
Expand Down

0 comments on commit b120b08

Please sign in to comment.