EvanQuan/hover-wars

XBox controller triggers no longer respond at all after PS4 controller support

EvanQuan opened this issue · 4 comments

Tisk tisk.

I do not have an xbox controller to test this. I set the Xbox mappings for Xbox_Trigger_Left and Xbox_Trigger_Right to 14 and 15 respectfully and was sure to not mess with the code that was there.

If I were to start debugging, I would go to InputHandler::initializeJoystick first to see what the buttoncount returned for an xbox controller is. I worked thinking that it was 16, so maybe that might need to be updated in stdafx.h

In InputHandler::updateJoystickButtonStates, it iterates through 0 - iButtonCount for the joystick. Maybe the Trigger buttons on the xbox controller are out of range based on the iButtonCount parameter?

I'm fairly certain the axis of the triggers aren't actually evaluated for commands since there are buttons associated to the triggers which I think are used instead since we only really care about whether the button is pressed or not rather than how hard it was pressed.

The only other culprit might be Menu::updateJoystickCommands. It iterates through the received button count as well now.

Can you look into this? If not, I can head to the school and test it on Monday.

I solved the problem.

The XBox controller button count is actually 14. So whenever we call glfwGetJoystickButtons() the sJostyickInfo::iButton value is set to 14. However, since we want to treat the two triggers as buttons, the input handler stores the trigger states as buttons, which is why the sJoystickInfo::eButtonState array stores 16 button states instead of 14 for the XBox controller.

In Menu::updateJoystickCommands(), in the Check buttons, we iterate through buttons 0 to iButtonCount, which is 14 for the Xbox, which skips out on the triggers.

To solve the issue, I just ensure that we iterate through all 16 buttons instead of 14.

A possible response would be to just update iButton to 16 whenever we update iButton for the Xbox controller. That was my initial solution, but it resulted in some rather wonky behaviour (which I could probably figure out why, but haven't bothered to do). I may revisit this later on.

Can also just add the triggers to the axis checks for the xbox section.

Interestingly enough, PS4 treats the L2 and R2 triggers as both buttons and axes.