Page 1 of 5

Xinput for Love (Real Xbox controller support) BETA

Posted: Sun Aug 05, 2012 3:54 am
by Charles Randall
Hey all, because there isn't native support for Xinput in Love, and thus Xbox controllers, I've decided to add it. The benefit of this will be: Proper working triggers on xbox controllers, as well as support for gamepad vibration. Extra benefits will be proper support for all those fun xbox accessories with USB connectors (like wheels, guitars, etc).

As I'm writing a drop-in replacement module for Joystick, I'm realizing more and more than the xinput paradigm doesn't match that of SDL. Also, SDL and Xinput can coexist side by side, so I'm thinking at this point rather than making a replacement module for joystick (so that love.joystick.* just magically works with a 360 controller), making a completely new module (love.xinput.*).

In either case, if the love devs don't want to pull in my changes, adding support for my changes will require building your own love executable.

Pros of Joystick replacement:
-super easy to drop in and compile.
-still works with all your existing love code

Cons of Joystick replacement:
-may break existing non-xbox controller functionality
-inability to easily use old SDL joystick code

Pros of new module:
-guaranteed to not break existing code
-can be built API compatible with Joystick
-easy for love devs to pull changes safely

Cons of new module:
-need to write new input code in love apps to support xbox functionality
-much harder to integrate changes to the love codebase for people making their own exe if the love devs don't accept the changes

Anyone have any thoughts? Love devs?

Re: Xinput for Love (Real Xbox controller support)

Posted: Sun Aug 05, 2012 5:54 pm
by OmarShehata
That sounds pretty awesome actually.

It would be super immensely helpful if you posted like an article or a tutorial about how you edited Love's source to do that, because right now, although I have yet to attempt it, editing love's source seems a bit daunting.

Re: Xinput for Love (Real Xbox controller support)

Posted: Sun Aug 05, 2012 6:07 pm
by Charles Randall
I've been making games for 14 years so mostly I'm just doing what I do normally at work. Which is: "find in files", read a lot of code, decide what to do. :)

Love's source is pretty slick though, the module system is making my life super easy doing this. I might even finish a first pass today.

Re: Xinput for Love (Real Xbox controller support)

Posted: Mon Aug 06, 2012 3:41 am
by Lafolie
Xinput seems to be made for xbox and windows. Will this module work on other platforms?

Re: Xinput for Love (Real Xbox controller support)

Posted: Mon Aug 06, 2012 4:48 am
by Charles Randall
Xinput is Windows specific, and I don't think anyone has made drivers for 360 devices for other platforms. But if at any point someone makes an Xinput compatible library, I would gladly hook it up.

That being said, first version is up. I have either the code you can drop in and build yourself, or I have a zipped up pre-packaged exe you can use to test things out.

https://github.com/mrcharles/love2d-xinput

I also have a controller test app you can play with to see what it's doing (and you can compare the differences between the SDL implementation and the XInput implementation).

https://github.com/mrcharles/love2d-x360-test

Re: Xinput for Love (Real Xbox controller support) ALPHA

Posted: Mon Aug 06, 2012 9:39 am
by bartbes
I don't see a reason to drop support for the majority of joystick devices just to support one.

Re: Xinput for Love (Real Xbox controller support) ALPHA

Posted: Mon Aug 06, 2012 9:49 am
by Nixola
Didn't he add a new module, instead of replacing love.joystick?

Re: Xinput for Love (Real Xbox controller support)

Posted: Mon Aug 06, 2012 1:55 pm
by Lafolie
Charles Randall wrote:Xinput is Windows specific, and I don't think anyone has made drivers for 360 devices for other platforms. But if at any point someone makes an Xinput compatible library, I would gladly hook it up.
There are dozens of driver software packages for all manner of devices like this. Xbox, Wii, and PS3 controllers for example, can all be used on OS X, Linux and Windows.

Whilst this is a neat idea, and I very much hope to see it working (the merged triggers thing is annoying!), I think that people value the cross-platform properties of Löve, and you will find that many of its users are not of the windows persuasion.

Besides, should SDL make it to the next version, I think the inbuilt joypad module will be able to compete with Xinput.
bartbes wrote:I don't see a reason to drop support for the majority of joystick devices just to support one.
I thought of adding a pre-configured option for people using the xbox controller in my games, but dismissed the idea as being too dismissive itself. I recently reinstalled Steam and tried some games to find that they only seem to support the Xbox controller. It's funny to see that we both arrive to this conclusion, yet major developers/publishers deem the Xbox pad to be "the controller". Despite the fact that it's probably the most popular pad, it seems to be a rather odd decision.

Re: Xinput for Love (Real Xbox controller support) ALPHA

Posted: Mon Aug 06, 2012 3:15 pm
by Charles Randall
First, this is just an alpha so for now it flat out replaces the joystick module. This was my proof of concept in order to make sure the idea was even possible.

Second, the reason everyone supports xbox 360 controllers is that they are the most common controller out there which you can simply plug into your system and have it work.

Third, the problem with non-XInput libraries is that without special drivers customized for the xbox 360 controllers, the triggers will never function properly, because to standard joystick libraries, both triggers read as the same axis, which means they are impossible to distinguish at run time. Holding both triggers is the same as not holding the triggers at all.

Fourth, supporting Xinput gives direct support for a ton of really awesome controllers. I've tested with a Guitar Hero 2 guitar, for example. Works great. I have a Forza racing wheel that I'll test as well at some point. Dance pads? Those should work too. I don't know how well these things work without Xinput, if at all.

Fifth, you get proper vibration support, which SDL doesn't support at all. As far as I can tell anyway.

That all being said, I am sharing this because I am going to do it anyway, and I expect there are probably a few devs out there who will appreciate the extra features this brings to Love2D.

My next steps is to make it into its own Module, and if need be, modify love's source directly to support dynamic module drop in, so that I can simply ship a DLL which you can put in your love directory if you want it, and have it work, without actually modifying love itself. Of course, this step will require acceptance on the part of the Love devs themselves, but the ability to create your own modules in C++ would certainly be a feature that more advanced developers would appreciate, and would contribute very strongly to the value of Love as a full scale game development tool.

Re: Xinput for Love (Real Xbox controller support)

Posted: Mon Aug 06, 2012 3:16 pm
by Charles Randall
Lafolie wrote:
Charles Randall wrote: Whilst this is a neat idea, and I very much hope to see it working (the merged triggers thing is annoying!), I think that people value the cross-platform properties of Löve, and you will find that many of its users are not of the windows persuasion.
It's working. You can grab it right now and give it a test.