From 7a1efc19a46426bab38e695d360fec9fd9458c75 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Wed, 15 Feb 2012 18:26:08 +0000 Subject: [PATCH] Support up to 16 joystick axes, select which to use with j_*_axis cvars. --- code/qcommon/qcommon.h | 10 +--------- code/sdl/sdl_input.c | 18 +++++++++++------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h index 938b46f1..da6f3b7f 100644 --- a/code/qcommon/qcommon.h +++ b/code/qcommon/qcommon.h @@ -1059,15 +1059,7 @@ NON-PORTABLE SYSTEM SERVICES ============================================================== */ -typedef enum { - AXIS_SIDE, - AXIS_FORWARD, - AXIS_UP, - AXIS_ROLL, - AXIS_YAW, - AXIS_PITCH, - MAX_JOYSTICK_AXIS -} joystickAxis_t; +#define MAX_JOYSTICK_AXIS 16 void Sys_Init (void); diff --git a/code/sdl/sdl_input.c b/code/sdl/sdl_input.c index 214b0e1d..ea1ececd 100644 --- a/code/sdl/sdl_input.c +++ b/code/sdl/sdl_input.c @@ -561,7 +561,7 @@ struct { qboolean buttons[16]; // !!! FIXME: these might be too many. unsigned int oldaxes; - int oldaaxes[16]; + int oldaaxes[MAX_JOYSTICK_AXIS]; unsigned int oldhats; } stick_state; @@ -808,13 +808,12 @@ static void IN_JoyMove( void ) total = SDL_JoystickNumAxes(stick); if (total > 0) { - if (total > 16) total = 16; - for (i = 0; i < total; i++) + if (in_joystickUseAnalog->integer) { - Sint16 axis = SDL_JoystickGetAxis(stick, i); - - if (in_joystickUseAnalog->integer) + if (total > MAX_JOYSTICK_AXIS) total = MAX_JOYSTICK_AXIS; + for (i = 0; i < total; i++) { + Sint16 axis = SDL_JoystickGetAxis(stick, i); float f = ( (float) abs(axis) ) / 32767.0f; if( f < in_joystickThreshold->value ) axis = 0; @@ -825,8 +824,13 @@ static void IN_JoyMove( void ) stick_state.oldaaxes[i] = axis; } } - else + } + else + { + if (total > 16) total = 16; + 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 ) );