GameInput: a tap between two current-state reads is not lost (input at low frame rates) #2230

Open
github-bot wants to merge 5 commits from github-bot/gh-2230 into main AGit
Owner

@⁠desplmfao on GitHub · 2026-11-25 08:24 UTC · original
desplmfao:fix/input-latch → main · +453 −23 · 1 files · 5 commits · open

Problem

At the frame rates Grand Theft Auto VI runs at today (one frame every 300 ms or more), a short key or button press is usually lost. You have to mash a key until it registers.

GTA VI reads the pad and keyboard with GetCurrentReading once per frame (confirmed with the diagnostics log below: GetCurrentReading, GetNextReading, IGameInputReading::GetGamepadState / GetKeyState). VIctory polls the host every 8 ms and hands out the newest reading. A tap that goes down and comes back up between two of the title's reads is never seen. Keeping more history (#2218) doesn't help a title that only asks for the current state.

Change

Presses are latched per device slot: host pads, the keyboard, and the keyboard stand-in pad.

  • When a button bit or key goes down, it stays down in the recorded readings until a GetCurrentReading hands that device out.
  • That read then records the host's real state as a new reading. A tap is therefore pressed in one read and released in the next, with no polling delay in between.
  • GetPreviousReading of the latched reading returns the state before the press, so an edge check sees the press too.
  • Only new presses are held. A release of a press the title has already seen is recorded at once. Sticks and triggers always carry the latest value.
  • It applies only to a device the title read through GetCurrentReading in the last 2 s. A title that only walks the history is unaffected, and nothing can stay held for good.
  • Opt-in: VICTORY_INPUT_LATCH=1 turns it on; it is off by default, since it departs from what the real GetCurrentReading returns.

Diagnostics builds log, once each, which GameInput functions the title calls. They also log every tap the latch kept for a read, meaning a press that was released before the read and would have been missed without the latch.

Measured

Grand Theft Auto VI (Series X 1.0.2.1) in the world, RTX 5080, Linux/Proton, about 306 ms per frame. I tapped keys for about 40 s, and the latch kept 39 taps for the title's reads that it would otherwise have missed: W ×9, J ×8, L ×5, Space ×5, K ×3, E ×3, three pad-button taps through the stand-in pad, and others. Each line in the log looks like a key tap kept for the title's read (released before it) virtual_key=87.

Risks

  • A title that reads the same device several times per frame (for example two subsystems each calling GetCurrentReading) shows a tap only to the first read after it. No read sees a tap twice.
  • On a device that is read through the current state, the history now records a held tap's release at the next current read, not when it happened. Two taps between reads become one press.

Tested

  • cargo test -p victory-hle gameinput (Windows x64, under Proton here): 15 passed, of which 6 are new:
    • a_tap_between_current_reads_is_pressed_in_one_read_and_released_in_the_next
    • a_held_button_stays_pressed_and_its_release_is_not_delayed
    • sticks_and_triggers_stay_the_latest_value
    • a_host_pad_tap_is_latched_too
    • a_key_tap_between_current_reads_is_latched_on_the_keyboard
    • without_current_reads_or_with_the_latch_off_the_history_is_as_recorded
  • cargo clippy -p victory-hle --all-targets -- -D warnings, with and without --features diagnostics: clean.
  • Independent of #2218 (history 32 → 256); they go together without conflicts.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠desplmfao** on GitHub · 2026-11-25 08:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2230) `desplmfao:fix/input-latch` → `main` · +453 −23 · 1 files · 5 commits · open ## Problem At the frame rates Grand Theft Auto VI runs at today (one frame every 300 ms or more), a short key or button press is usually lost. You have to mash a key until it registers. GTA VI reads the pad and keyboard with `GetCurrentReading` once per frame (confirmed with the diagnostics log below: `GetCurrentReading`, `GetNextReading`, `IGameInputReading::GetGamepadState` / `GetKeyState`). VIctory polls the host every 8 ms and hands out the newest reading. A tap that goes down and comes back up between two of the title's reads is never seen. Keeping more history (#2218) doesn't help a title that only asks for the current state. ## Change Presses are latched per device slot: host pads, the keyboard, and the keyboard stand-in pad. - When a button bit or key goes down, it stays down in the recorded readings until a `GetCurrentReading` hands that device out. - That read then records the host's real state as a new reading. A tap is therefore pressed in one read and released in the next, with no polling delay in between. - `GetPreviousReading` of the latched reading returns the state before the press, so an edge check sees the press too. - Only new presses are held. A release of a press the title has already seen is recorded at once. Sticks and triggers always carry the latest value. - It applies only to a device the title read through `GetCurrentReading` in the last 2 s. A title that only walks the history is unaffected, and nothing can stay held for good. - **Opt-in:** `VICTORY_INPUT_LATCH=1` turns it on; it is off by default, since it departs from what the real `GetCurrentReading` returns. Diagnostics builds log, once each, which GameInput functions the title calls. They also log every tap the latch kept for a read, meaning a press that was released before the read and would have been missed without the latch. ## Measured Grand Theft Auto VI (Series X 1.0.2.1) in the world, RTX 5080, Linux/Proton, about 306 ms per frame. I tapped keys for about 40 s, and the latch kept **39 taps** for the title's reads that it would otherwise have missed: W ×9, J ×8, L ×5, Space ×5, K ×3, E ×3, three pad-button taps through the stand-in pad, and others. Each line in the log looks like `a key tap kept for the title's read (released before it) virtual_key=87`. ## Risks - A title that reads the same device several times per frame (for example two subsystems each calling `GetCurrentReading`) shows a tap only to the first read after it. No read sees a tap twice. - On a device that is read through the current state, the history now records a held tap's release at the next current read, not when it happened. Two taps between reads become one press. ## Tested - `cargo test -p victory-hle gameinput` (Windows x64, under Proton here): 15 passed, of which 6 are new: - `a_tap_between_current_reads_is_pressed_in_one_read_and_released_in_the_next` - `a_held_button_stays_pressed_and_its_release_is_not_delayed` - `sticks_and_triggers_stay_the_latest_value` - `a_host_pad_tap_is_latched_too` - `a_key_tap_between_current_reads_is_latched_on_the_keyboard` - `without_current_reads_or_with_the_latch_off_the_history_is_as_recorded` - `cargo clippy -p victory-hle --all-targets -- -D warnings`, with and without `--features diagnostics`: clean. - Independent of #2218 (history 32 → 256); they go together without conflicts. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
At one or two frames a second, a title that reads only the current state
once per frame misses most taps: the press and release both land between
two reads. A button or key pressed since the title last read a device's
current state now stays pressed in what we record until such a read has
seen it; that read then records the host's own state, so the release shows
in the next read. Only presses are held (a release of a press already seen
is recorded at once); sticks and triggers stay the latest value. The latch
works per device (host pads, the stand-in pad, the keyboard), only on a
device read through GetCurrentReading within the last 2 s, and
VICTORY_INPUT_LATCH=0 turns it off.

