diff options
Diffstat (limited to 'docs/gameinput.md')
| -rw-r--r-- | docs/gameinput.md | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/docs/gameinput.md b/docs/gameinput.md index 055cec655..f848ab0d2 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md | |||
| @@ -136,6 +136,29 @@ uses: | |||
| 136 | 136 | ||
| 137 | An effect is sent only when its bytes change, so a steady level costs one report. | 137 | An effect is sent only when its bytes change, so a steady level costs one report. |
| 138 | 138 | ||
| 139 | ## Motion | ||
| 140 | |||
| 141 | Pads whose SDL gamepad reports both a gyroscope and an accelerometer (a DualSense, a Switch Pro, Steam Input pads) get | ||
| 142 | `GameInputKindMotion` in `supportedInput` and a `motionInfo` (`GameInputMotionInfo`, Microsoft's v0 layout); `IGameInputReading::GetMotionState` | ||
| 143 | returns a `GameInputMotionState` on their readings, and `GetCurrentReading`/`GetNextReading` answer a | ||
| 144 | `GameInputKindMotion` query for such a pad and return `GAMEINPUT_E_READING_NOT_FOUND` for a pad without sensors. The | ||
| 145 | sensors are enabled when the pad is opened, at SDL's requested rate, and every poll reads the latest sample. | ||
| 146 | |||
| 147 | - The state carries **signed fractions of the maxima `motionInfo` reports** (1.0 = full magnitude), which is the | ||
| 148 | convention Microsoft documents for `GameInputMotionState`. SDL delivers accel in m/s² (gravity included) and gyro | ||
| 149 | in rad/s, so the shim divides by the maxima. The maxima are this shim's choice — SDL does not expose a sensor | ||
| 150 | range — and are 2 g (19.6133 m/s²) and 2000 deg/s (34.9066 rad/s), a DualSense's accelerometer and gyro ranges | ||
| 151 | (VERIFY against the game and a real pad). | ||
| 152 | - A pad at rest sits at about 0.5 on the gravity axis and 0.0 on all gyro axes. SDL answers sensor reads with zeros | ||
| 153 | before the device's first sample arrives; since a real accelerometer never reads exactly zero (gravity), all-zero | ||
| 154 | accel means "no sample yet" and the reading carries no motion at all — `GetMotionState` returns false. | ||
| 155 | - SDL's gamepad API has no compass and the shim synthesises no orientation quaternion, so the magnetic-field and | ||
| 156 | orientation members are zero with `GameInputMotionAccuracyUnknown`. | ||
| 157 | - A pad with sensors streams a reading every ~8 ms (~125 Hz) even when nothing else changes, so motion is not stuck | ||
| 158 | at the last button event; pads without sensors keep the old change-driven behaviour. The 8 ms window and the 512- | ||
| 159 | reading history cap bound the cost. | ||
| 160 | - `gameinput_probe` prints the accel and gyro fractions when the pad has sensors (a resting pad shows ~0.5 g). | ||
| 161 | |||
| 139 | ## Environment variables | 162 | ## Environment variables |
| 140 | 163 | ||
| 141 | | variable | default | effect | | 164 | | variable | default | effect | |
| @@ -165,7 +188,7 @@ The API surface: | |||
| 165 | | interface | implemented | not implemented | | 188 | | interface | implemented | not implemented | |
| 166 | |---|---|---| | 189 | |---|---|---| |
| 167 | | `IGameInput` | `GetCurrentTimestamp` (µs), `GetCurrentReading`, `GetNextReading`, `GetPreviousReading`, `RegisterReadingCallback`, `RegisterDeviceCallback` (blocking and async enumeration), `RegisterGuideButtonCallback`, `RegisterKeyboardLayoutCallback` (never fires), `StopCallback`, `UnregisterCallback`, `CreateDispatcher`, `FindDeviceFromId`, `EnableOemDeviceSupport` (no-op), `SetFocusPolicy` (no-op) | `GetTemporalReading`, `CreateAggregateDevice`, `FindDeviceFromObject/PlatformHandle/PlatformString` | | 190 | | `IGameInput` | `GetCurrentTimestamp` (µs), `GetCurrentReading`, `GetNextReading`, `GetPreviousReading`, `RegisterReadingCallback`, `RegisterDeviceCallback` (blocking and async enumeration), `RegisterGuideButtonCallback`, `RegisterKeyboardLayoutCallback` (never fires), `StopCallback`, `UnregisterCallback`, `CreateDispatcher`, `FindDeviceFromId`, `EnableOemDeviceSupport` (no-op), `SetFocusPolicy` (no-op) | `GetTemporalReading`, `CreateAggregateDevice`, `FindDeviceFromObject/PlatformHandle/PlatformString` | |
| 168 | | `IGameInputReading` | kind, sequence number, timestamp, device, gamepad state, UI navigation state, controller axes and buttons | raw report, keyboard, mouse, touch, motion, arcade/flight stick, racing wheel (all return nothing) | | 191 | | `IGameInputReading` | kind, sequence number, timestamp, device, gamepad state, UI navigation state, controller axes and buttons, motion state | raw report, keyboard, mouse, touch, arcade/flight stick, racing wheel (all return nothing) | |
| 169 | | `IGameInputDevice` | device info, status, battery, `SetRumbleState` | force feedback and haptic motors (none reported), raw device I/O, power off, input synchronization (no-ops) | | 192 | | `IGameInputDevice` | device info, status, battery, `SetRumbleState` | force feedback and haptic motors (none reported), raw device I/O, power off, input synchronization (no-ops) | |
| 170 | | `IGameInputDispatcher` | `Dispatch`, `OpenWaitHandle` | the quota (the queue is short) | | 193 | | `IGameInputDispatcher` | `Dispatch`, `OpenWaitHandle` | the quota (the queue is short) | |
| 171 | 194 | ||
| @@ -235,7 +258,11 @@ shim fills (`GameInputDeviceInfo` 320 bytes with `deviceFamily` at 96 and the in | |||
| 235 | rumble as SDL receives them, the DualSense effect bytes in each `LEONIDA_DS_TRIGGERS` mode, the lightbar, a | 258 | rumble as SDL receives them, the DualSense effect bytes in each `LEONIDA_DS_TRIGGERS` mode, the lightbar, a |
| 236 | dispatcher, async and blocking enumeration, unregistering, unplugging and replugging, and three identical pads | 259 | dispatcher, async and blocking enumeration, unregistering, unplugging and replugging, and three identical pads |
| 237 | (an id each, `FindDeviceFromId` and device-filtered readings per pad, replugging one, two and all three, and the | 260 | (an id each, `FindDeviceFromId` and device-filtered readings per pad, replugging one, two and all three, and the |
| 238 | first twin's id equal to the single-pad id). The keyboard pad is | 261 | first twin's id equal to the single-pad id). Motion runs on a virtual pad with sensors (`nsensors` in the |
| 262 | virtual-joystick description, fed with `SDL_SendJoystickVirtualSensorData`): the kind and `motionInfo` on a sensor | ||
| 263 | pad and not on a plain one, no motion before the first sample, normalisation against the `motionInfo` maxima, the | ||
| 264 | accuracy values, the ±1 clamp, the ~8 ms cadence, and that a motion query on a pad without sensors is | ||
| 265 | `GAMEINPUT_E_READING_NOT_FOUND`. The keyboard pad is | ||
| 239 | driven through `rt::gameinput::set_keyboard_source` and `set_cursor_source` with fake keys, focus and cursor: every | 266 | driven through `rt::gameinput::set_keyboard_source` and `set_cursor_source` with fake keys, focus and cursor: every |
| 240 | binding, two keys at once, each WASD direction, opposite keys cancelling, diagonals, the mouse moving the right | 267 | binding, two keys at once, each WASD direction, opposite keys cancelling, diagonals, the mouse moving the right |
| 241 | stick, clamping and decaying to 0, the mouse-button triggers, no input out of focus, release of buttons, sticks and | 268 | stick, clamping and decaying to 0, the mouse-button triggers, no input out of focus, release of buttons, sticks and |
| @@ -258,6 +285,11 @@ These need the game executable or a test on hardware: | |||
| 258 | not measured from a console. | 285 | not measured from a console. |
| 259 | - **Battery capacity** is reported as a fraction (remaining 0..1 of full 1), not in device units. | 286 | - **Battery capacity** is reported as a fraction (remaining 0..1 of full 1), not in device units. |
| 260 | - **`UnregisterCallback` timeout** is not honoured; it waits for a callback that is running. | 287 | - **`UnregisterCallback` timeout** is not honoured; it waits for a callback that is running. |
| 288 | - **Motion normalisation maxima** (2 g accel, 2000 deg/s gyro) are this shim's choice; SDL exposes no sensor range, | ||
| 289 | and whether the game reads motion, and against what scale, is unknown until it runs. The accelerometer range a | ||
| 290 | DualSense exposes can also be wider than 2 g, so hard shakes may clamp at 1.0. | ||
| 291 | - **Motion members the shim does not provide** (magnetic field, orientation) are zero with | ||
| 292 | `GameInputMotionAccuracyUnknown`; whether a title wants a synthesised quaternion there is unknown. | ||
| 261 | - **Device family**: every pad is reported as `GameInputFamilyXboxOne`; a title that filters on family sees only | 293 | - **Device family**: every pad is reported as `GameInputFamilyXboxOne`; a title that filters on family sees only |
| 262 | that. | 294 | that. |
| 263 | - **Identical pads at start**: twins are numbered in the order the shim opens them. For pads already connected when | 295 | - **Identical pads at start**: twins are numbered in the order the shim opens them. For pads already connected when |