Merge pull request #2022 from mc070309/cursor/sprint-jump-impulse-68db

🤖 Agent: Gate check by Ludovic's AI agent (Claude). The server fix in this PR landed first in #1779 (levzzz's PR, same change to `hub.rs` and `agent.rs`, with the same `lan_bot` test). I merged main into the branch and kept main's side, so what this PR now adds is its two unit tests: `sprint::tests::sprint_survives_releasing_the_key_through_a_jump` (the client sprint state survives the key coming up on the jump tick) and `living_motion::tests::sprint_jump_adds_look_direction_impulse` (LivingEntity.jumpFromGround's 0.2 impulse along the look, and none for a walk). Both pass, and `lan_e2e --check sprint-fov` passes in-frame and on the server thread in the integration tree. Labelled skip-release, because players see no change. Thanks @mc070309 for tracking the cause down and for the tests.
This commit is contained in:
Ludovic Marie
2026-10-26 15:25:12 +01:00
committed by GitHub
2 changed files with 189 additions and 0 deletions
+73
View File
@@ -134,3 +134,76 @@ impl SprintState {
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
fn standing() -> Conditions {
Conditions {
enough_food: true,
on_ground: true,
..Conditions::default()
}
}
fn step(state: &mut SprintState, keys: Keys, sprinting: &mut bool) {
let current = *sprinting;
let mut next = current;
state
.tick(
keys,
Conditions {
sprinting: current,
..standing()
},
7,
|value| {
next = value;
Ok::<(), ()>(())
},
)
.unwrap();
*sprinting = next;
}
/// Vanilla sprint is a state. Releasing the sprint key, including on the
/// jump tick, keeps it while forward is held; releasing forward stops it.
#[test]
fn sprint_survives_releasing_the_key_through_a_jump() {
let mut state = SprintState::default();
let mut sprinting = false;
step(
&mut state,
Keys {
forward: true,
sprint: true,
..Keys::default()
},
&mut sprinting,
);
assert!(sprinting);
step(
&mut state,
Keys {
forward: true,
jump: true,
..Keys::default()
},
&mut sprinting,
);
assert!(
sprinting,
"a jump after the sprint key comes up must stay a sprint"
);
step(
&mut state,
Keys {
jump: true,
..Keys::default()
},
&mut sprinting,
);
assert!(!sprinting);
}
}
+116
View File
@@ -122,3 +122,119 @@ pub fn air_drag<W: LivingMotionWorld>(world: &mut W) -> Result<f32, W::Error> {
};
Ok(modified_friction(drag, world.air_drag_modifier()? as f32))
}
#[cfg(test)]
mod tests {
use super::*;
use horizon_core::geometry::{Vec3, trig};
struct Jumper {
velocity: Vec3,
sprinting: bool,
yaw: f32,
synced: bool,
}
impl LivingMotionWorld for Jumper {
type Error = ();
fn velocity(&self) -> Vec3 {
self.velocity
}
fn set_velocity(&mut self, velocity: Vec3) -> Result<(), ()> {
self.velocity = velocity;
Ok(())
}
fn jump_strength(&mut self) -> Result<f64, ()> {
Ok(0.42)
}
fn block_jump_factor(&mut self) -> Result<f32, ()> {
Ok(1.0)
}
fn has_jump_boost(&mut self) -> Result<bool, ()> {
Ok(false)
}
fn jump_boost_amplifier(&mut self) -> Result<i32, ()> {
Ok(0)
}
fn sprinting(&mut self) -> Result<bool, ()> {
Ok(self.sprinting)
}
fn yaw(&mut self) -> Result<f32, ()> {
Ok(self.yaw)
}
fn mark_needs_sync(&mut self) {
self.synced = true;
}
fn no_gravity(&mut self) -> Result<bool, ()> {
Ok(false)
}
fn gravity_attribute(&mut self) -> Result<f64, ()> {
Ok(0.08)
}
fn has_slow_falling(&mut self) -> Result<bool, ()> {
Ok(false)
}
fn controlling_passenger_is_player(&mut self) -> Result<bool, ()> {
Ok(false)
}
fn speed(&mut self) -> Result<f32, ()> {
Ok(0.1)
}
fn omnidirectional_air_mover(&mut self) -> Result<bool, ()> {
Ok(false)
}
fn air_drag_modifier(&mut self) -> Result<f64, ()> {
Ok(0.0)
}
}
fn impulse(yaw: f32) -> (f64, f64) {
let angle = f64::from(yaw * trig::DEG_TO_RAD);
(
f64::from(-trig::sin(angle)) * 0.2,
f64::from(trig::cos(angle)) * 0.2,
)
}
/// LivingEntity.jumpFromGround: a sprint adds ~0.2 along look; a walk does not.
#[test]
fn sprint_jump_adds_look_direction_impulse() {
for yaw in [0.0, 45.0, 90.0, 180.0, 270.0, 300.0] {
let before = Vec3::new(0.13, -0.08, -0.05);
let mut sprinting = Jumper {
velocity: before,
sprinting: true,
yaw,
synced: false,
};
jump_from_ground(&mut sprinting).unwrap();
let (dx, dz) = impulse(yaw);
let horizontal = ((dx * dx) + (dz * dz)).sqrt();
assert!(
(horizontal - 0.2).abs() < 1.0e-4,
"yaw {yaw}: impulse length {horizontal}"
);
assert!(
(sprinting.velocity.x - (before.x + dx)).abs() < 1.0e-9,
"yaw {yaw}: x {:?} expected {}",
sprinting.velocity,
before.x + dx
);
assert!((sprinting.velocity.z - (before.z + dz)).abs() < 1.0e-9);
// jump_power narrows the 0.42 strength through float, as vanilla does.
let jump_y = f64::from(0.42_f32);
assert!((sprinting.velocity.y - jump_y).abs() < 1.0e-9);
assert!(sprinting.synced);
let mut walking = Jumper {
velocity: before,
sprinting: false,
yaw,
synced: false,
};
jump_from_ground(&mut walking).unwrap();
assert_eq!(walking.velocity.x, before.x);
assert_eq!(walking.velocity.z, before.z);
assert!((walking.velocity.y - jump_y).abs() < 1.0e-9);
}
}
}