diff --git a/README b/README index a2dcaf61..903f5158 100644 --- a/README +++ b/README @@ -121,6 +121,26 @@ New cvars 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 diff --git a/code/client/cl_input.c b/code/client/cl_input.c index a42030da..898a7b5a 100644 --- a/code/client/cl_input.c +++ b/code/client/cl_input.c @@ -416,15 +416,19 @@ void CL_JoystickMove( usercmd_t *cmd ) { } 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] ); diff --git a/code/client/cl_main.c b/code/client/cl_main.c index 021388af..719902a6 100644 --- a/code/client/cl_main.c +++ b/code/client/cl_main.c @@ -83,6 +83,15 @@ cvar_t *m_forward; 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 @@ void CL_Init( void ) { 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 ); diff --git a/code/client/client.h b/code/client/client.h index d24f0622..ac9f3aa5 100644 --- a/code/client/client.h +++ b/code/client/client.h @@ -391,6 +391,15 @@ extern cvar_t *m_forward; 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; diff --git a/code/sdl/sdl_input.c b/code/sdl/sdl_input.c index a3f72662..394b962f 100644 --- a/code/sdl/sdl_input.c +++ b/code/sdl/sdl_input.c @@ -67,6 +67,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; @@ -561,6 +562,7 @@ struct { qboolean buttons[16]; // !!! FIXME: these might be too many. unsigned int oldaxes; + int oldaaxes[16]; unsigned int oldhats; } stick_state; @@ -615,6 +617,8 @@ static void IN_InitJoystick( void ) 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 @@ 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); } @@ -808,11 +813,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 ) ); + } } } }