Commit Graph

65 Commits

Author SHA1 Message Date
3580a9d308 Merge pull request #1831 from potatoe0100/carry/old-9966
gameinput: preserve controller transitions between polls (OLD-9966, carries #233)
2026-11-29 16:42:49 +01:00
371d8556f9 Merge pull request #1528 from kawaii-shakal/input-out-of-the-box
make_game, gameinput: controller, keyboard and mouse input out of the box (INPUT-OUT-OF-THE-BOX)
2026-11-29 04:36:04 +01:00
17f5b935db Merge pull request #2497 from Tyrannys/rt-gameinput-ffb-haptic-null
gameinput: force-feedback kind changes, SetParams features, locked motor reads, no null memcpy (RT-GAMEINPUT-FFB-HAPTIC-NULL)
2026-11-29 02:03:06 +01:00
2f99fd2cae Merge main into carry/old-9966 (resolve conflict in runtime/test/gameinput_test.cpp)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 21:25:16 +01:00
9b7944b4e5 Merge pull request #1510 from ProjectLeonida/claude/gameinput-slow-reader
gameinput: report a missed press once to a slow reader (RT-GAMEINPUT-SLOW-READER)
2026-11-28 21:18:21 +01:00
e8de040370 Merge pull request #1095 from sodove/restore/gameinput-current-callback-9769
GameInput: resolve the current token for self-stopping callbacks (OLD-9769)
2026-11-28 19:14:28 +01:00
423521c111 Merge pull request #2086 from alexandersato0830/codex/gameinput-cursor-source
Reset the mouse baseline when the cursor source changes (RT-KEYBOARD-PAD-CURSOR-SOURCE)
2026-11-28 19:12:09 +01:00
ab95ff8427 Merge upstream main into PR #1528 2026-11-28 13:59:13 +00:00
5fbcc642a5 Merge upstream main into PR #1559 2026-11-28 13:59:13 +00:00
c912546318 Merge pull request #2082 from alexandersato0830/codex/gameinput-mouse-delta
Keep keyboard-pad mouse deltas in range (RT-KEYBOARD-PAD-MOUSE-DELTA)
2026-11-28 09:05:40 +01:00
4a70845069 gameinput: SetParams keeps the force-feedback effect's kind
IGameInputForceFeedbackEffect::SetParams updates the parameters of the
effect's own kind; another kind is refused and the effect keeps what it
had (timbot103's review on #2497). SetParams checked only that the motor
reports the new kind, so a constant effect could become a sine. It now
refuses any params->kind other than the effect's.

An effect's SDL type therefore never changes, and the destroy-and-
recreate path this PR added to sync() for a kind change is unreachable,
so it is removed again.

gameinput_test: SetParams refuses both a kind the motor lacks and one it
reports, leaves the parameters and the SDL effect alone, and the sine
and spring checks run on effects of their own made with
CreateForceFeedbackEffect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 20:11:46 -06:00
aeb24285be gameinput: force-feedback kind changes, SetParams features, locked motor reads, no null memcpy
From a review of the shim by kevincommits (#1608):

- ForceFeedbackEffect::SetParams accepted any kind, also one the motor
  does not report, which CreateForceFeedbackEffect refuses. It now
  refuses it the same way.
- A kind change through SetParams was sent to SDL as an update of the
  existing effect, which SDL_UpdateHapticEffect refuses ("Updating
  effect type is illegal"), so the effect stopped. The poll thread now
  destroys the old SDL effect and creates one of the new type. The
  test's fake haptics refuses a type change in an update, as SDL does.
- CreateForceFeedbackEffect and IsForceFeedbackMotorPoweredOn read the
  motor count, features and haptic handle that open_pad and close_pad
  write on the poll thread under g().mu, without the lock. They take
  it now.
- GetControllerAxisState and GetControllerButtonState called memcpy
  with a null buffer for 0 bytes. They copy only when there is
  something to copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 13:37:20 -06:00
7ffcb8e260 Merge upstream/main into input-out-of-the-box
docs/gameinput.md conflicted on two passages, both kept:
- main's new LEONIDA_INPUT_FILE paragraph, with this branch's sentence on
  make_game.py running build_runtime.ps1 with -FetchSdl3 (and --no-sdl3)
  added to main's wording of the build paragraph;
- the settings table keeps this branch's LEONIDA_KEYBOARD_PAD default (1,
  focused; off removes it), which gameinput.cpp reads, and takes main's longer
  LEONIDA_INPUT_SCRIPT row (button@seconds:hold, the six-reads rule), saying
  "on unless LEONIDA_KEYBOARD_PAD=off" for the keyboard pad.

No code conflicted. Tested: full ctest, 113 of 113, on Linux (the portable
subset; the gameinput shim is Windows-only).

Changes made by Claude Code (AI-assisted).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
2026-11-26 18:59:07 +00:00
99f913a288 Merge upstream main into input-out-of-the-box
Keep the PR keyboard-pad default and document the retry behavior from main.

Conflict resolution assisted by Codex.
2026-11-26 06:36:39 +00:00
1ce60558c7 gameinput: the SDL keyboard pad honours a scripted hold too
#2098 gave the SDL path its own loop (held 300 ms, then until the title
has read the pads six times, at most 5 s), which ignored button@seconds:hold.
A press now lasts its own hold, then the read latch, and never past 5 s or
its hold if longer. The long-script test checks both: X kept past 300 ms
until six reads, Y kept for its 0.6 s after them. It fails on the old loop.

Found by AndreiKocherzhinskiiA on #1608.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 04:58:19 +00:00
f0e79141a4 gameinput: a scripted press can be held longer (button@seconds:hold)
At world-start frame rates the retail title reads its pad every few seconds,
so a 0.3 s scripted press falls between two reads and never arrives. An
entry may now give its own hold time; without one the press stays 0.3 s.
Holds of 0 or less, over 600 s or that are not a number reject the entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 04:58:19 +00:00
9ea22eaf44 gameinput test: read the pad before expecting a scripted press to end (TEST-GAMEINPUT-SCRIPT-READS)
Since #2098 a scripted press lasts its 300 ms and then until the title has made
six GetCurrentReading calls since it began. gameinput_test --input-script still
expected the press to be over after 350 ms and three reads, so ctest
gameinput_script failed on main in every build with SDL3 (it is disabled
without SDL3, so CI did not show it).

The test now checks that the press is still held at that point, reads the pad
six more times and then expects the release. Test only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-26 08:28:59 +08:00
361c3abe61 Reset mouse delta baseline when the cursor source changes 2026-11-25 13:51:01 -06:00
8b3db052e4 Keep virtual gamepad mouse deltas in range 2026-11-25 13:46:10 -06:00
9a96b8ba6a gameinput: preserve controller transitions between polls 2026-11-25 13:25:48 +00:00
a05f1f3cdb gameinput: queue only events a callback wants, so a later pad's connect is not stuck behind a backlog (RT-GAMEINPUT-LATE-PAD)
A pad connected after the title started was seen by the shim but not by the
title, while pads present at start worked. Pads present at start reach a title
through blocking enumeration, which runs synchronously in RegisterDeviceCallback.
A later pad reaches it only through a queued connect event. queue_event queued
every reading and guide change whether or not any callback listened. With a
dispatcher held, a title that runs one item a frame (Dispatch(0), the pattern
Microsoft's Dispatch page suggests) falls further behind every frame, because a
moving stick or a sensor pad's 125 Hz stream queues items faster. The later
pad's connect event then never comes out of the queue.

queue_event now drops an event no registered callback matches, as GameInput has
no work to dispatch then. The first few RegisterDeviceCallback calls and the
first CreateDispatcher and Dispatch calls are logged, so a retail run shows
whether the title holds a dispatcher (not yet confirmed for the retail title).

Test: test_late_pad_behind_dispatcher. A title with a dispatcher registers its
device callback with no pad, a first pad moves on every poll, and a pad attached
later must reach the callback within ten frames of Dispatch(0). Without the fix
it fails (2 of 371 checks); with it, 371 checks pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 09:29:04 +05:00
045bb0fcec gameinput_test: close_pad resets a missed press, pads keep their own, wider slow-reader margin
Review follow-up for the kSlowReaderUs missed-press logic:
- close_pad: a press missed by a slow reader, then an unplug/replug, must
  not come back on the first slow read after reconnecting.
- two pads: a missed press on the Xbox pad and one on the DualSense are
  each reported only on their own pad, once.
- the slow-reader sleeps are now 150 ms (3x kSlowReaderUs) for slow CI.

Tested: ctest -R ^gameinput passes plain and with LEONIDA_VK_VALIDATION=1
(VS 2022, Ninja). Against the pre-fix shim the slow-reader and both
two-pad checks fail (the close_pad check passes trivially there); with the
fix minus close_pad's missed reset, the close_pad check fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
2026-11-24 22:40:06 -05:00
d4d969a1fd make_game, gameinput: controller, keyboard and mouse input out of the box (INPUT-OUT-OF-THE-BOX)
A build made with make_game.py on Windows had no input at all. The runtime
stage ran scripts/build_runtime.ps1 without -FetchSdl3, so on a machine without
an installed SDL3 the GameInput shim was not built. gta6rt then logged "served
without SDL3 (no devices)", and a connected DualSense or Xbox pad did nothing.

- make_game.py: the Windows runtime stage passes -FetchSdl3 (the pinned SDL3
  3.4.20, SHA-256 checked by CMake). --no-sdl3 leaves the download out. The
  docstring's "what it downloads" sentence names it.
- gameinput: LEONIDA_KEYBOARD_PAD defaults to the focused mode, so a player
  without a pad still has the keyboard and mouse. Keys count only while the
  game window has focus. "off" or "0" removes the pad.
- gameinput_test: the other cases set LEONIDA_KEYBOARD_PAD=off, as they count
  only their own virtual pads. The keyboard pad case checks the new default.
- docs/gameinput.md: default and make_game behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 08:31:50 +05:00
0e5e33bc49 gameinput: report a missed press once to a slow reader (RT-GAMEINPUT-SLOW-READER)
A title that reads a pad with GetCurrentReading once a frame, at a few
frames a second, never sees a press that came and went between two
reads. A pad now keeps the newest reading that pressed a button the last
read did not report; a read more than kSlowReaderUs (50 ms) after the
previous one answers that press once, and the next read the pad's real
state.

Carried from DadaCap's boot-prototype fa497b930, split to the GameInput
part (runtime/shims/gameinput.cpp and its test in
runtime/test/gameinput_test.cpp); the other shims in that commit are not
included. Applied unchanged.

AI-assisted. Run on Windows 11, RTX 5080. No game data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
2026-11-24 21:45:32 -05:00
f9ba70b4de gameinput: keyboard pad input scripts of any length (RT-INPUT-SCRIPT-LENGTH)
Main had no keyboard pad script scheduler. Add timed button presses with
a full-length environment reader so entries beyond byte 63 reach the pad.
Combine scheduled and physical presses. Reject malformed entries and
report their count when the script is read on the first pad update.

Build gta6rt and gameinput_test. Exercise a long script, rejected items,
focus loss, configuration reload and release under Wine. Restore only the
old environment reader to reproduce the missing presses.

Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>


AI-assisted (Codex and Claude Code agents).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 12:57:22 -06:00
Luc
49f7133d96 gameinput: StopCallback and UnregisterCallback take the current-callback token
GAMEINPUT_CURRENT_CALLBACK_TOKEN_VALUE (all ones) names the callback that is
running on the calling thread, as the host's GameInput does (measured by
@Maraco91 on GameInput 0.2309): inside a callback, UnregisterCallback(CURRENT)
removes it and returns true and StopCallback(CURRENT) stops it; outside one the
token names nothing and UnregisterCallback returns false. The shim compared
it with registered tokens, matched none, and the callback kept firing.

call() records the running token in a thread_local, restored on return, and
both methods resolve the constant through it. gameinput_test drives a
self-cancelling reading callback through four button changes on the virtual
Xbox pad, once per method.

Finding: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7115359105

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 23:16:01 +05:00
e0f76d28b5 gameinput: serve GameInput.dll's ordinal 1, the retail executable's GameInputCreate import
The retail executable imports GameInputCreate from GameInput.dll by ordinal 1. The loader looks ordinal imports up
as "#1", which the shim table did not have, so the import bound to the host's GameInput.dll. On Windows the
installed GameInput answers; under Wine it is the builtin stub, the call fails and the title stops on its result.
The alias maps #1 to the same GameInputCreate, and gameinput_test checks it.

(cherry picked from commit 5e45c7da94)
2026-11-23 20:23:21 -06:00
2f6aa6fb5b Merge remote-tracking branch 'origin/pr/9765' 2026-11-23 17:24:53 -05:00
29bd7a11a6 gameinput: the device info has its GameInputLabel members
gameinput_abi.h left out the labels of the public v0 layout. In
GameInputControllerAxisInfo and GameInputControllerButtonInfo a label
sits at offset 4, in what is otherwise padding, so the sizes matched
while isContinuous, restValue, legacyDInputIndex and rawReportIndex were
four bytes early. GameInputGamepadInfo and GameInputUiNavigationInfo are
tables of 14 and 21 labels; they were declared empty, and the pointers
in GameInputDeviceInfo led to one-byte members, so a title reading a
label read whatever followed.

The header declares the enum, the two tables and the two label members
and pins each offset that moved. fill_info gives every control the Xbox
label of its position on every pad, since every pad is presented as an
Xbox One pad.

gameinput_test reads the tables by the public header's byte offsets, so
the shim's own header cannot agree with itself.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 23:15:46 +01:00
52b4f03b78 GameInput: honor the delay between trigger haptic pulses 2026-11-24 08:34:25 +11:00
3bbf352b7a gameinput: SetHapticMotorState saturates a request's end time instead of wrapping
IGameInputDevice::SetHapticMotorState computed the end of a request as
duration * playCount + repeatDelay * (playCount - 1), then now + total, all
in uint64 microseconds with no overflow check. A very long request wrapped:
duration = UINT64_MAX with playCount 1 put the deadline just before now, so
the motor never played, and duration = 2^63 + 50 ms with playCount 2 wrapped
to a 100 ms request that stopped early.

The products and sums now saturate at UINT64_MAX, a deadline the poll
thread never reaches, so such a request plays until the state is set again.
Requests that fit are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 19:26:21 +01:00
fb7575981b Merge pull request #4553 from Maxime Mansiet
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:15:52 -05:00
66d9217616 Merge pull request #4552 from Maxime Mansiet
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/gameinput.md
2026-11-22 23:15:51 -05:00
b6a73d3a89 Merge pull request #4102 from Felix Croasdale
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:11:17 -05:00
e549ac4c07 Merge pull request #3851 from Leonida local test
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:08:54 -05:00
0519bc2c81 gameinput: a reading callback's inputKind filter checks what the device supports
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
2026-11-23 03:05:55 +01:00
399b30f69b gameinput: GetRawReport holds hid_mu while it reads the raw reports
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
2026-11-23 02:59:55 +01:00
c5c9ff002a gameinput: the poll thread no longer revives a force-feedback effect being released (RT-262)
ForceFeedbackEffect::Release() drops the count to 0 and deletes the
effect; its destructor then waits for g().mu to unlink it from the
device. In that window apply_effects (holding g().mu) could AddRef the
dying effect from 0 to 1, sync it after it was freed, and delete it a
second time with its own Release (@AAyberkU's finding).

apply_effects now takes a reference only on a live effect
(add_ref_if_live: a compare-exchange that never moves a count up from 0),
so an effect whose last Release ran is skipped.

gameinput_test: add_ref_if_live itself, and 20,000 effects created and
released while a second thread runs the poll step. With the old AddRef
that run ends in STATUS_HEAP_CORRUPTION (0xC0000374) every time here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 17:26:51 -06:00
dc01a17397 gameinput: report SDL's effect result from gameinput_probe (RT-160)
`--force-feedback` now reads the shim's output state once the poll thread has
picked the effect up, and says whether SDL created it and is running it, or why
it did not, so a wheel owner can tell a silent drop from a real run. The shim
records SDL_CreateHapticEffect's id, SDL_RunHapticEffect's result and SDL's
error text per device; gameinput_test asserts the success and the refusal.

AI-assisted
2026-11-22 23:15:09 +01:00
793e35af55 Merge pull request #3685 from ICUMADETHIS 2026-11-22 17:03:25 -05:00
1fc162f4ba gameinput: track which kind of device the player used last
The shim tells the title every pad is an Xbox One pad, so nothing could
say what the player is really holding. rt::gameinput::active_input()
now returns the family of the device used last (Xbox, PlayStation 5,
PlayStation 4, PlayStation 3, Nintendo, or the keyboard pad), a
generation that counts changes, and whether LEONIDA_PROMPTS forced it.
It is groundwork for button prompts that follow the device in use.

Only deliberate input counts: a button going down, a trigger past 0.3
or a stick leaving a 0.35 radius. Held input, stick drift and noise do
not; a pad's first reading after it connects is its baseline; and
after a change the next one waits LEONIDA_PROMPTS_SWITCH_MS (300 ms).
The rules live in runtime/src/active_input.h with no SDL, tested by
active_input_test; gameinput_test drives them on SDL virtual pads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 21:17:56 +00:00
c77e9403a3 Merge pull request #3172 from Bora Sevim
# Conflicts:
#	docs/gameinput.md
2026-11-22 15:15:26 -05:00
cda0da18b8 Merge pull request #2567 from marquezini 2026-11-22 15:11:09 -05:00
76d1add3da Merge origin/main into rt-175-raw-hid
Keep RT-160's force-feedback interface and tests next to the raw HID ones.
The raw HID test fakes are renamed (FakeRawHid, raw_*) so they no longer clash
with the haptic fakes. The API table gets one IGameInputDevice row with both
feature sets; the stale duplicate IGameInputDevice and IGameInputDispatcher
rows are dropped.
2026-11-22 23:05:47 +03:00
364fdcbd28 gameinput: raw HID reports and raw device I/O through SDL's hidapi (RT-175)
The shim opens each pad's HID device with SDL_hid_* (by SDL's device path, else the one game-pad collection with the
pad's vendor and product id) and reads its report descriptor for every input, output and feature report's id and
size. Such a pad reports GameInputKindRawDeviceReport and GameInputDeviceRawIoEnabled and fills inputReportInfo,
outputReportInfo and featureReportInfo (no item tables). Readings carry the newest raw input report, and
IGameInputReading::GetRawReport returns it as an IGameInputRawDeviceReport. CreateRawDeviceReport,
GetRawDeviceFeature, SetRawDeviceFeature and SendRawDeviceOutput work through the backend; an undeclared id or kind
is E_INVALIDARG, a failed transfer E_FAIL, and a pad without a HID device keeps E_NOTIMPL.

gameinput_abi.h declares IGameInputRawDeviceReport, GameInputRawDeviceReportKind and the three raw report info
structs, checked against Microsoft's v0 header (offsetof for every field, the 12 vtable slots, the IID). Xbox pads on
Windows go through XInput, whose HID interface SDL's hidapi skips, so they have no raw I/O; the log says so.

gameinput_test covers the descriptor parser and the whole path with a fake HID backend (24 checks);
gameinput_probe prints each pad's report tables and newest raw input report. docs/gameinput.md: "Raw HID".
2026-11-22 22:35:50 +03:00
f5907ef65a Merge main (873a952a) into the RT-176 branch 2026-11-22 16:32:48 -03:00
e7c83353c7 RT-176: Dispatch runs only the batch queued when it starts
Review follow-up. Dispatch took events one at a time from the live
queue, so readings queued during the call (by the poll thread, or by a
callback) were delivered in the same call: with an unlimited quota a busy
queue could keep the title inside Dispatch, and each erase at the front
made a drain O(n^2) under deliver_mu.

Dispatch now swaps out the batch present at entry and walks it in order;
events it leaves (quota spent) go back to the front of the queue, ahead of
newer ones. gameinput_test adds a callback that queues a reading from
inside the call: each Dispatch(UINT64_MAX) runs exactly its starting batch
and returns true (the previous version never returned). The docs say so,
and the dispatcher row's open column reads a dash instead of a blank.
2026-11-22 16:32:10 -03:00
8599c9e64c Merge pull request #2567 from marquezini
# Conflicts:
#	docs/gameinput.md
2026-11-22 13:16:16 -05:00
c1543e3449 Merge pull request #2552 from Leonida local test 2026-11-22 13:16:07 -05:00
af330fcce3 gameinput: keep only the haptic calls the shim makes in the test seam (RT-160)
HapticApi carried SDL_GetNumHapticAxes and SDL_HapticEffectSupported, which
nothing calls: the motor's axes are the shim's choice and the effect kinds are
gated on SDL_GetHapticFeatures. They are gone from the table, its SDL
implementation and the test's fake, so the seam is exactly the calls a pad's
force feedback makes.

AI-assisted.
2026-11-22 18:37:28 +01:00