From dd0161f47514d87abb74e1e9af478b6b87801ef3 Mon Sep 17 00:00:00 2001 From: Thilo Schulz Date: Mon, 7 Mar 2011 22:56:03 +0000 Subject: [PATCH] Add in_availableJoysticks to list usable joysticks, similar to s_alAvailableDevices. Some parts of the patch provided by Zack Middleton --- README | 1 + code/sdl/sdl_input.c | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README b/README index 0481c739..1b25661d 100644 --- a/README +++ b/README @@ -158,6 +158,7 @@ New cvars next frame when set to non-zero value in_joystickNo - select which joystick to use + in_availableJoysticks - list of available Joysticks in_keyboardDebug - print keyboard debug info sv_dlURL - the base of the HTTP or FTP site that diff --git a/code/sdl/sdl_input.c b/code/sdl/sdl_input.c index 097177da..9a509cd8 100644 --- a/code/sdl/sdl_input.c +++ b/code/sdl/sdl_input.c @@ -574,6 +574,7 @@ static void IN_InitJoystick( void ) { int i = 0; int total = 0; + char buf[MAX_STRING_CHARS] = ""; if (stick != NULL) SDL_JoystickClose(stick); @@ -581,11 +582,6 @@ static void IN_InitJoystick( void ) stick = NULL; memset(&stick_state, '\0', sizeof (stick_state)); - if( !in_joystick->integer ) { - Com_DPrintf( "Joystick is not active.\n" ); - return; - } - if (!SDL_WasInit(SDL_INIT_JOYSTICK)) { Com_DPrintf("Calling SDL_Init(SDL_INIT_JOYSTICK)...\n"); @@ -599,8 +595,21 @@ static void IN_InitJoystick( void ) total = SDL_NumJoysticks(); Com_DPrintf("%d possible joysticks\n", total); + + // Print list and build cvar to allow ui to select joystick. for (i = 0; i < total; i++) - Com_DPrintf("[%d] %s\n", i, SDL_JoystickName(i)); + { + Q_strcat(buf, sizeof(buf), SDL_JoystickName(i)); + Q_strcat(buf, sizeof(buf), "\n"); + } + + Cvar_Get( "in_availableJoysticks", buf, CVAR_ROM ); + + if( !in_joystick->integer ) { + Com_DPrintf( "Joystick is not active.\n" ); + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); + return; + } in_joystickNo = Cvar_Get( "in_joystickNo", "0", CVAR_ARCHIVE ); if( in_joystickNo->integer < 0 || in_joystickNo->integer >= total )