Repository navigation
Description
Follows #34
- Add a gamepad tester to
examples; for validating mappings - Remap
axes[4]andaxes[5]extension (L2 and R2 analog triggers) tobuttons[me.GAMEPAD.L2].valueandbuttons[me.GAMEPAD.R2].value - Add a new API for reading and writing action states
-
me.input.isActionSet(action)(wasme.input.isKeyPressed) -
me.input.getActionState(action)(wasme.input.keyState) -
me.input.getActionValue(action)(NEW; returns action analog value) -
me.input.getAction(action)(NEW; returns action analog value, digital state, and digital edge) -
me.input.setAction(action, state, value)(NEW; sets action analog value and digital state)
-
- Add a new method for custom gamepad mapping, with a normalization function
me.input.setGamepadMapping(id, mapping)- The function signature has been changed to better fit the needs of remapping axes to button values; see below.
-
mappingis a hash table containing the following keys:- {Number[]}
mapping.axesStandard analog control stick axis locations - {Number[]}
mapping.buttonsStandard digital button locations - {Number[]}
[mapping.analog]Analog axis locations for buttons. See: https://developer.mozilla.org/en-US/docs/Web/API/GamepadButton - {Function}
[mapping.normalize_fn]will be called on an unmapped axis or button with the following parameters:- {Number}
valueThe raw value read from the gamepad driver - {Number}
axisThe axis index from the standard mapping, or -1 if not an axis - {Number}
buttonThe button index from the standard mapping, or -1 if not a button
- {Number}
normalize_fnmust return a normalized value in range[-1.0..1.0], or0.0if the axis is unknown.
- {Number[]}
mapping.analog is specially for mapping analog buttons or pressure-sensitive buttons from an axis location to a button location. This is for things like the L2 and R2 analog triggers, and pressure sensitive D-pad and face buttons on a PS3 controller. Here's how it might look for remapping L2 and R2 triggers on a wired XBox 360 controller:
{
"axes" : [ 0, 1, 3, 4 ],
"buttons" : [ 11, 12, 13, 14, 8, 9, -1, -1, 5, 4, 6, 7, 0, 1, 2, 3, 10 ],
"analog" : [ -1, -1, -1, -1, -1, -1, 2, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1 ]
}This will fill in that gap in the buttons array during remapping. A little extra code is necessary to combine the axis and the button to produce a meaningful result.
Some mapping test reports:
Chrome (45+) :
- PS3 Gamepad
- PS4 Gamepad
- XBox One Gamepad
- XBox 360 USB Gamepad
- XBox 360 Wireless Gamepad
-
Wii Remote(not recognised by the browser) -
Wii "Classic" Gamepad(not recognised by the browser) - Wii U Gamepad
- Ouya Gamepad
Firefox (39+) :
- PS3 Gamepad
- PS4 Gamepad
- XBox One Gamepad
- XBox 360 USB Gamepad
- XBox 360 Wireless Gamepad
-
Wii Remote(not recognised by the browser) -
Wii "Classic" Gamepad(not recognised by the browser) - Wii U Gamepad
- Ouya Gamepad
Wiimote on Mac requires a driver: https://github.com/alxn1/wjoy
I haven't mapped it out, yet. But initial testing shows a huge caveat; this driver reports the gamepad id as a string containing a MAC address (which is unique for each device). For this reason, I want to defer Wiimote support to a melonJS plugin; which is better suited to doing things like RegExp over gamepad id.
Ouya gamepad on Mac requires a driver: http://ouyaforum.com/showthread.php?3185-Ouya-controller-input-on-computer-macosx&p=78432&viewfull=1#post78432 This driver is unsigned, so requires disabling KEXT signature checking on OSX 10.10+:
$ sudo nvram boot-args=kext-dev-mode=1After restarting, load the driver:
$ sudo kextload /System/Library/Extensions/OUYAGameController.kext
Activity
obiot commentedon Aug 18, 2015
note that the device test example is maybe a right place where to add simple gamepad tester :P
obiot commentedon Aug 18, 2015
@parasyte : I added some testing report, based on my test, and the one you described in the other ticket, have a look to see if I missed anything
obiot commentedon Aug 18, 2015
other improvements I could see, by looking at the API and what you did today :
obiot commentedon Aug 18, 2015
also, just an idea, but for the mapping function, why not also use it to apply a mapping to keyboard event ?
as an Id we could use the
keyboardkeyword for the id, and then we can just pass a default array to map the gamepad array to the keyboard one ?parasyte commentedon Aug 18, 2015
Hmm, in regard to the stuff you added to the TODO list with 360 support... that isn't right. ;) melonJS only supports remapping USB 360 controllers on Firefox right now, because that's all I have. The Wireless 360 controller has a different
idstring at the very least. (So it won't automatically use the mapping for USB controllers.)As for the device test, I'm kind of OK with that, but I would prefer making it prettier than just dumping a bunch of text to the screen. I imagine something like the virtual gamepad on the HTML5 gamepad tester. We can use the Kenney gamepad UI graphics for it.
The connect/disconnect events won't help us, because the UA already removes disconnected gamepads from the
navigator.getGamepads()result. And it adds them automatically, too. I see these events as more of an application-level thing; that the game can automatically pause when the gamepad is disconnected, for example, and resume when reconnected. The engine doesn't need to do that kind of thing.The timestamp isn't portable, so I didn't bother with it. It also won't really save a whole lot of CPU or time anyway. It's a very, very minor optimization.
I already explained my reason for not mapping to keyboard events in #34 (comment) (It's already mapping to keyboard events right now, and it doesn't work for the analog axes.)
parasyte commentedon Aug 18, 2015
@obiot I corrected some of the test report stuff in the first post.
obiot commentedon Aug 18, 2015
about the timestamp, well i'm not sure, this is still a fair amount of code :
https://github.com/melonjs/melonJS/blob/ticket-34/src/input/gamepad.js#L78-L104
obiot commentedon Aug 18, 2015
For the Wiimote, interestingly enough, that's all I see under Chrome :

Firefox does not even recognize it !
parasyte commentedon Aug 18, 2015
The code you highlighted is just the inner loop that checks the state of buttons that are actually mapped. In the platformer demo, only
up,down,left,right, andface_1are mapped. So it only iterates five items. Hardly a worry for performance.obiot commentedon Aug 18, 2015
@agmcleod if i'm not wrong you do have a xbox one ? don't you ?
[#34][#724] few changes, see description
[#724] reverted some changes from yesterday commit
[#724] normalized vendor id parsing for non standard mapping
[#724] updated the `setGamepadMapping` function signature to match wi…
27 remaining items
[#724] manage gamepad with no analogue stick
[#724] some further code optimisation
Revert "[#724] manage gamepad with no analogue stick"
parasyte commentedon Mar 5, 2016
We can add the new API without breaking compatibility; binding inputs to actions, and querying action values. I'd like to start moving toward that soon, too. I'm open to better function naming conventions, if you have ideas!
[#724] typo fix
[#724] ignore "unsupported" axes id
adrianhartanto0 commentedon Feb 5, 2018
Just wondering, what are action states? Include example if possible. Thanks