From: Holger Schemel Date: Mon, 17 Jul 2017 16:16:21 +0000 (+0200) Subject: moved clearing joystick state from closing to initializing joysticks X-Git-Tag: 4.0.1.0~24 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=b6dd2f35e987ab55a904deff37194ee8507c7d7a;p=rocksndiamonds.git moved clearing joystick state from closing to initializing joysticks --- diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 8751f1b9..f9419312 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -2601,6 +2601,21 @@ static int sdl_js_axis[MAX_PLAYERS][2]; static int sdl_js_button[MAX_PLAYERS][2]; static boolean sdl_is_controller[MAX_PLAYERS]; +void SDLClearJoystickState() +{ + int i, j; + + for (i = 0; i < MAX_PLAYERS; i++) + { + for (j = 0; j < 2; j++) + { + sdl_js_axis_raw[i][j] = -1; + sdl_js_axis[i][j] = 0; + sdl_js_button[i][j] = 0; + } + } +} + static boolean SDLOpenJoystick(int nr) { if (nr < 0 || nr >= MAX_PLAYERS) @@ -2648,13 +2663,6 @@ static void SDLCloseJoystick(int nr) #endif sdl_joystick[nr] = NULL; - - sdl_js_axis_raw[nr][0] = -1; - sdl_js_axis_raw[nr][1] = -1; - sdl_js_axis[nr][0] = 0; - sdl_js_axis[nr][1] = 0; - sdl_js_button[nr][0] = 0; - sdl_js_button[nr][1] = 0; } boolean SDLCheckJoystickOpened(int nr) @@ -2935,6 +2943,8 @@ void SDLInitJoysticks() else if (print_warning) Error(ERR_WARN, "cannot open joystick %d", i); } + + SDLClearJoystickState(); } boolean SDLReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2) diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 590dadc8..5391b683 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -491,6 +491,7 @@ void HandleJoystickEvent(Event *); void SDLInitJoysticks(void); boolean SDLReadJoystick(int, int *, int *, boolean *, boolean *); boolean SDLCheckJoystickOpened(int); +void SDLClearJoystickState(); void PrepareFadeBitmap(int); diff --git a/src/libgame/system.c b/src/libgame/system.c index 2b283c1a..4d4c448f 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -1645,3 +1645,8 @@ boolean CheckJoystickOpened(int nr) { return SDLCheckJoystickOpened(nr); } + +void ClearJoystickState() +{ + SDLClearJoystickState(); +} diff --git a/src/libgame/system.h b/src/libgame/system.h index 1b1dc2a4..e5c96d31 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1549,5 +1549,6 @@ boolean CheckCloseWindowEvent(ClientMessageEvent *); void InitJoysticks(); boolean ReadJoystick(int, int *, int *, boolean *, boolean *); boolean CheckJoystickOpened(int); +void ClearJoystickState(); #endif /* SYSTEM_H */