diff options
| author | MoonEyes <14891700+MoonEyes@users.noreply.github.com> | 2026-11-28 21:25:16 +0100 |
|---|---|---|
| committer | MoonEyes <14891700+MoonEyes@users.noreply.github.com> | 2026-11-28 21:25:16 +0100 |
| commit | 2f99fd2caed4524217306d19c40801e7c9dafedc (patch) | |
| tree | e8284cbe62e68a459a795e29fb40b311808eb58d /docs/gameinput.md | |
| parent | 9a96b8ba6aaf2fc8ed3f3ad5177d0e3f420dc62c (diff) | |
| parent | 30fc2d68cc509ae9eeb2e39a900dbe1a98b2e745 (diff) | |
Merge main into carry/old-9966 (resolve conflict in runtime/test/gameinput_test.cpp)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'docs/gameinput.md')
| -rw-r--r-- | docs/gameinput.md | 218 |
1 files changed, 209 insertions, 9 deletions
diff --git a/docs/gameinput.md b/docs/gameinput.md index 291d8fb59..a942f01ee 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md | |||
| @@ -55,10 +55,13 @@ scripted pad, driven by the script alone: | |||
| 55 | shim, or through `IGameInputDispatcher::Dispatch` once the title made a dispatcher) and found by `FindDeviceFromId`. | 55 | shim, or through `IGameInputDispatcher::Dispatch` once the title made a dispatcher) and found by `FindDeviceFromId`. |
| 56 | It is already connected, so a callback registered without enumeration hears nothing. | 56 | It is already connected, so a callback registered without enumeration hears nothing. |
| 57 | - **The readings:** `GetCurrentReading`, `GetNextReading` and `GetPreviousReading`, with gamepad, UI navigation, | 57 | - **The readings:** `GetCurrentReading`, `GetNextReading` and `GetPreviousReading`, with gamepad, UI navigation, |
| 58 | controller axis and controller button state. A reading is taken when the title asks for one and the script's state | 58 | controller axis and controller button state. A reading is taken when the title asks for one, so no thread polls, |
| 59 | has changed since the last, so no thread polls; the history keeps the last 64 readings. | 59 | but it first adds one reading for every change the script made since the last, stamped with the script's own time: |
| 60 | a press that starts and ends between two reads of the title is still in the history, where `GetNextReading` finds | ||
| 61 | it, and the readings are the same however often the title reads. The history keeps the last 64 readings. | ||
| 60 | - **The timeline:** the same as with SDL3 (`runtime/shims/gameinput_script.h` holds the parser, the timeline and the | 62 | - **The timeline:** the same as with SDL3 (`runtime/shims/gameinput_script.h` holds the parser, the timeline and the |
| 61 | log lines for both): seconds from the first `GameInputCreate`, each press held 300 ms, then released. | 63 | log lines for both): seconds from the first `GameInputCreate`, each press held 300 ms (or its own `:hold`, see |
| 64 | `LEONIDA_INPUT_SCRIPT` below), then released. | ||
| 62 | - **Not served:** reading callbacks, aggregate devices, rumble and every other device. Those slots answer `E_NOTIMPL` | 65 | - **Not served:** reading callbacks, aggregate devices, rumble and every other device. Those slots answer `E_NOTIMPL` |
| 63 | and log the slot once. Controllers and the [keyboard pad](#keyboard-pad) still need SDL3. | 66 | and log the slot once. Controllers and the [keyboard pad](#keyboard-pad) still need SDL3. |
| 64 | 67 | ||
| @@ -70,10 +73,17 @@ The start of the run logs one line with the counts, and each press logs the same | |||
| 70 | [rt] gameinput: press a@40.0 (Scripted pad (Leonida)) | 73 | [rt] gameinput: press a@40.0 (Scripted pad (Leonida)) |
| 71 | ``` | 74 | ``` |
| 72 | 75 | ||
| 73 | A press is logged when the title reads it, so a press the title never reads is not logged. `LEONIDA_INPUT_LOG=0` | 76 | A press is logged at the next reading the title asks for, with the script's time of the press, so a press is logged |
| 74 | turns the `press` lines off. Without `LEONIDA_INPUT_SCRIPT`, the shim serves no devices and answers `E_NOTIMPL` for | 77 | once the title reads its pad again. `LEONIDA_INPUT_LOG=0` turns the `press` lines off. `LEONIDA_INPUT_TRACE=1` |
| 78 | (diagnostic, this shim only) logs what the title asks for: the first 128 `GetCurrentReading`, `GetNextReading` and | ||
| 79 | `GetPreviousReading` calls, then every one that returns a pressed button and every 1000th, the device callbacks and | ||
| 80 | `RegisterDeviceCallback` calls, and the first few calls of each reading method. Without `LEONIDA_INPUT_SCRIPT`, the shim serves no devices and answers `E_NOTIMPL` for | ||
| 75 | every slot past `Release`, as before. | 81 | every slot past `Release`, as before. |
| 76 | 82 | ||
| 83 | `LEONIDA_INPUT_FILE=<path>` drives a run whose display takes no keyboard input (a headless session): every line | ||
| 84 | appended to that file names one button of the script's table (`a`, `down`, ...) and becomes a press at once, held | ||
| 85 | like a scripted one. The file is read again at most every 250 ms. It is for local runs only. | ||
| 86 | |||
| 77 | `scripts/build_runtime.ps1` (what `make_game.py` runs) builds the shim only on its CMake path, when Visual Studio's | 87 | `scripts/build_runtime.ps1` (what `make_game.py` runs) builds the shim only on its CMake path, when Visual Studio's |
| 78 | C++ CMake tools are installed. Its direct-`cl.exe` fallback compiles a fixed file list without the shim and warns | 88 | C++ CMake tools are installed. Its direct-`cl.exe` fallback compiles a fixed file list without the shim and warns |
| 79 | about it. | 89 | about it. |
| @@ -113,7 +123,8 @@ The title reads gamepads only, so keyboard input has to arrive as a gamepad. Wit | |||
| 113 | shim attaches one SDL virtual gamepad named `Keyboard pad (Leonida)` and presses its buttons from the keyboard on | 123 | shim attaches one SDL virtual gamepad named `Keyboard pad (Leonida)` and presses its buttons from the keyboard on |
| 114 | every poll. It then goes through the same path as a real pad: a device object, the next free player slot, readings, | 124 | every poll. It then goes through the same path as a real pad: a device object, the next free player slot, readings, |
| 115 | reading and device callbacks, and UI navigation derived from its buttons. It reports no rumble motors. It is off by | 125 | reading and device callbacks, and UI navigation derived from its buttons. It reports no rumble motors. It is off by |
| 116 | default. | 126 | default. If SDL fails to attach or open the keyboard pad, the shim retries after one second while the pad is |
| 127 | enabled. Only the first failure in a continuous series is logged; turning the pad off and back on retries immediately. | ||
| 117 | 128 | ||
| 118 | | key | button | | 129 | | key | button | |
| 119 | |---|---| | 130 | |---|---| |
| @@ -152,7 +163,9 @@ sensor, about a pixel at Windows' default pointer speed without acceleration, so | |||
| 152 | 163 | ||
| 153 | With raw input on and a window of this process in the foreground, the cursor is kept inside that window's client | 164 | With raw input on and a window of this process in the foreground, the cursor is kept inside that window's client |
| 154 | area (`ClipCursor`, re-applied every 100 ms) so that a click cannot land on another window; it is released when focus | 165 | area (`ClipCursor`, re-applied every 100 ms) so that a click cannot land on another window; it is released when focus |
| 155 | moves away or the keyboard pad is turned off. The cursor stays visible: hiding it has to happen on the thread that | 166 | moves away or the keyboard pad is turned off. It is also released while the window is moved or sized, while a |
| 167 | menu loop runs, and while a mouse press that began outside the client area (on the title bar or a border) is held, so | ||
| 168 | the window can still be dragged; it comes back once the button is released. The cursor stays visible: hiding it has to happen on the thread that | ||
| 156 | owns the game's window, which is the title's, not the shim's. | 169 | owns the game's window, which is the title's, not the shim's. |
| 157 | 170 | ||
| 158 | Keys are read with `GetAsyncKeyState`, which needs no window or message loop (SDL's keyboard is part of its video | 171 | Keys are read with `GetAsyncKeyState`, which needs no window or message loop (SDL's keyboard is part of its video |
| @@ -173,6 +186,189 @@ afresh on return so the right stick does not jump. Scripted presses run with or | |||
| 173 | 186 | ||
| 174 | To try it by hand: `set LEONIDA_KEYBOARD_PAD=always`, then `gameinput_probe --seconds 20` and press keys. | 187 | To try it by hand: `set LEONIDA_KEYBOARD_PAD=always`, then `gameinput_probe --seconds 20` and press keys. |
| 175 | 188 | ||
| 189 | ## The keyboard-and-mouse pad of the D3D12 runtime | ||
| 190 | |||
| 191 | The D3D12 runtime (`d3d12/`) has its own GameInput module (`d3d12/crates/leonida-hle/src/modules/gameinput.rs`) | ||
| 192 | with a stand-in pad made from the keyboard and mouse, present while no host pad is connected (or beside one, with | ||
| 193 | `LEONIDA_ONE_PAD`, the default). Keys and mouse buttons count only while a window of the runtime has focus. | ||
| 194 | |||
| 195 | ### Grand Theft Auto V's layout: one table on foot, one in a vehicle | ||
| 196 | |||
| 197 | The title reads a pad only, and on a pad one button is two actions: the right trigger shoots on foot and accelerates | ||
| 198 | in a vehicle, the left trigger aims and brakes. One table of keys cannot be a PC layout then, so there are two | ||
| 199 | (`gameinput/kbm.rs`), and the stand-in pad uses the one of what the player is in. The keys are Grand Theft Auto V's | ||
| 200 | PC defaults (its key bindings as listed in BisectHosting's "GTA V controls guide" and on StrategyWiki's controls | ||
| 201 | page). The pad button of each action is the title's default pad layout as far as it is known: the table below is the | ||
| 202 | one that came with the PC prompt glyphs (a contributor's notes on the Xbox layout), not measured here. | ||
| 203 | |||
| 204 | | pad | on foot | in a vehicle | | ||
| 205 | |---|---|---| | ||
| 206 | | left stick, click | move, run | steer (lean on a bike), horn | | ||
| 207 | | right stick, click | camera, look behind (zoom while aiming) | camera, look behind | | ||
| 208 | | A / B / X / Y | jump and climb / crouch / melee and reload / interact, enter a vehicle | handbrake / duck, headlights / not known / leave the vehicle | | ||
| 209 | | LB / RB | loadout wheel, holster / cover | loadout wheel / shoot from the vehicle | | ||
| 210 | | LT / RT | aim / shoot | brake and reverse / accelerate | | ||
| 211 | | d-pad up, down, left, right | phone, HUD and objective, radio menu, partner menu | the same | | ||
| 212 | | Menu / View | pause / map | the same | | ||
| 213 | |||
| 214 | | key | on foot | in a vehicle | | ||
| 215 | |---|---|---| | ||
| 216 | | W, S | left stick up, down: move | RT, LT (fully): accelerate, brake and reverse | | ||
| 217 | | A, D | left stick left, right: move | the same: steer | | ||
| 218 | | mouse | right stick: camera (mouse look, below) | the same | | ||
| 219 | | left mouse button | RT: shoot | RB: shoot from the vehicle | | ||
| 220 | | right mouse button | LT: aim | nothing (the button that aims from a vehicle is not known) | | ||
| 221 | | Space | A: jump, climb | A: handbrake | | ||
| 222 | | Left Shift | left stick click: run | left stick up: lean forward on a bike, nose down in an aircraft | | ||
| 223 | | Left Ctrl | B: crouch (GTA V's stealth) | left stick down: lean back, nose up | | ||
| 224 | | Num 8, Num 5, Num 4, Num 6 | nothing | left stick up, down, left, right (GTA V's aircraft keys) | | ||
| 225 | | Q | RB: cover | d-pad left: radio menu (GTA V's radio wheel) | | ||
| 226 | | E | Y: interact (GTA V's context action) | left stick click: horn | | ||
| 227 | | F | Y: enter a vehicle | Y: leave it | | ||
| 228 | | R | X: reload, melee | X (the same button; GTA V's cinematic camera has none known) | | ||
| 229 | | X, H | nothing | B: duck, headlights | | ||
| 230 | | Tab | LB: loadout wheel (hold), holster | LB | | ||
| 231 | | C | right stick click: look behind | the same | | ||
| 232 | | M | View: map | the same | | ||
| 233 | | Esc, P | Menu: pause | the same | | ||
| 234 | | arrows | d-pad: phone (up) and its menus | the same | | ||
| 235 | | Enter, Backspace | A, B: accept and back in the phone and menus | the same | | ||
| 236 | | Z | d-pad down: HUD and objective (GTA V's radar zoom, the same press on its pad) | the same | | ||
| 237 | | Y; I J K L | Y; right stick (kept from the layout before; GTA V has nothing on them on foot) | the same | | ||
| 238 | |||
| 239 | GTA V keys left without a binding, because the title's pad button for the action is not known: V (camera view), G | ||
| 240 | (grenade; landing gear), O (heavy melee), the number keys (weapon slots), `[` `]` `,` `.` `=` `-` (zoom, radio), T, B, | ||
| 241 | N, the F keys (character switch), Insert, Page Up and Page Down, the middle mouse button, and Caps Lock (GTA V's | ||
| 242 | special ability), which is the switch described below. Left Alt (GTA V's character switch) would be the partner | ||
| 243 | menu, d-pad right, and is left out because every Alt+Tab would press it; the right arrow is that button. For the | ||
| 244 | same reason Tab, Enter, Space and Esc give nothing while an Alt key is down. The mouse wheel (GTA V's next and previous weapon, and zoom | ||
| 245 | while aiming) is not bound either: the pad has no button known for the next weapon, and the host source polls key | ||
| 246 | states (`GetAsyncKeyState`), which a wheel does not have; it would have to be counted from `WM_MOUSEWHEEL` in the | ||
| 247 | window procedure of `lifecycle.rs`. The layout before had Z and V as the triggers, X as X, H as a second right stick | ||
| 248 | click and Left Ctrl as a second left stick click; those went where GTA V has another meaning for the key. | ||
| 249 | `LEONIDA_KBM=classic` brings the table of before back whole (`FALLBACK_BUTTONS`: W A S D and I J K L the sticks, | ||
| 250 | Space or Enter A, R or Backspace B, X, F or Y, Q and E the shoulders, Left Shift or Left Ctrl and C or H the stick | ||
| 251 | clicks, Z or the right mouse button LT, V or the left mouse button RT, Esc Menu, Tab View). | ||
| 252 | |||
| 253 | In an aircraft A and D are the left stick (roll), not GTA V's rudder: only "in a vehicle" is known, not which kind. | ||
| 254 | |||
| 255 | ### Which table counts | ||
| 256 | |||
| 257 | `gameinput::set_player_context(OnFoot | InVehicle | Unknown)` tells the stand-in pad, lock-free from any thread; a | ||
| 258 | context that is not set again for 500 ms is unknown (and the pad only lets go of a known one after 100 ms of | ||
| 259 | unknown). Unknown is the on-foot table, and then **Caps Lock** switches to the driving table and back by hand, with a | ||
| 260 | line in the log at every change of table; driving by hand also ends when F (leave the vehicle) is pressed, so that W | ||
| 261 | cannot stay the right trigger on foot. While a context is measured Caps Lock does nothing: it is GTA V's special | ||
| 262 | ability key, and a press out of habit on foot must not make W a shot. `gameinput::driving_controls()` says which | ||
| 263 | table is in use (for whoever draws key prompts). | ||
| 264 | |||
| 265 | **The hand-over** when the table changes: a key that is another pad input in the other table (W, S, the mouse buttons, | ||
| 266 | Left Shift, Left Ctrl, Q, E, X, H) and is down at that moment gives nothing until it has been let go and pressed | ||
| 267 | again, and no such key gives anything for 400 ms after the change (`LEONIDA_KBM_SETTLE_MS`, 0 to 3000). So the left | ||
| 268 | mouse button held on foot never becomes the accelerator and W held in a car never becomes a shot; the price is that W | ||
| 269 | held while getting in has to be pressed again to drive off. Keys that are the same pad input in both tables (A, D, | ||
| 270 | Space, F, ...) carry over as a real pad's button would. Unit-tested over every set of held keys in both directions | ||
| 271 | (`cargo test -p leonida-hle gameinput`). | ||
| 272 | |||
| 273 | **Who tells.** `d3d12/apps/leonida/src/player_context.rs` reads the title every 16 ms from a thread of its own | ||
| 274 | (`ReadProcessMemory` on the own process: nothing is written and no title code is called, so it does not need | ||
| 275 | `LEONIDA_GAME_ACTIONS=1`; without the game actions it looks the two globals up itself at start, two more passes over | ||
| 276 | the image's code, about 0.15 s together on the retail executable's 99.9 MB of code). It tells `Unknown` while there is no player ped, and a change counts after three equal reads. What | ||
| 277 | says "in a vehicle" is, in this order: | ||
| 278 | |||
| 279 | 1. `LEONIDA_PED_VEHICLE_AT=0x<offset>`: a field of the player's ped that points at its vehicle and is null on foot. | ||
| 280 | None is known (see below why there may be none), so this is unset by default. | ||
| 281 | 2. The title's own global of the player's vehicle (`Site::PlayerVehicle` in `leonida-loader/src/game_actions.rs`, | ||
| 282 | found by a pattern that is in the 1.0.2.1 executable once; `LEONIDA_PLAYER_VEHICLE_AT=0x<offset in the image>` | ||
| 283 | names another, `=off` turns it off). **Read from the code, not yet seen in the running title:** | ||
| 284 | - The title keeps what belongs to a ped apart from the ped's entity, in tables looked up by the entity's id | ||
| 285 | (`+9Ch`; a ped's id has `60000h` under the mask `3E0000h`, its index is the low 17 bits, and a 16-bit slot of | ||
| 286 | `FFFFh` means "none"). Its "the vehicle this ped is in" (the function at `4DD7510h`) takes column `47h` of | ||
| 287 | those tables and gives the pointer at `+898h` of it when bit `20h` of the byte at `+10h` is set, else null: the | ||
| 288 | shape of GTA V's `GetVehiclePedInside`, a "my vehicle" pointer that outlives the ride plus a flag. That is why a | ||
| 289 | pointer in the ped that is null on foot may not exist at all. | ||
| 290 | - The global at `AB760C8h` is written by one function (`CA4DE0h`), which has three callers: one passes a | ||
| 291 | vehicle (in a function of 129Fh bytes, taken to be where a ped is put in a vehicle), one passes null after | ||
| 292 | testing that the ped's id is the player's (taken to be where a ped is taken out), and the function that sets | ||
| 293 | the player's ped passes what `4DD7510h` gives for the new ped. The first two are methods of that same column | ||
| 294 | `47h` record: the first begins by reading its `+10h` and `+898h` and testing bit `20h`, the second tests | ||
| 295 | other bits beside it (`+12h`). 167 places in the code read the global; the vehicle cheats read a type byte | ||
| 296 | at `+FAh` of what it points at. | ||
| 297 | - Not known until it has run: that it is null in every on-foot state (after a crash through the windscreen, a | ||
| 298 | vehicle that blows up, a cutscene), and when during getting in and out it changes compared with the title's own | ||
| 299 | switch of its controls. The reader logs every change with its time, and warns when the ped moves at 12 m/s for | ||
| 300 | a second while it says "on foot", or the vehicle is 60 m from the ped while it says "in a vehicle". | ||
| 301 | 3. `LEONIDA_KBM_SPEED=1`: the speed rule. From the ped's position (taken every 0.2 s): 12 m/s (43 km/h; a sprint is | ||
| 302 | about 7) or more for a second without a break is "in a vehicle", until 3 s have passed below that speed; a fall | ||
| 303 | (more down than along) and a jump of the position (a teleport, a respawn) do not count. Its limits are why it is | ||
| 304 | off unless asked for: it never says "on foot" (a car at a red light and a ped standing are the same to it), it | ||
| 305 | cannot see a drive begin, so it never switches from a standstill and the first metres of every drive are on the | ||
| 306 | on-foot keys, and so the meaning of W and of the mouse buttons would change in the middle of a drive, at every | ||
| 307 | stop. It always runs as the check named above. | ||
| 308 | |||
| 309 | With none of the three the context stays unknown: the on-foot table, and Caps Lock. | ||
| 310 | |||
| 311 | | switch | effect | | ||
| 312 | |---|---| | ||
| 313 | | `LEONIDA_KBM=classic` | the single table of before; nothing reads the title | | ||
| 314 | | `LEONIDA_KBM_DRIVE=on` / `off` / `auto` | forces the driving table on or off (a test; nothing reads the title and Caps Lock does nothing then); `auto` is the default | | ||
| 315 | | `LEONIDA_KBM_SETTLE_MS=<ms>` | the pause after a change of table, 400 | | ||
| 316 | | `LEONIDA_PED_VEHICLE_AT`, `LEONIDA_PLAYER_VEHICLE_AT`, `LEONIDA_KBM_SPEED` | what says "in a vehicle", above | | ||
| 317 | | `LEONIDA_PED_DUMP=<folder>` | for measuring: F8 in the game's window, or a file named `dump` in that folder (its text is the label), writes the first 4000h bytes of the player's ped to `ped-<date>-<time>-<label>.bin`, the first 1000h of the vehicle the global names to `vehicle-...bin`, and a line to `index.txt` (time, addresses, the ped's id, position, speed, what was read). The folder must be outside the repository; the files are the title's memory and are never committed. | | ||
| 318 | |||
| 319 | The mouse buttons are not passed to the title while the F1 settings menu or the F4 trainer menu is open, and they | ||
| 320 | never reach the title as keyboard keys. | ||
| 321 | |||
| 322 | **Mouse look (D3D12 runtime).** The console title turns its camera with the right stick only; it does not read the | ||
| 323 | mouse for that. A left click in the game window makes the window hold the mouse: the cursor is hidden and kept in the | ||
| 324 | window, and the mouse's motion becomes a right-stick push (`MouseLook` in `d3d12/crates/leonida-hle/src/modules/ | ||
| 325 | gameinput.rs`): its speed over the last 40 ms, a full push at 1600 pixels a second, lifted past a 0.24 dead zone with a | ||
| 326 | 0.6 power curve, merged with the pad's own stick. That click is not a shot; the mouse buttons reach the title as | ||
| 327 | triggers only while the window holds the mouse. Esc (which also pauses), the F1 or F4 menu, or another window in front | ||
| 328 | gives the mouse back. Settings: `LEONIDA_MOUSE_SENSITIVITY` (1, 0.1..10), `LEONIDA_MOUSE_INVERT_Y=1`, | ||
| 329 | `LEONIDA_MOUSE_DEADZONE` (0.24), `LEONIDA_MOUSE_CURVE` (0.6), `LEONIDA_MOUSE_LOOK=0` (off: the old behaviour, buttons | ||
| 330 | whenever the window has focus). Unit-tested (`mouse_look_turns_speed_into_a_stick_past_the_dead_zone`); the dead zone | ||
| 331 | and curve are first guesses at the title's own stick response, not measured. | ||
| 332 | |||
| 333 | ## PlayStation pads and the active input of the D3D12 runtime | ||
| 334 | |||
| 335 | The D3D12 runtime has no SDL. Besides XInput it reads Sony pads (vendor `054C`: DualSense `0CE6`, DualSense Edge `0DF2`, | ||
| 336 | DualShock 4 `05C4`, `09CC`, USB adapter `0BA0`) over Windows HID directly (`gameinput/hid.rs`), on USB and Bluetooth, | ||
| 337 | written from the public report layouts (the Linux `hid-playstation` driver documents them). One thread per pad reads | ||
| 338 | input reports; a rescan every 2 s finds pads that came or went. A Bluetooth pad is moved to its full report by reading | ||
| 339 | calibration feature report `0x05`. | ||
| 340 | |||
| 341 | | | USB input | Bluetooth input | USB output | Bluetooth output | | ||
| 342 | |---|---|---|---|---| | ||
| 343 | | DualSense | `0x01`, 64 bytes, data from byte 1 | `0x31`, 78 bytes, data from byte 2 | `0x02`, 63 | `0x31`, 78, CRC-32 last | | ||
| 344 | | DualShock 4 | `0x01`, 64 bytes, data from byte 1 | `0x11`, data from byte 3 | `0x05`, 32 | `0x11`, 78, CRC-32 last | | ||
| 345 | |||
| 346 | Buttons: Cross, Circle, Square, Triangle are A, B, X, Y; L1/R1 the shoulders; L2/R2 the triggers (analog byte, the | ||
| 347 | digital bit is ignored); L3/R3 the stick clicks; Options is Menu; Create (Share) and the touchpad click are View; | ||
| 348 | the PS and mute buttons are not passed. Sticks are 0..255, centre 128. Rumble: the big motor of the title's | ||
| 349 | `SetRumbleState` goes to the pad's left motor, the small one to its right (`rumble_report`; on Bluetooth the CRC is | ||
| 350 | seeded with `0xA2`). Trigger effects and the lightbar are not driven. A Sony pad takes the first slot XInput leaves | ||
| 351 | empty (all pads are one pad for the title anyway, `LEONIDA_ONE_PAD`). | ||
| 352 | |||
| 353 | A pad that Steam Input or DS4Windows already shows through XInput is not read twice: when input comes on an XInput pad and | ||
| 354 | on a readable Sony pad within 150 ms of each other, they are one controller for the next 10 s, and the Sony pad's own | ||
| 355 | reading is left out of what the title sees. A Sony pad present but not openable (hidden by HidHide, held exclusively) | ||
| 356 | counts the same way: input on XInput is then PlayStation input. | ||
| 357 | |||
| 358 | **Active input.** `gameinput::active_family()` (`leonida-hle`, readable from any thread, lock-free) says which kind of | ||
| 359 | device was used last: `Family::Xbox`, `Family::PlayStation` or `Family::KeyboardMouse`; `family_generation()` goes up by one | ||
| 360 | with each change. It follows the rules of [Active input](#active-input) above (an edge counts, the first reading of a | ||
| 361 | device is its baseline), with the keyboard and mouse as a third family (a key going down, or mouse look pushing the | ||
| 362 | stick past 0.35). A switch is immediate: the first deliberate input of another family changes the answer, however long | ||
| 363 | the one before was in use; only the change after that one waits, `LEONIDA_PROMPTS_SWITCH_MS` = 300 ms from the switch, | ||
| 364 | so two devices used at once change it at most about three times a second. Before the first input it is what is | ||
| 365 | connected when the runtime first looks: PlayStation with a Sony pad, Xbox with any other pad, the keyboard and mouse | ||
| 366 | with no pad at all (a wireless pad still asleep counts as none: `LEONIDA_PROMPTS=xbox` is the way round it). One line | ||
| 367 | is logged on each change (`input in use: PlayStation (Sony pad input)`). | ||
| 368 | `LEONIDA_PROMPTS=xbox|playstation|keyboard|auto` forces it. The button prompts follow it at the title's one read of its | ||
| 369 | glyph movie: see [prompt_glyphs.md](prompt_glyphs.md). Unit-tested on hand-made report bytes and the family rules; not | ||
| 370 | run against a real pad yet. | ||
| 371 | |||
| 176 | ## Rumble and triggers | 372 | ## Rumble and triggers |
| 177 | 373 | ||
| 178 | `IGameInputDevice::SetRumbleState` takes four motor levels, 0..1. The two body motors go to `SDL_RumbleGamepad` on | 374 | `IGameInputDevice::SetRumbleState` takes four motor levels, 0..1. The two body motors go to `SDL_RumbleGamepad` on |
| @@ -334,7 +530,7 @@ line is logged when it takes effect); tracking goes on underneath, so clearing i | |||
| 334 | | `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | | 530 | | `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | |
| 335 | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | | 531 | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | |
| 336 | | `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | | 532 | | `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | |
| 337 | | `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons and invalid times (including negative or non-finite values) are counted and ignored. | | 533 | | `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms, or `hold` seconds when the entry is `button@seconds:hold` (more than 0, at most 600). With SDL3 a press then stays down until the title has read the pads six times since it began, but never past 5 s from its start (or its hold, if longer). A title reads its pad once a frame, so at a few seconds a frame a 300 ms press can fall between two reads and never arrive: on the retail title's "Couldn't autosave" prompt, three 300 ms `b` presses did nothing, while 120 presses 0.5 s apart got through; one `b@1100:3` replaces them. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons, invalid times (including negative or non-finite values) and invalid holds (0 or less, more than 600, not a number) are counted and ignored. | |
| 338 | | `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | | 534 | | `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | |
| 339 | 535 | ||
| 340 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to | 536 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to |
| @@ -350,7 +546,11 @@ button) run on that thread, as GameInput runs them on its own threads. Once the | |||
| 350 | `IGameInputDispatcher::Dispatch` runs them on the title's thread, oldest first, within its quota: at least one queued | 546 | `IGameInputDispatcher::Dispatch` runs them on the title's thread, oldest first, within its quota: at least one queued |
| 351 | event per call (a quota of 0 runs exactly one), no further event once the quota has passed, and only the events | 547 | event per call (a quota of 0 runs exactly one), no further event once the quota has passed, and only the events |
| 352 | queued when the call started (later ones wait for the next call, so even an unlimited quota returns). The wait | 548 | queued when the call started (later ones wait for the next call, so even an unlimited quota returns). The wait |
| 353 | handle is signalled again while events remain. | 549 | handle is signalled again while events remain. An event is queued only when a registered callback wants it (a |
| 550 | reading with no reading callback, say, is no work), so readings nobody hears cannot build a backlog that a title | ||
| 551 | running one item a frame (`Dispatch(0)`) never catches up on, with a later pad's connect event stuck behind it. The | ||
| 552 | first few `RegisterDeviceCallback` calls (filter, kind, status filter, enumeration) and the first `CreateDispatcher` | ||
| 553 | and `Dispatch` calls are logged, since they decide how the title hears of a pad plugged in after start. | ||
| 354 | 554 | ||
| 355 | The API surface: | 555 | The API surface: |
| 356 | 556 | ||