diff options
| author | nicolas <44988633+nschlaepfer@users.noreply.github.com> | 2026-11-21 21:38:20 -0700 |
|---|---|---|
| committer | nicolas <44988633+nschlaepfer@users.noreply.github.com> | 2026-11-21 21:46:14 -0700 |
| commit | b72fc5a4fec776ffa4b19d37c7bf8d62836e3df5 (patch) | |
| tree | a9352dc77152799d399cead60e7bd8271ab1d5cf /docs/gameinput.md | |
| parent | 4a36bb19979b611f525d027f92e0fefad1626546 (diff) | |
Keep gamepad readings in order between title polls
Diffstat (limited to 'docs/gameinput.md')
| -rw-r--r-- | docs/gameinput.md | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/docs/gameinput.md b/docs/gameinput.md index 0096285b2..2faa2fdbc 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md | |||
| @@ -118,7 +118,7 @@ The API surface: | |||
| 118 | 118 | ||
| 119 | | interface | implemented | not implemented | | 119 | | interface | implemented | not implemented | |
| 120 | |---|---|---| | 120 | |---|---|---| |
| 121 | | `IGameInput` | `GetCurrentTimestamp` (µs), `GetCurrentReading`, `GetNextReading`, `RegisterReadingCallback`, `RegisterDeviceCallback` (blocking and async enumeration), `RegisterGuideButtonCallback`, `RegisterKeyboardLayoutCallback` (never fires), `StopCallback`, `UnregisterCallback`, `CreateDispatcher`, `FindDeviceFromId`, `EnableOemDeviceSupport` (no-op), `SetFocusPolicy` (no-op) | `GetPreviousReading` and `GetTemporalReading` (no history kept), `CreateAggregateDevice`, `FindDeviceFromObject/PlatformHandle/PlatformString` | | 121 | | `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` | |
| 122 | | `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) | | 122 | | `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) | |
| 123 | | `IGameInputDevice` | device info, status, battery, `SetRumbleState` | force feedback and haptic motors (none reported), raw device I/O, power off, input synchronization (no-ops) | | 123 | | `IGameInputDevice` | device info, status, battery, `SetRumbleState` | force feedback and haptic motors (none reported), raw device I/O, power off, input synchronization (no-ops) | |
| 124 | | `IGameInputDispatcher` | `Dispatch`, `OpenWaitHandle` | the quota (the queue is short) | | 124 | | `IGameInputDispatcher` | `Dispatch`, `OpenWaitHandle` | the quota (the queue is short) | |
| @@ -127,6 +127,32 @@ A device object stays alive for the whole process. When a pad is unplugged its s | |||
| 127 | `GameInputDeviceNoStatus` and its device callback runs; when the same pad is plugged in again (matched by SDL GUID and | 127 | `GameInputDeviceNoStatus` and its device callback runs; when the same pad is plugged in again (matched by SDL GUID and |
| 128 | serial or device path) the title gets the same object back, connected again. | 128 | serial or device path) the title gets the same object back, connected again. |
| 129 | 129 | ||
| 130 | ## Reading history | ||
| 131 | |||
| 132 | Each pad keeps the readings the poll took for it, one per change it saw, so `GetNextReading` and `GetPreviousReading` | ||
| 133 | can step through input the title has not read yet, such as a button pressed and released between two of its frames. | ||
| 134 | A reading leaves the history once the reading after it is more than 500 ms old, so the current state stays reachable | ||
| 135 | however long the pad then idles. A pad keeps at most 512 readings, and none once it is unplugged. A reading the title | ||
| 136 | holds stays valid after it leaves the history. | ||
| 137 | |||
| 138 | - With a device the search covers that pad; with none, every connected pad. Readings of different pads are ordered by | ||
| 139 | when the shim took them, not by timestamp, since pads polled together share one. | ||
| 140 | - `GetNextReading` returns the first reading after the reference, `GetPreviousReading` the last one before it. | ||
| 141 | - The horizon is the newest reading dropped from the histories searched (with no device, the reference's pad counts | ||
| 142 | too, even unplugged). A step that would cross it fails rather than skip input. | ||
| 143 | |||
| 144 | | situation | result | | ||
| 145 | |---|---| | ||
| 146 | | output null; reference null | `E_POINTER`; `E_INVALIDARG` | | ||
| 147 | | no supported kind in the mask | `GAMEINPUT_E_READING_NOT_FOUND` | | ||
| 148 | | the device given is unplugged | `GAMEINPUT_E_DEVICE_DISCONNECTED` | | ||
| 149 | | next: the horizon is after the reference; previous: it is not before it | `GAMEINPUT_E_REFERENCE_READING_TOO_OLD` | | ||
| 150 | | nothing newer, or nothing older after the horizon | `GAMEINPUT_E_READING_NOT_FOUND` | | ||
| 151 | |||
| 152 | After a pad is plugged back in, its last reading before the unplug leads to the reconnect snapshot, older ones are | ||
| 153 | `REFERENCE_READING_TOO_OLD`, and sequence numbers carry on. Timestamps are poll times, so a change shorter than one poll | ||
| 154 | (2 ms with the thread) is not seen. | ||
| 155 | |||
| 130 | ## ABI | 156 | ## ABI |
| 131 | 157 | ||
| 132 | `runtime/shims/gameinput_abi.h` declares the v0 GameInput API as Leonida's own code: the interfaces in vtable order, | 158 | `runtime/shims/gameinput_abi.h` declares the v0 GameInput API as Leonida's own code: the interfaces in vtable order, |
| @@ -141,7 +167,9 @@ shim fills (`GameInputDeviceInfo` 320 bytes with `deviceFamily` at 96 and the in | |||
| 141 | - `gameinput_test` (CTest, no controller): turns SDL's real backends off and drives the shim through | 167 | - `gameinput_test` (CTest, no controller): turns SDL's real backends off and drives the shim through |
| 142 | `rt::shims::find` with SDL virtual joysticks, an Xbox-style pad with trigger motors, a DualSense (Sony | 168 | `rt::shims::find` with SDL virtual joysticks, an Xbox-style pad with trigger motors, a DualSense (Sony |
| 143 | `054c:0ce6`) and a pad without trigger motors. It checks enumeration and device callbacks, the button, stick, | 169 | `054c:0ce6`) and a pad without trigger motors. It checks enumeration and device callbacks, the button, stick, |
| 144 | trigger and UI-navigation mapping, reading callbacks and sequence numbers, the guide button, motor and trigger | 170 | trigger and UI-navigation mapping, reading callbacks and sequence numbers, the reading history (a tap read after |
| 171 | the fact, both directions, two pads interleaved and filtered by device, ageing out, held readings, unplug and | ||
| 172 | replug), the guide button, motor and trigger | ||
| 145 | rumble as SDL receives them, the DualSense effect bytes in each `LEONIDA_DS_TRIGGERS` mode, the lightbar, a | 173 | rumble as SDL receives them, the DualSense effect bytes in each `LEONIDA_DS_TRIGGERS` mode, the lightbar, a |
| 146 | dispatcher, async and blocking enumeration, unregistering, and unplugging and replugging. | 174 | dispatcher, async and blocking enumeration, unregistering, and unplugging and replugging. |
| 147 | - `gameinput_probe [--seconds N] [--rumble]` (by hand, with a pad connected): lists the pads, plays each motor and | 175 | - `gameinput_probe [--seconds N] [--rumble]` (by hand, with a pad connected): lists the pads, plays each motor and |
| @@ -155,9 +183,9 @@ These need the game executable or a test on hardware: | |||
| 155 | and `xgameruntime.dll`. GameInput v1 and later (NuGet 1.x and up) changed the interfaces; if the executable was | 183 | and `xgameruntime.dll`. GameInput v1 and later (NuGet 1.x and up) changed the interfaces; if the executable was |
| 156 | built against one of those, the vtables need a second set. | 184 | built against one of those, the vtables need a second set. |
| 157 | - **IIDs.** `QueryInterface` answers the v0 IIDs from the public header. | 185 | - **IIDs.** `QueryInterface` answers the v0 IIDs from the public header. |
| 158 | - **Reading history.** `GetNextReading` returns the newest reading when it is newer than the reference, and | 186 | - **Reading history.** Microsoft's [next reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading) |
| 159 | `GetPreviousReading` has no history. A title that replays every input frame between two polls would miss the | 187 | and [previous reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading) pages describe half a second of readings per device and failure when old readings leave the stream. The table above records the shim's HRESULT choices. Changes faster than the poll are not seen, and |
| 160 | intermediate states. | 188 | `GetTemporalReading` is not implemented. |
| 161 | - **UI navigation mapping** and the **controller-axis convention** (0..1 with sticks at 0.5) are this shim's choice, | 189 | - **UI navigation mapping** and the **controller-axis convention** (0..1 with sticks at 0.5) are this shim's choice, |
| 162 | not measured from a console. | 190 | not measured from a console. |
| 163 | - **Battery capacity** is reported as a fraction (remaining 0..1 of full 1), not in device units. | 191 | - **Battery capacity** is reported as a fraction (remaining 0..1 of full 1), not in device units. |