[quake3-commits] r1912 - in trunk: . code/sdl

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Mar 7 17:56:03 EST 2011


Author: thilo
Date: 2011-03-07 17:56:03 -0500 (Mon, 07 Mar 2011)
New Revision: 1912

Modified:
   trunk/README
   trunk/code/sdl/sdl_input.c
Log:
Add in_availableJoysticks to list usable joysticks, similar to s_alAvailableDevices. Some parts of the patch provided by Zack Middleton


Modified: trunk/README
===================================================================
--- trunk/README	2011-03-07 22:08:48 UTC (rev 1911)
+++ trunk/README	2011-03-07 22:56:03 UTC (rev 1912)
@@ -158,6 +158,7 @@
                                       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

Modified: trunk/code/sdl/sdl_input.c
===================================================================
--- trunk/code/sdl/sdl_input.c	2011-03-07 22:08:48 UTC (rev 1911)
+++ trunk/code/sdl/sdl_input.c	2011-03-07 22:56:03 UTC (rev 1912)
@@ -574,6 +574,7 @@
 {
 	int i = 0;
 	int total = 0;
+	char buf[MAX_STRING_CHARS] = "";
 
 	if (stick != NULL)
 		SDL_JoystickClose(stick);
@@ -581,11 +582,6 @@
 	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,9 +595,22 @@
 
 	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 )
 		Cvar_Set( "in_joystickNo", "0" );



More information about the quake3-commits mailing list