Browse Source

engine: input: adapt gamepad code for new engine, remove gamepad ids, as it was never used and probably will never be, small optimizations

pull/2/head
Alibek Omarov 5 years ago
parent
commit
fa68108907
  1. 55
      engine/client/in_joy.c
  2. 12
      engine/client/input.h
  3. 22
      engine/platform/android/android.c
  4. 18
      engine/platform/sdl/events.c

55
engine/client/in_joy.c

@ -39,8 +39,6 @@ typedef enum engineAxis_e
#define MAX_AXES JOY_AXIS_NULL #define MAX_AXES JOY_AXIS_NULL
#define JOY_SIMULATED_HAT_ID ( -1 )
// index - axis num come from event // index - axis num come from event
// value - inner axis // value - inner axis
static engineAxis_t joyaxesmap[MAX_AXES] = static engineAxis_t joyaxesmap[MAX_AXES] =
@ -58,7 +56,6 @@ static struct joy_axis_s
short val; short val;
short prevval; short prevval;
} joyaxis[MAX_AXES] = { 0 }; } joyaxis[MAX_AXES] = { 0 };
static qboolean forcedisable = false;
static byte currentbinding; // add posibility to remap keys, to place it in joykeys[] static byte currentbinding; // add posibility to remap keys, to place it in joykeys[]
static convar_t *joy_enable; static convar_t *joy_enable;
static convar_t *joy_pitch; static convar_t *joy_pitch;
@ -84,7 +81,7 @@ Joy_IsActive
*/ */
qboolean Joy_IsActive( void ) qboolean Joy_IsActive( void )
{ {
return !forcedisable && joy_found->value; return joy_found->value && joy_enable->value;
} }
/* /*
@ -94,7 +91,7 @@ Joy_HatMotionEvent
DPad events DPad events
============ ============
*/ */
void Joy_HatMotionEvent( int id, byte hat, byte value ) void Joy_HatMotionEvent( byte hat, byte value )
{ {
struct struct
{ {
@ -132,7 +129,7 @@ void Joy_HatMotionEvent( int id, byte hat, byte value )
Joy_ProcessTrigger Joy_ProcessTrigger
============= =============
*/ */
void Joy_ProcessTrigger( const engineAxis_t engineAxis, short value ) static void Joy_ProcessTrigger( const engineAxis_t engineAxis, short value )
{ {
int trigButton = 0, trigThreshold = 0; int trigButton = 0, trigThreshold = 0;
@ -167,7 +164,7 @@ void Joy_ProcessTrigger( const engineAxis_t engineAxis, short value )
} }
} }
int Joy_GetHatValueForAxis( const engineAxis_t engineAxis ) static int Joy_GetHatValueForAxis( const engineAxis_t engineAxis )
{ {
int threshold, negative, positive; int threshold, negative, positive;
@ -207,7 +204,7 @@ int Joy_GetHatValueForAxis( const engineAxis_t engineAxis )
Joy_ProcessStick Joy_ProcessStick
============= =============
*/ */
void Joy_ProcessStick( const engineAxis_t engineAxis, short value ) static void Joy_ProcessStick( const engineAxis_t engineAxis, short value )
{ {
int deadzone = 0; int deadzone = 0;
@ -238,7 +235,7 @@ void Joy_ProcessStick( const engineAxis_t engineAxis, short value )
val |= Joy_GetHatValueForAxis( JOY_AXIS_SIDE ); val |= Joy_GetHatValueForAxis( JOY_AXIS_SIDE );
val |= Joy_GetHatValueForAxis( JOY_AXIS_FWD ); val |= Joy_GetHatValueForAxis( JOY_AXIS_FWD );
Joy_HatMotionEvent( JOY_SIMULATED_HAT_ID, 0, val ); Joy_HatMotionEvent( 0, val );
} }
} }
@ -249,7 +246,7 @@ Joy_AxisMotionEvent
Axis events Axis events
============= =============
*/ */
void Joy_AxisMotionEvent( int id, byte axis, short value ) void Joy_AxisMotionEvent( byte axis, short value )
{ {
byte engineAxis; byte engineAxis;
@ -283,7 +280,7 @@ Joy_BallMotionEvent
Trackball events. UNDONE Trackball events. UNDONE
============= =============
*/ */
void Joy_BallMotionEvent( int id, byte ball, short xrel, short yrel ) void Joy_BallMotionEvent( byte ball, short xrel, short yrel )
{ {
//if( !joy_found->value ) //if( !joy_found->value )
// return; // return;
@ -296,7 +293,7 @@ Joy_ButtonEvent
Button events Button events
============= =============
*/ */
void Joy_ButtonEvent( int id, byte button, byte down ) void Joy_ButtonEvent( byte button, byte down )
{ {
if( !joy_found->value ) if( !joy_found->value )
return; return;
@ -321,10 +318,10 @@ Joy_RemoveEvent
Called when joystick is removed. For future expansion Called when joystick is removed. For future expansion
============= =============
*/ */
void Joy_RemoveEvent( int id ) void Joy_RemoveEvent( void )
{ {
if( !forcedisable && joy_found->value ) if( joy_found->value )
Cvar_SetValue("joy_found", joy_found->value - 1.0f); Cvar_FullSet( "joy_found", "0", FCVAR_READ_ONLY );
} }
/* /*
@ -334,12 +331,10 @@ Joy_RemoveEvent
Called when joystick is removed. For future expansion Called when joystick is removed. For future expansion
============= =============
*/ */
void Joy_AddEvent( int id ) void Joy_AddEvent( void )
{ {
if( forcedisable ) if( joy_enable->value && !joy_found->value )
return; Cvar_FullSet( "joy_found", "1", FCVAR_READ_ONLY );
Cvar_SetValue("joy_found", joy_found->value + 1.0f);
} }
/* /*
@ -351,16 +346,15 @@ Append movement from axis. Called everyframe
*/ */
void Joy_FinalizeMove( float *fw, float *side, float *dpitch, float *dyaw ) void Joy_FinalizeMove( float *fw, float *side, float *dpitch, float *dyaw )
{ {
if( !joy_found->value || !joy_enable->value ) if( !Joy_IsActive() )
return; return;
if( FBitSet( joy_axis_binding->flags, FCVAR_CHANGED ) ) if( FBitSet( joy_axis_binding->flags, FCVAR_CHANGED ) )
{ {
char bind[7] = { 0 }; // fill it with zeros const char *bind = joy_axis_binding->string;
size_t i; size_t i;
Q_strncpy( bind, joy_axis_binding->string, sizeof(bind) );
for( i = 0; i < sizeof(bind); i++ ) for( i = 0; bind[i]; i++ )
{ {
switch( bind[i] ) switch( bind[i] )
{ {
@ -373,6 +367,7 @@ void Joy_FinalizeMove( float *fw, float *side, float *dpitch, float *dyaw )
default : joyaxesmap[i] = JOY_AXIS_NULL; break; default : joyaxesmap[i] = JOY_AXIS_NULL; break;
} }
} }
ClearBits( joy_axis_binding->flags, FCVAR_CHANGED ); ClearBits( joy_axis_binding->flags, FCVAR_CHANGED );
} }
@ -416,21 +411,21 @@ void Joy_Init( void )
joy_yaw_deadzone = Cvar_Get( "joy_yaw_deadzone", "0", FCVAR_ARCHIVE, "yaw axis deadzone. Value from 0 to 32767" ); joy_yaw_deadzone = Cvar_Get( "joy_yaw_deadzone", "0", FCVAR_ARCHIVE, "yaw axis deadzone. Value from 0 to 32767" );
joy_axis_binding = Cvar_Get( "joy_axis_binding", "sfpyrl", FCVAR_ARCHIVE, "axis hardware id to engine inner axis binding, " joy_axis_binding = Cvar_Get( "joy_axis_binding", "sfpyrl", FCVAR_ARCHIVE, "axis hardware id to engine inner axis binding, "
"s - side, f - forward, y - yaw, p - pitch, r - left trigger, l - right trigger" ); "s - side, f - forward, y - yaw, p - pitch, r - left trigger, l - right trigger" );
joy_found = Cvar_Get( "joy_found", "0", FCVAR_READ_ONLY, "total num of connected joysticks" ); joy_found = Cvar_Get( "joy_found", "0", FCVAR_READ_ONLY, "is joystick is connected" );
// we doesn't loaded config.cfg yet, so this cvar is not archive. // we doesn't loaded config.cfg yet, so this cvar is not archive.
// change by +set joy_index in cmdline // change by +set joy_index in cmdline
joy_index = Cvar_Get( "joy_index", "0", FCVAR_READ_ONLY, "current active joystick" ); joy_index = Cvar_Get( "joy_index", "0", FCVAR_READ_ONLY, "current active joystick" );
joy_enable = Cvar_Get( "joy_enable", "1", FCVAR_ARCHIVE, "enable joystick" ); joy_enable = Cvar_Get( "joy_enable", "1", FCVAR_ARCHIVE, "enable joystick" );
if( Sys_CheckParm("-nojoy" ) ) if( Sys_CheckParm( "-nojoy" ))
{ {
forcedisable = true; Cvar_FullSet( "joy_enable", "0", FCVAR_READ_ONLY );
return; return;
} }
Cvar_SetValue( "joy_found", Platform_JoyInit( joy_index->value ) ); Cvar_FullSet( "joy_found", va( "%d", Platform_JoyInit( joy_index->value )), FCVAR_READ_ONLY );
} }
/* /*
@ -442,7 +437,7 @@ Shutdown joystick code
*/ */
void Joy_Shutdown( void ) void Joy_Shutdown( void )
{ {
Cvar_SetValue( "joy_found", 0 ); Cvar_FullSet( "joy_found", 0, FCVAR_READ_ONLY );
} }
#endif // XASH_DEDICATED #endif // XASH_DEDICATED

12
engine/client/input.h

@ -89,12 +89,12 @@ enum
}; };
qboolean Joy_IsActive( void ); qboolean Joy_IsActive( void );
void Joy_HatMotionEvent( int id, byte hat, byte value ); void Joy_HatMotionEvent( byte hat, byte value );
void Joy_AxisMotionEvent( int id, byte axis, short value ); void Joy_AxisMotionEvent( byte axis, short value );
void Joy_BallMotionEvent( int id, byte ball, short xrel, short yrel ); void Joy_BallMotionEvent( byte ball, short xrel, short yrel );
void Joy_ButtonEvent( int id, byte button, byte down ); void Joy_ButtonEvent( byte button, byte down );
void Joy_AddEvent( int id ); void Joy_AddEvent( void );
void Joy_RemoveEvent( int id ); void Joy_RemoveEvent( void );
void Joy_FinalizeMove( float *fw, float *side, float *dpitch, float *dyaw ); void Joy_FinalizeMove( float *fw, float *side, float *dpitch, float *dyaw );
void Joy_Init( void ); void Joy_Init( void );
void Joy_Shutdown( void ); void Joy_Shutdown( void );

22
engine/platform/android/android.c

@ -864,31 +864,31 @@ void Platform_RunEvents()
} }
break; break;
case event_joyadd: case event_joyadd:
Joy_AddEvent( events.queue[i].arg ); Joy_AddEvent();
break; break;
case event_joyremove: case event_joyremove:
Joy_RemoveEvent( events.queue[i].arg ); Joy_RemoveEvent();
break; break;
case event_joyball: case event_joyball:
if( !Joy_IsActive() ) if( !Joy_IsActive() )
Joy_AddEvent( 0 ); Joy_AddEvent();
Joy_BallMotionEvent( events.queue[i].arg, events.queue[i].ball.ball, Joy_BallMotionEvent( events.queue[i].ball.ball,
events.queue[i].ball.xrel, events.queue[i].ball.yrel ); events.queue[i].ball.xrel, events.queue[i].ball.yrel );
break; break;
case event_joyhat: case event_joyhat:
if( !Joy_IsActive() ) if( !Joy_IsActive() )
Joy_AddEvent( 0 ); Joy_AddEvent();
Joy_HatMotionEvent( events.queue[i].arg, events.queue[i].hat.hat, events.queue[i].hat.key ); Joy_HatMotionEvent( events.queue[i].hat.hat, events.queue[i].hat.key );
break; break;
case event_joyaxis: case event_joyaxis:
if( !Joy_IsActive() ) if( !Joy_IsActive() )
Joy_AddEvent( 0 ); Joy_AddEvent();
Joy_AxisMotionEvent( events.queue[i].arg, events.queue[i].axis.axis, events.queue[i].axis.val ); Joy_AxisMotionEvent( events.queue[i].axis.axis, events.queue[i].axis.val );
break; break;
case event_joybutton: case event_joybutton:
if( !Joy_IsActive() ) if( !Joy_IsActive() )
Joy_AddEvent( 0 ); Joy_AddEvent();
Joy_ButtonEvent( events.queue[i].arg, events.queue[i].button.button, (byte)events.queue[i].button.down ); Joy_ButtonEvent( events.queue[i].button.button, (byte)events.queue[i].button.down );
break; break;
case event_ondestroy: case event_ondestroy:
//host.skip_configs = true; // skip config save, because engine may be killed during config save //host.skip_configs = true; // skip config save, because engine may be killed during config save

18
engine/platform/sdl/events.c

@ -306,27 +306,27 @@ static void SDLash_EventFilter( SDL_Event *event )
/* Joystick events */ /* Joystick events */
case SDL_JOYAXISMOTION: case SDL_JOYAXISMOTION:
Joy_AxisMotionEvent( event->jaxis.which, event->jaxis.axis, event->jaxis.value ); Joy_AxisMotionEvent( event->jaxis.axis, event->jaxis.value );
break; break;
case SDL_JOYBALLMOTION: case SDL_JOYBALLMOTION:
Joy_BallMotionEvent( event->jball.which, event->jball.ball, event->jball.xrel, event->jball.yrel ); Joy_BallMotionEvent( event->jball.ball, event->jball.xrel, event->jball.yrel );
break; break;
case SDL_JOYHATMOTION: case SDL_JOYHATMOTION:
Joy_HatMotionEvent( event->jhat.which, event->jhat.hat, event->jhat.value ); Joy_HatMotionEvent( event->jhat.hat, event->jhat.value );
break; break;
case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP: case SDL_JOYBUTTONUP:
Joy_ButtonEvent( event->jbutton.which, event->jbutton.button, event->jbutton.state ); Joy_ButtonEvent( event->jbutton.button, event->jbutton.state );
break; break;
case SDL_JOYDEVICEADDED: case SDL_JOYDEVICEADDED:
Joy_AddEvent( event->jdevice.which ); Joy_AddEvent();
break; break;
case SDL_JOYDEVICEREMOVED: case SDL_JOYDEVICEREMOVED:
Joy_RemoveEvent( event->jdevice.which ); Joy_RemoveEvent();
break; break;
/* GameController API */ /* GameController API */
@ -341,7 +341,7 @@ static void SDLash_EventFilter( SDL_Event *event )
else if( event->caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT ) else if( event->caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT )
event->caxis.axis = SDL_CONTROLLER_AXIS_TRIGGERLEFT; event->caxis.axis = SDL_CONTROLLER_AXIS_TRIGGERLEFT;
Joy_AxisMotionEvent( event->caxis.which, event->caxis.axis, event->caxis.value ); Joy_AxisMotionEvent( event->caxis.axis, event->caxis.value );
break; break;
case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONDOWN:
@ -364,11 +364,11 @@ static void SDLash_EventFilter( SDL_Event *event )
} }
case SDL_CONTROLLERDEVICEADDED: case SDL_CONTROLLERDEVICEADDED:
Joy_AddEvent( event->cdevice.which ); Joy_AddEvent( );
break; break;
case SDL_CONTROLLERDEVICEREMOVED: case SDL_CONTROLLERDEVICEREMOVED:
Joy_RemoveEvent( event->cdevice.which ); Joy_RemoveEvent( );
break; break;
case SDL_QUIT: case SDL_QUIT:

Loading…
Cancel
Save