Pages: [1]
  Print  
Author Topic: XInput, Gamepads, and Windows Joysticks  (Read 2896 times)
Offline (Male) Goombert
Posted on: August 07, 2013, 09:12:09 AM

Contributor
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2988

View Profile
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)...


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
« Last Edit: August 08, 2013, 05:02:05 AM by Robert B Colton » Logged
Welcome to ENIGMO, the game engine built by fucking aliens.

Offline (Male) Josh @ Dreamland
Reply #1 Posted on: August 07, 2013, 10:35:03 AM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2934

View Profile Email
Yoyo's (GM's) joystick functions suck dick. They're underpowered, inconsistent, and fuck-ugly. Use my Linux joystick functions.

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.
« Last Edit: August 07, 2013, 10:42:22 AM by Josh @ Dreamland » Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) Goombert
Reply #2 Posted on: August 07, 2013, 10:39:08 AM

Contributor
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2988

View Profile
??? They are exactly the same as Yoyo's?
Logged
Welcome to ENIGMO, the game engine built by fucking aliens.

Offline (Male) Josh @ Dreamland
Reply #3 Posted on: August 07, 2013, 10:44:44 AM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2934

View Profile Email
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!"
« Last Edit: August 07, 2013, 11:04:30 AM by Josh @ Dreamland » Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) Goombert
Reply #4 Posted on: August 07, 2013, 02:19:56 PM

Contributor
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2988

View Profile
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!
Logged
Welcome to ENIGMO, the game engine built by fucking aliens.

Offline (Male) Goombert
Reply #5 Posted on: August 08, 2013, 05:01:06 AM

Contributor
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2988

View Profile
*Update* Windows Joystick functions implemented fully in a DirectInput extension...
https://github.com/enigma-dev/enigma-dev/pull/303
Logged
Welcome to ENIGMO, the game engine built by fucking aliens.

Offline (Unknown gender) forthevin
Reply #6 Posted on: August 08, 2013, 04:06:16 PM

Contributor
Joined: Jun 2012
Posts: 171

View Profile
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 :).
Logged
Offline (Male) Goombert
Reply #7 Posted on: August 08, 2013, 08:04:33 PM

Contributor
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2988

View Profile
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.
Logged
Welcome to ENIGMO, the game engine built by fucking aliens.

Pages: [1]
  Print