Make gamecontroller triggers have values in 0 - 32767.
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Fri, 19 Apr 2013 10:51:21 -0700
changeset 7080 7353267a2ce2
parent 7079 99d6803195fe
child 7081 ab543a0ef80c
Make gamecontroller triggers have values in 0 - 32767. This changes the old behavior of having values in the -32768 - 32767 range, like regular joystick axis. Now "button as axis" triggers (like on Logitech controllers) and regular axis triggers (like on Xbox controllers) have the same resting value, 0.
src/joystick/SDL_gamecontroller.c
--- a/src/joystick/SDL_gamecontroller.c	Fri Apr 19 14:40:39 2013 -0300
+++ b/src/joystick/SDL_gamecontroller.c	Fri Apr 19 10:51:21 2013 -0700
@@ -157,7 +157,18 @@
 				{
 					if ( controllerlist->mapping.raxes[event->jaxis.axis] >= 0 ) // simple axis to axis, send it through
 					{
-						SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.raxes[event->jaxis.axis], event->jaxis.value );
+						SDL_GameControllerAxis axis = controllerlist->mapping.raxes[event->jaxis.axis];
+                        Sint16 value = event->jaxis.value;
+						switch (axis)
+						{
+							case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
+							case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
+								/* Shift it to be 0 - 32767. */
+								value = ( value + 32768 ) / 2;
+							default:
+								break;
+						}
+						SDL_PrivateGameControllerAxis( controllerlist, axis, value );
 					}
 					else if ( controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0 ) // simlate an axis as a button
 					{
@@ -187,7 +198,7 @@
 					}
 					else if ( controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0 ) // an button pretending to be an axis
 					{
-						SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32768 : 0 );
+						SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32767 : 0 );
 					}
 					break;
 				}