upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/gameinput.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/gameinput.md')
-rw-r--r--docs/gameinput.md53
1 files changed, 52 insertions, 1 deletions
diff --git a/docs/gameinput.md b/docs/gameinput.md
index fa216a2ee..90e0a3d2e 100644
--- a/docs/gameinput.md
+++ b/docs/gameinput.md
@@ -8,7 +8,12 @@ the lightbar colour can be set.
8 8
9Without the shim the loader would bind `GameInputCreate` to the host's `GameInput.dll` if there is one 9Without the shim the loader would bind `GameInputCreate` to the host's `GameInput.dll` if there is one
10([#279](https://github.com/ItsNotRexed/Leonida/pull/279)). That works for Xbox pads only, and gives no DualSense 10([#279](https://github.com/ItsNotRexed/Leonida/pull/279)). That works for Xbox pads only, and gives no DualSense
11features. The game executable is not available yet, so whether it imports GameInput this way, and under which 11features. That path is tested without the game: `gameinput_host_test` (ctest `gameinput_host`) maps a synthetic DLL
12built against the SDK's `gameinput.lib` and checks that its `GameInput.dll` import binds to the host's copy, that
13`GameInputCreate` and `GetCurrentTimestamp` work from mapped code, and that `GetCurrentReading` answers; with a pad
14attached, `GetGamepadState` must succeed on the reading. It passes on Windows 11 build 26300 (GameInput 0.2309) without
15a pad attached. The test skips only where Windows cannot load `GameInput.dll`; with the DLL present, an import that binds to nothing fails it. The game executable is not available yet,
16so whether it imports GameInput this way, and under which
12module, is unverified (see [VERIFY](#verify)). 17module, is unverified (see [VERIFY](#verify)).
13 18
14## Building 19## Building
@@ -240,6 +245,39 @@ sensors are enabled when the pad is opened, at SDL's requested rate, and every p
240 reading history cap bound the cost. 245 reading history cap bound the cost.
241- `gameinput_probe` prints the accel and gyro fractions when the pad has sensors (a resting pad shows ~0.5 g). 246- `gameinput_probe` prints the accel and gyro fractions when the pad has sensors (a resting pad shows ~0.5 g).
242 247
248## Active input
249
250The title is told that every pad is an Xbox One pad, so it cannot know what the player is holding. The shim keeps
251that record itself, for the runtime's own use, such as button prompt glyphs that follow the device in use:
252`rt::gameinput::active_input()` returns the family of the device used last, a generation that goes up by one with each
253change, and whether `LEONIDA_PROMPTS` forced it. It needs no lock and can be read from any thread, every frame.
254
255| SDL gamepad type | family |
256|---|---|
257| `PS5` (DualSense, DualSense Edge) | PlayStation 5 |
258| `PS4` (DualShock 4) | PlayStation 4 |
259| `PS3` (DualShock 3) | PlayStation 3 |
260| `NINTENDO_SWITCH_PRO`, the Joy-Con types | Nintendo |
261| the [keyboard pad](#keyboard-pad) | keyboard and mouse |
262| everything else (Xbox One/Series, Xbox 360, generic, unknown) | Xbox |
263
264SDL takes the type from the pad's vendor and product id. Only deliberate input changes the answer
265(`runtime/src/active_input.h`, tested by `active_input_test` without SDL):
266
267- an edge: a button going down (any of SDL's, the DualSense touchpad included), a trigger rising past 0.3, or a stick
268 leaving a radius of 0.35. A held button, trigger or stick, stick drift inside the radius and analog noise never
269 count. The mouse moves the keyboard pad's right stick, so a real mouse movement counts through the same rule and a
270 jitter of a count or two does not;
271- a pad's first reading after it connects is its baseline, so connecting a pad with a button held, or with a worn
272 stick resting past the radius, changes nothing;
273- after a change, the next one waits `LEONIDA_PROMPTS_SWITCH_MS` (300 ms by default). Input from another family inside
274 that time is ignored, not queued, so two devices used at once cannot make the answer flicker;
275- input from a second device of the family already in use changes nothing.
276
277Before the first deliberate input the answer is Xbox. Each change logs one line, for example
278`input in use: PlayStation 5 (DualSense Wireless Controller, button press)`. `LEONIDA_PROMPTS` forces a family (a
279line is logged when it takes effect); tracking goes on underneath, so clearing it returns at once to the device in use.
280
243## Environment variables 281## Environment variables
244 282
245| variable | default | effect | 283| variable | default | effect |
@@ -249,6 +287,8 @@ sensors are enabled when the pad is opened, at SDL's requested rate, and every p
249| `LEONIDA_DS_TRIGGER_FREQ` | `30` | vibration frequency of the `rumble` mode, 1..255 | 287| `LEONIDA_DS_TRIGGER_FREQ` | `30` | vibration frequency of the `rumble` mode, 1..255 |
250| `LEONIDA_DS_LIGHTBAR` | unset | `RRGGBB` (hex) sets the DualSense/DualShock 4 lightbar when the pad connects; `off` turns it dark; unset keeps SDL's player colour | 288| `LEONIDA_DS_LIGHTBAR` | unset | `RRGGBB` (hex) sets the DualSense/DualShock 4 lightbar when the pad connects; `off` turns it dark; unset keeps SDL's player colour |
251| `LEONIDA_RUMBLE` | `1` | `0` turns all rumble, trigger and force-feedback output off | 289| `LEONIDA_RUMBLE` | `1` | `0` turns all rumble, trigger and force-feedback output off |
290| `LEONIDA_PROMPTS` | `auto` | forces the [active input](#active-input) family: `xbox`, `playstation` (or `ps5`), `ps4`, `ps3`, `nintendo` or `keyboard`; `auto` follows the devices |
291| `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms |
252| `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | 292| `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) |
253| `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | 293| `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus |
254| `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | 294| `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 |
@@ -276,6 +316,8 @@ The API surface:
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) | 316| `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) |
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) | 317| `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) |
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) | 318| `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) |
319| `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) |
320| `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) |
279| `IGameInputDispatcher` | `Dispatch` (with its quota), `OpenWaitHandle` | | 321| `IGameInputDispatcher` | `Dispatch` (with its quota), `OpenWaitHandle` | |
280 322
281`CreateAggregateDevice` takes exactly one of the keyboard, mouse, gamepad, arcade stick, flight stick or racing wheel 323`CreateAggregateDevice` takes exactly one of the keyboard, mouse, gamepad, arcade stick, flight stick or racing wheel
@@ -391,6 +433,12 @@ rests on a transcription rather than on a side-by-side compile.
391 433
392## Tests 434## Tests
393 435
436- `active_input_test` (CTest, no SDL): the [active input](#active-input) tracker's rules on synthetic samples with
437 its own clock. `gameinput_test` runs them on a DualSense, a DualShock 4 (Sony `054c:09cc`), an Xbox pad and the
438 keyboard pad: no change when pads connect (one with a button held) or a held button is let go, each family by a
439 button, the touchpad, a trigger or a stick, stick drift and a one-count mouse jitter ignored, a real mouse movement
440 counted, the 300 ms window on the real clock, and `LEONIDA_PROMPTS` forcing, changing, ignoring an unknown value
441 and clearing.
394- `gameinput_test` (CTest, no controller): turns SDL's real backends off and drives the shim through 442- `gameinput_test` (CTest, no controller): turns SDL's real backends off and drives the shim through
395 `rt::shims::find` with SDL virtual joysticks, an Xbox-style pad with trigger motors, a DualSense (Sony 443 `rt::shims::find` with SDL virtual joysticks, an Xbox-style pad with trigger motors, a DualSense (Sony
396 `054c:0ce6`) and a pad without trigger motors. It checks enumeration and device callbacks, the button, stick, 444 `054c:0ce6`) and a pad without trigger motors. It checks enumeration and device callbacks, the button, stick,
@@ -446,6 +494,9 @@ These need the game executable or a test on hardware:
446 `GameInputMotionAccuracyUnknown`; whether a title wants a synthesised quaternion there is unknown. 494 `GameInputMotionAccuracyUnknown`; whether a title wants a synthesised quaternion there is unknown.
447- **Device family**: every pad is reported as `GameInputFamilyXboxOne`; a title that filters on family sees only 495- **Device family**: every pad is reported as `GameInputFamilyXboxOne`; a title that filters on family sees only
448 that. 496 that.
497- **Active input behind Steam Input**: when Steam turns a PlayStation pad into a virtual Xbox pad, SDL may report the
498 virtual one's type, and the active input then says Xbox; `LEONIDA_PROMPTS` is the way round it until that is
499 checked on a real setup.
449- **Identical pads at start**: twins are numbered in the order the shim opens them. For pads already connected when 500- **Identical pads at start**: twins are numbered in the order the shim opens them. For pads already connected when
450 it starts, that is SDL's enumeration order, not measured on Windows for identical pads; if it varies between runs, 501 it starts, that is SDL's enumeration order, not measured on Windows for identical pads; if it varies between runs,
451 so does which pad gets which id. 502 so does which pad gets which id.