diff options
author | Simon Howard | 2014-04-30 22:56:04 -0400 |
---|---|---|
committer | Simon Howard | 2014-04-30 22:56:04 -0400 |
commit | 4890591ba50bfc8b11cda684b223cb7c551e6dd3 (patch) | |
tree | 589edddb7f25d68f2f7f9b990b82078eca728491 /src/setup | |
parent | 96ff3f7bc127889c9f47e4ec17faa445ade623f1 (diff) | |
download | chocolate-doom-4890591ba50bfc8b11cda684b223cb7c551e6dd3.tar.gz chocolate-doom-4890591ba50bfc8b11cda684b223cb7c551e6dd3.tar.bz2 chocolate-doom-4890591ba50bfc8b11cda684b223cb7c551e6dd3.zip |
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.
Diffstat (limited to 'src/setup')
-rw-r--r-- | src/setup/joystick.c | 15 |
1 files changed, 15 insertions, 0 deletions
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]); + } } |