From 0ae8c5aa7dc47a72ed8617eaf2e1556266434452 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 14 Nov 2026 08:48:47 +0400 Subject: fix(game): count full simulation intervals for player movement --- crates/fparkan-runtime/src/lib.rs | 40 ++++++++++++++++++++++++++++- crates/fparkan-runtime/src/player_motion.rs | 7 ++++- 2 files changed, 45 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 3fae8ea6..6609149e 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -17193,6 +17193,17 @@ mod tests { mouse_y: 0.0, ..input }; + assert!(matches!( + plan_player_motion( + &engine, + cockpit, + PlayerMotion { + delta_seconds: f32::MAX, + ..movement + } + ), + Err(EngineError::Movement(_)) + )); let proposed = plan_player_motion(&engine, cockpit, movement) .unwrap() .unwrap(); @@ -17209,7 +17220,34 @@ mod tests { .unwrap() }; assert!(((z1 - ground([x1, y1])) - (z0 - ground([x0, y0]))).abs() < 1e-5); - let idle = frame(&mut engine, 300).unwrap(); + let slow_frame = plan_player_motion( + &engine, + cockpit, + PlayerMotion { + delta_seconds: 0.2, + ..movement + }, + ) + .unwrap() + .unwrap(); + let [x2, y2, _] = + pose(&frame_with_player_motion(&mut engine, 400, cockpit, slow_frame, false).unwrap()) + .position + .map(f32::from_bits); + assert!(((x2 - x1).hypot(y2 - y1) - 1.6).abs() < 1e-4); + set_transform(&mut engine.world, cockpit.handle, walked).unwrap(); + let mut split = walked; + for clock_ms in [500, 600] { + let proposed = plan_player_motion(&engine, cockpit, movement) + .unwrap() + .unwrap(); + split = pose( + &frame_with_player_motion(&mut engine, clock_ms, cockpit, proposed, false).unwrap(), + ); + } + let [split_x, split_y, _] = split.position.map(f32::from_bits); + assert!((split_x - x2).hypot(split_y - y2) < 1e-4); + let idle = frame(&mut engine, 700).unwrap(); assert_eq!(idle.player_pitch_bits, blocked.player_pitch_bits); } diff --git a/crates/fparkan-runtime/src/player_motion.rs b/crates/fparkan-runtime/src/player_motion.rs index 439429cd..7f88d41a 100644 --- a/crates/fparkan-runtime/src/player_motion.rs +++ b/crates/fparkan-runtime/src/player_motion.rs @@ -86,12 +86,17 @@ fn plan_motion( yaw }; let [right, forward] = input.movement.map(|axis| axis.clamp(-1.0, 1.0)); - let distance = 8.0 * input.delta_seconds.min(0.1) / right.hypot(forward).max(1.0); + let distance = 8.0 * input.delta_seconds / right.hypot(forward).max(1.0); let (sin, cos) = yaw.sin_cos(); let xy = [ from[0] + (cos * right - sin * forward) * distance, from[1] + (sin * right + cos * forward) * distance, ]; + if !xy.iter().all(|axis| axis.is_finite()) { + return Err(EngineError::Movement( + "player step exceeds finite coordinates".into(), + )); + } let mut sweep = None; if xy != [from[0], from[1]] { if let (Some(old_ground), Some(new_ground)) = ( -- cgit v1.2.3