diff options
Diffstat (limited to 'docs/gameinput.md')
| -rw-r--r-- | docs/gameinput.md | 83 |
1 files changed, 75 insertions, 8 deletions
diff --git a/docs/gameinput.md b/docs/gameinput.md index 21421351e..fa216a2ee 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md | |||
| @@ -264,24 +264,74 @@ never touch SDL: they read the latest reading or leave a request, so a call cost | |||
| 264 | button) run on that thread, as GameInput runs them on its own threads. Once the title creates a dispatcher | 264 | button) run on that thread, as GameInput runs them on its own threads. Once the title creates a dispatcher |
| 265 | (`IGameInput::CreateDispatcher`), callbacks are queued instead, the dispatcher's wait handle is signalled, and | 265 | (`IGameInput::CreateDispatcher`), callbacks are queued instead, the dispatcher's wait handle is signalled, and |
| 266 | `IGameInputDispatcher::Dispatch` runs them on the title's thread, oldest first, within its quota: at least one queued | 266 | `IGameInputDispatcher::Dispatch` runs them on the title's thread, oldest first, within its quota: at least one queued |
| 267 | event per call (a quota of 0 runs exactly one), no further event once the quota has passed, and the wait handle is | 267 | event per call (a quota of 0 runs exactly one), no further event once the quota has passed, and only the events |
| 268 | signalled again while events remain. | 268 | queued when the call started (later ones wait for the next call, so even an unlimited quota returns). The wait |
| 269 | handle is signalled again while events remain. | ||
| 269 | 270 | ||
| 270 | The API surface: | 271 | The API surface: |
| 271 | 272 | ||
| 272 | | interface | implemented | not implemented | | 273 | | interface | implemented | not implemented | |
| 273 | |---|---|---| | 274 | |---|---|---| |
| 274 | | `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` (`E_NOTIMPL`, as in GameInput v0 itself; see below), `CreateAggregateDevice`, `FindDeviceFromObject/PlatformHandle/PlatformString` | | 275 | | `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` (`E_NOTIMPL`, as in GameInput v0 itself; see below), `CreateAggregateDevice`, `FindDeviceFromObject/PlatformHandle/PlatformString` | |
| 275 | | `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) | | 276 | | `IGameInputReading` | kind, sequence number, timestamp, device, gamepad state, UI navigation state, controller axes and buttons, motion state, raw report (pads opened through HID, see [Raw HID](#raw-hid)) | keyboard, mouse, touch, arcade/flight stick, racing wheel (all return nothing) | |
| 276 | | `IGameInputDevice` | device info, status, battery, `SetRumbleState`, force-feedback motors with `CreateForceFeedbackEffect`/`IGameInputForceFeedbackEffect`, `IsForceFeedbackMotorPoweredOn`, `SetForceFeedbackMotorGain`, haptic trigger motors with `SetHapticMotorState` | raw device I/O, power off, input synchronization (no-ops) | | 277 | | `IGameInputDevice` | device info, status, battery, `SetRumbleState`, force-feedback motors with `CreateForceFeedbackEffect`/`IGameInputForceFeedbackEffect`, `IsForceFeedbackMotorPoweredOn`, `SetForceFeedbackMotorGain`, haptic trigger motors with `SetHapticMotorState`, `CreateRawDeviceReport`, `GetRawDeviceFeature`, `SetRawDeviceFeature`, `SendRawDeviceOutput` (pads opened through HID) | `SendRawDeviceOutputWithResponse`, `ExecuteRawDeviceIoControl`, exclusive raw access, power off, input synchronization (no-ops) | |
| 277 | | `IGameInputDispatcher` | `Dispatch`, `OpenWaitHandle` | the quota (the queue is short) | | 278 | | `IGameInputRawDeviceReport` | device, report info (kind, id, size), raw data size, get and set raw data | item values (`Get/Set/ResetItemValue`, `ResetAllItems` answer false: no item tables) | |
| 278 | | `IGameInputDevice` | device info, status, battery, `SetRumbleState` | force feedback and haptic motors (none reported), raw device I/O, power off, input synchronization (no-ops) | | ||
| 279 | | `IGameInputDispatcher` | `Dispatch` (with its quota), `OpenWaitHandle` | | | 279 | | `IGameInputDispatcher` | `Dispatch` (with its quota), `OpenWaitHandle` | | |
| 280 | 280 | ||
| 281 | `CreateAggregateDevice` takes exactly one of the keyboard, mouse, gamepad, arcade stick, flight stick or racing wheel | ||
| 282 | kinds (none, several, or another kind is `E_INVALIDARG`) and returns one device per kind, the same object on every | ||
| 283 | call: family `GameInputFamilyAggregate`, always connected, with that kind as its `supportedInput`, and a fixed | ||
| 284 | `deviceId` per kind that `FindDeviceFromId` also answers. Readings asked | ||
| 285 | through it (`GetCurrentReading`, `GetNextReading`, `GetPreviousReading`) come from every connected device of that | ||
| 286 | kind (`GetCurrentReading` answers the most recent of them); asking it for another kind is | ||
| 287 | `GAMEINPUT_E_READING_NOT_FOUND`. A reading or device callback registered with an aggregate device as its filter is | ||
| 288 | refused with `E_NOTIMPL` and an invalid token. | ||
| 289 | |||
| 281 | A device object stays alive for the whole process. When a pad is unplugged its status drops to | 290 | A device object stays alive for the whole process. When a pad is unplugged its status drops to |
| 282 | `GameInputDeviceNoStatus` and its device callback runs; when the same pad is plugged in again (matched by SDL GUID and | 291 | `GameInputDeviceNoStatus` and its device callback runs; when the same pad is plugged in again (matched by SDL GUID and |
| 283 | serial or device path) the title gets the same object back, connected again. | 292 | serial or device path) the title gets the same object back, connected again. |
| 284 | 293 | ||
| 294 | ## Raw HID | ||
| 295 | |||
| 296 | A title can read a pad's raw HID input reports and send it output and feature reports (RT-175). The shim opens each | ||
| 297 | pad's HID device through SDL's hidapi (`SDL_hid_*`), by the device path SDL reports for the pad. When that path is not | ||
| 298 | a HID path, it falls back to the pad's vendor and product id, but only when exactly one game-pad collection (usage page | ||
| 299 | 1, usage 5) has them, so twins never mix. It reads the report descriptor to find every input, output and feature | ||
| 300 | report: its id (0 when the descriptor declares none) and its payload size in bytes, without the id byte. | ||
| 301 | |||
| 302 | A pad opened this way gets the following: | ||
| 303 | |||
| 304 | - `GameInputKindRawDeviceReport` in `supportedInput` and `GameInputDeviceRawIoEnabled` in its status. | ||
| 305 | - `inputReportInfo`, `outputReportInfo` and `featureReportInfo` tables with their counts. Every report has `itemCount` | ||
| 306 | 0: the descriptor's items (usages, logical ranges, units) are not decoded. | ||
| 307 | - Readings that carry the newest raw input report. Each poll drains the reports that arrived, the last declared one | ||
| 308 | wins, and a report with new bytes makes a reading of its own. Before the first report, a reading carries none. | ||
| 309 | - These device calls, each on any `IGameInputRawDeviceReport` of the right kind whose id the pad declares: | ||
| 310 | - `CreateRawDeviceReport(id, kind)` makes a zeroed report. | ||
| 311 | - `GetRawDeviceFeature(id)` reads a feature report. | ||
| 312 | - `SetRawDeviceFeature` sends one. | ||
| 313 | - `SendRawDeviceOutput` writes an output report. | ||
| 314 | |||
| 315 | An undeclared id or kind is `E_INVALIDARG`, and a failed transfer `E_FAIL`. | ||
| 316 | |||
| 317 | `SetRawData` takes a buffer of exactly the report's size and refuses any other size, so a report is never half old and | ||
| 318 | half new. The item calls answer false. `SendRawDeviceOutputWithResponse`, `ExecuteRawDeviceIoControl` and exclusive | ||
| 319 | access still return `E_NOTIMPL` / false. | ||
| 320 | |||
| 321 | A pad without such a HID device keeps the old answers: no raw kind, no tables, `E_NOTIMPL` from the raw calls. | ||
| 322 | |||
| 323 | - **Xbox pads on Windows** are read by SDL through XInput (path `XInput#n`). SDL's hidapi skips their XInput HID | ||
| 324 | interface (`&IG_` in the path), noting that it carries no full HID reports. So they have no raw I/O here, and the log | ||
| 325 | says so. | ||
| 326 | - **SDL virtual joysticks and the keyboard pad** have no path, so no HID device either. | ||
| 327 | - **Pads SDL reads through hidapi** can have raw I/O: DualSense, DualShock 4, Switch Pro, and most others in DirectInput | ||
| 328 | mode. | ||
| 329 | |||
| 330 | `rt::gameinput::set_hid_backend` replaces the hidapi backend (tests). `rt::gameinput::parse_report_descriptor` is the | ||
| 331 | descriptor walk: main items Input, Output and Feature add Report Size × Report Count bits to the current Report ID, Push | ||
| 332 | and Pop save and restore the globals, and long items are skipped. It refuses a truncated item, Report ID 0 or above | ||
| 333 | 255, a Pop without a Push, and a report over 64 KiB. | ||
| 334 | |||
| 285 | ## Reading history | 335 | ## Reading history |
| 286 | 336 | ||
| 287 | Each pad keeps the readings the poll took for it, one per change it saw, so `GetNextReading` and `GetPreviousReading` | 337 | Each pad keeps the readings the poll took for it, one per change it saw, so `GetNextReading` and `GetPreviousReading` |
| @@ -359,8 +409,16 @@ rests on a transcription rather than on a side-by-side compile. | |||
| 359 | binding, two keys at once, each WASD direction, opposite keys cancelling, diagonals, the mouse moving the right | 409 | binding, two keys at once, each WASD direction, opposite keys cancelling, diagonals, the mouse moving the right |
| 360 | stick, clamping and decaying to 0, the mouse-button triggers, no input out of focus, release of buttons, sticks and | 410 | stick, clamping and decaying to 0, the mouse-button triggers, no input out of focus, release of buttons, sticks and |
| 361 | triggers on focus loss, the `always` mode, and turning it off and on again. | 411 | triggers on focus loss, the `always` mode, and turning it off and on again. |
| 362 | - `gameinput_probe [--seconds N] [--rumble]` (by hand, with a pad connected): lists the pads, plays each motor and | 412 | Raw HID (RT-175) is tested in two ways: |
| 363 | trigger for a second with `--rumble`, then prints the live reading. | 413 | - `parse_report_descriptor` runs on synthetic descriptors: report ids, none, Push/Pop, a long item, and the refused |
| 414 | forms. | ||
| 415 | - A fake backend (`set_hid_backend`) stands behind a virtual pad with pid.codes test ids. The test checks the report | ||
| 416 | tables, the kind and status bits, a reading's raw report (newest declared id, without the id byte, an undeclared id | ||
| 417 | ignored), creating, sending and reading back output and feature reports with their id byte, `SetRawData`'s exact | ||
| 418 | size, the item calls, `E_INVALIDARG` / `E_FAIL` / `E_NOTIMPL`, and the HID device closing on unplug. | ||
| 419 | - `gameinput_probe [--seconds N] [--rumble]` (by hand, with a pad connected): lists the pads with each one's raw HID | ||
| 420 | report tables (or why it has none), plays each motor and trigger for a second with `--rumble`, then prints the live | ||
| 421 | reading and the newest raw input report. | ||
| 364 | 422 | ||
| 365 | ## VERIFY | 423 | ## VERIFY |
| 366 | 424 | ||
| @@ -416,3 +474,12 @@ These need the game executable or a test on hardware: | |||
| 416 | - **Haptic waveforms**: the single intensity waveform (usage 0x0F/0x58) is this shim's choice, not the pad's table, so | 474 | - **Haptic waveforms**: the single intensity waveform (usage 0x0F/0x58) is this shim's choice, not the pad's table, so |
| 417 | a title that asks for a particular waveform gets intensity-only behaviour. Whether the game uses haptic motors at | 475 | a title that asks for a particular waveform gets intensity-only behaviour. Whether the game uses haptic motors at |
| 418 | all — as opposed to `SetRumbleState` — is unknown. | 476 | all — as opposed to `SetRumbleState` — is unknown. |
| 477 | - **Raw HID on a real pad**: only the synthetic tests and the XInput refusal have run. | ||
| 478 | - What ran: an Xbox Series X controller over Bluetooth on Windows 11 connects and plays normally, with no raw I/O, | ||
| 479 | and the log names the reason. | ||
| 480 | - Still to confirm: a DualSense, DualShock 4 or Switch Pro through `gameinput_probe`, which should print the | ||
| 481 | descriptor's reports and changing raw input bytes. | ||
| 482 | - Size convention: report sizes exclude the id byte, and `GetRawData` returns the payload without it. What | ||
| 483 | Microsoft's runtime does for a device with report ids is not documented on the reference pages. | ||
| 484 | - Readings: a pad that streams reports makes a reading for each changed one, like the runtime's | ||
| 485 | `GameInputKindRawDeviceReport` stream, but whether the title asks for raw reports at all is unknown. | ||