- From: Matt Reynolds <notifications@github.com>
- Date: Wed, 28 Jul 2021 19:04:16 -0700
- To: w3c/gamepad <gamepad@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/gamepad/pull/152/c888740965@github.com>
I like proposal 1 (a single `change` event) since most gamepads deliver all button and axis state in one report and many applications would prefer to consume inputs that way. I think buttons and axes should be handled the same way. ``` interface GamepadChangeEvent : Event { // A copy of the gamepad state when this event was created. readonly attribute Gamepad gamepadSnapshot; // Indices of axes for which the value has changed since the previously dispatched event. readonly attribute FrozenArray<long> axesChanged; // Indices of buttons for which the value has changed since the previously dispatched event. readonly attribute FrozenArray<long> buttonsChanged; // Indices of buttons that were pressed since the previously dispatched event. readonly attribute FrozenArray<long> buttonsDown; // Indices of buttons that were released since the previously dispatched event. readonly attribute FrozenArray<long> buttonsUp; // Returns the sequence of GamepadChangeEvent instances that were coalesced into this event, // or an empty sequence if this instance is not a coalesced event. sequence<GamepadChangeEvent> getCoalescedEvents(); }; ``` When an input frame is received from the gamepad, if a `change` event listener is registered on the Gamepad then create a GamepadChangeEvent from the input frame and queue it to an internal slot on the Gamepad. Then, queue a task on the main thread to (maybe) dispatch the event. When dispatching, dequeue all the queued instances. If there were no queued instances, don't dispatch an event. Otherwise, create a new GamepadChangeEvent and stash the queued instances in an internal slot so they can be returned by getCoalescedEvents(). Initialize its gamepadSnapshot attribute to the gamepadSnapshot of the most recent instance. Initialize the button and axis index arrays to the set union of the corresponding arrays in the dequeued instances. If a button or axis changed in any coalesced event then its index should be in the buttonsChanged or axesChanged arrays. If a button is pressed and released in separate coalesced events then its index should be in both buttonsDown and buttonsUp. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/w3c/gamepad/pull/152#issuecomment-888740965
Received on Thursday, 29 July 2021 02:04:29 UTC