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

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Apr 19 09:26:15 EDT 2011


Author: thilo
Date: 2011-04-19 09:26:15 -0400 (Tue, 19 Apr 2011)
New Revision: 1946

Modified:
   trunk/README
   trunk/code/client/cl_input.c
   trunk/code/client/cl_main.c
   trunk/code/client/client.h
   trunk/code/sdl/sdl_input.c
Log:
Add better support for analog joysticks, patch by use.less01


Modified: trunk/README
===================================================================
--- trunk/README	2011-04-18 18:55:58 UTC (rev 1945)
+++ trunk/README	2011-04-19 13:26:15 UTC (rev 1946)
@@ -121,6 +121,26 @@
   cl_gamename                       - Gamename sent to master server in
                                       getserversExt query
 
+  in_joystickUseAnalog              - Do not translate joystick axis events
+                                      to keyboard commands
+
+  j_forward                         - Joystick analogue to m_forward,
+                                      for forward movement speed/direction.
+  j_side                            - Joystick analogue to m_side,
+                                      for side movement speed/direction.
+  j_pitch                           - Joystick analogue to m_pitch,
+                                      for pitch rotation speed/direction.
+  j_yaw                             - Joystick analogue to m_yaw,
+                                      for yaw rotation speed/direction.
+  j_forward_axis                    - Selects which joystick axis
+                                      controls forward/back.
+  j_side_axis                       - Selects which joystick axis
+                                      controls left/right.
+  j_pitch_axis                      - Selects which joystick axis
+                                      controls pitch.
+  j_yaw_axis                        - Selects which joystick axis
+                                      controls yaw.
+
   s_useOpenAL                       - use the OpenAL sound backend if available
   s_alPrecache                      - cache OpenAL sounds before use
   s_alGain                          - the value of AL_GAIN for each source

Modified: trunk/code/client/cl_input.c
===================================================================
--- trunk/code/client/cl_input.c	2011-04-18 18:55:58 UTC (rev 1945)
+++ trunk/code/client/cl_input.c	2011-04-19 13:26:15 UTC (rev 1946)
@@ -416,15 +416,19 @@
 	}
 
 	if ( !in_strafe.active ) {
-		cl.viewangles[YAW] += anglespeed * cl_yawspeed->value * cl.joystickAxis[AXIS_SIDE];
+		cl.viewangles[YAW] += anglespeed * j_yaw->value * cl.joystickAxis[j_yaw_axis->integer];
+		cmd->rightmove = ClampChar( cmd->rightmove + (int) (j_side->value * cl.joystickAxis[j_side_axis->integer]) );
 	} else {
-		cmd->rightmove = ClampChar( cmd->rightmove + cl.joystickAxis[AXIS_SIDE] );
+		cl.viewangles[YAW] += anglespeed * j_side->value * cl.joystickAxis[j_side_axis->integer];
+		cmd->rightmove = ClampChar( cmd->rightmove + (int) (j_yaw->value * cl.joystickAxis[j_yaw_axis->integer]) );
 	}
 
 	if ( in_mlooking ) {
-		cl.viewangles[PITCH] += anglespeed * cl_pitchspeed->value * cl.joystickAxis[AXIS_FORWARD];
+		cl.viewangles[PITCH] += anglespeed * j_forward->value * cl.joystickAxis[j_forward_axis->integer];
+		cmd->forwardmove = ClampChar( cmd->forwardmove + (int) (j_pitch->value * cl.joystickAxis[j_pitch_axis->integer]) );
 	} else {
-		cmd->forwardmove = ClampChar( cmd->forwardmove + cl.joystickAxis[AXIS_FORWARD] );
+		cl.viewangles[PITCH] += anglespeed * j_pitch->value * cl.joystickAxis[j_pitch_axis->integer];
+		cmd->forwardmove = ClampChar( cmd->forwardmove + (int) (j_forward->value * cl.joystickAxis[j_forward_axis->integer]) );
 	}
 
 	cmd->upmove = ClampChar( cmd->upmove + cl.joystickAxis[AXIS_UP] );

Modified: trunk/code/client/cl_main.c
===================================================================
--- trunk/code/client/cl_main.c	2011-04-18 18:55:58 UTC (rev 1945)
+++ trunk/code/client/cl_main.c	2011-04-19 13:26:15 UTC (rev 1946)
@@ -83,6 +83,15 @@
 cvar_t	*m_side;
 cvar_t	*m_filter;
 
+cvar_t	*j_pitch;
+cvar_t	*j_yaw;
+cvar_t	*j_forward;
+cvar_t	*j_side;
+cvar_t	*j_pitch_axis;
+cvar_t	*j_yaw_axis;
+cvar_t	*j_forward_axis;
+cvar_t	*j_side_axis;
+
 cvar_t	*cl_activeAction;
 
 cvar_t	*cl_motdString;
@@ -3194,6 +3203,15 @@
 	m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE);
 #endif
 
+	j_pitch =        Cvar_Get ("j_pitch",        "0.022", CVAR_ARCHIVE);
+	j_yaw =          Cvar_Get ("j_yaw",          "-0.022", CVAR_ARCHIVE);
+	j_forward =      Cvar_Get ("j_forward",      "-0.25", CVAR_ARCHIVE);
+	j_side =         Cvar_Get ("j_side",         "0.25", CVAR_ARCHIVE);
+	j_pitch_axis =   Cvar_Get ("j_pitch_axis",   "3", CVAR_ARCHIVE);
+	j_yaw_axis =     Cvar_Get ("j_yaw_axis",     "4", CVAR_ARCHIVE);
+	j_forward_axis = Cvar_Get ("j_forward_axis", "1", CVAR_ARCHIVE);
+	j_side_axis =    Cvar_Get ("j_side_axis",    "0", CVAR_ARCHIVE);
+
 	cl_motdString = Cvar_Get( "cl_motdString", "", CVAR_ROM );
 
 	Cvar_Get( "cl_maxPing", "800", CVAR_ARCHIVE );

