Getting 360 Controller Support Into an A5 Game
Kris Asick

Basically, I'm just wondering what recommendations everyone has for going about adding X-Box 360 controller support into my game; if there's any tutorials I should look into or if there's any existing libraries that would make the process go much more smoothly than trying to code it myself.

torhu

Have you got a controller? Just plug it in and try it with ex_joystick_events and ex_joystick_hotplugging. It's really straight forward.

Kris Asick

I don't have a controller yet but can borrow one when I'm ready to make this work, but I thought you had to use Xinput to access 360 controllers and that they didn't show up over the DirectInput interface?

torhu

My (Logitech F510) controller has an X/D switch on the back, and it works fine with Allegro in both modes.

EDIT: The axes and buttons don't work the same in both modes, different order, etc.

Kris Asick

*is reading up on some Xinput stuff*

Well, from what I've read so far, 360 controllers do indeed show up in DirectInput, but there's a big problem, at least for the type of game I'm making: On 360 controllers under DirectInput, the triggers, being analog, function as a single axis, where one trigger reports full negative when not held and the other reports full positive, resulting in a return value of 0 for the trigger axis. You could detect pushing one trigger or the other, but not both at the same time because this would ALSO result in a 0 return value.

To read each trigger independetly requires the use of the Xinput interface, and since I'm making a twin-stick game, this is pretty much a necessity.

So... yeah. Any recommendations for tutorials or libraries to utilize?

Elias

My original 360 controller has both triggers show up as independent axes. I'm in Linux though.

Kris Asick

Well, the good news is that, from what I've read so far, Xinput only has like, 8 functions, 2 of which are audio related, so there's not much to learn. As is typical with Windows stuff, return values tend to be structures containing all the return data.

Heck, I might even be able to pull this off without a tutorial, just wing it with the MSDN reference materials in hand. Just have to see about borrowing that controller now. :P

Neil Walker

After you've that, put in some Kinect support :D

Kris Asick

...does anyone even own one of those? ::)

Elias

It's useless for games, but I'd say quite nice if you want to do motion capture.

Anyway, all we need for it is basic video recording support - whether that comes from a webcam or from the kinect wouldn't matter much.

MiquelFire

I remember wanting to submit a patch so that Allegro 5 could support Xinput behind the scenes. Actually, if I had followed through with my plans, support would of been in there since 5.0.0! The thread I made we were still on 4.9

It sucks not having free time.

Anyway, useful docs in case someone wants to make that patch at some point: http://msdn.microsoft.com/en-us/library/windows/desktop/ee417014%28v=vs.85%29.aspx

Relevant thread

torhu

On 360 controllers under DirectInput, the triggers, being analog, function as a single axis, where one trigger reports full negative when not held and the other reports full positive, resulting in a return value of 0 for the trigger axis.

Yeah, that's what I get when I try it. And in DirectInput mode the triggers are just seen as digital buttons, which is even worse. When testing with XInput mode in x360ce the triggers both go from 0 to 255, as expected.

Thread #611465. Printed from Allegro.cc