- From: <bugzilla@jessica.w3.org>
- Date: Thu, 18 Dec 2014 14:59:31 +0000
- To: public-webapps-bugzilla@w3.org
https://www.w3.org/Bugs/Public/show_bug.cgi?id=26181 --- Comment #32 from Philip Jägenstedt <philipj@opera.com> --- (In reply to Ted Mielczarek [:ted] from comment #28) > > Off-topically, I'd be interested to know what purpose Gamepad.index and > > trying to preserve that index in the returned array serves. It seems a bit > > odd, but I assume it's been discussed to death already. > > I don't know that it's been discussed much in the spec context, it's pretty > simple really. The index can be thought of as the "player number". This is > pretty common in console-land where you have a fixed number of controllers, > and Gamepad is taking a cue from them (most specifically you can look at > Microsoft's XInput: > http://msdn.microsoft.com/en-us/library/windows/desktop/ee417001%28v=vs. > 85%29.aspx#multiple_controllers ). Being able to keep track of which > controller is which, especially when you may have multiple devices of the > same type connected is pretty important. Having .index correspond to the > index in the getGamepads array just seemed sensible at the time, since it > allows you to write code like: > > function onconnected(e) { > player.gamepad = e.gamepad.index; > } > > function handleInput() { > var gamepad = navigator.getGamepads()[player.gamepad]; > } > > If we compacted the array and got rid of empty entries you'd have to search > the array to find the matching device, which seems awkward. Why not: function onconnected(e) { player.gamepad = e.gamepad; } And then just use that until the gamepaddisconnected fires or player.gamepad.connected is false? Getting the gamepad via getGamepads() on each input event or animation frame will generate a lot of garbage since a new Array is returned each time. The XInputGetState API seems to need an index because there's no equivalent to Gamepad objects to hold on to. -- You are receiving this mail because: You are the QA Contact for the bug.
Received on Thursday, 18 December 2014 14:59:34 UTC