Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Getting 360 Controller Support Into an A5 Game

This thread is locked; no one can reply to it. rss feed Print
Getting 360 Controller Support Into an A5 Game
Kris Asick
Member #1,424
July 2001

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.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

torhu
Member #2,727
September 2002
avatar

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
Member #1,424
July 2001

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?

--- Kris Asick (Gemini)
--- http://www.pixelships.com

torhu
Member #2,727
September 2002
avatar

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
Member #1,424
July 2001

*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?

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Elias
Member #358
May 2000

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

--
"Either help out or stop whining" - Evert

Kris Asick
Member #1,424
July 2001

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

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Neil Walker
Member #210
April 2000
avatar

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

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Kris Asick
Member #1,424
July 2001

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

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Elias
Member #358
May 2000

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.

--
"Either help out or stop whining" - Evert

MiquelFire
Member #3,110
January 2003
avatar

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

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

torhu
Member #2,727
September 2002
avatar

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.

Go to: