Skip to content

Commit

Permalink
Merge pull request #805 from AXDOOMER/master
Browse files Browse the repository at this point in the history
Fix number of joystick buttons so Chocolate-Setup doesn't crash
  • Loading branch information
fragglet authored Nov 13, 2016
2 parents 226a67f + 8c282de commit dc4eb0b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/i_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static int joystick_strafe_invert = 0;
// Virtual to physical button joystick button mapping. By default this
// is a straight mapping.
static int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
};

void I_ShutdownJoystick(void)
Expand Down
2 changes: 1 addition & 1 deletion src/i_joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Number of "virtual" joystick buttons defined in configuration files.
// This needs to be at least as large as the number of different key
// bindings supported by the higher-level game code (joyb* variables).
#define NUM_VIRTUAL_BUTTONS 10
#define NUM_VIRTUAL_BUTTONS 11

// If this bit is set in a configuration file axis value, the axis is
// not actually a joystick axis, but instead is a "button axis". This
Expand Down
7 changes: 7 additions & 0 deletions src/m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,13 @@ static default_t extra_defaults_list[] =

CONFIG_VARIABLE_INT(joystick_physical_button9),

//!
// The physical joystick button that corresponds to joystick
// virtual button #10.
//

CONFIG_VARIABLE_INT(joystick_physical_button10),

//!
// Joystick virtual button to make the player strafe left.
//
Expand Down
2 changes: 1 addition & 1 deletion src/setup/joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static int joystick_strafe_invert = 0;

// Virtual to physical mapping.
int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
};

static txt_button_t *joystick_button;
Expand Down
6 changes: 3 additions & 3 deletions src/setup/txt_joybinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS];
// button that the user wants to use for firing. We do this so that
// the menus work (the game code is hard coded to interpret
// button #0 = select menu item, button #1 = go back to previous menu).
static int *all_joystick_buttons[] =
static int *all_joystick_buttons[NUM_VIRTUAL_BUTTONS] =
{
&joybfire,
&joybuse,
Expand Down Expand Up @@ -72,7 +72,7 @@ static int PhysicalForVirtualButton(int vbutton)
}

// Get the virtual button number for the given variable, ie. the
// variable's index in all_joystick_buttons[].
// variable's index in all_joystick_buttons[NUM_VIRTUAL_BUTTONS].
static int VirtualButtonForVariable(int *variable)
{
int i;
Expand All @@ -91,7 +91,7 @@ static int VirtualButtonForVariable(int *variable)

// Rearrange joystick button configuration to be in "canonical" form:
// each joyb* variable should have a value equal to its index in
// all_joystick_buttons[] above.
// all_joystick_buttons[NUM_VIRTUAL_BUTTONS] above.
static void CanonicalizeButtons(void)
{
int new_mapping[NUM_VIRTUAL_BUTTONS];
Expand Down

0 comments on commit dc4eb0b

Please sign in to comment.