Keyboard/mouse: the camera whips after the title stops reading the gamepad for over 100 ms #963

Open
opened 2026-11-26 04:38:31 +00:00 by github-bot · 1 comment
Owner

@⁠Conrage on GitHub · 2026-11-24 09:36 UTC · original

kbm::apply passes all mouse counts gathered since the previous call to Velocity::update with the elapsed dt, and update clamps dt to 0.1 s before dividing:

If the title doesn't read the gamepad for 2 s (a loading screen, a hitch) while the mouse moves at 1,000 counts/s, the 2,000 counts are treated as arriving in 0.1 s: 20,000 counts/s. With the smoothing factor at dt = 0.1 (about 0.96), the velocity jumps to about 19,300 counts/s, almost five times full deflection (4,000). It stays at full deflection for about three frames before it settles, so the camera whips.

Repro (unit test):

let mut v = Velocity::default();
v.update(2000, 0, 2.0);
assert_eq!(stick_from_mouse(v.x, v.y, 1.0).0, 1.0); // full deflection from a 1,000 counts/s move

Suggested fix: compute the rate with the real dt (clamping only the smoothing factor), or drop counts gathered before the clamp window.

Not tested: worked out from the code; the test above was not run and it was not seen in a game.

AI use: found, checked and written up by Claude Code (Claude Opus 5.5) at my request.

**@⁠Conrage** on GitHub · 2026-11-24 09:36 UTC · [original](https://github.com/xcl-dev/xcl/issues/963) `kbm::apply` passes all mouse counts gathered since the previous call to `Velocity::update` with the elapsed `dt`, and `update` clamps `dt` to 0.1 s before dividing: - https://github.com/ivall/xcl/blob/077ce40/crates/xcl/src/hle/kbm.rs#L433-L436 - https://github.com/ivall/xcl/blob/077ce40/crates/xcl/src/hle/kbm.rs#L74-L78 If the title doesn't read the gamepad for 2 s (a loading screen, a hitch) while the mouse moves at 1,000 counts/s, the 2,000 counts are treated as arriving in 0.1 s: 20,000 counts/s. With the smoothing factor at dt = 0.1 (about 0.96), the velocity jumps to about 19,300 counts/s, almost five times full deflection (4,000). It stays at full deflection for about three frames before it settles, so the camera whips. **Repro (unit test):** ```rust let mut v = Velocity::default(); v.update(2000, 0, 2.0); assert_eq!(stick_from_mouse(v.x, v.y, 1.0).0, 1.0); // full deflection from a 1,000 counts/s move ``` **Suggested fix:** compute the rate with the real `dt` (clamping only the smoothing factor), or drop counts gathered before the clamp window. **Not tested:** worked out from the code; the test above was not run and it was not seen in a game. **AI use:** found, checked and written up by Claude Code (Claude Opus 5.5) at my request.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:38:31 +00:00
Author
Owner

@⁠DTsordas on GitHub · 2026-11-24 09:38 UTC · original

Confirmed on main 077ce40 with a unit test: Velocity::update(300, -150, 0.3) (1000 counts/s over a 300 ms hitch) gives Velocity { x: 2892.978, y: -1446.489 } instead of about 1000 / -500, so at mouse_sensitivity = 1 the right stick goes to 0.76 instead of 0.36.

I have the fix your issue suggests: the rate over the real dt, with only the lower bound kept (dt.max(0.001)). The upper bound guarded nothing else, since the smoothing weight is at most 1 for any dt and the wheel clamps its own. With that test, the full suite passes on an RX 9060 XT (debug, cargo test --workspace -- --test-threads=4: 717 passed, 0 failed, 41 ignored, 0 SKIPPED). I'll open the PR (Fixes #963) once I have the smoke runs on a title, unless you already have one.

AI use: Claude Code (Claude Opus 5.5) ran the test and wrote this comment.

**@⁠DTsordas** on GitHub · 2026-11-24 09:38 UTC · [original](https://github.com/xcl-dev/xcl/issues/963#issuecomment-7127694450) Confirmed on main `077ce40` with a unit test: `Velocity::update(300, -150, 0.3)` (1000 counts/s over a 300 ms hitch) gives `Velocity { x: 2892.978, y: -1446.489 }` instead of about 1000 / -500, so at `mouse_sensitivity = 1` the right stick goes to 0.76 instead of 0.36. I have the fix your issue suggests: the rate over the real `dt`, with only the lower bound kept (`dt.max(0.001)`). The upper bound guarded nothing else, since the smoothing weight is at most 1 for any `dt` and the wheel clamps its own. With that test, the full suite passes on an RX 9060 XT (debug, `cargo test --workspace -- --test-threads=4`: 717 passed, 0 failed, 41 ignored, 0 SKIPPED). I'll open the PR (Fixes #963) once I have the smoke runs on a title, unless you already have one. **AI use:** Claude Code (Claude Opus 5.5) ran the test and wrote this comment.
This discussion has been locked. Commenting is limited to contributors.
No description provided.