# ENIGMA Forums

## General fluff => Announcements => Topic started by: Goombert on August 07, 2013, 09:12:09 AM

Title: XInput, Gamepads, and Windows Joysticks
Post by: Goombert on August 07, 2013, 09:12:09 AM
Well I implemented and finished up XInput and DirectInput extensions for Windows.

The constants...
The functions...
http://enigma-dev.org/docs/Wiki/Input_Functions

Greg has tested them already and we know they work, even from an emulator or virtual machine. Gamepads currently only support Xbox 360 controllers and only on Windows when you enable the XInput extension. You may connect up to 4 devices at any given time, but you should query xinput using the gamepad function provided to see the max number of gamepads you actually can connect. Everything is well documented for you guys, happy programming!

Also, here is a map of the control constants (right click->View Image to enlarge)...

Here is a simple little code example that you can move an object around with the left axis and run with the letter 'A' using.
Code: (EDL) [Select]
`// demonstrates using the 'A' button on player 1's Xbox 360 controller to move a player around the screenvar spd, lhaxis, lvaxis;lhaxis = gamepad_axis_value(0, gp_axislh);lvaxis = gamepad_axis_value(0, gp_axislv);spd = sqrt(lhaxis * lhaxis + lvaxis * lvaxis) * 5; // calculate the magnitudespd += gamepad_button_check(0, gp_face1) * 15; // when player is pressing 'A' speed will increase 15direction = point_direction(0, 0, lhaxis, lvaxis); // use the value of the left axis to determine the player directionx += lengthdir_x(spd, direction); // use the horizontal position of the left axis to throttle horizontal speedy -= lengthdir_y(spd, direction); // use the vertical position of the left axis to throttle vertical speed`
Post by: Josh @ Dreamland on August 07, 2013, 10:35:03 AM
Yoyo's (GM's) joystick functions suck dick. They're underpowered, inconsistent, and fuck-ugly. Use my Linux joystick functions (https://github.com/enigma-dev/enigma-dev/blob/master/ENIGMAsystem/SHELL/Platforms/xlib/LINUXjoystick.h).

If any functionality is missing in my joystick functions, by all means, add more. The Linux joystick API is missing a write mechanism for such features as rumble. It's been missing this for years... So yes, feel free to add a joystick_rumble, etc.
Post by: Goombert on August 07, 2013, 10:39:08 AM
??? They are exactly the same as Yoyo's?
Post by: Josh @ Dreamland on August 07, 2013, 10:44:44 AM
I did my best to emulate their original API using my own. The functions most notable in my set are joystick_map_button and joystick_map_axis, which allow you to make a joystick button behave like an arbitrary keyboard key, or a joystick axis behave like two. No other code needs written to add joystick support for your game.

Another key difference is that my joystick numbering begins at zero, as opposed to one.

Also, please tell me you made that image yourself. If you got that from Yoyo, we're about to have serious legal issues.

And one more thing: I'd rather not use an XBox controller as our only example. Microshit's worthless-fuck toolkits only support XBox controllers. I would rather use a Logitech controller to show prospective developers, "hey, we support shit that Microsoft The Great did not bestow upon us rectally!"
Post by: Goombert on August 07, 2013, 02:19:56 PM
There we go, wow I am amazed, I didn't even test this before committing them and me and cheeseboy got them working right away perfectly. Have fun with the new controller support guys!
Post by: Goombert on August 08, 2013, 05:01:06 AM
*Update* Windows Joystick functions implemented fully in a DirectInput extension...
https://github.com/enigma-dev/enigma-dev/pull/303
Title: Re: XInput, Gamepads, and Windows Joysticks
Post by: forthevin on August 08, 2013, 04:06:16 PM
In regards to the image, it seems like a modified version from someone describing how to set up an X-box controller on Linux to play Cave Story (http://linuxtidbits.wordpress.com/2009/11/11/doukutsu-aka-cave-story-with-an-xbox-controller/). If it turns out to be a problem, we can always take it down and replace it with another image. YoYoGames are using a different image in any case.

In regards to the controller support, nicely done :).
Title: Re: XInput, Gamepads, and Windows Joysticks
Post by: Goombert on August 08, 2013, 08:04:33 PM
Quote
In regards to the image, it seems like a modified version from someone describing how to set up an X-box controller on Linux to play Cave Story
... son of bitch, thought you'd never catch on to me forthevin XD hahaha, I was hoping Josh would make a nice SVG for me, mine looks like crap :P
Quote
In regards to the controller support, nicely done
Thanks forthevin, we appreciate all your hardwork, and thanks to you if it wasn't for you I would not know how to fix merge conflicts, Josh still can't do it either, even though its easy as pie.