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...
http://enigma-dev.org/docs/Wiki/Gamepad_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)...
(http://enigma-dev.org/docs/wiki/images/4/48/Gamepadconstants.png)

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 screen
var 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 magnitude
spd += gamepad_button_check(0, gp_face1) * 15; // when player is pressing 'A' speed will increase 15
direction = point_direction(0, 0, lhaxis, lvaxis); // use the value of the left axis to determine the player direction

x += lengthdir_x(spd, direction); // use the horizontal position of the left axis to throttle horizontal speed
y -= lengthdir_y(spd, direction); // use the vertical position of the left axis to throttle vertical speed
Title: Re: XInput and Gamepads
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.
Title: Re: XInput and Gamepads
Post by: Goombert on August 07, 2013, 10:39:08 am
??? They are exactly the same as Yoyo's?
Title: Re: XInput and Gamepads
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!"
Title: Re: XInput and Gamepads
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!
Title: Re: XInput and Gamepads
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 :).