diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-14 07:48:47 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-14 07:48:47 +0300 |
| commit | 0ae8c5aa7dc47a72ed8617eaf2e1556266434452 (patch) | |
| tree | 1ff766767be807be9452315b1966b04c9cd7ce88 | |
| parent | a5e3539789aa3eba2b486b3bdfd7961761bc7df4 (diff) | |
| download | fparkan-0ae8c5aa7dc47a72ed8617eaf2e1556266434452.tar.xz fparkan-0ae8c5aa7dc47a72ed8617eaf2e1556266434452.zip | |
fix(game): count full simulation intervals for player movement
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 40 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/player_motion.rs | 7 | ||||
| -rw-r--r-- | docs/tomes/06-behavior.md | 4 |
3 files changed, 48 insertions, 3 deletions
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)) = ( diff --git a/docs/tomes/06-behavior.md b/docs/tomes/06-behavior.md index 381c35b7..392c02fe 100644 --- a/docs/tomes/06-behavior.md +++ b/docs/tomes/06-behavior.md @@ -1696,7 +1696,9 @@ Control получает world-interface Terrain и использует повÐ На каждом шаге FParkan переводит направления из осей корпуса в мировые координаты, измеряет высоту поверхности на старой и новой позиции и -сохраняет высоту героя над поверхностью. Например, при подъёме земли +сохраняет высоту героя над поверхностью. Дальность шага учитывает весь +интервал игровых часов, поэтому на ровном участке один кадр в 200 мс +даёт то же смещение, что два кадра по 100 мс. Например, при подъёме земли на две единицы корень героя тоже поднимется на две единицы. Если отрезок между позициями пересекает стену строения, шаг сохраняет старую позицию и применяет поворот. Камера, рендер объекта и сценарий |
