Skip to content
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

Merged
merged 8 commits into from
Jul 8, 2021
Merged

Add algorithms for getGamepads and events #151

merged 8 commits into from
Jul 8, 2021

Conversation

nondebug
Copy link
Collaborator

@nondebug nondebug commented Jun 10, 2021

Closes #114

The following tasks have been completed:

  • Modified Web platform tests (link to pull request)

Implementation commitment:


Preview | Diff

Copy link
Member

@marcoscaceres marcoscaceres left a 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>`{}`
Copy link
Member

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.

Suggested change
<td>`{}`
<td>An empty [=ordered map=].

Copy link
Collaborator Author

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 Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
index.html Outdated
Comment on lines 359 to 372
<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>
Copy link
Member

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.

Copy link
Member

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 dfns if you are creating an alias.

Like

<dfn data-lt="fruit of the gods">bananas</dfn>  where the [=fruit of the gods=], and yet...

Copy link
Collaborator Author

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

index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
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
Copy link
Member

@marcoscaceres marcoscaceres left a 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 Show resolved Hide resolved
index.html Outdated
|now|.
</li>
<li>If |gamepad|'s [=relevant global object=] is a
{{Window}} object, [=queue a global task=] on |gamepad|'s
Copy link
Member

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.

Copy link
Collaborator Author

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 Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
index.html Outdated
<li>Let |gamepad:Gamepad| be the {{Gamepad}} representing the
unavailable device.
</li>
<li>Set |gamepad|.{{Gamepad/[[connected]]}} to `false`.
Copy link
Member

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.

Copy link
Collaborator Author

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:

  1. Create gamepad with gamepad.connected initialized to true
  2. Add gamepad to navigator.[[gamepads]]
  3. Dispatch gamepadconnected

And for gamepaddisconnected:

  1. Set gamepad.connected to false
  2. Dispatch gamepaddisconnected
  3. 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
Copy link
Member

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.

Copy link
Collaborator Author

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.

index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
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.
@nondebug nondebug merged commit 390abc2 into gh-pages Jul 8, 2021
@nondebug nondebug deleted the algorithms branch July 8, 2021 23:51
@marcoscaceres
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite things as algorithms...
2 participants