Skip to content

[upstream #1066] kbm: calculate mouse velocity over real dt to prevent camera whip (#963) - #85

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1066
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1066

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

When a title paused polling the gamepad for over 100 ms (such as during loading screens, level transitions, or hitching), mouse counts continued gathering in DX and DY. In Velocity::update, dt was clamped to 0.1 before dividing (dx as f32 / dt), which artificially multiplied the apparent mouse rate by up to 20x. This caused the stick deflection to peg at 100% and violently whip the camera around upon returning to gameplay.

Fixes xcl-dev#963.

What is in it

  • crates/xcl/src/hle/kbm.rs: compute the mouse velocity rate over the real dt (with dt.max(0.001) to avoid division by zero). The smoothing factor (1 - exp(-dt / SMOOTHING)) naturally bounds the exponential decay in [0, 1).
  • crates/xcl/src/hle/kbm.rs: add frame_hitch_does_not_artificially_accelerate_velocity unit test covering 300 ms and 2 s hitch scenarios, asserting that stick deflection remains moderate.

Tested

  • Windows 11 x64, Rust 1.98.1
  • Synthetic unit tests for Velocity::update and stick_from_mouse under 300 ms and 2 s pauses; confirms deflection stays proportional (< 0.5) instead of pegging at 1.0.

Regression run

  • Retail title smoke run was not performed (no game title dump on this system). The change is narrow and confined to keyboard/mouse velocity calculation, verified with unit tests. Awaiting maintainer review / test-only label or community smoke run.

Not tested

  • Physical gamepad or retail title run (the change is purely to keyboard/mouse velocity rate calculation).

AI use

  • Antigravity with Gemini 3.8 Flash investigated the issue, wrote the fix and unit test, and drafted this PR.

Mirror of xcl-dev#1066 (auto-synced, do not edit).

…l-dev#963)

When a title paused polling the gamepad for over 100 ms (during loading
screens or frame hitches), mouse counts accumulated over the entire
pause window. In Velocity::update, dt was clamped to 0.1 s before
dividing, which artificially multiplied the apparent mouse rate by up to
20x and caused stick deflection to peg at 100%, violently whipping the
camera.

Compute the velocity rate using the actual elapsed time (with dt.max(0.001)
to prevent division by zero). The exponential smoothing factor
(1 - exp(-dt / SMOOTHING)) naturally decays without overshooting.

Fixes xcl-dev#963.
Assisted-by: Antigravity (Gemini 3.8 Flash)
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1066 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1066 branch November 25, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant