mirror of
https://github.com/FWGS/xash3d-fwgs
synced 2024-12-23 17:25:24 +01:00
SDL2 GameController: Map axes to engine explicitly
This commit is contained in:
parent
3e8e751dc7
commit
4daa7c23a0
@ -24,17 +24,6 @@ GNU General Public License for more details.
|
|||||||
#define SHRT_MAX 0x7FFF
|
#define SHRT_MAX 0x7FFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum engineAxis_e
|
|
||||||
{
|
|
||||||
JOY_AXIS_SIDE = 0,
|
|
||||||
JOY_AXIS_FWD,
|
|
||||||
JOY_AXIS_PITCH,
|
|
||||||
JOY_AXIS_YAW,
|
|
||||||
JOY_AXIS_RT,
|
|
||||||
JOY_AXIS_LT,
|
|
||||||
JOY_AXIS_NULL
|
|
||||||
} engineAxis_t;
|
|
||||||
|
|
||||||
#define MAX_AXES JOY_AXIS_NULL
|
#define MAX_AXES JOY_AXIS_NULL
|
||||||
|
|
||||||
// index - axis num come from event
|
// index - axis num come from event
|
||||||
@ -246,8 +235,6 @@ Axis events
|
|||||||
*/
|
*/
|
||||||
void Joy_AxisMotionEvent( byte axis, short value )
|
void Joy_AxisMotionEvent( byte axis, short value )
|
||||||
{
|
{
|
||||||
byte engineAxis;
|
|
||||||
|
|
||||||
if( !joy_found->value )
|
if( !joy_found->value )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -257,8 +244,11 @@ void Joy_AxisMotionEvent( byte axis, short value )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
engineAxis = joyaxesmap[axis]; // convert to engine inner axis control
|
return Joy_KnownAxisMotionEvent( joyaxesmap[axis], value );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Joy_KnownAxisMotionEvent( engineAxis_t engineAxis, short value )
|
||||||
|
{
|
||||||
if( engineAxis == JOY_AXIS_NULL )
|
if( engineAxis == JOY_AXIS_NULL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -93,9 +93,21 @@ enum
|
|||||||
JOY_HAT_LEFTDOWN = JOY_HAT_LEFT | JOY_HAT_DOWN
|
JOY_HAT_LEFTDOWN = JOY_HAT_LEFT | JOY_HAT_DOWN
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef enum engineAxis_e
|
||||||
|
{
|
||||||
|
JOY_AXIS_SIDE = 0,
|
||||||
|
JOY_AXIS_FWD,
|
||||||
|
JOY_AXIS_PITCH,
|
||||||
|
JOY_AXIS_YAW,
|
||||||
|
JOY_AXIS_RT,
|
||||||
|
JOY_AXIS_LT,
|
||||||
|
JOY_AXIS_NULL
|
||||||
|
} engineAxis_t;
|
||||||
|
|
||||||
qboolean Joy_IsActive( void );
|
qboolean Joy_IsActive( void );
|
||||||
void Joy_HatMotionEvent( byte hat, byte value );
|
void Joy_HatMotionEvent( byte hat, byte value );
|
||||||
void Joy_AxisMotionEvent( byte axis, short value );
|
void Joy_AxisMotionEvent( byte axis, short value );
|
||||||
|
void Joy_KnownAxisMotionEvent( engineAxis_t engineAxis, short value );
|
||||||
void Joy_BallMotionEvent( byte ball, short xrel, short yrel );
|
void Joy_BallMotionEvent( byte ball, short xrel, short yrel );
|
||||||
void Joy_ButtonEvent( byte button, byte down );
|
void Joy_ButtonEvent( byte button, byte down );
|
||||||
void Joy_AddEvent( void );
|
void Joy_AddEvent( void );
|
||||||
|
@ -532,18 +532,21 @@ static void SDLash_EventFilter( SDL_Event *event )
|
|||||||
|
|
||||||
/* GameController API */
|
/* GameController API */
|
||||||
case SDL_CONTROLLERAXISMOTION:
|
case SDL_CONTROLLERAXISMOTION:
|
||||||
if( event->caxis.axis == (Uint8)SDL_CONTROLLER_AXIS_INVALID )
|
{
|
||||||
break;
|
|
||||||
|
|
||||||
// Swap axis to follow default axis binding:
|
// Swap axis to follow default axis binding:
|
||||||
// LeftX, LeftY, RightX, RightY, TriggerRight, TriggerLeft
|
// LeftX, LeftY, RightX, RightY, TriggerRight, TriggerLeft
|
||||||
if( event->caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT )
|
static int sdlControllerAxisToEngine[] = {
|
||||||
event->caxis.axis = SDL_CONTROLLER_AXIS_TRIGGERRIGHT;
|
JOY_AXIS_SIDE, // SDL_CONTROLLER_AXIS_LEFTX,
|
||||||
else if( event->caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT )
|
JOY_AXIS_FWD, // SDL_CONTROLLER_AXIS_LEFTY,
|
||||||
event->caxis.axis = SDL_CONTROLLER_AXIS_TRIGGERLEFT;
|
JOY_AXIS_PITCH, // SDL_CONTROLLER_AXIS_RIGHTX,
|
||||||
|
JOY_AXIS_YAW, // SDL_CONTROLLER_AXIS_RIGHTY,
|
||||||
Joy_AxisMotionEvent( event->caxis.axis, event->caxis.value );
|
JOY_AXIS_LT, // SDL_CONTROLLER_AXIS_TRIGGERLEFT,
|
||||||
|
JOY_AXIS_RT, // SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
|
||||||
|
};
|
||||||
|
if( Joy_IsActive() && event->caxis.axis != (Uint8)SDL_CONTROLLER_AXIS_INVALID )
|
||||||
|
Joy_KnownAxisMotionEvent( sdlControllerAxisToEngine[event->caxis.axis], event->caxis.value );
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case SDL_CONTROLLERBUTTONDOWN:
|
case SDL_CONTROLLERBUTTONDOWN:
|
||||||
case SDL_CONTROLLERBUTTONUP:
|
case SDL_CONTROLLERBUTTONUP:
|
||||||
@ -558,7 +561,7 @@ static void SDLash_EventFilter( SDL_Event *event )
|
|||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Use joyinput funcs, for future multiple gamepads support
|
// TODO: Use joyinput funcs, for future multiple gamepads support
|
||||||
if( Joy_IsActive() && event->cbutton.button != SDL_CONTROLLER_BUTTON_INVALID )
|
if( Joy_IsActive() && event->cbutton.button != (Uint8)SDL_CONTROLLER_BUTTON_INVALID )
|
||||||
Key_Event( sdlControllerButtonToEngine[event->cbutton.button], event->cbutton.state );
|
Key_Event( sdlControllerButtonToEngine[event->cbutton.button], event->cbutton.state );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user