From e4127187e0e5de9c94a92301b4dc780bc9153fb8 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Wed, 13 Jun 2007 19:12:13 +0000 Subject: Working joystick code. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 903 --- setup/joystick.c | 14 +++++++++++++- setup/txt_joybinput.c | 9 +++++++++ src/i_joystick.c | 2 ++ src/i_video.c | 2 ++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/setup/joystick.c b/setup/joystick.c index 41c30067..d491aadf 100644 --- a/setup/joystick.c +++ b/setup/joystick.c @@ -79,6 +79,11 @@ static int OpenAllJoysticks(void) int num_joysticks; int result; + if (SDL_Init(SDL_INIT_JOYSTICK) < 0) + { + return 0; + } + // SDL_JoystickOpen() all joysticks. num_joysticks = SDL_NumJoysticks(); @@ -104,6 +109,10 @@ static int OpenAllJoysticks(void) free(all_joysticks); all_joysticks = NULL; } + else + { + SDL_JoystickEventState(SDL_ENABLE); + } return result; } @@ -125,6 +134,9 @@ static void CloseAllJoysticks(void) } } + SDL_JoystickEventState(SDL_DISABLE); + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); + free(all_joysticks); all_joysticks = NULL; } @@ -178,7 +190,7 @@ static void CalibrateAxis(int *axis_index, int *axis_invert) if (abs(axis_value) > best_value) { best_value = abs(axis_value); - best_invert = axis_value < 0; + best_invert = axis_value > 0; best_axis = i; } } diff --git a/setup/txt_joybinput.c b/setup/txt_joybinput.c index 56aaa47e..0f05eaf4 100644 --- a/setup/txt_joybinput.c +++ b/setup/txt_joybinput.c @@ -64,6 +64,8 @@ static void PromptWindowClosed(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(joystick)) SDL_JoystickClose(joystick); TXT_SDL_SetEventCallback(NULL, NULL); + SDL_JoystickEventState(SDL_DISABLE); + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } static void OpenErrorWindow(void) @@ -86,6 +88,11 @@ static void OpenPromptWindow(txt_joystick_input_t *joystick_input) txt_label_t *label; SDL_Joystick *joystick; + if (SDL_Init(SDL_INIT_JOYSTICK) < 0) + { + return; + } + // Check the current joystick is valid joystick = SDL_JoystickOpen(joystick_index); @@ -111,6 +118,8 @@ static void OpenPromptWindow(txt_joystick_input_t *joystick_input) TXT_SDL_SetEventCallback(EventCallback, joystick_input); TXT_SignalConnect(window, "closed", PromptWindowClosed, joystick); joystick_input->prompt_window = window; + + SDL_JoystickEventState(SDL_ENABLE); } static void TXT_JoystickInputSizeCalc(TXT_UNCAST_ARG(joystick_input)) diff --git a/src/i_joystick.c b/src/i_joystick.c index 0e0f7590..3eb9069d 100644 --- a/src/i_joystick.c +++ b/src/i_joystick.c @@ -108,6 +108,8 @@ void I_InitJoystick(void) SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } + SDL_JoystickEventState(SDL_ENABLE); + // Initialised okay! printf("I_InitJoystick: %s\n", SDL_JoystickName(joystick_index)); diff --git a/src/i_video.c b/src/i_video.c index 39208ec3..0dfccfa3 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -555,6 +555,8 @@ void I_StartTic (void) { I_ReadMouse(); } + + I_UpdateJoystick(); } -- cgit v1.2.3