From: fgsfds Date: Fri, 5 Apr 2019 17:28:43 +0000 (+0300) Subject: fix joystick deadzones X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=00d0916c734ba21be4aa008b39dea80db7a419da;p=d2df-sdl.git fix joystick deadzones --- diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 5689ceb..245efa3 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -464,7 +464,7 @@ end; function EventHandler (var ev: TSDL_Event): Boolean; var - key, keychr: Word; + key, keychr, minuskey: Word; uc: UnicodeChar; down: Boolean; i: Integer; @@ -528,14 +528,44 @@ begin SDL_JOYAXISMOTION: if (ev.jaxis.which < e_MaxJoys) and (ev.jaxis.axis < e_MaxJoyAxes) then begin - down := ev.jaxis.value <> Joysticks[ev.jaxis.which].AxisZero[ev.jaxis.axis]; + key := e_JoyAxisToKey(ev.jaxis.which, ev.jaxis.axis, AX_PLUS); + minuskey := e_JoyAxisToKey(ev.jaxis.which, ev.jaxis.axis, AX_MINUS); + if ev.jaxis.value < Joysticks[ev.jaxis.which].AxisZero[ev.jaxis.axis] - e_JoystickDeadzones[ev.jaxis.which] then - key := e_JoyAxisToKey(ev.jaxis.which, ev.jaxis.axis, AX_MINUS) + begin + if (e_KeyPressed(key)) then + begin + e_KeyUpDown(key, False); + g_Console_ProcessBind(key, False); + end; + e_KeyUpDown(minuskey, True); + g_Console_ProcessBind(minuskey, True); + KeyPress(minuskey); + end + else if ev.jaxis.value > Joysticks[ev.jaxis.which].AxisZero[ev.jaxis.axis] + e_JoystickDeadzones[ev.jaxis.which] then + begin + if (e_KeyPressed(minuskey)) then + begin + e_KeyUpDown(minuskey, False); + g_Console_ProcessBind(minuskey, False); + end; + e_KeyUpDown(key, True); + g_Console_ProcessBind(key, True); + KeyPress(key); + end else - key := e_JoyAxisToKey(ev.jaxis.which, ev.jaxis.axis, AX_PLUS); - e_KeyUpDown(key, down); - g_Console_ProcessBind(key, down); - if down then KeyPress(key) + begin + if (e_KeyPressed(minuskey)) then + begin + e_KeyUpDown(minuskey, False); + g_Console_ProcessBind(minuskey, False); + end; + if (e_KeyPressed(key)) then + begin + e_KeyUpDown(key, False); + g_Console_ProcessBind(key, False); + end; + end; end; SDL_JOYHATMOTION: