d3d12 gameinput: a leaving tap the hand-over pause swallowed keeps driving by hand

merzleckeier's review of c179023f9: with vehicle:G=Y;foot:G=RB and no
context, a G tapped inside the 400 ms pause after Caps Lock gave a neutral
pad (the pause holds back keys that change with the table), yet letting it
go switched to the on-foot table: `leaving` was armed from the raw press.
Now `leaving_sent` records that the key counted in a driving pad (its Y
sent); letting it go switches only then, otherwise driving by hand goes on.
Holding it through the pause sends Y and switches on release as before.

Tests: leaving_a_vehicle_by_hand_follows_the_remap gains the swallowed tap
(still driving, leaving cleared) and the held press (Y, then on foot).
cargo test -p leonida-hle 258 passed, 2 ignored; clippy -D warnings clean.
With the release switching unconditionally the test fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
OreoFR
2026-12-03 03:44:49 +01:00
parent c179023f9c
commit 2ab7c60e8f

View File

@ -624,6 +624,9 @@ pub(super) struct Kbm {
/// That key, held down while it leaves the vehicle by hand and is another input on foot: the driving table stays
/// until it is let go, so its Y reaches the title first.
leaving: Option<u8>,
/// Whether that key's Y reached the pad (not held back by the hand-over pause or a latch): only then does letting
/// it go switch to the on-foot table; a tap the pause swallowed leaves the player in the vehicle, driving.
leaving_sent: bool,
/// The measured context as it counts (see [`UNKNOWN_AFTER`]).
measured: PlayerContext,
unknown_since: Option<u64>,
@ -650,6 +653,7 @@ impl Kbm {
driving: false,
by_hand: false,
leaving: None,
leaving_sent: false,
measured: PlayerContext::Unknown,
unknown_since: None,
down: Keys::default(),
@ -679,6 +683,7 @@ impl Kbm {
self.measured = measured;
self.by_hand = false;
self.leaving = None;
self.leaving_sent = false;
}
match self.measured {
PlayerContext::InVehicle => (true, "the player is in a vehicle"),
@ -686,14 +691,20 @@ impl Kbm {
PlayerContext::Unknown if pressed(VK_CAPITAL) => {
self.by_hand = !self.by_hand;
self.leaving = None;
self.leaving_sent = false;
(self.by_hand, "Caps Lock")
}
PlayerContext::Unknown if self.by_hand => match self.leaving {
// The key that leaves, another input on foot, let go: now the on-foot table.
// The key that leaves, another input on foot, let go: now the on-foot table, if its Y was
// sent; a tap the hand-over pause swallowed left nobody, so driving goes on.
Some(key) if !down.has(key) => {
self.by_hand = false;
self.leaving = None;
(false, "the key that leaves the vehicle was let go; Caps Lock is the driving keys")
if std::mem::take(&mut self.leaving_sent) {
self.by_hand = false;
(false, "the key that leaves the vehicle was let go; Caps Lock is the driving keys")
} else {
(true, "the key that leaves the vehicle was let go before its Y was sent")
}
}
Some(_) => (true, "leaving the vehicle"),
// Driving by hand, and the player leaves the vehicle (the driving table's Y, F unless
@ -702,6 +713,7 @@ impl Kbm {
None => match self.binds.exit_pressed(pressed) {
Some(key) if self.binds.changes(key) => {
self.leaving = Some(key);
self.leaving_sent = false;
(true, "leaving the vehicle")
}
Some(_) => {
@ -731,7 +743,14 @@ impl Kbm {
self.down = down;
let settling = now < self.settle_until;
let latched = self.latched;
binds.pad(self.driving, |key| down.has(key) && !latched.has(key) && !(settling && changes(key)))
let counts = |key: u8| down.has(key) && !latched.has(key) && !(settling && changes(key));
if let Some(key) = self.leaving
&& self.driving
&& counts(key)
{
self.leaving_sent = true; // its Y is in this pad (the driving table's)
}
binds.pad(self.driving, counts)
}
/// The measured context, an unknown one only once it has been unknown for [`UNKNOWN_AFTER`].
@ -1420,6 +1439,19 @@ mod tests {
assert_eq!(k.pad(&keys(b"W"), UNKNOWN, 2000 * MS), PadState { left_y: 1.0, ..Default::default() });
k.pad(&keys(&[]), UNKNOWN, 2008 * MS);
assert_eq!(k.pad(&keys(b"G"), UNKNOWN, 2016 * MS), button(RIGHT_SHOULDER));
// A tap of G inside the hand-over pause after Caps Lock (no Y sent): still driving after it is let go.
let mut k = Kbm::with_binds(Config::default(), binds("vehicle:G=Y;foot:G=RB"));
k.pad(&keys(&[VK_CAPITAL]), UNKNOWN, 0);
assert_eq!(k.pad(&keys(b"G"), UNKNOWN, 16 * MS), PadState::default());
assert!(k.driving);
k.pad(&keys(&[]), UNKNOWN, 24 * MS);
assert!(k.driving, "a swallowed tap leaves nobody");
assert_eq!(k.leaving, None);
// Held through the pause, its Y goes out and letting it go switches.
k.pad(&keys(b"G"), UNKNOWN, 100 * MS);
assert_eq!(k.pad(&keys(b"G"), UNKNOWN, 600 * MS), button(Y));
k.pad(&keys(&[]), UNKNOWN, 700 * MS);
assert!(!k.driving);
// Caps Lock while G is held to leave: Caps Lock's word counts, the leaving is dropped.
let mut k = Kbm::with_binds(Config::default(), binds("vehicle:G=Y;foot:G=RB"));
by_hand_press(&mut k, b"G");