-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add algorithms for getGamepads and events #151
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff @nondebug! I didn't manage to get all the way through it yet, but here is the initial set of comments.
index.html
Outdated
<td>A flag indicating that the {{Gamepad}} object has been exposed to script. | ||
<tr> | ||
<td><dfn>[[\axisMapping]]</dfn> | ||
<td>`{}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the internal slots, we can switch to using infra types. That gives us nicer ways of working with things.
<td>`{}` | |
<td>An empty [=ordered map=]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good for these internal arrays. I've left the Navigator.gamepads list as an empty array [] since we need to expose that array to script for getGamepads. Is there some incantation for converting from infra types to Javascript types?
index.html
Outdated
<p> | ||
The <a>user agent</a> MUST provide methods for retrieving <dfn data-lt="ordered array of axis inputs">ordered arrays of axis inputs</dfn> and <dfn data-lt="ordered array of button inputs">button inputs</dfn> for a gamepad such that there is a unique element in the axis array for each axis input and a unique element in the button array for each button input. | ||
If the system enumerates axis and button inputs in a consistent order, then the methods SHOULD provide the inputs in that order. | ||
Otherwise, the methods MAY use any consistent ordering. | ||
</p> | ||
<p> | ||
The <a>user agent</a> MUST provide methods for retrieving <dfn data-lt="ordered array of minimum logical values">ordered arrays of minimum logical values</dfn> and <dfn data-lt="ordered array of maximum logical values">maximum logical values</dfn> for each gamepad input. | ||
The ordering of these arrays MUST match the ordering of the <a>ordered array of axis inputs</a> and <a>ordered array of button inputs</a>. | ||
</p> | ||
<p> | ||
The <a>user agent</a> MUST provide methods for retrieving <dfn data-lt="ordered array of logical axis input values">ordered arrays of logical axis input values</dfn> and <dfn data-lt="ordered array of logical button input values">button input values</dfn>. | ||
These arrays MUST contain the most recent values received from the gamepad for each button and axis input. | ||
The ordering of these arrays MUST match the ordering of the <a>ordered array of axis inputs</a> and <a>ordered array of button inputs</a>. | ||
</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest we delete these and just use Infra types. Also, it will avoid descriptors for things that happen algorithmically anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note, only add a data-lt=
to dfn
s if you are creating an alias.
Like
<dfn data-lt="fruit of the gods">bananas</dfn> where the [=fruit of the gods=], and yet...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed these definitions and rewritten the relevant part of the algorithm, please take a look
Replace <a>anchor tags</a> with [=definition links=] Add internal slots and getters for readonly attributes Add a Gamepad initializer algorithm Add HR-TIME clock resolution warning More Infra references and syntax Fix gamepaddisconnected algorithm Specify event targets Add gh-contributors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wowser! This is so much better! Nice one @nondebug!
I'd be inclined for us to take this as is (with the suggestions) and we should just build on it.
index.html
Outdated
|now|. | ||
</li> | ||
<li>If |gamepad|'s [=relevant global object=] is a | ||
{{Window}} object, [=queue a global task=] on |gamepad|'s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we might want to also do the fully active check (as we are checking the {{Window}} is still there, per #149).... we can come back to this tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a fully active check so we won't try to fire events for non-fully-active Documents.
I removed the Window check since I think we'll implicitly make that check when trying to get the associated (or responsible) Document. If the global object isn't a Window then it won't have a Document. Is that correct?
index.html
Outdated
<li>Let |gamepad:Gamepad| be the {{Gamepad}} representing the | ||
unavailable device. | ||
</li> | ||
<li>Set |gamepad|.{{Gamepad/[[connected]]}} to `false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be done in the steps of the task (right before the event is fired), no? Otherwise, it would update somewhat randomly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. We should update the gamepad state synchronously with firing the event to make sure the state changes are handled sequentially and predictably.
I think this order makes the most sense for gamepadconnected:
- Create gamepad with gamepad.connected initialized to true
- Add gamepad to navigator.[[gamepads]]
- Dispatch gamepadconnected
And for gamepaddisconnected:
- Set gamepad.connected to false
- Dispatch gamepaddisconnected
- Remove gamepad from navigator.[[gamepads]]
Updating in this order ensures the gamepad.connected state matches the stated reflected by the gamepadconnected or gamepaddisconnected event, and also ensures the item in the getGamepads() array at index gamepad.index is the same instance as the gamepad instance in the event.
object. Registration for and firing of the | ||
<code>gamepaddisconnected</code> event MUST follow the usual behavior | ||
of DOM Events. [[DOM]] | ||
event, named {{gamepaddisconnected}}. The corresponding event MUST be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they "allowed to use" checks should only happen when the developer tries to use the API.
We can maybe have a global check that if the permission to use the API gets disabled, then just bring down everything... but that's probably overkill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the "allowed to use" check here but there's still a reference in the gamepadconnected algorithm.
Changes the gamepadconnected/disconnected algorithms to update gamepad state synchronously with firing the event. Checks that the Document is fully active before firing events. Removes some unnecessary language.
#151 Requested on the TAG review: w3ctag/design-reviews#662 (comment)
Closes #114
The following tasks have been completed:
Implementation commitment:
Preview | Diff