Skip to content

Commit a6b5b32

Browse files
committed
avoid Math.sqrt call in gamepad deadzone handling
1 parent d9d33c5 commit a6b5b32

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/SMAPI/Framework/Input/GamePadStateBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ internal class GamePadStateBuilder : IInputStateBuilder<GamePadStateBuilder, Gam
1515
/// <summary>The maximum direction to ignore for the left thumbstick.</summary>
1616
private const float LeftThumbstickDeadZone = 0.2f;
1717

18-
/// <summary>The maximum direction to ignore for the right thumbstick.</summary>
19-
private const float RightThumbstickDeadZone = 0.9f;
18+
/// <summary>The maximum direction to ignore for the right thumbstick, squared for comparison.</summary>
19+
private const float RightThumbstickDeadZoneSquared = 0.9f * 0.9f;
2020

2121
/// <summary>The underlying controller state.</summary>
2222
/// <remarks>This value is null if it needs to be regenerated for overrides. Most code should call <see cref="GetState"/> instead.</remarks>
@@ -188,7 +188,7 @@ public void FillPressedButtons(HashSet<SButton> set)
188188
set.Add(SButton.LeftThumbstickLeft);
189189

190190
// right thumbstick direction
191-
if (this.RightStickPos.Length() > GamePadStateBuilder.RightThumbstickDeadZone)
191+
if (this.RightStickPos.LengthSquared() > GamePadStateBuilder.RightThumbstickDeadZoneSquared)
192192
{
193193
if (this.RightStickPos.Y > 0)
194194
set.Add(SButton.RightThumbstickUp);

0 commit comments

Comments
 (0)