Game Development Community

Beta 2 Bug: Gamepad Button Presses (w/ fix)

by Jason Parker · in Torque 3D Professional · 06/07/2009 (1:37 pm) · 6 replies

EDIT:

Okay, now that I've gotten a clean eight hours of sleep here's a clear explanation of the problem:

When a keyboard key or mouse button is pressed, the event that is built contains a value. This value is set depending on whether or not the key is being pressed or released. In the code, this is a make event or break event.

For Xbox gamepads, this value is always 0 (not sure if the problem applies to other gamepads). The way the code is written, it can't be anything else.
This is the existing code in winDirectInput.cpp in the function called DInputManager::fireXInputButtonEvent near the bottom after the code for logging.
buildXInputEvent( controllerID, SI_BUTTON, objInst, ((mXInputStateNew[controllerID].state.Gamepad.wButtons & button) != 0) ? SI_MAKE : SI_BREAK, 0);

To fix this, you need to determine the action type and set the value accordingly.
The following code is meant to replace the code above. Again, it is found in winDirectInput.cpp in the function called DInputManager::fireXInputButtonEvent.
buildXInputEvent( controllerID, SI_BUTTON, objInst, ((mXInputStateNew[controllerID].state.Gamepad.wButtons & button) != 0) ? SI_MAKE : SI_BREAK, ((mXInputStateNew[controllerID].state.Gamepad.wButtons & button) != 0) ? 1 : 0);

I used the code for keyboard and mouse button events to figure out what I was looking at, and how it's determined there. This is near identical except that it's inline in the call to the function.

I tested this fix with every "button" type on the Xbox 360 gamepad. It works as expected where the button press produces a value of 1, and releasing the button produces a value of 0. This also does not appear to interfere with the analog stick or left and right triggers as they still work as expected.

#1
06/07/2009 (5:35 pm)
Here's a link to a gamepad input reporter utility from Microsoft - This should help you out. They also have gamepad graphics you can use on the site.
http://creators.xna.com/en-US/utilities/inputreporter
#2
06/07/2009 (5:42 pm)
The issue isn't that buttons aren't being detected correctly by Torque. It's the value set during the press (or in this case, not set) and then after. As far as I can tell, this is all within Torque's realm. If you look at SI_MAKE and SI_BREAK for keyboard events, there is a clear 1 and 0 value. I can't find anything similar for gamepad button events.

I could be barking up the wrong tree, and %val could be coming from elsewhere in the source code, but I'm pretty sure I'm on the right track. Just don't have a clue what, precisely, to do about it.

Key presses on the keyboard also report two.

So to amend my bug, the button isn't being detected as being pressed twice. It's merely that SI_MAKE and SI_BREAK aren't being assigned separate values, I believe.
#3
06/08/2009 (8:47 am)
Wait, you're using Xinput?
#4
06/08/2009 (11:59 am)
EDIT:
I'm using what's in use by default since at least TGEA 1.8.1 (only version I have to compare with).
#5
06/11/2009 (1:09 am)
I've finally gotten some *good* sleep and fixed this issue. I've edited the post to be more clear and include the fix.
#6
06/18/2009 (10:17 am)

Merged into repo for B3.

Thanks a lot for the fix.