Skip to content

Commit 775ead6

Browse files
authored
Fix deadzone not being applied on SDL gamepads (#451)
* apply deadzone to sdl gamepad * Single line if switched to block statements as suggested in PR review
1 parent 23f9bd4 commit 775ead6

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

src/Input/Silk.NET.Input.Sdl/SdlGamepad.cs

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using Silk.NET.SDL;
44

@@ -76,30 +76,54 @@ public void DoEvent(Event @event)
7676
{
7777
case GameControllerAxis.ControllerAxisLeftx:
7878
{
79-
_thumbsticksChanged[0] = true;
80-
_thumbsticks[0] = new Thumbstick
81-
(0, (float) @event.Caxis.Value / short.MaxValue, _thumbsticks[0].Y);
79+
var thumbstick0 = new Thumbstick(0,
80+
Deadzone.Apply((float) @event.Caxis.Value / short.MaxValue),
81+
Deadzone.Apply(_thumbsticks[0].Y));
82+
83+
if (thumbstick0.X != _thumbsticks[0].X)
84+
{
85+
_thumbsticksChanged[0] = true;
86+
}
87+
_thumbsticks[0] = thumbstick0;
8288
break;
8389
}
8490
case GameControllerAxis.ControllerAxisLefty:
8591
{
86-
_thumbsticksChanged[0] = true;
87-
_thumbsticks[0] = new Thumbstick
88-
(0, _thumbsticks[0].X, (float) @event.Caxis.Value / short.MaxValue);
92+
var thumbstick0 = new Thumbstick(0,
93+
Deadzone.Apply(_thumbsticks[0].X),
94+
Deadzone.Apply((float) @event.Caxis.Value / short.MaxValue));
95+
96+
if (thumbstick0.Y != _thumbsticks[0].Y)
97+
{
98+
_thumbsticksChanged[0] = true;
99+
}
100+
_thumbsticks[0] = thumbstick0;
89101
break;
90102
}
91103
case GameControllerAxis.ControllerAxisRightx:
92104
{
93-
_thumbsticksChanged[1] = true;
94-
_thumbsticks[1] = new Thumbstick
95-
(1, (float) @event.Caxis.Value / short.MaxValue, _thumbsticks[1].Y);
105+
var thumbstick1 = new Thumbstick(1,
106+
Deadzone.Apply((float) @event.Caxis.Value / short.MaxValue),
107+
Deadzone.Apply(_thumbsticks[1].Y));
108+
109+
if (thumbstick1.X != _thumbsticks[1].X)
110+
{
111+
_thumbsticksChanged[1] = true;
112+
}
113+
_thumbsticks[1] = thumbstick1;
96114
break;
97115
}
98116
case GameControllerAxis.ControllerAxisRighty:
99117
{
100-
_thumbsticksChanged[1] = true;
101-
_thumbsticks[1] = new Thumbstick
102-
(1, _thumbsticks[1].X, (float) @event.Caxis.Value / short.MaxValue);
118+
var thumbstick1 = new Thumbstick(1,
119+
Deadzone.Apply(_thumbsticks[1].X),
120+
Deadzone.Apply((float) @event.Caxis.Value / short.MaxValue));
121+
122+
if (thumbstick1.Y != _thumbsticks[1].Y)
123+
{
124+
_thumbsticksChanged[1] = true;
125+
}
126+
_thumbsticks[1] = thumbstick1;
103127
break;
104128
}
105129
case GameControllerAxis.ControllerAxisTriggerleft:

0 commit comments

Comments
 (0)