pub struct GamepadManager { /* private fields */ }Expand description
Owns the state of every gamepad the page has seen and drives the per-frame poll.
A poll re-reads navigator.get_gamepads() and folds the fresh raw
readings into the stored state, computing this frame’s edge sets
from the previous frame’s held set. The DOM connect / disconnect
events are honoured too: a device announced between two polls is
already present as a state when the next poll runs, so polling
alone never loses a connect or a disconnect.
Implementations§
Source§impl GamepadManager
Implements the manager query surface on GamepadManager.
impl GamepadManager
Implements the manager query surface on GamepadManager.
Sourcepub fn state(&self, index: u32) -> Option<&GamepadState>
pub fn state(&self, index: u32) -> Option<&GamepadState>
Sourcepub fn state_mut(&mut self, index: u32) -> Option<&mut GamepadState>
pub fn state_mut(&mut self, index: u32) -> Option<&mut GamepadState>
Sourcepub fn is_connected(&self, index: u32) -> bool
pub fn is_connected(&self, index: u32) -> bool
Sourcepub fn connected_count(&self) -> usize
pub fn connected_count(&self) -> usize
Counts the gamepads that are currently connected.
§Returns
usize- The number of connected gamepads.
Sourcepub fn end_frame(&mut self)
pub fn end_frame(&mut self)
Clears every pad’s per-frame data and the manager’s edge sets.
Mirrors InputState::end_frame: pressed and released are
per-frame and are dropped, while held sets and the connected
flags survive.
Source§impl GamepadManager
Implements the DOM wiring layer on GamepadManager.
impl GamepadManager
Implements the DOM wiring layer on GamepadManager.
The Gamepad API is a polling API: the browser only mutates
navigator.get_gamepads() snapshots and never emits per-button
events, so button edges must be derived by diffing one frame’s
snapshot against the last. The two connect / disconnect events are
still bound so a device that appears or vanishes between two polls
is reflected in connected / disconnected on the same frame
rather than one frame late; a poll alone would also detect both, so
the events are a latency optimisation and the poll is the
authority.
Sourcepub fn poll(&mut self, window: &Window)
pub fn poll(&mut self, window: &Window)
Re-reads every gamepad from the DOM and recomputes this frame’s button edges.
A pad that the browser no longer lists is marked disconnected and its edge sets flushed, so a yanked controller cannot keep reporting held buttons forever.
§Arguments
&Window- The global window, used to reachnavigator.
Sourcepub fn attach(
manager_cell: GamepadManagerCell,
window: &Window,
) -> GamepadManagerCell
pub fn attach( manager_cell: GamepadManagerCell, window: &Window, ) -> GamepadManagerCell
Sourcepub fn attach_gamepad(manager_cell: &GamepadManagerCell, window: &Window)
pub fn attach_gamepad(manager_cell: &GamepadManagerCell, window: &Window)
Binds the connect / disconnect listeners to window.
§Arguments
&GamepadManagerCell- The shared gamepad manager.&Window- The global window.