Modified: trunk/code/client/client.h
===================================================================
--- trunk/code/client/client.h	2011-04-18 18:55:58 UTC (rev 1945)
+++ trunk/code/client/client.h	2011-04-19 13:26:15 UTC (rev 1946)
@@ -391,6 +391,15 @@
 extern	cvar_t	*m_side;
 extern	cvar_t	*m_filter;
 
+extern	cvar_t	*j_pitch;
+extern	cvar_t	*j_yaw;
+extern	cvar_t	*j_forward;
+extern	cvar_t	*j_side;
+extern	cvar_t	*j_pitch_axis;
+extern	cvar_t	*j_yaw_axis;
+extern	cvar_t	*j_forward_axis;
+extern	cvar_t	*j_side_axis;
+
 extern	cvar_t	*cl_timedemo;
 extern	cvar_t	*cl_aviFrameRate;
 extern	cvar_t	*cl_aviMotionJpeg;

Modified: trunk/code/sdl/sdl_input.c
===================================================================
--- trunk/code/sdl/sdl_input.c	2011-04-18 18:55:58 UTC (rev 1945)
+++ trunk/code/sdl/sdl_input.c	2011-04-19 13:26:15 UTC (rev 1946)
@@ -67,6 +67,7 @@
 static cvar_t *in_joystickDebug     = NULL;
 static cvar_t *in_joystickThreshold = NULL;
 static cvar_t *in_joystickNo        = NULL;
+static cvar_t *in_joystickUseAnalog = NULL;
 
 static int vidRestartTime = 0;
 
@@ -561,6 +562,7 @@
 {
 	qboolean buttons[16];  // !!! FIXME: these might be too many.
 	unsigned int oldaxes;
+	int oldaaxes[16];
 	unsigned int oldhats;
 } stick_state;
 
@@ -615,6 +617,8 @@
 	if( in_joystickNo->integer < 0 || in_joystickNo->integer >= total )
 		Cvar_Set( "in_joystickNo", "0" );
 
+	in_joystickUseAnalog = Cvar_Get( "in_joystickUseAnalog", "0", CVAR_ARCHIVE );
+
 	stick = SDL_JoystickOpen( in_joystickNo->integer );
 
 	if (stick == NULL) {
@@ -623,11 +627,12 @@
 	}
 
 	Com_DPrintf( "Joystick %d opened\n", in_joystickNo->integer );
-	Com_DPrintf( "Name:    %s\n", SDL_JoystickName(in_joystickNo->integer) );
-	Com_DPrintf( "Axes:    %d\n", SDL_JoystickNumAxes(stick) );
-	Com_DPrintf( "Hats:    %d\n", SDL_JoystickNumHats(stick) );
-	Com_DPrintf( "Buttons: %d\n", SDL_JoystickNumButtons(stick) );
-	Com_DPrintf( "Balls: %d\n", SDL_JoystickNumBalls(stick) );
+	Com_DPrintf( "Name:       %s\n", SDL_JoystickName(in_joystickNo->integer) );
+	Com_DPrintf( "Axes:       %d\n", SDL_JoystickNumAxes(stick) );
+	Com_DPrintf( "Hats:       %d\n", SDL_JoystickNumHats(stick) );
+	Com_DPrintf( "Buttons:    %d\n", SDL_JoystickNumButtons(stick) );
+	Com_DPrintf( "Balls:      %d\n", SDL_JoystickNumBalls(stick) );
+	Com_DPrintf( "Use Analog: %s\n", in_joystickUseAnalog->integer ? "Yes" : "No" );
 
 	SDL_JoystickEventState(SDL_QUERY);
 }
@@ -808,12 +813,28 @@
 		for (i = 0; i < total; i++)
 		{
 			Sint16 axis = SDL_JoystickGetAxis(stick, i);
-			float f = ( (float) axis ) / 32767.0f;
-			if( f < -in_joystickThreshold->value ) {
-				axes |= ( 1 << ( i * 2 ) );
-			} else if( f > in_joystickThreshold->value ) {
-				axes |= ( 1 << ( ( i * 2 ) + 1 ) );
+
+			if (in_joystickUseAnalog->integer)
+			{
+				float f = ( (float) abs(axis) ) / 32767.0f;
+				
+				if( f < in_joystickThreshold->value ) axis = 0;
+
+				if ( axis != stick_state.oldaaxes[i] )
+				{
+					Com_QueueEvent( 0, SE_JOYSTICK_AXIS, i, axis, 0, NULL );
+					stick_state.oldaaxes[i] = axis;
+				}
 			}
+			else
+			{
+				float f = ( (float) axis ) / 32767.0f;
+				if( f < -in_joystickThreshold->value ) {
+					axes |= ( 1 << ( i * 2 ) );
+				} else if( f > in_joystickThreshold->value ) {
+					axes |= ( 1 << ( ( i * 2 ) + 1 ) );
+				}
+			}
 		}
 	}
 



More information about the quake3-commits mailing list