mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-25 09:17:12 +01:00
Fixed issue where the throttle and other axes on racing wheels don't start at zero and show up as immediate input when the wheel is turned for the first time. Wait until they are actually moved before generating input from them.
This commit is contained in:
parent
b2f6c4c1bd
commit
ca019dada5
@ -1132,12 +1132,12 @@ SDL_GameControllerOpen(int device_index)
|
|||||||
int leftTriggerMapping = gamecontroller->mapping.axes[SDL_CONTROLLER_AXIS_TRIGGERLEFT];
|
int leftTriggerMapping = gamecontroller->mapping.axes[SDL_CONTROLLER_AXIS_TRIGGERLEFT];
|
||||||
int rightTriggerMapping = gamecontroller->mapping.axes[SDL_CONTROLLER_AXIS_TRIGGERRIGHT];
|
int rightTriggerMapping = gamecontroller->mapping.axes[SDL_CONTROLLER_AXIS_TRIGGERRIGHT];
|
||||||
if (leftTriggerMapping >= 0) {
|
if (leftTriggerMapping >= 0) {
|
||||||
gamecontroller->joystick->axes[leftTriggerMapping] =
|
gamecontroller->joystick->axes[leftTriggerMapping].value =
|
||||||
gamecontroller->joystick->axes_zero[leftTriggerMapping] = (Sint16)-32768;
|
gamecontroller->joystick->axes[leftTriggerMapping].zero = (Sint16)-32768;
|
||||||
}
|
}
|
||||||
if (rightTriggerMapping >= 0) {
|
if (rightTriggerMapping >= 0) {
|
||||||
gamecontroller->joystick->axes[rightTriggerMapping] =
|
gamecontroller->joystick->axes[rightTriggerMapping].value =
|
||||||
gamecontroller->joystick->axes_zero[rightTriggerMapping] = (Sint16)-32768;
|
gamecontroller->joystick->axes[rightTriggerMapping].zero = (Sint16)-32768;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,20 +170,16 @@ SDL_JoystickOpen(int device_index)
|
|||||||
joystick->name = NULL;
|
joystick->name = NULL;
|
||||||
|
|
||||||
if (joystick->naxes > 0) {
|
if (joystick->naxes > 0) {
|
||||||
joystick->axes = (Sint16 *) SDL_malloc(joystick->naxes * sizeof(Sint16));
|
joystick->axes = (SDL_JoystickAxisInfo *) SDL_calloc(joystick->naxes, sizeof(SDL_JoystickAxisInfo));
|
||||||
joystick->axes_zero = (Sint16 *) SDL_malloc(joystick->naxes * sizeof(Sint16));
|
|
||||||
}
|
}
|
||||||
if (joystick->nhats > 0) {
|
if (joystick->nhats > 0) {
|
||||||
joystick->hats = (Uint8 *) SDL_malloc
|
joystick->hats = (Uint8 *) SDL_calloc(joystick->nhats, sizeof(Uint8));
|
||||||
(joystick->nhats * sizeof(Uint8));
|
|
||||||
}
|
}
|
||||||
if (joystick->nballs > 0) {
|
if (joystick->nballs > 0) {
|
||||||
joystick->balls = (struct balldelta *) SDL_malloc
|
joystick->balls = (struct balldelta *) SDL_calloc(joystick->nballs, sizeof(*joystick->balls));
|
||||||
(joystick->nballs * sizeof(*joystick->balls));
|
|
||||||
}
|
}
|
||||||
if (joystick->nbuttons > 0) {
|
if (joystick->nbuttons > 0) {
|
||||||
joystick->buttons = (Uint8 *) SDL_malloc
|
joystick->buttons = (Uint8 *) SDL_calloc(joystick->nbuttons, sizeof(Uint8));
|
||||||
(joystick->nbuttons * sizeof(Uint8));
|
|
||||||
}
|
}
|
||||||
if (((joystick->naxes > 0) && !joystick->axes)
|
if (((joystick->naxes > 0) && !joystick->axes)
|
||||||
|| ((joystick->nhats > 0) && !joystick->hats)
|
|| ((joystick->nhats > 0) && !joystick->hats)
|
||||||
@ -194,20 +190,6 @@ SDL_JoystickOpen(int device_index)
|
|||||||
SDL_UnlockJoystickList();
|
SDL_UnlockJoystickList();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (joystick->axes) {
|
|
||||||
SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16));
|
|
||||||
SDL_memset(joystick->axes_zero, 0, joystick->naxes * sizeof(Sint16));
|
|
||||||
}
|
|
||||||
if (joystick->hats) {
|
|
||||||
SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8));
|
|
||||||
}
|
|
||||||
if (joystick->balls) {
|
|
||||||
SDL_memset(joystick->balls, 0,
|
|
||||||
joystick->nballs * sizeof(*joystick->balls));
|
|
||||||
}
|
|
||||||
if (joystick->buttons) {
|
|
||||||
SDL_memset(joystick->buttons, 0, joystick->nbuttons * sizeof(Uint8));
|
|
||||||
}
|
|
||||||
joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
|
joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
|
||||||
|
|
||||||
/* Add joystick to list */
|
/* Add joystick to list */
|
||||||
@ -302,7 +284,7 @@ SDL_JoystickGetAxis(SDL_Joystick * joystick, int axis)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if (axis < joystick->naxes) {
|
if (axis < joystick->naxes) {
|
||||||
state = joystick->axes[axis];
|
state = joystick->axes[axis].value;
|
||||||
} else {
|
} else {
|
||||||
SDL_SetError("Joystick only has %d axes", joystick->naxes);
|
SDL_SetError("Joystick only has %d axes", joystick->naxes);
|
||||||
state = 0;
|
state = 0;
|
||||||
@ -486,7 +468,6 @@ SDL_JoystickClose(SDL_Joystick * joystick)
|
|||||||
|
|
||||||
/* Free the data associated with this joystick */
|
/* Free the data associated with this joystick */
|
||||||
SDL_free(joystick->axes);
|
SDL_free(joystick->axes);
|
||||||
SDL_free(joystick->axes_zero);
|
|
||||||
SDL_free(joystick->hats);
|
SDL_free(joystick->hats);
|
||||||
SDL_free(joystick->balls);
|
SDL_free(joystick->balls);
|
||||||
SDL_free(joystick->buttons);
|
SDL_free(joystick->buttons);
|
||||||
@ -621,22 +602,34 @@ SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
|
|||||||
if (axis >= joystick->naxes) {
|
if (axis >= joystick->naxes) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (value == joystick->axes[axis]) {
|
if (value == joystick->axes[axis].value) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (!joystick->axes[axis].moved) {
|
||||||
|
if (joystick->axes[axis].intial_value == 0) {
|
||||||
|
joystick->axes[axis].intial_value = value;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (value == joystick->axes[axis].intial_value) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We got more than 0 and the initial value from the joystick, consider it as having actually moved */
|
||||||
|
joystick->axes[axis].moved = SDL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* We ignore events if we don't have keyboard focus, except for centering
|
/* We ignore events if we don't have keyboard focus, except for centering
|
||||||
* events.
|
* events.
|
||||||
*/
|
*/
|
||||||
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
|
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
|
||||||
if ((value > joystick->axes_zero[axis] && value >= joystick->axes[axis]) ||
|
if ((value > joystick->axes[axis].zero && value >= joystick->axes[axis].value) ||
|
||||||
(value < joystick->axes_zero[axis] && value <= joystick->axes[axis])) {
|
(value < joystick->axes[axis].zero && value <= joystick->axes[axis].value)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update internal joystick state */
|
/* Update internal joystick state */
|
||||||
joystick->axes[axis] = value;
|
joystick->axes[axis].value = value;
|
||||||
|
|
||||||
/* Post the event, if desired */
|
/* Post the event, if desired */
|
||||||
posted = 0;
|
posted = 0;
|
||||||
@ -807,7 +800,7 @@ SDL_JoystickUpdate(void)
|
|||||||
|
|
||||||
/* Tell the app that everything is centered/unpressed... */
|
/* Tell the app that everything is centered/unpressed... */
|
||||||
for (i = 0; i < joystick->naxes; i++) {
|
for (i = 0; i < joystick->naxes; i++) {
|
||||||
SDL_PrivateJoystickAxis(joystick, i, joystick->axes_zero[i]);
|
SDL_PrivateJoystickAxis(joystick, i, joystick->axes[i].zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < joystick->nbuttons; i++) {
|
for (i = 0; i < joystick->nbuttons; i++) {
|
||||||
|
@ -29,14 +29,21 @@
|
|||||||
#include "SDL_joystick_c.h"
|
#include "SDL_joystick_c.h"
|
||||||
|
|
||||||
/* The SDL joystick structure */
|
/* The SDL joystick structure */
|
||||||
|
typedef struct _SDL_JoystickAxisInfo
|
||||||
|
{
|
||||||
|
Sint16 value; /* Current axis states */
|
||||||
|
Sint16 zero; /* Zero point on the axis (-32768 for triggers) */
|
||||||
|
Sint16 intial_value; /* The very first value we saw on this axis */
|
||||||
|
SDL_bool moved; /* Whether the axis has moved */
|
||||||
|
} SDL_JoystickAxisInfo;
|
||||||
|
|
||||||
struct _SDL_Joystick
|
struct _SDL_Joystick
|
||||||
{
|
{
|
||||||
SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */
|
SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */
|
||||||
char *name; /* Joystick name - system dependent */
|
char *name; /* Joystick name - system dependent */
|
||||||
|
|
||||||
int naxes; /* Number of axis controls on the joystick */
|
int naxes; /* Number of axis controls on the joystick */
|
||||||
Sint16 *axes; /* Current axis states */
|
SDL_JoystickAxisInfo *axes;
|
||||||
Sint16 *axes_zero; /* Zero point on the axis (-32768 for triggers) */
|
|
||||||
|
|
||||||
int nhats; /* Number of hats on the joystick */
|
int nhats; /* Number of hats on the joystick */
|
||||||
Uint8 *hats; /* Current hat states */
|
Uint8 *hats; /* Current hat states */
|
||||||
|
Loading…
Reference in New Issue
Block a user