From 4890591ba50bfc8b11cda684b223cb7c551e6dd3 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Wed, 30 Apr 2014 22:56:04 -0400 Subject: joystick: Add virtual-physical button mapping. The solution to solving #386 is to add a layer of indirection: the game code can only support up to ~20 joystick buttons, but this doesn't matter as long as we never want to bind more than 20 buttons to actions anyway. Redefine the game's notion of buttons to be based on "virtual" joystick buttons, and map these buttons to physical (SDL) buttons based on configuration file variables. --- src/setup/joystick.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/setup') diff --git a/src/setup/joystick.c b/src/setup/joystick.c index ab442fe2..cc5c4a8e 100644 --- a/src/setup/joystick.c +++ b/src/setup/joystick.c @@ -26,6 +26,7 @@ #include "i_joystick.h" #include "m_config.h" #include "m_controls.h" +#include "m_misc.h" #include "textscreen.h" #include "execute.h" @@ -88,6 +89,11 @@ static int joystick_y_invert = 0; static int joystick_strafe_axis = -1; static int joystick_strafe_invert = 0; +// Virtual to physical mapping. +static int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 +}; + static txt_button_t *joystick_button; static int *all_joystick_buttons[] = { @@ -682,6 +688,8 @@ void ConfigJoystick(void) void BindJoystickVariables(void) { + int i; + M_BindVariable("use_joystick", &usejoystick); M_BindVariable("joystick_index", &joystick_index); M_BindVariable("joystick_x_axis", &joystick_x_axis); @@ -690,5 +698,12 @@ void BindJoystickVariables(void) M_BindVariable("joystick_x_invert", &joystick_x_invert); M_BindVariable("joystick_y_invert", &joystick_y_invert); M_BindVariable("joystick_strafe_invert",&joystick_strafe_invert); + + for (i = 0; i < NUM_VIRTUAL_BUTTONS; ++i) + { + char name[32]; + M_snprintf(name, sizeof(name), "joystick_physical_button%i", i); + M_BindVariable(name, &joystick_physical_buttons[i]); + } } -- cgit v1.2.3