From 7821af13039145f41561f079d1ab5b5277b4898a Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 19 Sep 2015 23:04:35 +0000 Subject: [PATCH] Move axis values into individual joysticks SDL2 allows joysticks to come and go. This conflicts with the unified virtual joystick. --- common/arch/sdl/joy.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/common/arch/sdl/joy.cpp b/common/arch/sdl/joy.cpp index e62c52dc6..71d1c06ce 100644 --- a/common/arch/sdl/joy.cpp +++ b/common/arch/sdl/joy.cpp @@ -29,7 +29,6 @@ int num_joysticks = 0; static struct joyinfo { int n_axes; int n_buttons; - array axis_value; array button_state; } Joystick; @@ -51,7 +50,8 @@ struct d_physical_joystick { int n_buttons; int n_hats; int hat_map[MAX_HATS_PER_JOYSTICK]; //Note: Descent expects hats to be buttons, so these are indices into Joystick.buttons - int axis_map[MAX_AXES_PER_JOYSTICK]; + array axis_map; + array axis_value; int button_map[MAX_BUTTONS_PER_JOYSTICK]; }; @@ -121,18 +121,17 @@ void joy_hat_handler(SDL_JoyHatEvent *jhe) int joy_axis_handler(SDL_JoyAxisEvent *jae) { - int axis; d_event_joystick_moved event; - - axis = SDL_Joysticks[jae->which].axis_map[jae->axis]; - + auto &js = SDL_Joysticks[jae->which]; + const auto axis = js.axis_map[jae->axis]; + auto &axis_value = js.axis_value[jae->axis]; // inaccurate stick is inaccurate. SDL might send SDL_JoyAxisEvent even if the value is the same as before. - if (Joystick.axis_value[axis] == jae->value/256) + if (axis_value == jae->value/256) return 0; + event.value = axis_value = jae->value/256; event.type = EVENT_JOYSTICK_MOVED; event.axis = axis; - event.value = Joystick.axis_value[axis] = jae->value/256; con_printf(CON_DEBUG, "Sending event EVENT_JOYSTICK_MOVED, axis: %d, value: %d",event.axis, event.value); event_send(event);