Diagnostics builds log the first call of each GameInput function, to see
which ones Grand Theft Auto VI uses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Presses from different polls between two current-state reads were OR'd
into one reading: A then B arrived as A+B, a chord nobody pressed
(Dathinel on #2230). The latch now keeps them in order, each the
buttons or keys that went down in one poll; a read takes the oldest,
the next press goes to the next read. Presses down together in one poll
stay together. At most 16 are held.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
It departs from what the real GetCurrentReading returns, so it is off by
default, as the triage suggested; VICTORY_INPUT_LATCH=1 turns it on. The
tests' hub turns it on (they are about it), and a new test checks that
nothing else does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
main's #1430 hides a pad that has only reported zeros until it reports
input, so the two latch tests that start from an idle host pad now start
from one with a stick slightly off centre (no button down).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:59:07 +00:00
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 08:25 UTC · original

A note on intent: this isn't console behaviour. On hardware, GetCurrentReading returns the device's state at that moment, and at 30/60 fps a tap isn't lost anyway. The latch only makes up for the low frame rates VIctory runs at today. If exact parity with the console API is preferred, I'm fine with flipping the default to off (one line, VICTORY_INPUT_LATCH=1 to opt in), or with leaving this out. The two side effects are listed under Risks above.

**@⁠desplmfao** on GitHub · 2026-11-25 08:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2230#issuecomment-7157017119) A note on intent: this isn't console behaviour. On hardware, `GetCurrentReading` returns the device's state at that moment, and at 30/60 fps a tap isn't lost anyway. The latch only makes up for the low frame rates VIctory runs at today. If exact parity with the console API is preferred, I'm fine with flipping the default to off (one line, `VICTORY_INPUT_LATCH=1` to opt in), or with leaving this out. The two side effects are listed under Risks above.
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 08:37 UTC · original

One concrete tradeoff for the default-on decision: different buttons tapped in sequence can be reported as a chord. I checked 84da49a on Windows with a synthetic connected pad, an active current-state reader, and four host polls between reads: A only → released → B only → released.

With the latch enabled, the next GetCurrentReading returned A+B, and an immediate second read returned neither. With it disabled both reads returned neither. The same sequence with Q and E on the keyboard produced the same distinction. No host poll contained both inputs. This matters to consumers that interpret simultaneous buttons as a separate command; whether the title does so is untested. I'd mention this alongside the existing repeated-tap caveat. AI-assisted synthetic validation.

**@⁠Dathinel** on GitHub · 2026-11-25 08:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2230#issuecomment-7157278635) One concrete tradeoff for the default-on decision: different buttons tapped in sequence can be reported as a chord. I checked 84da49a on Windows with a synthetic connected pad, an active current-state reader, and four host polls between reads: A only → released → B only → released. With the latch enabled, the next GetCurrentReading returned A+B, and an immediate second read returned neither. With it disabled both reads returned neither. The same sequence with Q and E on the keyboard produced the same distinction. No host poll contained both inputs. This matters to consumers that interpret simultaneous buttons as a separate command; whether the title does so is untested. I'd mention this alongside the existing repeated-tap caveat. AI-assisted synthetic validation.
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 08:40 UTC · original

@⁠Dathinel good catch, thanks for checking it. You're right: presses from separate polls are OR'd together, so A-then-B between two reads arrives as the chord A+B. I'll change the latch to keep presses in order instead: each current-state read takes the oldest held press (together with whatever is really down at that moment), and the next press goes to the next read. A then B then reads as A, then B. The second one comes a read later, but it's never a chord that wasn't pressed. Presses that really were down together in one poll stay together. I'll add your sequence (pad A→B and keyboard Q→E) as tests.

**@⁠desplmfao** on GitHub · 2026-11-25 08:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2230#issuecomment-7157322918) @⁠Dathinel good catch, thanks for checking it. You're right: presses from separate polls are OR'd together, so A-then-B between two reads arrives as the chord A+B. I'll change the latch to keep presses in order instead: each current-state read takes the oldest held press (together with whatever is really down at that moment), and the next press goes to the next read. A then B then reads as A, then B. The second one comes a read later, but it's never a chord that wasn't pressed. Presses that really were down together in one poll stay together. I'll add your sequence (pad A→B and keyboard Q→E) as tests.
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 08:49 UTC · original

@⁠Dathinel fixed in d3d9cd1. The latch keeps presses in order now. Each entry is the buttons or keys that went down in one host poll; a current-state read takes the oldest, and the next press goes to the next read. Your sequence (A, release, B, release between two reads) now reads A, then B alone, then nothing. Buttons that went down in the same poll still arrive together. New tests: taps_in_sequence_are_not_reported_as_a_chord (pad A→B, plus the same-poll chord case) and key_taps_in_sequence_are_not_reported_together (keyboard Q→E). cargo test -p victory-hle gameinput gives 17 passed under Proton here, and clippy is clean with and without --features diagnostics.

**@⁠desplmfao** on GitHub · 2026-11-25 08:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2230#issuecomment-7157519628) @⁠Dathinel fixed in `d3d9cd1`. The latch keeps presses in order now. Each entry is the buttons or keys that went down in one host poll; a current-state read takes the oldest, and the next press goes to the next read. Your sequence (A, release, B, release between two reads) now reads A, then B alone, then nothing. Buttons that went down in the same poll still arrive together. New tests: `taps_in_sequence_are_not_reported_as_a_chord` (pad A→B, plus the same-poll chord case) and `key_taps_in_sequence_are_not_reported_together` (keyboard Q→E). `cargo test -p victory-hle gameinput` gives 17 passed under Proton here, and clippy is clean with and without `--features diagnostics`.
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 08:51 UTC · original

Confirmed on native Windows/MSVC at d3d9cd1. I reran the same synthetic probe that failed on 84da49a. With both taps released before the reader polls, the pad now returns A, B, then empty, and the keyboard returns Q, E, then empty. Inputs pressed together in one host poll still arrive together in the first read on both devices. All 17 cases selected by the gameinput::tests filter passed, including the independent probe. That resolves my reported sequence. Thanks for the fix! AI-assisted verification.

**@⁠Dathinel** on GitHub · 2026-11-25 08:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2230#issuecomment-7157564392) Confirmed on native Windows/MSVC at d3d9cd1. I reran the same synthetic probe that failed on 84da49a. With both taps released before the reader polls, the pad now returns A, B, then empty, and the keyboard returns Q, E, then empty. Inputs pressed together in one host poll still arrive together in the first read on both devices. All 17 cases selected by the gameinput::tests filter passed, including the independent probe. That resolves my reported sequence. Thanks for the fix! AI-assisted verification.
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 08:58 UTC · original

@⁠catminou4 thanks. On the HISTORY overlap: I merged the two branches to check, and #2218 and #2230 merge with no conflict. The result keeps HISTORY = 256; #2230 doesn't touch the constant (details on #2218). Dathinel has also run the latch tests and their own probe on native Windows/MSVC at d3d9cd1, all passing.

**@⁠desplmfao** on GitHub · 2026-11-25 08:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2230#issuecomment-7157711324) @⁠catminou4 thanks. On the HISTORY overlap: I merged the two branches to check, and #2218 and #2230 merge with no conflict. The result keeps `HISTORY = 256`; #2230 doesn't touch the constant (details on #2218). Dathinel has also run the latch tests and their own probe on native Windows/MSVC at `d3d9cd1`, all passing.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:31 UTC · original · edited 2026-11-26 01:25 UTC

Automated triage for the maintainers.

Merge candidate (re-checked on 7288f45). The new head merges main into the opt-in version (f66f86d) and merges cleanly. The resolution in crates/victory-hle/src/modules/gameinput.rs keeps main's #1430 change: State::seen_input and the all-zero-pad filter in State::poll. The latch sits on top of it, unchanged. Presses are held per slot until a GetCurrentReading hands them out, only while that device had a current read in the last 2 s, and only with VICTORY_INPUT_LATCH=1 (latch_enabled/latch_asked). Without the variable, GetCurrentReading behaves as on main.

On the suggestion to turn it on by default: that departs from the real API and is the maintainer's call. This PR doesn't need it to merge.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2230#issuecomment-7163891015) · edited 2026-11-26 01:25 UTC <!-- victory-triage v1 head=7288f452241717df7803c5b51bc7547efb44b1f1 verdict=merge-candidate at=2026-11-26T01:25:01Z --> Automated triage for the maintainers. **Merge candidate (re-checked on `7288f45`).** The new head merges `main` into the opt-in version (`f66f86d`) and merges cleanly. The resolution in `crates/victory-hle/src/modules/gameinput.rs` keeps `main`'s #1430 change: `State::seen_input` and the all-zero-pad filter in `State::poll`. The latch sits on top of it, unchanged. Presses are held per slot until a `GetCurrentReading` hands them out, only while that device had a current read in the last 2 s, and only with `VICTORY_INPUT_LATCH=1` (`latch_enabled`/`latch_asked`). Without the variable, `GetCurrentReading` behaves as on `main`. On the suggestion to turn it on by default: that departs from the real API and is the maintainer's call. This PR doesn't need it to merge. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 13:45 UTC · original

Following the triage, the latch is opt-in as of f66f86d. VICTORY_INPUT_LATCH=1 turns it on, and without it GetCurrentReading behaves exactly as on main. The behaviour with the latch on is unchanged, including the in-order fix Dathinel confirmed at d3d9cd1.

  • The tests' hub turns the latch on, since they test it. One test still turns it off to check the plain history.
  • A new test, the_latch_is_off_unless_asked_for, checks that only 1 enables it.
  • cargo test -p victory-hle --lib gameinput gives 18 passed under Proton, and clippy is clean with and without --features diagnostics. The PR description says opt-in now.
**@⁠desplmfao** on GitHub · 2026-11-25 13:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/2230#issuecomment-7164234050) Following the triage, the latch is opt-in as of `f66f86d`. `VICTORY_INPUT_LATCH=1` turns it on, and without it `GetCurrentReading` behaves exactly as on `main`. The behaviour with the latch on is unchanged, including the in-order fix Dathinel confirmed at `d3d9cd1`. - The tests' hub turns the latch on, since they test it. One test still turns it off to check the plain history. - A new test, `the_latch_is_off_unless_asked_for`, checks that only `1` enables it. - `cargo test -p victory-hle --lib gameinput` gives 18 passed under Proton, and clippy is clean with and without `--features diagnostics`. The PR description says opt-in now.
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 13:45 UTC · original

A recommendation for the maintainer's decision, nothing more: we'd suggest considering it on by default (VICTORY_INPUT_LATCH=0 to turn it off) once you're comfortable with the departure from the real API.

Why: at today's frame rates (one frame every 200 to 1,000 ms in the world), a tap shorter than a frame is lost without the latch, so menus and prompts feel unresponsive or miss presses. The measured effect is in the PR description. With the latch, every press arrives, at most one read later. Most people who'd benefit won't know the variable exists.

Why it doesn't break anything: it differs from how the console handles input, but not from what a title sees on the console. At its normal 30 to 60 fps, an Xbox reads often enough that these taps are never lost, so the latch only restores that at low frame rates. #2218's 256-entry history is the same kind of change (more history than the console needs, for the same reason), and it's already a merge candidate.

The PR stays opt-in as it is now, so merging it doesn't depend on this.

**@⁠desplmfao** on GitHub · 2026-11-25 13:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/2230#issuecomment-7164240860) A recommendation for the maintainer's decision, nothing more: we'd suggest considering it **on by default** (`VICTORY_INPUT_LATCH=0` to turn it off) once you're comfortable with the departure from the real API. **Why:** at today's frame rates (one frame every 200 to 1,000 ms in the world), a tap shorter than a frame is lost without the latch, so menus and prompts feel unresponsive or miss presses. The measured effect is in the PR description. With the latch, every press arrives, at most one read later. Most people who'd benefit won't know the variable exists. **Why it doesn't break anything:** it differs from how the console handles input, but not from what a title sees on the console. At its normal 30 to 60 fps, an Xbox reads often enough that these taps are never lost, so the latch only restores that at low frame rates. #2218's 256-entry history is the same kind of change (more history than the console needs, for the same reason), and it's already a merge candidate. The PR stays opt-in as it is now, so merging it doesn't depend on this.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 08:48 UTC · original · reviewed

GameInput: presses latched only on devices whose current state was read within 2 ms; diagnostics call tracing. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Substantial rework (+363); overlaps #2218 on HISTORY — see note there.

**@⁠catminou4** on GitHub · 2026-11-25 08:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2230#pullrequestreview-6054380031) · **reviewed** GameInput: presses latched only on devices whose current state was read within 2 ms; diagnostics call tracing. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Substantial rework (+363); overlaps #2218 on HISTORY — see note there.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 17:01 UTC · original · requested changes

Verified 7288f452241717df7803c5b51bc7547efb44b1f1 merged cleanly onto 63bcca43 on Windows 11 (cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-hle --all-targets -- -D warnings clean with default and --all-features; cargo test --locked -p victory-hle --lib gameinput::: 19/19 passed in both default and --features diagnostics builds).

Blocking issue: consecutive presses of the same button/key stick held across N reads and delay release (crates/victory-hle/src/modules/gameinput.rs:423-437)

When Latch was switched to a VecDeque to prevent A -> B from merging into a chord, Latch::hold (gameinput.rs:423-437) began pushing every rising edge unconditionally, even when the exact same button mask or key set is already at the back of the queue:

if pressed != 0 && self.buttons.len() < LATCH_QUEUE {
    self.buttons.push_back(pressed);
}

When a user taps the same button/key multiple times during a slow frame (e.g., mashing A or Q 4 times between two GetCurrentReading calls), buttons becomes [A, A, A, A] (up to LATCH_QUEUE = 16). On each GetCurrentReading, Latch::seen (gameinput.rs:473-497) pops one A, sees the next A at the front, computes apply(raw) == A == recorded, and records no release — leaving the button stuck down with the exact same reading/sequence for 4 consecutive frames (up to 16 frames if mashed).

It also delays the release of a held button after an earlier tap in the same frame: if the user taps A, releases A, then presses and holds A before read 1 (which sees A), and then releases A before read 2, read 2 still sees A pressed because the second queued A has not been popped yet.

Reproduced directly with a synthetic probe on 7288f452:

  • 4x A tap ([A, 0] * 4) between read 0 and read 1 -> reads 1..5 return [(0x4, ts=153), (0x4, ts=153), (0x4, ts=153), (0x4, ts=153), (0x0, ts=184)] (stuck pressed on the same reading for 4 consecutive reads).
  • 4x keyboard Q tap ([Q, empty] * 4) -> reads 1..5 return [[81], [81], [81], [81], []].
  • Tap A -> release A -> press & hold A -> read 1 (0x4) -> release A -> read 2 returns 0x4 (release delayed until read 3 0x0).

This breaks both stated invariants ("Two taps between reads become one press" and "A release of a press the title has already seen is recorded at once") and can falsely trigger hold-button actions when mashing a key at low frame rates.

Suggested fix

Skip pushing consecutive duplicate entries onto the latch queues in Latch::hold (gameinput.rs:424 and gameinput.rs:435):

  • Pad: if pressed != 0 && self.buttons.back() != Some(&pressed) && self.buttons.len() < LATCH_QUEUE
  • Keyboard: check that self.keys.back() does not already hold the exact same key set (by same_key and length) before pushing pressed.

Verified locally with that change on 7288f452: all 19 existing gameinput:: tests plus the new probes pass (20/20) — 4x mashed A or Q produces one press then immediate release, tap-then-hold releases immediately on read 2, and alternating A -> B -> A still delivers A, B, A, 0 in order.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 17:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2230#pullrequestreview-6077994781) · **requested changes** Verified `7288f452241717df7803c5b51bc7547efb44b1f1` merged cleanly onto `63bcca43` on Windows 11 (`cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` clean with default and `--all-features`; `cargo test --locked -p victory-hle --lib gameinput::`: `19/19` passed in both default and `--features diagnostics` builds). ### Blocking issue: consecutive presses of the same button/key stick held across N reads and delay release (`crates/victory-hle/src/modules/gameinput.rs:423-437`) When `Latch` was switched to a `VecDeque` to prevent `A -> B` from merging into a chord, `Latch::hold` (`gameinput.rs:423-437`) began pushing every rising edge unconditionally, even when the exact same button mask or key set is already at the back of the queue: ```rust if pressed != 0 && self.buttons.len() < LATCH_QUEUE { self.buttons.push_back(pressed); } ``` When a user taps the same button/key multiple times during a slow frame (e.g., mashing `A` or `Q` 4 times between two `GetCurrentReading` calls), `buttons` becomes `[A, A, A, A]` (up to `LATCH_QUEUE = 16`). On each `GetCurrentReading`, `Latch::seen` (`gameinput.rs:473-497`) pops one `A`, sees the next `A` at the front, computes `apply(raw) == A == recorded`, and records no release — leaving the button stuck down with the exact same reading/sequence for 4 consecutive frames (up to 16 frames if mashed). It also delays the release of a held button after an earlier tap in the same frame: if the user taps `A`, releases `A`, then presses and holds `A` before read 1 (which sees `A`), and then releases `A` before read 2, read 2 still sees `A` pressed because the second queued `A` has not been popped yet. Reproduced directly with a synthetic probe on `7288f452`: - 4x `A` tap (`[A, 0] * 4`) between read 0 and read 1 -> reads 1..5 return `[(0x4, ts=153), (0x4, ts=153), (0x4, ts=153), (0x4, ts=153), (0x0, ts=184)]` (stuck pressed on the same reading for 4 consecutive reads). - 4x keyboard `Q` tap (`[Q, empty] * 4`) -> reads 1..5 return `[[81], [81], [81], [81], []]`. - Tap `A` -> release `A` -> press & hold `A` -> read 1 (`0x4`) -> release `A` -> read 2 returns `0x4` (release delayed until read 3 `0x0`). This breaks both stated invariants ("Two taps between reads become one press" and "A release of a press the title has already seen is recorded at once") and can falsely trigger hold-button actions when mashing a key at low frame rates. #### Suggested fix Skip pushing consecutive duplicate entries onto the latch queues in `Latch::hold` (`gameinput.rs:424` and `gameinput.rs:435`): - Pad: `if pressed != 0 && self.buttons.back() != Some(&pressed) && self.buttons.len() < LATCH_QUEUE` - Keyboard: check that `self.keys.back()` does not already hold the exact same key set (by `same_key` and length) before pushing `pressed`. Verified locally with that change on `7288f452`: all 19 existing `gameinput::` tests plus the new probes pass (20/20) — 4x mashed `A` or `Q` produces one press then immediate release, tap-then-hold releases immediately on read 2, and alternating `A -> B -> A` still delivers `A`, `B`, `A`, `0` in order.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2230/head:github-bot/gh-2230'
git switch 'github-bot/gh-2230'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2230'
git switch 'github-bot/gh-2230'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2230'
git switch 'github-bot/gh-2230'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2230'
git switch 'main'
git merge --squash 'github-bot/gh-2230'
git switch 'main'
git merge --ff-only 'github-bot/gh-2230'
git switch 'main'
git merge 'github-bot/gh-2230'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2230
No description provided.