1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use *;
/// Applies the analog deadzone to a single raw axis reading.
///
/// A reading at or inside the deadzone band reports `0.0`; a reading
/// beyond it is rescaled so the usable range still reaches `1.0` at
/// full deflection. Sign is preserved, so a stick pushed left stays
/// negative.
///
/// # Arguments
///
/// - `f64` - The raw axis reading as reported by the browser.
///
/// # Returns
///
/// - `f64` - The deadzone-corrected reading, centered inside the band.
/// Folds one frame of raw gamepad readings into the per-pad edge sets.
///
/// This is the DOM-free half of a poll: it takes the previous frame's
/// held set and this frame's raw button pressures, and recomputes
/// pressed / held / released exactly the way [`InputState::press_key`]
/// and [`InputState::release_key`] do for keys. A button counts as
/// down when its pressure is at least half, which makes digital
/// buttons (`0.0` / `1.0`) and analog triggers agree.
///
/// # Arguments
///
/// - `&GamepadButtonSet` - The previous frame's held button indices.
/// - `&[f64]` - This frame's raw button pressure per button index.
///
/// # Returns
///
/// - `GamepadButtonSet` - The buttons newly pressed on this frame.
/// Folds one frame of raw gamepad readings into the per-pad edge sets.
///
/// The held set this frame is every button at or above half pressure;
/// the released set is every button that was held last frame and is
/// no longer down, which is what a caller polls with to fire a
/// one-shot action on button-up.
///
/// # Arguments
///
/// - `&GamepadButtonSet` - The previous frame's held button indices.
/// - `&[f64]` - This frame's raw button pressure per button index.
///
/// # Returns
///
/// - `GamepadButtonSet` - The buttons that came up on this frame.
/// Folds one frame of raw gamepad readings into the per-pad edge sets.
///
/// # Arguments
///
/// - `&[f64]` - This frame's raw button pressure per button index.
///
/// # Returns
///
/// - `GamepadButtonSet` - Every button currently down this frame.
/// Tests whether one raw button pressure counts as the button being down.
///
/// The threshold is one half so that a digital button reporting
/// `1.0` and an analog trigger crossing its midpoint agree.
///
/// # Arguments
///
/// - `f64` - The raw button pressure as reported by the browser.
///
/// # Returns
///
/// - `bool` - True when the pressure reaches the press threshold.
/// Reads the nth analog axis out of a raw axis reading list.
///
/// # Arguments
///
/// - `&[f64]` - The raw axis readings as reported by the browser.
/// - `u32` - The axis index to read.
///
/// # Returns
///
/// - `f64` - The raw reading, or `0.0` when the pad has no such axis.