summaryrefslogtreecommitdiff
path: root/src/sdl/sdl_input.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sdl/sdl_input.c')
-rw-r--r--src/sdl/sdl_input.c88
1 files changed, 66 insertions, 22 deletions
diff --git a/src/sdl/sdl_input.c b/src/sdl/sdl_input.c
index 0d1164fb..8de34078 100644
--- a/src/sdl/sdl_input.c
+++ b/src/sdl/sdl_input.c
@@ -35,8 +35,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../client/client.h"
#include "../sys/sys_local.h"
-#define ARRAYLEN(x) (sizeof(x)/sizeof(x[0]))
-
#ifdef MACOS_X
// Mouse acceleration needs to be disabled
#define MACOS_X_ACCELERATION_HACK
@@ -70,6 +68,7 @@ static cvar_t *in_joystick = NULL;
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;
@@ -612,6 +611,7 @@ struct
{
qboolean buttons[16]; // !!! FIXME: these might be too many.
unsigned int oldaxes;
+ int oldaaxes[16];
unsigned int oldhats;
} stick_state;
@@ -625,6 +625,7 @@ static void IN_InitJoystick( void )
{
int i = 0;
int total = 0;
+ char buf[16384] = "";
if (stick != NULL)
SDL_JoystickClose(stick);
@@ -632,11 +633,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");
@@ -650,13 +646,28 @@ 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 )
Cvar_Set( "in_joystickNo", "0" );
+ in_joystickUseAnalog = Cvar_Get( "in_joystickUseAnalog", "0", CVAR_ARCHIVE );
+
stick = SDL_JoystickOpen( in_joystickNo->integer );
if (stick == NULL) {
@@ -665,11 +676,12 @@ static void IN_InitJoystick( void )
}
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);
}
@@ -697,7 +709,7 @@ IN_JoyMove
*/
static void IN_JoyMove( void )
{
- qboolean joy_pressed[ARRAYLEN(joy_keys)];
+ qboolean joy_pressed[ARRAY_LEN(joy_keys)];
unsigned int axes = 0;
unsigned int hats = 0;
int total = 0;
@@ -740,8 +752,8 @@ static void IN_JoyMove( void )
total = SDL_JoystickNumButtons(stick);
if (total > 0)
{
- if (total > ARRAYLEN(stick_state.buttons))
- total = ARRAYLEN(stick_state.buttons);
+ if (total > ARRAY_LEN(stick_state.buttons))
+ total = ARRAY_LEN(stick_state.buttons);
for (i = 0; i < total; i++)
{
qboolean pressed = (SDL_JoystickGetButton(stick, i) != 0);
@@ -850,11 +862,27 @@ static void IN_JoyMove( void )
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 ) );
+ }
}
}
}
@@ -1037,6 +1065,20 @@ void IN_Frame( void )
/*
===============
+IN_InitKeyLockStates
+===============
+*/
+void IN_InitKeyLockStates( void )
+{
+ unsigned char *keystate = SDL_GetKeyState(NULL);
+
+ keys[K_SCROLLOCK].down = keystate[SDLK_SCROLLOCK];
+ keys[K_KP_NUMLOCK].down = keystate[SDLK_NUMLOCK];
+ keys[K_CAPSLOCK].down = keystate[SDLK_CAPSLOCK];
+}
+
+/*
+===============
IN_Init
===============
*/
@@ -1060,7 +1102,7 @@ void IN_Init( void )
in_joystick = Cvar_Get( "in_joystick", "0", CVAR_ARCHIVE|CVAR_LATCH );
in_joystickDebug = Cvar_Get( "in_joystickDebug", "0", CVAR_TEMP );
- in_joystickThreshold = Cvar_Get( "in_joystickThreshold", "0.15", CVAR_ARCHIVE );
+ in_joystickThreshold = Cvar_Get( "joy_threshold", "0.15", CVAR_ARCHIVE );
#ifdef MACOS_X_ACCELERATION_HACK
in_disablemacosxmouseaccel = Cvar_Get( "in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE );
@@ -1085,6 +1127,8 @@ void IN_Init( void )
Cvar_SetValue( "com_unfocused", !( appState & SDL_APPINPUTFOCUS ) );
Cvar_SetValue( "com_minimized", !( appState & SDL_APPACTIVE ) );
+ IN_InitKeyLockStates( );
+
IN_InitJoystick( );
Com_DPrintf( "------------------------------------\n" );
}