Files
horizon-airdef/crates/horizon-world/examples/stepped_interpolation_fixture.rs
T
Ludovic Marie feeefb3a33 Mobs: a punch shows smooth and slow, as on vanilla's client
The server sends a knocked-back, pushed or jumping mob's move at once
(Entity.needsSync), and the remote client walks every living entity along
the server's positions with vanilla's SteppedInterpolationHandler: each
position takes the type's update interval to reach, sped up while steps
pile up. Before, the client waited for the next due update and then
lerped there in fewer ticks, so a hit pig jumped away fast.

tools/test_stepped_interpolation_parity.py drives vanilla's unmodified
InterpolationData and the Rust port with the same packets and ticks
(random cases and a punched pig's knockback); 135236 positions and
rotations match bit for bit.

Fixes #1374

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 05:38:46 +02:00

94 lines
3.5 KiB
Rust

//! The Rust side of tools/test_stepped_interpolation_parity.py: replays the
//! harness's events (VanillaSteppedInterpolationOracle's input format) on
//! `SteppedInterpolation` and writes the entity after each one.
use horizon_world::stepped_interpolation::{Path, PosRot, Start, SteppedInterpolation};
use std::fmt::Write as _;
/// `Entity.setRot`: yaw and pitch wrapped, pitch clamped (`setXRot`).
fn set_rot(entity: &mut PosRot, yaw: f32, pitch: f32) {
entity.yaw = yaw % 360.0;
entity.pitch = (pitch % 360.0 % 360.0).clamp(-90.0, 90.0);
}
fn main() {
let args: Vec<String> = std::env::args().collect();
let input = std::fs::read_to_string(&args[1]).expect("input");
let mut out = String::new();
let mut handler = SteppedInterpolation::new(0);
let mut entity = PosRot::default();
for line in input.lines() {
let f: Vec<&str> = line.split_whitespace().collect();
let num = |i: usize| f[i].parse::<f64>().expect("number");
let what = match f[0] {
"case" => {
handler = SteppedInterpolation::new(f[1].parse().expect("steps"));
entity = PosRot {
position: [num(2), num(3), num(4)],
yaw: f[5].parse().expect("yaw"),
pitch: f[6].parse().expect("pitch"),
};
"c"
}
"move" => {
let mut i = 2;
let path = match f[1] {
"L" => {
i += 3;
Some(Path::Linear([num(2), num(3), num(4)]))
}
"S" => {
let n: usize = f[2].parse().expect("count");
i = 3;
let mut steps = Vec::new();
for _ in 0..n {
steps.push((
[num(i), num(i + 1), num(i + 2)],
f[i + 3].parse().expect("ticks"),
));
i += 4;
}
Some(Path::Stepped(steps))
}
_ => None,
};
let rotation = (f[i] == "R").then(|| {
(
f[i + 1].parse().expect("yaw"),
f[i + 2].parse().expect("pitch"),
)
});
match handler.interpolate_to(entity, path, rotation) {
Start::Snap(at) => {
entity.position = at.position;
set_rot(&mut entity, at.yaw, at.pitch);
"s"
}
Start::Unchanged => "k",
Start::Interpolating => "i",
}
}
"tick" => match handler.interpolate() {
Some(at) => {
entity.position = at.position;
set_rot(&mut entity, at.yaw, at.pitch);
"t"
}
None => "n",
},
other => panic!("unknown event {other}"),
};
let p = entity.position;
writeln!(
out,
"{what} {:x} {:x} {:x} {:x} {:x}",
p[0].to_bits(),
p[1].to_bits(),
p[2].to_bits(),
entity.yaw.to_bits(),
entity.pitch.to_bits()
)
.expect("write");
}
std::fs::write(&args[2], out).expect("output");
}