horizon-world probes: one copy of the helpers they shared

Now that the probes are modules of one binary, the helpers copied between
them live once in examples/probe/support: the collision probes' shape
printer (emit, values, box_values, bounds, 8 copies each), the canonical
NaN bits of f64 and f32 (50 copies), the registry JSON-to-NBT reader (15)
and the JSON block position (4). -1,097 lines of copies.

f64::NAN.to_bits() is 0x7ff8000000000000, the literal some copies used,
so every probe prints the same bytes.

tools/parity.py follows include!: three probes include another probe's
source, and stay dependent on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-23 14:23:44 +02:00
parent fdae4b895c
commit 7092f16a06
83 changed files with 561 additions and 1400 deletions
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_world::attributes::{
AttributeError, Definition, Instance, Modifier, Observer, Operation, Packed,
};
@@ -10,13 +11,6 @@ use std::{
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
f64::NAN.to_bits()
} else {
v.to_bits()
}
}
fn refs<'a>(mods: impl IntoIterator<Item = &'a Modifier>, pool: &[Modifier]) -> String {
let s = mods
.into_iter()
@@ -43,9 +37,9 @@ impl Observer for Callback<'_> {
self.out,
"dirty {} {:016x} {} {:016x} {} {}",
self.target,
bits(a.base_value()),
f64_bits(a.base_value()),
a.is_dirty(),
bits(a.cached_value()),
f64_bits(a.cached_value()),
a.modifiers().len(),
a.permanent_modifiers().len()
)?;
@@ -55,7 +49,7 @@ impl Observer for Callback<'_> {
return Err(io::Error::other("injected attribute observer failure"));
}
if self.op["read"].as_bool().unwrap() {
writeln!(self.out, "observed {:016x}", bits(a.value()))?;
writeln!(self.out, "observed {:016x}", f64_bits(a.value()))?;
}
Ok(())
}
@@ -64,9 +58,9 @@ fn state(out: &mut dyn Write, id: usize, a: &Instance, pool: &[Modifier]) -> io:
writeln!(
out,
"state {id} {:016x} {} {:016x}",
bits(a.base_value()),
f64_bits(a.base_value()),
a.is_dirty(),
bits(a.cached_value())
f64_bits(a.cached_value())
)?;
writeln!(out, "all {}", refs(a.modifiers(), pool))?;
writeln!(out, "permanent {}", refs(a.permanent_modifiers(), pool))?;
@@ -165,7 +159,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(
cb.out,
"packed {:016x} {}",
bits(p.base),
f64_bits(p.base),
refs(&p.modifiers, &pool)
)?;
packed = Some(p);
@@ -181,7 +175,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
),
"many" => instances[target].add_permanent_many(mods(), &mut cb),
"value" => {
writeln!(cb.out, "value {:016x}", bits(instances[target].value()))?;
writeln!(cb.out, "value {:016x}", f64_bits(instances[target].value()))?;
Ok(())
}
_ => panic!("fixture mode"),
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::{
attribute_health::{AttributeHealth, HealthAttributes, HealthError, HealthObserver},
attributes::{
@@ -21,13 +22,6 @@ fn single(v: &Value) -> f32 {
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
fn double_bits(v: f64) -> u64 {
if v.is_nan() {
f64::NAN.to_bits()
@@ -55,7 +49,7 @@ impl Observer<'_> {
impl HealthObserver for Observer<'_> {
type Error = io::Error;
fn updated(&mut self, h: &mut SyncedFloat) -> io::Result<()> {
self.effect(&format!("updated {:08x}", bits(h.value())))
self.effect(&format!("updated {:08x}", f32_bits(h.value())))
}
}
// This fixture observes health/food values, not cross-attribute hash order.
@@ -168,7 +162,7 @@ impl<A: TestAttributes> FoodWorld for World<'_, A> {
}
fn hurt_starvation(&mut self, _: (), _: &mut FoodData, v: f32) -> Result<(), Self::Error> {
self.observer
.effect(&format!("starve {:08x}", bits(v)))
.effect(&format!("starve {:08x}", f32_bits(v)))
.map_err(HealthError::Observer)
}
}
@@ -261,7 +255,7 @@ fn run<A: TestAttributes>(dir: &Path, output: &str) -> Result<(), Box<dyn std::e
"packed {}",
w.health
.take_dirty()
.map(|v| format!("{:08x}", bits(v)))
.map(|v| format!("{:08x}", f32_bits(v)))
.unwrap_or_else(|| "none".into())
)
.map_err(HealthError::Observer),
@@ -275,13 +269,13 @@ fn run<A: TestAttributes>(dir: &Path, output: &str) -> Result<(), Box<dyn std::e
writeln!(
w.observer.out,
"state {:08x} {} {} {:08x} {} {:08x} {:08x} {} {}",
bits(w.health.value()),
f32_bits(w.health.value()),
w.health.is_dirty(),
w.health.is_default(),
bits(w.absorption),
f32_bits(w.absorption),
food.food,
bits(food.saturation),
bits(food.exhaustion),
f32_bits(food.saturation),
f32_bits(food.exhaustion),
food.timer,
w.observer.calls
)?;
@@ -244,9 +244,9 @@ mod integration {
};
let prefix = format!(
"prototype {id} {} {} {}",
bits(a.base_value()),
f64_hex(a.base_value()),
a.is_dirty(),
bits(a.cached_value())
f64_hex(a.cached_value())
);
let all = a.modifiers().to_vec();
let permanent = a.permanent_modifiers().to_vec();
@@ -377,14 +377,14 @@ mod integration {
} else {
ValueKind::Base
};
map.value(world.key(op), kind, &mut world).map(bits)
map.value(world.key(op), kind, &mut world).map(f64_hex)
}
"modifier-value" => {
let id = world.templates[op["template"].as_u64().unwrap() as usize]
.id()
.to_owned();
map.modifier_value(world.key(op), &id, &mut world)
.map(bits)
.map(f64_hex)
.map_err(|e| match e {
ModifierValueError::World(e) => e,
ModifierValueError::MissingInstanceModifier => Stop::Null,
@@ -475,7 +475,7 @@ mod integration {
"value" => world
.handle(op["instance"].as_i64().unwrap())
.and_then(|h| h.ok_or(Stop::Null))
.map(|h| bits(world.instances[h.id].value.as_mut().unwrap().value())),
.map(|h| f64_hex(world.instances[h.id].value.as_mut().unwrap().value())),
_ => world.raw(&mut map, op).map(|()| "ok".into()),
};
world.logs.push(format!(
@@ -1,5 +1,6 @@
use crate::support::shapes::emit;
use horizon_core::{
geometry::{Aabb, Axis, ShapeOp, Vec3, VoxelShape},
geometry::{Aabb, ShapeOp, Vec3, VoxelShape},
position::{BlockPos, ChunkPos},
};
use horizon_world::{
@@ -20,70 +21,6 @@ use std::{
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn values(
out: &mut impl Write,
label: &str,
values: impl IntoIterator<Item = f64>,
) -> io::Result<()> {
write!(out, "{label}")?;
for v in values {
let bits = if v.is_nan() {
0x7ff8_0000_0000_0000
} else {
v.to_bits()
};
write!(out, " {bits:016x}")?;
}
writeln!(out)
}
fn box_values(out: &mut impl Write, label: &str, b: Aabb) -> io::Result<()> {
values(
out,
label,
[
b.min(Axis::X),
b.min(Axis::Y),
b.min(Axis::Z),
b.max(Axis::X),
b.max(Axis::Y),
b.max(Axis::Z),
],
)
}
fn emit(out: &mut impl Write, shape: &VoxelShape) -> io::Result<()> {
writeln!(
out,
"shape {} {} {}",
shape.is_empty(),
shape.boxes().len(),
shape.is_cube()
)?;
for (axis, name) in Axis::ALL.into_iter().zip(["x", "y", "z"]) {
values(out, name, shape.coordinates(axis).iter().copied())?;
}
let axes = shape.cube_coordinate_axes();
writeln!(
out,
"axes {}",
u8::from(axes[0]) + 2 * u8::from(axes[1]) + 4 * u8::from(axes[2])
)?;
values(
out,
"extrema",
Axis::ALL
.map(|a| shape.min(a))
.into_iter()
.chain(Axis::ALL.map(|a| shape.max(a))),
)?;
match shape.bounds() {
Some(b) => box_values(out, "bounds", b)?,
None => writeln!(out, "bounds none")?,
}
for b in shape.boxes() {
box_values(out, "box", *b)?;
}
Ok(())
}
fn shape(index: u64) -> VoxelShape {
let cuboid = |min, max| VoxelShape::from_box(Aabb::new(min, max)).unwrap();
@@ -1,5 +1,7 @@
use crate::support::common::f64_bits;
use crate::support::shapes::bounds;
use horizon_core::{
geometry::{Aabb, Axis, Vec3, VoxelShape},
geometry::{Aabb, Vec3, VoxelShape},
position::BlockPos,
};
use horizon_world::{
@@ -24,13 +26,6 @@ fn number(v: &Value) -> f64 {
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn fbits(v: f32) -> u32 {
if v.is_nan() { 0x7fc00000 } else { v.to_bits() }
}
@@ -43,17 +38,6 @@ fn bbox(v: &Value) -> Aabb {
Vec3::new(number(&v[3]), number(&v[4]), number(&v[5])),
)
}
fn bounds(label: &str, b: Aabb) -> String {
format!(
"{label} {:016x} {:016x} {:016x} {:016x} {:016x} {:016x}",
bits(b.min(Axis::X)),
bits(b.min(Axis::Y)),
bits(b.min(Axis::Z)),
bits(b.max(Axis::X)),
bits(b.max(Axis::Y)),
bits(b.max(Axis::Z))
)
}
struct World<'a, 'r> {
f: &'a Value,
out: &'a mut dyn Write,
@@ -100,9 +84,9 @@ impl BlockPushWorld for World<'_, '_> {
self.query(format!(
"teleport {} {:016x} {:016x} {:016x}",
e.0,
bits(v.x),
bits(v.y),
bits(v.z)
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
))?;
let i = e.0 as usize;
self.entities[i] = self.entities[i].move_by(v);
@@ -169,7 +153,7 @@ impl BlockLandingWorld for World<'_, '_> {
Ok(k)
}
fn cause_fall_damage(&mut self, d: f64, m: f32, s: Self::DamageSource) -> io::Result<bool> {
self.query(format!("damage {:016x} {:08x} {s}", bits(d), fbits(m)))?;
self.query(format!("damage {:016x} {:08x} {s}", f64_bits(d), fbits(m)))?;
Ok(self.flag("damage"))
}
fn known_sound(&self, s: LandingSound) -> Self::Sound {
@@ -1,5 +1,7 @@
use crate::support::common::f64_bits;
use crate::support::shapes::bounds;
use horizon_core::{
geometry::{Aabb, Axis, ShapeOp, Vec3, VoxelShape},
geometry::{Aabb, ShapeOp, Vec3, VoxelShape},
position::BlockPos,
};
use horizon_world::{
@@ -16,30 +18,12 @@ use std::{
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn bbox(v: &Value) -> Aabb {
Aabb::new(
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2])),
Vec3::new(number(&v[3]), number(&v[4]), number(&v[5])),
)
}
fn bounds(label: &str, b: Aabb) -> String {
format!(
"{label} {:016x} {:016x} {:016x} {:016x} {:016x} {:016x}",
bits(b.min(Axis::X)),
bits(b.min(Axis::Y)),
bits(b.min(Axis::Z)),
bits(b.max(Axis::X)),
bits(b.max(Axis::Y)),
bits(b.max(Axis::Z))
)
}
fn shape(v: &Value) -> Result<VoxelShape, Box<dyn std::error::Error>> {
let mut s = VoxelShape::empty();
for b in v.as_array().unwrap() {
@@ -85,9 +69,9 @@ impl BlockPushWorld for World<'_> {
self.query(format!(
"teleport {} {:016x} {:016x} {:016x}",
e.0,
bits(v.x),
bits(v.y),
bits(v.z)
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
))?;
let index = e.0 as usize;
self.entities[index] = self.entities[index].move_by(v);
@@ -1,4 +1,5 @@
//! Original JSON block-state codec comparison transport.
use crate::support::common::tag;
use horizon_world::{
DATA_VERSION,
nbt::Tag,
@@ -11,17 +12,6 @@ use std::{
io::{self, Write},
path::Path,
};
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
_ => panic!("invalid registry metadata"),
}
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = crate::args().nth(1).expect("private fixture directory");
let dir = Path::new(&arg);
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::blocking_rules::{
BlockingRules, DamageReduction, ItemDamageFunction, TypeMatchWorld,
};
@@ -13,13 +14,6 @@ fn single(v: &Value) -> f32 {
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
struct World<'a> {
f: &'a Value,
out: &'a mut dyn Write,
@@ -96,7 +90,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
)?;
writeln!(w.out, "item {}", rules.item_damage.apply(damage))?;
match rules.resolve(&mut w, damage, number(&f["angle"])) {
Ok(v) => writeln!(w.out, "blocked {:08x}\nresult ok", bits(v))?,
Ok(v) => writeln!(w.out, "blocked {:08x}\nresult ok", f32_bits(v))?,
Err(_) => writeln!(w.out, "result error")?,
};
writeln!(w.out, "queries {} {}", w.calls, w.changed)?;
@@ -1,3 +1,4 @@
use crate::support::common::tag;
use horizon_world::worldgen::{
anchor::WorldGenerationContext, bulk_section::TerrainBulkAccess, feature_region::TerrainRegion,
};
@@ -55,17 +56,6 @@ impl TerrainBlockStates for Properties<'_> {
fn n(v: &Value) -> i32 {
v.as_i64().unwrap() as i32
}
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(i) => Tag::Int(i.as_i64().unwrap() as i32),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
_ => panic!("unsupported registry fixture value"),
}
}
fn fixture(
f: &Value,
registry: &BlockRegistry,
@@ -1,4 +1,5 @@
//! Transport for shared cave/canyon geometry and ordered output failures.
use crate::support::common::f64_bits;
use horizon_core::{
carving::{CarverOutput, CarvingMask, can_reach, carve_ellipsoid},
position::ChunkPos,
@@ -15,13 +16,6 @@ fn n(v: &Value) -> i32 {
fn d(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
struct Output<'a> {
mask: &'a mut CarvingMask,
trace: &'a std::cell::RefCell<Vec<String>>,
@@ -78,9 +72,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
};
trace.borrow_mut().push(format!(
"skip {:x} {:x} {:x} {by} {skip}",
bits(x),
bits(y),
bits(z)
f64_bits(x),
f64_bits(y),
f64_bits(z)
));
skip
},
@@ -11,6 +11,7 @@
//! quart layer (16 columns, z-major), one `y Y ID...` line per block row and
//! one `be X Y Z CANONICAL_NBT` line per block entity and one `t block|fluid
//! NAME X Y Z PRIORITY` line per scheduled tick.
use crate::support::common::tag;
use horizon_core::position::ChunkPos;
use horizon_world::{
DATA_VERSION,
@@ -23,17 +24,6 @@ use std::{collections::HashMap, fmt::Write as _, fs, io::Write as _, path::Path}
type Error = Box<dyn std::error::Error + Send + Sync>;
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
Value::Object(o) => {
Tag::Compound(o.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
_ => panic!("invalid registry metadata"),
}
}
fn registry(resources: &Path) -> Result<&'static BlockRegistry, Error> {
let facts: Value = serde_json::from_str(&fs::read_to_string(resources.join("facts.json"))?)?;
let states = facts["states"].as_array().ok_or("facts states")?;
@@ -1,4 +1,5 @@
//! Test transport for pre-light ProtoChunk writes and stage heightmap transitions.
use crate::support::common::tag;
use horizon_core::position::ChunkPos;
use horizon_world::{
DATA_VERSION,
@@ -54,17 +55,6 @@ impl TerrainBlockStates for Properties<'_> {
fn n(v: &Value) -> i32 {
v.as_i64().unwrap() as i32
}
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(i) => Tag::Int(i.as_i64().unwrap() as i32),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
_ => panic!("unsupported registry fixture value"),
}
}
fn fixture(
f: &Value,
registry: &BlockRegistry,
@@ -1,5 +1,6 @@
use crate::support::shapes::emit;
use horizon_core::{
geometry::{Aabb, Axis, ShapeOp, Vec3, VoxelShape},
geometry::{Aabb, ShapeOp, Vec3, VoxelShape},
position::BlockPos,
};
use horizon_world::{
@@ -31,70 +32,6 @@ const ITEMS: [&str; 5] = [
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn values(
out: &mut impl Write,
label: &str,
values: impl IntoIterator<Item = f64>,
) -> io::Result<()> {
write!(out, "{label}")?;
for v in values {
let bits = if v.is_nan() {
0x7ff8_0000_0000_0000
} else {
v.to_bits()
};
write!(out, " {bits:016x}")?;
}
writeln!(out)
}
fn box_values(out: &mut impl Write, label: &str, b: Aabb) -> io::Result<()> {
values(
out,
label,
[
b.min(Axis::X),
b.min(Axis::Y),
b.min(Axis::Z),
b.max(Axis::X),
b.max(Axis::Y),
b.max(Axis::Z),
],
)
}
fn emit(out: &mut impl Write, shape: &VoxelShape) -> io::Result<()> {
writeln!(
out,
"shape {} {} {}",
shape.is_empty(),
shape.boxes().len(),
shape.is_cube()
)?;
for (axis, name) in Axis::ALL.into_iter().zip(["x", "y", "z"]) {
values(out, name, shape.coordinates(axis).iter().copied())?;
}
let axes = shape.cube_coordinate_axes();
writeln!(
out,
"axes {}",
u8::from(axes[0]) + 2 * u8::from(axes[1]) + 4 * u8::from(axes[2])
)?;
values(
out,
"extrema",
Axis::ALL
.map(|a| shape.min(a))
.into_iter()
.chain(Axis::ALL.map(|a| shape.max(a))),
)?;
match shape.bounds() {
Some(b) => box_values(out, "bounds", b)?,
None => writeln!(out, "bounds none")?,
}
for b in shape.boxes() {
box_values(out, "box", *b)?;
}
Ok(())
}
struct LiquidWorld<'a, W> {
out: &'a mut W,
calls: i32,
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::combat_rules::{self, ArmorWorld};
use serde_json::Value;
use std::{
@@ -8,13 +9,6 @@ use std::{
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
struct World<'a> {
f: &'a Value,
out: &'a mut dyn Write,
@@ -77,7 +71,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
};
match result {
Ok(v) => {
writeln!(w.out, "value {:08x}\nresult ok", bits(v))?;
writeln!(w.out, "value {:08x}\nresult ok", f32_bits(v))?;
}
Err(_) => writeln!(w.out, "result error")?,
}
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{
geometry::Vec3,
random::{LegacyRandom, RandomSource, XoroshiroRandom},
@@ -23,13 +24,6 @@ fn n(v: &Value, k: &str) -> i32 {
fn fl(v: &Value, k: &str) -> f32 {
f32::from_bits(v[k].as_u64().unwrap() as u32)
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn opt(v: Option<&i32>) -> String {
v.map_or("none".into(), i32::to_string)
}
@@ -142,12 +136,12 @@ impl<R: RandomSource> ItemParticleWorld<u8, u8, i32> for World<'_, R> {
"particle {level} {} {} {damage} {same} {} {} {} {} {} {}",
t.item(),
t.count(),
bits(p.x),
bits(p.y),
bits(p.z),
bits(v.x),
bits(v.y),
bits(v.z)
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z),
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
))
}
}
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{
geometry::Vec3,
random::{LegacyRandom, RandomSource, XoroshiroRandom},
@@ -33,13 +34,6 @@ fn n(v: &Value, k: &str) -> i32 {
fn fl(v: &Value, k: &str) -> f32 {
f32::from_bits(v[k].as_u64().unwrap() as u32)
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn opt(v: Option<&Component>) -> String {
match v {
None => "none".into(),
@@ -189,12 +183,12 @@ impl<R: RandomSource> ItemParticleWorld<u8, u8, Component> for World<'_, R> {
"particle {level} {} {} {damage} {same} {} {} {} {} {} {}",
t.item(),
t.count(),
bits(p.x),
bits(p.y),
bits(p.z),
bits(v.x),
bits(v.y),
bits(v.z)
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z),
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
))
}
}
@@ -263,9 +257,9 @@ impl<R: RandomSource> FoodConsumptionWorld for World<'_, R> {
"food-sound {} {} {category} {} {} {} {} {}",
s.level,
s.sound,
bits(s.position.x),
bits(s.position.y),
bits(s.position.z),
f64_bits(s.position.x),
f64_bits(s.position.y),
f64_bits(s.position.z),
fbits(s.volume),
fbits(s.pitch)
))
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::{
combat_rules::ArmorWorld,
damage_reduction::{self, Bypass, DamageReductionWorld},
@@ -14,13 +15,6 @@ fn single(v: &Value) -> f32 {
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
struct World<'a> {
f: &'a Value,
out: &'a mut dyn Write,
@@ -73,7 +67,7 @@ impl DamageReductionWorld for World<'_> {
Ok(self.state()[format!("bypass_{n}")].as_bool().unwrap())
}
fn hurt_armor(&mut self, v: f32) -> io::Result<()> {
self.query(&format!("hurt-armor {:08x}", bits(v)))
self.query(&format!("hurt-armor {:08x}", f32_bits(v)))
}
fn armor_value(&mut self) -> io::Result<i32> {
self.query("armor")?;
@@ -139,7 +133,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
} else {
damage_reduction::after_magic(&mut w, d)
};
r.and_then(|v| writeln!(w.out, "float {:08x}", bits(v)))
r.and_then(|v| writeln!(w.out, "float {:08x}", f32_bits(v)))
};
writeln!(
w.out,
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_world::damage_source::{Catalog, EntityKind, SourceWorld};
use serde_json::Value;
use std::{
@@ -11,21 +12,14 @@ fn number(v: &Value) -> f64 {
fn position(v: &Value) -> [f64; 3] {
std::array::from_fn(|i| number(&v[i]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
f64::NAN.to_bits()
} else {
v.to_bits()
}
}
fn vec(v: Option<[f64; 3]>) -> String {
match v {
None => "none".into(),
Some(v) => format!(
"{:016x} {:016x} {:016x}",
bits(v[0]),
bits(v[1]),
bits(v[2])
f64_bits(v[0]),
f64_bits(v[1]),
f64_bits(v[2])
),
}
}
@@ -1,4 +1,5 @@
use horizon_core::geometry::{Aabb, Axis, Direction, VoxelShape};
use crate::support::shapes::{emit, values};
use horizon_core::geometry::{Direction, VoxelShape};
use horizon_world::{
block_collision::{DynamicCollisionWorld, ShulkerCollisionState},
block_support::SupportType,
@@ -15,70 +16,6 @@ use std::{
io::{self, Write},
path::Path,
};
fn values(
out: &mut impl Write,
label: &str,
values: impl IntoIterator<Item = f64>,
) -> io::Result<()> {
write!(out, "{label}")?;
for v in values {
let bits = if v.is_nan() {
0x7ff8_0000_0000_0000
} else {
v.to_bits()
};
write!(out, " {bits:016x}")?;
}
writeln!(out)
}
fn box_values(out: &mut impl Write, label: &str, b: Aabb) -> io::Result<()> {
values(
out,
label,
[
b.min(Axis::X),
b.min(Axis::Y),
b.min(Axis::Z),
b.max(Axis::X),
b.max(Axis::Y),
b.max(Axis::Z),
],
)
}
fn emit(out: &mut impl Write, shape: &VoxelShape) -> io::Result<()> {
writeln!(
out,
"shape {} {} {}",
shape.is_empty(),
shape.boxes().len(),
shape.is_cube()
)?;
for (axis, name) in Axis::ALL.into_iter().zip(["x", "y", "z"]) {
values(out, name, shape.coordinates(axis).iter().copied())?;
}
let axes = shape.cube_coordinate_axes();
writeln!(
out,
"axes {}",
u8::from(axes[0]) + 2 * u8::from(axes[1]) + 4 * u8::from(axes[2])
)?;
values(
out,
"extrema",
Axis::ALL
.map(|a| shape.min(a))
.into_iter()
.chain(Axis::ALL.map(|a| shape.max(a))),
)?;
match shape.bounds() {
Some(b) => box_values(out, "bounds", b)?,
None => writeln!(out, "bounds none")?,
}
for b in shape.boxes() {
box_values(out, "box", *b)?;
}
Ok(())
}
struct World<'a, W> {
collisions: &'a CachedCollisionRegistry<'a>,
pistons: &'a PistonBlockBindings<'a>,
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::geometry::{Aabb, Axis, Vec3};
use horizon_world::edge_backoff::{EdgeBackoffInput, EdgeBackoffWorld, back_off_from_edge};
use serde_json::Value;
@@ -12,13 +13,6 @@ fn number(v: &Value) -> f64 {
fn vector(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
struct World<'a> {
input: &'a Value,
out: &'a mut dyn Write,
@@ -56,12 +50,12 @@ impl EdgeBackoffWorld for World<'_> {
fn no_collision(&mut self, b: Aabb) -> io::Result<bool> {
self.query(format!(
"clear {:016x} {:016x} {:016x} {:016x} {:016x} {:016x}",
bits(b.min(Axis::X)),
bits(b.min(Axis::Y)),
bits(b.min(Axis::Z)),
bits(b.max(Axis::X)),
bits(b.max(Axis::Y)),
bits(b.max(Axis::Z))
f64_bits(b.min(Axis::X)),
f64_bits(b.min(Axis::Y)),
f64_bits(b.min(Axis::Z)),
f64_bits(b.max(Axis::X)),
f64_bits(b.max(Axis::Y)),
f64_bits(b.max(Axis::Z))
))?;
let p = self.probes;
self.probes += 1;
@@ -105,9 +99,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(v) => writeln!(
world.out,
"movement {:016x} {:016x} {:016x}",
bits(v.x),
bits(v.y),
bits(v.z)
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
)?,
Err(_) => writeln!(world.out, "error")?,
};
@@ -1,3 +1,4 @@
use crate::support::common::f64_hex;
use horizon_world::{
attributes::{AttributeError, Definition, Instance, Modifier, Observer, Operation},
effect_attribute_modifiers::{self as effects, Definitions, Error, ModifierWorld, Template},
@@ -24,21 +25,11 @@ enum Stop {
Callback,
Duplicate,
}
fn bits(v: f64) -> String {
format!(
"{:016x}",
if v.is_nan() {
f64::NAN.to_bits()
} else {
v.to_bits()
}
)
}
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn desc(m: &Modifier) -> String {
format!("{}:{}:{}", m.id(), bits(m.amount()), m.operation() as u8)
format!("{}:{}:{}", m.id(), f64_hex(m.amount()), m.operation() as u8)
}
fn key_desc(k: Option<&Key>) -> String {
k.map_or("null".into(), |k| k.id.to_string())
@@ -66,7 +57,7 @@ impl Shared {
.iter()
.map(|(k, v)| {
let v = v.as_ref().map_or("null".into(), |t| {
format!("{}:{}:{}", t.id(), bits(t.amount()), t.operation() as u8)
format!("{}:{}:{}", t.id(), f64_hex(t.amount()), t.operation() as u8)
});
format!("{}={v}", key_desc(k.as_ref()))
})
@@ -126,9 +117,9 @@ impl Shared {
fn state(&mut self, id: usize, a: &Instance) {
self.logs.push(format!(
"instance {id} {} {} {} | {} | {}",
bits(a.base_value()),
f64_hex(a.base_value()),
a.is_dirty(),
bits(a.cached_value()),
f64_hex(a.cached_value()),
self.refs(a.modifiers()),
self.refs(a.permanent_modifiers())
));
@@ -153,7 +144,7 @@ impl Observer for Dirty<'_> {
if self.shared.op["read"].as_bool().unwrap() {
self.shared
.logs
.push(format!("observed {}", bits(a.value())));
.push(format!("observed {}", f64_hex(a.value())));
}
Ok(())
}
@@ -316,10 +307,10 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
}
"value" => {
let id = op["target"].as_u64().unwrap() as usize;
world
.shared
.logs
.push(format!("value {id} {}", bits(world.instances[id].value())));
world.shared.logs.push(format!(
"value {id} {}",
f64_hex(world.instances[id].value())
));
Ok(())
}
_ => {
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_world::attributes::{
AttributeError, Modifier, Operation,
entity::{Catalog, LookupError},
@@ -12,17 +13,10 @@ use std::{
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
f64::NAN.to_bits()
} else {
v.to_bits()
}
}
fn lookup(out: &mut dyn Write, label: &str, result: Result<f64, LookupError>) -> io::Result<()> {
match result {
Ok(v) => {
writeln!(out, "{label} {:016x}", bits(v))?;
writeln!(out, "{label} {:016x}", f64_bits(v))?;
writeln!(out, "ok")
}
Err(e) => writeln!(
@@ -114,9 +108,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(
out,
"state {i} {:016x} {} {:016x} {} {} {} {}",
bits(a.base_value()),
f64_bits(a.base_value()),
a.is_dirty(),
bits(a.cached_value()),
f64_bits(a.cached_value()),
map.needs_update(id),
map.needs_sync(id),
a.modifiers().len(),
@@ -1,4 +1,5 @@
use horizon_core::geometry::{Aabb, Axis, Vec3, VoxelShape};
use crate::support::shapes::{box_values, emit};
use horizon_core::geometry::{Aabb, Vec3};
use horizon_world::{
entity_collision::{CollisionCandidate, EntityCollisionWorld, entity_collision_shapes},
entity_obstruction::EntityIdentity,
@@ -12,70 +13,6 @@ use std::{
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn values(
out: &mut impl Write,
label: &str,
values: impl IntoIterator<Item = f64>,
) -> io::Result<()> {
write!(out, "{label}")?;
for v in values {
let bits = if v.is_nan() {
0x7ff8_0000_0000_0000
} else {
v.to_bits()
};
write!(out, " {bits:016x}")?;
}
writeln!(out)
}
fn box_values(out: &mut impl Write, label: &str, b: Aabb) -> io::Result<()> {
values(
out,
label,
[
b.min(Axis::X),
b.min(Axis::Y),
b.min(Axis::Z),
b.max(Axis::X),
b.max(Axis::Y),
b.max(Axis::Z),
],
)
}
fn emit(out: &mut impl Write, shape: &VoxelShape) -> io::Result<()> {
writeln!(
out,
"shape {} {} {}",
shape.is_empty(),
shape.boxes().len(),
shape.is_cube()
)?;
for (axis, name) in Axis::ALL.into_iter().zip(["x", "y", "z"]) {
values(out, name, shape.coordinates(axis).iter().copied())?;
}
let axes = shape.cube_coordinate_axes();
writeln!(
out,
"axes {}",
u8::from(axes[0]) + 2 * u8::from(axes[1]) + 4 * u8::from(axes[2])
)?;
values(
out,
"extrema",
Axis::ALL
.map(|a| shape.min(a))
.into_iter()
.chain(Axis::ALL.map(|a| shape.max(a))),
)?;
match shape.bounds() {
Some(b) => box_values(out, "bounds", b)?,
None => writeln!(out, "bounds none")?,
}
for b in shape.boxes() {
box_values(out, "box", *b)?;
}
Ok(())
}
fn bounds(v: &Value) -> Aabb {
Aabb::new(
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2])),
@@ -1,3 +1,4 @@
use crate::support::common::{f64_bits, position};
use horizon_core::{
geometry::{Aabb, Vec3},
position::BlockPos,
@@ -28,26 +29,17 @@ fn single(v: &Value) -> f32 {
fn vector(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
f64::NAN.to_bits()
} else {
v.to_bits()
}
}
fn show(v: Vec3) -> String {
format!("{:016x} {:016x} {:016x}", bits(v.x), bits(v.y), bits(v.z))
format!(
"{:016x} {:016x} {:016x}",
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
)
}
fn pos(p: BlockPos) -> String {
format!("{} {} {}", p.x, p.y, p.z)
}
fn position(v: &Value) -> BlockPos {
BlockPos::new(
v[0].as_i64().unwrap() as i32,
v[1].as_i64().unwrap() as i32,
v[2].as_i64().unwrap() as i32,
)
}
#[derive(Clone, Copy, Default)]
struct Tick {
touch: bool,
@@ -446,7 +438,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
w.out,
"tracker {} {:016x} {}",
t.fluid as u8,
bits(t.height),
f64_bits(t.height),
t.eyes_inside
)?;
}
@@ -455,7 +447,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
w.out,
"current {} {:016x} {} {}",
tag.0,
bits(c.height),
f64_bits(c.height),
show(c.accumulated),
c.count
)?;
@@ -465,7 +457,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let height = interaction.fluid_height(&w, tag);
let inside = interaction.is_in_fluid(&w, tag);
let eyes = interaction.is_eye_in_fluid(&w, tag);
writeln!(w.out, "tag {t} {:016x} {inside} {eyes}", bits(height))?;
writeln!(w.out, "tag {t} {:016x} {inside} {eyes}", f64_bits(height))?;
}
writeln!(w.out, "final {}", show(w.velocity))?;
writeln!(w.out, "queries {}", w.calls)?;
@@ -476,7 +468,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
"tick {} {} {:016x}",
tick.touch,
tick.first,
bits(tick.fall)
f64_bits(tick.fall)
)?;
}
}
@@ -1,5 +1,7 @@
use crate::support::common::f64_bits;
use crate::support::shapes::bounds;
use horizon_core::{
geometry::{Aabb, Axis, Vec3, VoxelShape, resolve_shape_movement},
geometry::{Aabb, Vec3, VoxelShape, resolve_shape_movement},
position::BlockPos,
};
use horizon_world::{
@@ -23,30 +25,12 @@ fn single(v: &Value) -> f32 {
fn vector(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn vec(label: &str, v: Vec3) -> String {
format!(
"{label} {:016x} {:016x} {:016x}",
bits(v.x),
bits(v.y),
bits(v.z)
)
}
fn bounds(label: &str, b: Aabb) -> String {
format!(
"{label} {:016x} {:016x} {:016x} {:016x} {:016x} {:016x}",
bits(b.min(Axis::X)),
bits(b.min(Axis::Y)),
bits(b.min(Axis::Z)),
bits(b.max(Axis::X)),
bits(b.max(Axis::Y)),
bits(b.max(Axis::Z))
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
)
}
fn pos(p: BlockPos) -> String {
@@ -213,7 +197,7 @@ impl EntityMoveWorld for World<'_> {
_: BlockStateId,
p: BlockPos,
) -> io::Result<()> {
self.query(format!("fall {:016x} {ground} {}", bits(dy), pos(p)))?;
self.query(format!("fall {:016x} {ground} {}", f64_bits(dy), pos(p)))?;
if self.flag("fall_mutates") {
self.fall = 3.0;
self.velocity = Vec3::new(17.0, 18.0, 19.0);
@@ -399,7 +383,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
w.flags.minor,
w.grounded,
w.removed,
bits(w.fall)
f64_bits(w.fall)
)?;
writeln!(w.out, "history {}", w.history.records().len())?;
for r in w.history.records() {
@@ -1,4 +1,5 @@
use horizon_core::geometry::{Aabb, Axis, Direction, ShapeOp, Vec3, VoxelShape};
use crate::support::shapes::emit;
use horizon_core::geometry::{Aabb, Direction, ShapeOp, Vec3, VoxelShape};
use horizon_world::block_support::SupportType;
use serde_json::Value;
use std::{
@@ -13,70 +14,6 @@ fn numbers(v: &Value) -> Vec<f64> {
.map(|v| f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap()))
.collect()
}
fn values(
out: &mut impl Write,
label: &str,
values: impl IntoIterator<Item = f64>,
) -> io::Result<()> {
write!(out, "{label}")?;
for v in values {
let bits = if v.is_nan() {
0x7ff8_0000_0000_0000
} else {
v.to_bits()
};
write!(out, " {bits:016x}")?;
}
writeln!(out)
}
fn box_values(out: &mut impl Write, label: &str, b: Aabb) -> io::Result<()> {
values(
out,
label,
[
b.min(Axis::X),
b.min(Axis::Y),
b.min(Axis::Z),
b.max(Axis::X),
b.max(Axis::Y),
b.max(Axis::Z),
],
)
}
fn emit(out: &mut impl Write, shape: &VoxelShape) -> io::Result<()> {
writeln!(
out,
"shape {} {} {}",
shape.is_empty(),
shape.boxes().len(),
shape.is_cube()
)?;
for (axis, name) in Axis::ALL.into_iter().zip(["x", "y", "z"]) {
values(out, name, shape.coordinates(axis).iter().copied())?;
}
let axes = shape.cube_coordinate_axes();
writeln!(
out,
"axes {}",
u8::from(axes[0]) + 2 * u8::from(axes[1]) + 4 * u8::from(axes[2])
)?;
values(
out,
"extrema",
Axis::ALL
.map(|a| shape.min(a))
.into_iter()
.chain(Axis::ALL.map(|a| shape.max(a))),
)?;
match shape.bounds() {
Some(b) => box_values(out, "bounds", b)?,
None => writeln!(out, "bounds none")?,
}
for b in shape.boxes() {
box_values(out, "box", *b)?;
}
Ok(())
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = crate::args().nth(1).expect("private fixture directory");
let dir = Path::new(&arg);
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{geometry::Vec3, position::BlockPos};
use horizon_world::fall_damage::{FallDamageWorld, check_fall_damage};
use serde_json::Value;
@@ -9,13 +10,6 @@ use std::{
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn support(v: &Value) -> Option<BlockPos> {
if v.is_null() {
None
@@ -66,7 +60,7 @@ impl FallDamageWorld for World<'_> {
p.x,
p.y,
p.z,
bits(distance)
f64_bits(distance)
))?;
if self.input["mutate"].as_bool().unwrap() {
self.fall = 17.25;
@@ -88,9 +82,9 @@ impl FallDamageWorld for World<'_> {
fn hit_ground(&mut self, p: Vec3, s: u8) -> io::Result<()> {
self.query(format!(
"hit-ground {:016x} {:016x} {:016x} {}",
bits(p.x),
bits(p.y),
bits(p.z),
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z),
if s == 1 { "queried" } else { "input" }
))
}
@@ -130,10 +124,10 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(
world.out,
"final {:016x} {:016x} {:016x} {:016x}",
bits(world.fall),
bits(p.x),
bits(p.y),
bits(p.z)
f64_bits(world.fall),
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z)
)?;
if let Some(p) = world.support {
writeln!(world.out, "support {} {} {}", p.x, p.y, p.z)?;
@@ -1,4 +1,5 @@
//! Feature world transport retaining ordered mutations and partial failures.
use crate::support::common::tag;
use horizon_core::random::{LegacyRandom, RandomSource, WorldgenRandom, XoroshiroRandom};
use horizon_world::{
DATA_VERSION,
@@ -178,17 +179,6 @@ fn fixture(
writeln!(out, "tail {}", random.next_long())?;
Ok(())
}
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
_ => panic!("invalid registry metadata"),
}
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = crate::args().nth(1).expect("private fixture directory");
let dir = Path::new(&arg);
@@ -1,3 +1,4 @@
use crate::support::common::tag;
use horizon_core::random::{LegacyRandom, RandomSource, WorldgenRandom, XoroshiroRandom};
use horizon_world::worldgen::{
anchor::WorldGenerationContext,
@@ -66,17 +67,6 @@ impl TerrainBlockStates for Properties<'_> {
fn n(v: &Value) -> i32 {
v.as_i64().unwrap() as i32
}
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(i) => Tag::Int(i.as_i64().unwrap() as i32),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
_ => panic!("unsupported registry fixture value"),
}
}
fn fixture(
f: &Value,
registry: &BlockRegistry,
@@ -1,4 +1,5 @@
//! Feature world transport retaining ordered mutations and partial failures.
use crate::support::common::tag;
use horizon_core::random::{LegacyRandom, RandomSource, XoroshiroRandom};
use horizon_world::{
DATA_VERSION,
@@ -134,17 +135,6 @@ fn fixture(
writeln!(out, "tail {}", random.next_long())?;
Ok(())
}
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
_ => panic!("invalid registry metadata"),
}
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = crate::args().nth(1).expect("private fixture directory");
let dir = Path::new(&arg);
@@ -1,3 +1,4 @@
use crate::support::common::tag;
use horizon_world::{
DATA_VERSION,
fluid::{FluidBlockBindings, FluidHeightWorld, FluidKind, FluidState, FluidStateTable},
@@ -40,17 +41,6 @@ impl<W: Write> FluidHeightWorld for World<'_, W> {
Ok(self.sturdy)
}
}
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
_ => panic!("invalid registry metadata"),
}
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = crate::args().nth(1).expect("private fixture directory");
let dir = Path::new(&arg);
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::food::{Difficulty, FoodData, FoodWorld};
use serde_json::Value;
use std::{
@@ -8,13 +9,6 @@ use std::{
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
fn state(v: &Value) -> FoodData {
FoodData {
food: v["food"].as_i64().unwrap() as i32,
@@ -72,7 +66,7 @@ impl FoodWorld for World<'_> {
Ok(self.world()["hurt"].as_bool().unwrap())
}
fn heal(&mut self, f: &mut FoodData, v: f32) -> io::Result<()> {
self.query(f, &format!("heal {:08x}", bits(v)))
self.query(f, &format!("heal {:08x}", f32_bits(v)))
}
fn health(&mut self, f: &mut FoodData) -> io::Result<f32> {
self.query(f, "health")?;
@@ -81,7 +75,7 @@ impl FoodWorld for World<'_> {
fn hurt_starvation(&mut self, _: (), f: &mut FoodData, v: f32) -> io::Result<()> {
self.query(f, "damage-sources")?;
self.query(f, "starve-source")?;
self.query(f, &format!("hurt {:08x}", bits(v)))
self.query(f, &format!("hurt {:08x}", f32_bits(v)))
}
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -123,8 +117,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
w.out,
"state {} {:08x} {:08x} {} {} {}",
food.food,
bits(food.saturation),
bits(food.exhaustion),
f32_bits(food.saturation),
f32_bits(food.exhaustion),
food.timer,
food.has_enough_food(),
food.needs_food()
@@ -135,8 +129,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
w.out,
"final {} {:08x} {:08x} {}",
food.food,
bits(food.saturation),
bits(food.exhaustion),
f32_bits(food.saturation),
f32_bits(food.exhaustion),
food.timer
)?;
writeln!(w.out, "queries {}", w.calls)?;
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::{
food::FoodData,
nbt::{Compound, Tag},
@@ -17,13 +18,6 @@ const KEYS: [&str; 4] = [
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
fn tag(v: &Value) -> Option<Tag> {
let value = &v["value"];
Some(match v["type"].as_i64().unwrap() {
@@ -82,8 +76,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
"state {} {} {:08x} {:08x}",
food.food,
food.timer,
bits(food.saturation),
bits(food.exhaustion)
f32_bits(food.saturation),
f32_bits(food.exhaustion)
)?;
let mut saved = Compound::new();
saved.insert("unrelated".into(), Tag::Int(42));
@@ -96,7 +90,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
for key in KEYS {
match saved[&key.into()] {
Tag::Int(v) => writeln!(out, "tag 3 {v}")?,
Tag::Float(v) => writeln!(out, "tag 5 {:08x}", bits(f32::from_bits(v)))?,
Tag::Float(v) => writeln!(out, "tag 5 {:08x}", f32_bits(f32::from_bits(v)))?,
_ => panic!("saved type"),
}
}
@@ -106,8 +100,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
"roundtrip {} {} {:08x} {:08x}",
food.food,
food.timer,
bits(food.saturation),
bits(food.exhaustion)
f32_bits(food.saturation),
f32_bits(food.exhaustion)
)?;
}
Ok(())
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{
geometry::{Aabb, Axis, Vec3},
position::BlockPos,
@@ -15,13 +16,6 @@ fn number(v: &Value) -> f64 {
fn vector(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn position(v: &Value) -> Option<BlockPos> {
if v.is_null() {
None
@@ -62,12 +56,12 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(
out,
"find {:016x} {:016x} {:016x} {:016x} {:016x} {:016x}",
bits(b.min(Axis::X)),
bits(b.min(Axis::Y)),
bits(b.min(Axis::Z)),
bits(b.max(Axis::X)),
bits(b.max(Axis::Y)),
bits(b.max(Axis::Z))
f64_bits(b.min(Axis::X)),
f64_bits(b.min(Axis::Y)),
f64_bits(b.min(Axis::Z)),
f64_bits(b.max(Axis::X)),
f64_bits(b.max(Axis::Y)),
f64_bits(b.max(Axis::Z))
)?;
let call = calls;
calls += 1;
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{
geometry::{Aabb, Axis, ShapeOp, Vec3, VoxelShape},
position::BlockPos,
@@ -20,13 +21,6 @@ fn number(v: &Value) -> f64 {
fn vector(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn shape(v: &Value) -> Result<VoxelShape, Box<dyn std::error::Error>> {
let mut result = VoxelShape::empty();
for b in v.as_array().unwrap() {
@@ -131,12 +125,12 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(
out,
"box {:016x} {:016x} {:016x} {:016x} {:016x} {:016x}",
bits(b.min(Axis::X)),
bits(b.min(Axis::Y)),
bits(b.min(Axis::Z)),
bits(b.max(Axis::X)),
bits(b.max(Axis::Y)),
bits(b.max(Axis::Z))
f64_bits(b.min(Axis::X)),
f64_bits(b.min(Axis::Y)),
f64_bits(b.min(Axis::Z)),
f64_bits(b.max(Axis::X)),
f64_bits(b.max(Axis::Y)),
f64_bits(b.max(Axis::Z))
)?;
}
}
@@ -160,9 +154,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
Some(h) => writeln!(
out,
"hit {:016x} {:016x} {:016x} {} {} {} {} {}",
bits(h.location.x),
bits(h.location.y),
bits(h.location.z),
f64_bits(h.location.x),
f64_bits(h.location.y),
f64_bits(h.location.z),
format!("{:?}", h.direction).to_lowercase(),
h.block.x,
h.block.y,
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_core::geometry::Vec3;
use horizon_world::{
blocking_rules::{BlockingRules, DamageReduction, ItemDamageFunction, TypeMatchWorld},
@@ -19,13 +20,6 @@ fn number(v: &Value) -> f64 {
fn vec(v: &Value) -> Option<Vec3> {
(!v.is_null()).then(|| Vec3::new(number(&v[0]), number(&v[1]), number(&v[2])))
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
struct Component {
present: bool,
bypass: Option<u64>,
@@ -154,7 +148,7 @@ impl ItemBlockingWorld for World<'_> {
e == 1
}
fn block_using_item(&mut self, _: u64, damage: f32, fully: bool) -> io::Result<()> {
self.event(&format!("block-using 0 {:08x} {fully}", bits(damage)))
self.event(&format!("block-using 0 {:08x} {fully}", f32_bits(damage)))
}
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -207,7 +201,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
changed: false,
};
match item_blocking::apply(&mut w, single(&f["damage"])) {
Ok(v) => writeln!(w.out, "blocked {:08x}\nresult ok", bits(v))?,
Ok(v) => writeln!(w.out, "blocked {:08x}\nresult ok", f32_bits(v))?,
Err(_) => writeln!(w.out, "result error")?,
};
writeln!(w.out, "queries {} {}", w.calls, w.changed)?;
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{
geometry::Vec3,
random::{LegacyRandom, RandomSource, XoroshiroRandom},
@@ -22,13 +23,6 @@ fn n(v: &Value, k: &str) -> i32 {
fn fl(v: &Value, k: &str) -> f32 {
f32::from_bits(v[k].as_u64().unwrap() as u32)
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn opt(v: Option<&i32>) -> String {
v.map_or("none".into(), i32::to_string)
}
@@ -141,12 +135,12 @@ impl<R: RandomSource> ItemParticleWorld<u8, u8, i32> for World<'_, R> {
"particle {level} {} {} {damage} {same} {} {} {} {} {} {}",
t.item(),
t.count(),
bits(p.x),
bits(p.y),
bits(p.z),
bits(v.x),
bits(v.y),
bits(v.z)
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z),
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
))
}
}
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::{
blocking_rules::{BlockingRules, ItemDamageFunction},
item_use::{self, ItemUseWorld},
@@ -11,13 +12,6 @@ use std::{
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
struct World<'a> {
f: &'a Value,
out: &'a mut dyn Write,
@@ -127,7 +121,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
item_use::ticks_using_item(&mut w).and_then(|v| writeln!(w.out, "ticks {v}"))
}
"partial" => item_use::ticks_using_item_partial(&mut w, single(&f["partial"]))
.and_then(|v| writeln!(w.out, "float {:08x}", bits(v))),
.and_then(|v| writeln!(w.out, "float {:08x}", f32_bits(v))),
_ => panic!("mode"),
};
writeln!(
@@ -252,9 +252,9 @@ mod integration {
"instance {} {} {} {} {} | {} | {}",
h.index(),
key.name(),
bits(a.base_value()),
f64_hex(a.base_value()),
a.is_dirty(),
bits(a.cached_value()),
f64_hex(a.cached_value()),
refs(a.modifiers(), &mut self.pools[i]),
refs(a.permanent_modifiers(), &mut self.pools[i])
)
@@ -541,8 +541,8 @@ mod integration {
None,
);
let result = match op["mode"].as_str().unwrap() {
"value" => w.attribute_value(key).map(bits),
"base" => live_updates::value(&mut w, key, ValueKind::Base).map(bits),
"value" => w.attribute_value(key).map(f64_hex),
"base" => live_updates::value(&mut w, key, ValueKind::Base).map(f64_hex),
"set-health" => w
.dispatch_set_health(single(&op["value"]))
.map(|()| "ok".into()),
@@ -1,3 +1,4 @@
use crate::support::common::f64_hex;
use horizon_world::{
attribute_map::ValueKind,
attributes::{
@@ -17,16 +18,6 @@ use std::{
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f64) -> String {
format!(
"{:016x}",
if v.is_nan() {
f64::NAN.to_bits()
} else {
v.to_bits()
}
)
}
fn error(e: Error) -> &'static str {
match e {
Error::NullAttribute | Error::MissingInstanceModifier => "null",
@@ -52,7 +43,7 @@ fn refs(mods: &[Modifier], pool: &mut Vec<Modifier>) -> String {
format!(
"{id}:{}:{}:{}",
m.id(),
bits(m.amount()),
f64_hex(m.amount()),
m.operation() as u8
)
})
@@ -104,11 +95,11 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
)?;
let mode = op["mode"].as_str().unwrap();
let result: Result<String, Error> = match mode {
"value" => attrs.value(key, ValueKind::Computed).map(bits),
"base" => attrs.value(key, ValueKind::Base).map(bits),
"value" => attrs.value(key, ValueKind::Computed).map(f64_hex),
"base" => attrs.value(key, ValueKind::Base).map(f64_hex),
"has" => attrs.has_attribute(key).map(|v| v.to_string()),
"has_modifier" => attrs.has_modifier(key, m.id()).map(|v| v.to_string()),
"modifier" => attrs.modifier_value(key, m.id()).map(bits),
"modifier" => attrs.modifier_value(key, m.id()).map(f64_hex),
"ensure" => attrs.get_instance(key).map(|h| handle(h.as_ref())),
"reset" => attrs.reset_base(key).map(|v| v.to_string()),
"ack_update" => {
@@ -208,9 +199,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
"instance {} {} {} {} {} | {} | {}",
h.index(),
key.name(),
bits(a.base_value()),
f64_hex(a.base_value()),
a.is_dirty(),
bits(a.cached_value()),
f64_hex(a.cached_value()),
refs(a.modifiers(), &mut pool),
refs(a.permanent_modifiers(), &mut pool)
)?;
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{geometry::Vec3, position::BlockPos};
use horizon_world::living_air::*;
use serde_json::Value;
@@ -15,18 +16,16 @@ fn single(v: &Value) -> f32 {
fn vec(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn fbits(v: f32) -> u32 {
if v.is_nan() { 0x7fc00000 } else { v.to_bits() }
}
fn vector(v: Vec3) -> String {
format!("{:016x} {:016x} {:016x}", bits(v.x), bits(v.y), bits(v.z))
format!(
"{:016x} {:016x} {:016x}",
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
)
}
struct World<'a> {
f: &'a Value,
@@ -239,7 +238,12 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
"result {}",
if result.is_ok() { "ok" } else { "error" }
)?;
writeln!(w.out, "final {} {:016x}", vector(w.velocity), bits(w.fall))?;
writeln!(
w.out,
"final {} {:016x}",
vector(w.velocity),
f64_bits(w.fall)
)?;
writeln!(w.out, "queries {}", w.calls)?;
}
Ok(())
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::{
living_damage::{self, DamageStat, DamageWorld},
living_health::{self, HealthWorld},
@@ -14,13 +15,6 @@ fn single(v: &Value) -> f32 {
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
fn stat(s: DamageStat) -> &'static str {
match s {
DamageStat::Absorbed => "absorbed",
@@ -69,11 +63,11 @@ impl DamageWorld for World<'_> {
Ok(self.state()["invulnerable"].as_bool().unwrap())
}
fn after_armor(&mut self, v: f32) -> io::Result<f32> {
self.query(&format!("armor {:08x}", bits(v)))?;
self.query(&format!("armor {:08x}", f32_bits(v)))?;
Ok(single(&self.state()["armor"]))
}
fn after_magic(&mut self, v: f32) -> io::Result<f32> {
self.query(&format!("magic {:08x}", bits(v)))?;
self.query(&format!("magic {:08x}", f32_bits(v)))?;
Ok(single(&self.state()["magic"]))
}
fn absorption(&mut self) -> io::Result<f32> {
@@ -98,13 +92,13 @@ impl DamageWorld for World<'_> {
Ok(single(&self.state()["food_exhaustion"]))
}
fn cause_food_exhaustion(&mut self, v: f32) -> io::Result<()> {
self.query(&format!("exhaust {:08x}", bits(v)))?;
self.query(&format!("exhaust {:08x}", f32_bits(v)))?;
self.exhaustion += v;
Ok(())
}
fn record_damage(&mut self, v: f32) -> io::Result<()> {
self.query("tracker")?;
self.query(&format!("record {:08x}", bits(v)))?;
self.query(&format!("record {:08x}", f32_bits(v)))?;
self.recorded = v;
Ok(())
}
@@ -113,7 +107,7 @@ impl DamageWorld for World<'_> {
Ok(self.health)
}
fn set_health(&mut self, v: f32) -> io::Result<()> {
self.query(&format!("set-health {:08x}", bits(v)))?;
self.query(&format!("set-health {:08x}", f32_bits(v)))?;
self.health = v;
Ok(())
}
@@ -140,7 +134,7 @@ impl HealthWorld for World<'_> {
DamageWorld::set_health(self, v)
}
fn store_absorption(&mut self, v: f32) -> io::Result<()> {
self.query(&format!("set-absorption {:08x}", bits(v)))?;
self.query(&format!("set-absorption {:08x}", f32_bits(v)))?;
self.absorption = v;
Ok(())
}
@@ -181,10 +175,10 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(
w.out,
"final {:08x} {:08x} {:08x} {:08x}",
bits(w.health),
bits(w.absorption),
bits(w.exhaustion),
bits(w.recorded)
f32_bits(w.health),
f32_bits(w.absorption),
f32_bits(w.exhaustion),
f32_bits(w.recorded)
)?;
writeln!(w.out, "queries {}", w.calls)?;
}
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::geometry::Vec3;
use horizon_world::living_fall::{
ImpulseContext, LivingFallWorld, calculate_fall_damage, cause_living_fall_damage,
@@ -14,13 +15,6 @@ fn number(v: &Value) -> f64 {
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn vector(v: &Value) -> Option<Vec3> {
if v.is_null() {
None
@@ -60,9 +54,9 @@ impl World<'_> {
writeln!(
self.out,
"impact {:016x} {:016x} {:016x}",
bits(p.x),
bits(p.y),
bits(p.z)
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z)
)
} else {
writeln!(self.out, "impact none")
@@ -100,7 +94,7 @@ impl LivingFallWorld for World<'_> {
fn propagate_fall_to_passengers(&mut self, d: f64, m: f32) -> io::Result<()> {
self.query(format!(
"passengers {:016x} {:08x}",
bits(d),
f64_bits(d),
if m.is_nan() { 0x7fc00000 } else { m.to_bits() }
))?;
if self.f["mutate"].as_bool().unwrap() {
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{geometry::Vec3, position::BlockPos};
use horizon_world::living_air::*;
use horizon_world::living_fluid::*;
@@ -16,18 +17,16 @@ fn single(v: &Value) -> f32 {
fn vec(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn fbits(v: f32) -> u32 {
if v.is_nan() { 0x7fc00000 } else { v.to_bits() }
}
fn vector(v: Vec3) -> String {
format!("{:016x} {:016x} {:016x}", bits(v.x), bits(v.y), bits(v.z))
format!(
"{:016x} {:016x} {:016x}",
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
)
}
struct World<'a> {
f: &'a Value,
@@ -320,7 +319,12 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
"result {}",
if result.is_ok() { "ok" } else { "error" }
)?;
writeln!(w.out, "final {} {:016x}", vector(w.velocity), bits(w.fall))?;
writeln!(
w.out,
"final {} {:016x}",
vector(w.velocity),
f64_bits(w.fall)
)?;
writeln!(w.out, "queries {}", w.calls)?;
}
Ok(())
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::living_health::{self, HealthWorld, SyncedFloat};
use serde_json::Value;
use std::{
@@ -11,13 +12,6 @@ fn single(v: &Value) -> f32 {
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
struct Context<'a> {
f: &'a Value,
out: &'a mut dyn Write,
@@ -70,7 +64,7 @@ impl HealthWorld for World<'_> {
self.stores[data].set(v, false, |_| self.ctx.query("updated"))
}
fn store_absorption(&mut self, v: f32) -> io::Result<()> {
self.ctx.query(&format!("absorption {:08x}", bits(v)))?;
self.ctx.query(&format!("absorption {:08x}", f32_bits(v)))?;
self.absorption = v;
Ok(())
}
@@ -78,7 +72,7 @@ impl HealthWorld for World<'_> {
self.ctx.world()["dead"].as_bool().unwrap()
}
fn dispatch_set_health(&mut self, v: f32) -> io::Result<()> {
self.ctx.query(&format!("set {:08x}", bits(v)))?;
self.ctx.query(&format!("set {:08x}", f32_bits(v)))?;
living_health::set_health(self, v)
}
}
@@ -123,7 +117,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
"packed {}",
w.stores[w.ctx.active]
.take_dirty()
.map(|v| format!("{:08x}", bits(v)))
.map(|v| format!("{:08x}", f32_bits(v)))
.unwrap_or_else(|| "none".into())
)
}
@@ -138,7 +132,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(
w.ctx.out,
"data {i} {:08x} {} {} {}",
bits(s.value()),
f32_bits(s.value()),
s.is_dirty(),
s.item_dirty(),
s.is_default()
@@ -149,7 +143,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
w.ctx.out,
"state {} {:08x} {dead} {}",
w.ctx.active,
bits(w.absorption),
f32_bits(w.absorption),
w.ctx.calls
)?;
}
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::living_hurt::{HurtState, HurtTag, HurtWorld, hurt_server};
use serde_json::Value;
use std::{
@@ -8,19 +9,12 @@ use std::{
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
fn state(s: &HurtState<()>) -> String {
format!(
"{} {} {:08x} {} {} {} {}",
s.no_action_time,
s.cooldown,
bits(s.last_hurt),
f32_bits(s.last_hurt),
s.hurt_duration,
s.hurt_time,
s.last_source.is_some(),
@@ -126,7 +120,7 @@ impl HurtWorld for Env<'_> {
Ok(self.flag("component"))
}
fn apply_blocking(&mut self, _: &mut HurtState<()>, v: f32) -> io::Result<f32> {
self.event(&format!("blocking {:08x}", bits(v)))?;
self.event(&format!("blocking {:08x}", f32_bits(v)))?;
Ok(single(&self.op["blocked"]))
}
fn helmet_empty(&mut self, _: &mut HurtState<()>) -> io::Result<bool> {
@@ -134,10 +128,10 @@ impl HurtWorld for Env<'_> {
Ok(!self.flag("helmet"))
}
fn hurt_helmet(&mut self, _: &mut HurtState<()>, v: f32) -> io::Result<()> {
self.event(&format!("hurt-helmet {:08x}", bits(v)))
self.event(&format!("hurt-helmet {:08x}", f32_bits(v)))
}
fn actually_hurt(&mut self, s: &mut HurtState<()>, v: f32) -> io::Result<()> {
self.event(&format!("hurt {:08x} {}", bits(v), state(s)))?;
self.event(&format!("hurt {:08x} {}", f32_bits(v), state(s)))?;
self.hit = true;
self.recorded = v;
if self.flag("mutate_hit") {
@@ -155,7 +149,7 @@ impl HurtWorld for Env<'_> {
Ok(())
}
fn knockback(&mut self, _: &mut HurtState<()>, v: f32, b: bool) -> io::Result<()> {
self.event(&format!("knockback {:08x} {b}", bits(v)))
self.event(&format!("knockback {:08x} {b}", f32_bits(v)))
}
fn death_protection(&mut self, _: &mut HurtState<()>) -> io::Result<bool> {
self.event("tag bypasses_invulnerability")?;
@@ -179,7 +173,7 @@ impl HurtWorld for Env<'_> {
fn effects_on_hurt(&mut self, _: &mut HurtState<()>, v: f32) -> io::Result<()> {
self.event("effects")?;
for i in 0..self.op["effects"].as_u64().unwrap() {
self.event(&format!("effect {i} {:08x}", bits(v)))?;
self.event(&format!("effect {i} {:08x}", f32_bits(v)))?;
}
Ok(())
}
@@ -239,7 +233,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
e.out,
"state {} {:08x} {} {}",
state(&s),
bits(recorded),
f32_bits(recorded),
e.hit,
e.calls
)?;
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{geometry::Vec3, position::BlockPos};
use horizon_world::fall_damage::FallDamageWorld;
use horizon_world::living_landing::{LivingLandingWorld, check_living_fall_damage};
@@ -10,13 +11,6 @@ use std::{
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn support(v: &Value) -> Option<BlockPos> {
if v.is_null() {
None
@@ -69,7 +63,7 @@ impl FallDamageWorld for World<'_> {
p.x,
p.y,
p.z,
bits(distance)
f64_bits(distance)
))?;
if self.input["mutate"].as_bool().unwrap() {
self.fall = 17.25;
@@ -91,9 +85,9 @@ impl FallDamageWorld for World<'_> {
fn hit_ground(&mut self, p: Vec3, s: u8) -> io::Result<()> {
self.query(format!(
"hit-ground {:016x} {:016x} {:016x} {}",
bits(p.x),
bits(p.y),
bits(p.z),
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z),
if s == 1 { "queried" } else { "input" }
))
}
@@ -142,11 +136,11 @@ impl LivingLandingWorld for World<'_> {
assert_eq!(s, 0);
self.query(format!(
"particles {:016x} {:016x} {:016x} {} {:016x}",
bits(p.x),
bits(p.y),
bits(p.z),
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z),
count,
bits(speed)
f64_bits(speed)
))?;
if self.input["particle_mutate"].as_bool().unwrap() {
self.fall = number(&self.input["after_fall"]);
@@ -194,10 +188,10 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(
world.out,
"final {:016x} {:016x} {:016x} {:016x}",
bits(world.fall),
bits(p.x),
bits(p.y),
bits(p.z)
f64_bits(world.fall),
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z)
)?;
if let Some(p) = world.support {
writeln!(world.out, "support {} {} {}", p.x, p.y, p.z)?;
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::geometry::Vec3;
use horizon_world::living_motion::*;
use serde_json::Value;
@@ -15,18 +16,16 @@ fn single(v: &Value) -> f32 {
fn vec(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn fbits(v: f32) -> u32 {
if v.is_nan() { 0x7fc00000 } else { v.to_bits() }
}
fn vector(v: Vec3) -> String {
format!("{:016x} {:016x} {:016x}", bits(v.x), bits(v.y), bits(v.z))
format!(
"{:016x} {:016x} {:016x}",
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
)
}
struct World<'a> {
f: &'a Value,
@@ -138,10 +137,11 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
"power" => jump_power(&mut w, single(&f["scale"]))
.and_then(|v| writeln!(w.out, "float {:08x}", fbits(v))),
"jump" => jump_from_ground(&mut w),
"gravity" => gravity(&mut w).and_then(|v| writeln!(w.out, "double {:016x}", bits(v))),
"effective" => {
effective_gravity(&mut w).and_then(|v| writeln!(w.out, "double {:016x}", bits(v)))
"gravity" => {
gravity(&mut w).and_then(|v| writeln!(w.out, "double {:016x}", f64_bits(v)))
}
"effective" => effective_gravity(&mut w)
.and_then(|v| writeln!(w.out, "double {:016x}", f64_bits(v))),
"apply" => apply_gravity(&mut w),
"up" => swim_vertical(&mut w, true),
"down" => swim_vertical(&mut w, false),
@@ -5,8 +5,10 @@ use std::process::{ExitCode, Termination};
/// Code shared by several probes.
mod support {
pub mod common;
pub mod decoration_storage;
pub mod placement_queries;
pub mod shapes;
}
mod active_effect_tick_fixture;
@@ -1,4 +1,5 @@
//! Original transport for complete surface-stage chunk comparison.
use crate::support::common::tag;
use horizon_core::{
biome::{BiomeZoom, obfuscate_seed},
carving::CarvingMask,
@@ -78,17 +79,6 @@ impl TerrainBlockStates for Properties<'_> {
self.0[id.0 as usize]
}
}
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
Value::Object(o) => {
Tag::Compound(o.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
_ => panic!("invalid registry metadata"),
}
}
fn n(v: &Value) -> i32 {
v.as_i64().unwrap() as i32
}
@@ -1,3 +1,4 @@
use crate::support::common::{f64_bits, position};
use horizon_core::{geometry::Vec3, position::BlockPos};
use horizon_world::movement_emission::*;
use serde_json::Value;
@@ -15,23 +16,9 @@ fn single(v: &Value) -> f32 {
fn vector(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn position(v: &Value) -> BlockPos {
BlockPos::new(
v[0].as_i64().unwrap() as i32,
v[1].as_i64().unwrap() as i32,
v[2].as_i64().unwrap() as i32,
)
}
fn pos(p: BlockPos) -> String {
format!("{} {} {}", p.x, p.y, p.z)
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn fbits(v: f32) -> u32 {
if v.is_nan() { 0x7fc00000 } else { v.to_bits() }
}
@@ -137,9 +124,9 @@ impl MovementEmissionWorld for World<'_> {
let p = vector(&self.f["position"]);
self.query(format!(
"step {s} {:016x} {:016x} {:016x}",
bits(p.x),
bits(p.y),
bits(p.z)
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z)
))?;
self.mutate();
Ok(())
@@ -1,3 +1,4 @@
use crate::support::common::position;
use horizon_core::{geometry::Vec3, position::BlockPos};
use horizon_world::movement_support::{self as support, MovementLocation};
use horizon_world::{
@@ -21,13 +22,6 @@ fn number(v: &Value) -> f64 {
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn position(v: &Value) -> BlockPos {
BlockPos::new(
v[0].as_i64().unwrap() as i32,
v[1].as_i64().unwrap() as i32,
v[2].as_i64().unwrap() as i32,
)
}
struct World<'a> {
input: &'a Value,
out: &'a mut dyn Write,
@@ -1,3 +1,4 @@
use crate::support::common::position;
use horizon_core::{geometry::Vec3, position::BlockPos};
use horizon_world::movement_support::{self as support, MovementBlockWorld, MovementLocation};
use serde_json::Value;
@@ -12,13 +13,6 @@ fn number(v: &Value) -> f64 {
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn position(v: &Value) -> BlockPos {
BlockPos::new(
v[0].as_i64().unwrap() as i32,
v[1].as_i64().unwrap() as i32,
v[2].as_i64().unwrap() as i32,
)
}
struct World<'a> {
input: &'a Value,
out: &'a mut dyn Write,
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::geometry::Vec3;
use horizon_world::piston_movement::PistonMovement;
use serde_json::Value;
@@ -12,13 +13,6 @@ fn number(v: &Value) -> f64 {
fn vector(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = crate::args().nth(1).expect("private fixture directory");
let dir = Path::new(&arg);
@@ -45,18 +39,18 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(v) => writeln!(
out,
"movement {:016x} {:016x} {:016x}",
bits(v.x),
bits(v.y),
bits(v.z)
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
)?,
Err(_) => writeln!(out, "error")?,
}
writeln!(
out,
"deltas {:016x} {:016x} {:016x}",
bits(state.deltas[0]),
bits(state.deltas[1]),
bits(state.deltas[2])
f64_bits(state.deltas[0]),
f64_bits(state.deltas[1]),
f64_bits(state.deltas[2])
)?;
writeln!(out, "tick {}", state.game_time)?;
writeln!(out, "queries {calls}")?;
@@ -1,4 +1,5 @@
use horizon_core::geometry::{Aabb, Axis, Direction, VoxelShape};
use crate::support::shapes::emit;
use horizon_core::geometry::{Direction, VoxelShape};
use horizon_world::{
collision::CachedCollisionRegistry,
dynamic_support::{DynamicSupport, DynamicSupportWorld},
@@ -12,70 +13,6 @@ use std::{
io::{self, Write},
path::Path,
};
fn values(
out: &mut impl Write,
label: &str,
values: impl IntoIterator<Item = f64>,
) -> io::Result<()> {
write!(out, "{label}")?;
for v in values {
let bits = if v.is_nan() {
0x7ff8_0000_0000_0000
} else {
v.to_bits()
};
write!(out, " {bits:016x}")?;
}
writeln!(out)
}
fn box_values(out: &mut impl Write, label: &str, b: Aabb) -> io::Result<()> {
values(
out,
label,
[
b.min(Axis::X),
b.min(Axis::Y),
b.min(Axis::Z),
b.max(Axis::X),
b.max(Axis::Y),
b.max(Axis::Z),
],
)
}
fn emit(out: &mut impl Write, shape: &VoxelShape) -> io::Result<()> {
writeln!(
out,
"shape {} {} {}",
shape.is_empty(),
shape.boxes().len(),
shape.is_cube()
)?;
for (axis, name) in Axis::ALL.into_iter().zip(["x", "y", "z"]) {
values(out, name, shape.coordinates(axis).iter().copied())?;
}
let axes = shape.cube_coordinate_axes();
writeln!(
out,
"axes {}",
u8::from(axes[0]) + 2 * u8::from(axes[1]) + 4 * u8::from(axes[2])
)?;
values(
out,
"extrema",
Axis::ALL
.map(|a| shape.min(a))
.into_iter()
.chain(Axis::ALL.map(|a| shape.max(a))),
)?;
match shape.bounds() {
Some(b) => box_values(out, "bounds", b)?,
None => writeln!(out, "bounds none")?,
}
for b in shape.boxes() {
box_values(out, "box", *b)?;
}
Ok(())
}
struct World<'a, 'r, W> {
collisions: &'a CachedCollisionRegistry<'r>,
dynamic: &'a [Option<DynamicSupport>],
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::{
food::FoodData,
player_food::{self, PlayerFoodWorld, StoredPlayerFood},
@@ -11,13 +12,6 @@ use std::{
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
struct World<'a> {
f: &'a Value,
out: &'a mut dyn Write,
@@ -68,7 +62,7 @@ impl PlayerFoodWorld for World<'_> {
}
fn add_exhaustion_direct(&mut self, v: f32) -> io::Result<()> {
let i = self.index("direct");
self.query(&format!("exhaust {i} {:08x}", bits(v)))?;
self.query(&format!("exhaust {i} {:08x}", f32_bits(v)))?;
self.foods[i].add_exhaustion(v);
Ok(())
}
@@ -136,7 +130,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
w.out,
"food {i} {} {:08x}",
food.food,
bits(food.exhaustion)
f32_bits(food.exhaustion)
)?;
}
writeln!(w.out, "queries {}", w.calls)?;
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::{
attributes::{
Modifier, Operation,
@@ -19,20 +20,13 @@ fn single(v: &Value) -> f32 {
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
fn values(v: Option<&[FloatValue]>) -> String {
match v {
None => "none".into(),
Some([]) => "empty".into(),
Some(v) => v
.iter()
.map(|v| format!("{}:{:08x}", v.id, bits(v.value)))
.map(|v| format!("{}:{:08x}", v.id, f32_bits(v.value)))
.collect::<Vec<_>>()
.join(","),
}
@@ -59,7 +53,7 @@ impl Observer for Callback<'_> {
fn updated(&mut self, data: &mut SyncedFloats, id: u8) -> io::Result<()> {
self.event(&format!(
"updated {id} {:08x} {}",
bits(data.get(id).unwrap()),
f32_bits(data.get(id).unwrap()),
data.is_dirty()
))?;
if self.op["pack_callback"].as_bool().unwrap() {
@@ -145,7 +139,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
.bind(&mut cb)
.absorption()
.map_err(|_| ())
.and_then(|v| writeln!(cb.out, "float {:08x}", bits(v)).map_err(|_| ())),
.and_then(|v| writeln!(cb.out, "float {:08x}", f32_bits(v)).map_err(|_| ())),
"hurt" => state
.bind(&mut cb)
.is_hurt()
@@ -227,8 +221,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(
cb.out,
"state {:08x} {:08x} {} {} {} {} {} {}",
bits(state.data.get(ids.health).unwrap()),
bits(state.data.get(ids.absorption).unwrap()),
f32_bits(state.data.get(ids.health).unwrap()),
f32_bits(state.data.get(ids.absorption).unwrap()),
state.data.is_dirty(),
state.data.item_dirty(ids.health).unwrap(),
state.data.item_dirty(ids.absorption).unwrap(),
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::living_hurt::{HurtState, HurtTag, HurtWorld};
use horizon_world::{
food::Difficulty,
@@ -15,19 +16,12 @@ use std::{
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
fn state(s: &HurtState<()>) -> String {
format!(
"{} {} {:08x} {} {} {} {}",
s.no_action_time,
s.cooldown,
bits(s.last_hurt),
f32_bits(s.last_hurt),
s.hurt_duration,
s.hurt_time,
s.last_source.is_some(),
@@ -134,7 +128,7 @@ impl HurtWorld for Env<'_> {
Ok(self.flag("component"))
}
fn apply_blocking(&mut self, _: &mut HurtState<()>, v: f32) -> io::Result<f32> {
self.event(&format!("blocking {:08x}", bits(v)))?;
self.event(&format!("blocking {:08x}", f32_bits(v)))?;
Ok(single(&self.op["blocked"]))
}
fn helmet_empty(&mut self, _: &mut HurtState<()>) -> io::Result<bool> {
@@ -142,10 +136,10 @@ impl HurtWorld for Env<'_> {
Ok(!self.flag("helmet"))
}
fn hurt_helmet(&mut self, _: &mut HurtState<()>, v: f32) -> io::Result<()> {
self.event(&format!("hurt-helmet {:08x}", bits(v)))
self.event(&format!("hurt-helmet {:08x}", f32_bits(v)))
}
fn actually_hurt(&mut self, s: &mut HurtState<()>, v: f32) -> io::Result<()> {
self.event(&format!("hurt {:08x} {}", bits(v), state(s)))?;
self.event(&format!("hurt {:08x} {}", f32_bits(v), state(s)))?;
self.hit = true;
self.recorded = v;
if self.flag("mutate_hit") {
@@ -163,7 +157,7 @@ impl HurtWorld for Env<'_> {
Ok(())
}
fn knockback(&mut self, _: &mut HurtState<()>, v: f32, b: bool) -> io::Result<()> {
self.event(&format!("knockback {:08x} {b}", bits(v)))
self.event(&format!("knockback {:08x} {b}", f32_bits(v)))
}
fn death_protection(&mut self, _: &mut HurtState<()>) -> io::Result<bool> {
self.event("tag bypasses_invulnerability")?;
@@ -187,7 +181,7 @@ impl HurtWorld for Env<'_> {
fn effects_on_hurt(&mut self, _: &mut HurtState<()>, v: f32) -> io::Result<()> {
self.event("effects")?;
for i in 0..self.op["effects"].as_u64().unwrap() {
self.event(&format!("effect {i} {:08x}", bits(v)))?;
self.event(&format!("effect {i} {:08x}", f32_bits(v)))?;
}
Ok(())
}
@@ -303,7 +297,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
e.out,
"state {} {:08x} {} {}",
state(&s),
bits(recorded),
f32_bits(recorded),
e.hit,
e.calls
)?;
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{geometry::Vec3, position::BlockPos};
use horizon_world::player_travel::*;
use serde_json::Value;
@@ -15,18 +16,16 @@ fn single(v: &Value) -> f32 {
fn vec(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn fbits(v: f32) -> u32 {
if v.is_nan() { 0x7fc00000 } else { v.to_bits() }
}
fn vector(v: Vec3) -> String {
format!("{:016x} {:016x} {:016x}", bits(v.x), bits(v.y), bits(v.z))
format!(
"{:016x} {:016x} {:016x}",
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
)
}
struct World<'a> {
f: &'a Value,
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::damage_immunity::{DamageRule, ImmunityTag, ImmunityWorld};
use horizon_world::damage_source::{
Catalog as DamageCatalog, DamageSource, EntityKind, SourceWorld,
@@ -31,19 +32,12 @@ use std::{
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
fn state(s: &HurtState<()>) -> String {
format!(
"{} {} {:08x} {} {} {} {}",
s.no_action_time,
s.cooldown,
bits(s.last_hurt),
f32_bits(s.last_hurt),
s.hurt_duration,
s.hurt_time,
s.last_source.is_some(),
@@ -151,7 +145,7 @@ impl HurtWorld for Env<'_> {
Ok(self.flag("component"))
}
fn apply_blocking(&mut self, _: &mut HurtState<()>, v: f32) -> io::Result<f32> {
self.event(&format!("blocking {:08x}", bits(v)))?;
self.event(&format!("blocking {:08x}", f32_bits(v)))?;
Ok(single(&self.op["blocked"]))
}
fn helmet_empty(&mut self, _: &mut HurtState<()>) -> io::Result<bool> {
@@ -159,7 +153,7 @@ impl HurtWorld for Env<'_> {
Ok(!self.flag("helmet"))
}
fn hurt_helmet(&mut self, _: &mut HurtState<()>, v: f32) -> io::Result<()> {
self.event(&format!("hurt-helmet {:08x}", bits(v)))
self.event(&format!("hurt-helmet {:08x}", f32_bits(v)))
}
fn actually_hurt(&mut self, _s: &mut HurtState<()>, _v: f32) -> io::Result<()> {
panic!("combat binding supplies actual inner damage")
@@ -171,7 +165,7 @@ impl HurtWorld for Env<'_> {
Ok(())
}
fn knockback(&mut self, _: &mut HurtState<()>, v: f32, b: bool) -> io::Result<()> {
self.event(&format!("knockback {:08x} {b}", bits(v)))
self.event(&format!("knockback {:08x} {b}", f32_bits(v)))
}
fn death_protection(&mut self, _: &mut HurtState<()>) -> io::Result<bool> {
if !self
@@ -197,7 +191,7 @@ impl HurtWorld for Env<'_> {
fn effects_on_hurt(&mut self, _: &mut HurtState<()>, v: f32) -> io::Result<()> {
self.event("effects")?;
for i in 0..self.op["effects"].as_u64().unwrap() {
self.event(&format!("effect {i} {:08x}", bits(v)))?;
self.event(&format!("effect {i} {:08x}", f32_bits(v)))?;
}
Ok(())
}
@@ -280,7 +274,7 @@ fn values(v: Option<&[FloatValue]>) -> String {
Some([]) => "empty".into(),
Some(v) => v
.iter()
.map(|v| format!("{}:{:08x}", v.id, bits(v.value)))
.map(|v| format!("{}:{:08x}", v.id, f32_bits(v.value)))
.collect::<Vec<_>>()
.join(","),
}
@@ -290,7 +284,7 @@ impl Observer for Env<'_> {
fn updated(&mut self, data: &mut SyncedFloats, id: u8) -> io::Result<()> {
self.event(&format!(
"updated {id} {:08x} {}",
bits(data.get(id).unwrap()),
f32_bits(data.get(id).unwrap()),
data.is_dirty()
))?;
if self.flag("pack_callback") {
@@ -329,7 +323,7 @@ impl ServerDamageEnvironment for Env<'_> {
Ok(self.source.bypasses(b))
}
fn hurt_armor(&mut self, a: &mut EntityAttributes, v: f32) -> io::Result<()> {
self.event(&format!("hurt-armor {:08x}", bits(v)))?;
self.event(&format!("hurt-armor {:08x}", f32_bits(v)))?;
if self.flag("break_armor") {
let id = a.catalog().id("minecraft:armor").unwrap();
a.edit(id, |a, o| {
@@ -387,7 +381,7 @@ impl ServerDamageEnvironment for Env<'_> {
}
fn record_damage(&mut self, v: f32) -> io::Result<()> {
self.event("tracker")?;
self.event(&format!("record {:08x}", bits(v)))?;
self.event(&format!("record {:08x}", f32_bits(v)))?;
self.recorded = v;
self.hit = true;
Ok(())
@@ -513,16 +507,16 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
e.out,
"state {} {:08x} {} {}",
state(&s),
bits(recorded),
f32_bits(recorded),
e.hit,
e.calls
)?;
writeln!(
e.out,
"storage {:08x} {:08x} {:08x} {} {} {} {}",
bits(data.get(ids.health).unwrap()),
bits(data.get(ids.absorption).unwrap()),
bits(food.exhaustion),
f32_bits(data.get(ids.health).unwrap()),
f32_bits(data.get(ids.absorption).unwrap()),
f32_bits(food.exhaustion),
data.is_dirty(),
data.item_dirty(ids.health).unwrap(),
data.item_dirty(ids.absorption).unwrap(),
@@ -1,4 +1,5 @@
//! Integrated registry/cursor differential transport using resident TerrainChunk storage.
use crate::support::shapes::{emit, values};
use horizon_core::{
geometry::{Aabb, Axis, Vec3, VoxelShape},
position::{BlockPos, ChunkPos},
@@ -43,70 +44,6 @@ use std::{
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn values(
out: &mut impl Write,
label: &str,
values: impl IntoIterator<Item = f64>,
) -> io::Result<()> {
write!(out, "{label}")?;
for v in values {
let bits = if v.is_nan() {
0x7ff8_0000_0000_0000
} else {
v.to_bits()
};
write!(out, " {bits:016x}")?;
}
writeln!(out)
}
fn box_values(out: &mut impl Write, label: &str, b: Aabb) -> io::Result<()> {
values(
out,
label,
[
b.min(Axis::X),
b.min(Axis::Y),
b.min(Axis::Z),
b.max(Axis::X),
b.max(Axis::Y),
b.max(Axis::Z),
],
)
}
fn emit(out: &mut impl Write, shape: &VoxelShape) -> io::Result<()> {
writeln!(
out,
"shape {} {} {}",
shape.is_empty(),
shape.boxes().len(),
shape.is_cube()
)?;
for (axis, name) in Axis::ALL.into_iter().zip(["x", "y", "z"]) {
values(out, name, shape.coordinates(axis).iter().copied())?;
}
let axes = shape.cube_coordinate_axes();
writeln!(
out,
"axes {}",
u8::from(axes[0]) + 2 * u8::from(axes[1]) + 4 * u8::from(axes[2])
)?;
values(
out,
"extrema",
Axis::ALL
.map(|a| shape.min(a))
.into_iter()
.chain(Axis::ALL.map(|a| shape.max(a))),
)?;
match shape.bounds() {
Some(b) => box_values(out, "bounds", b)?,
None => writeln!(out, "bounds none")?,
}
for b in shape.boxes() {
box_values(out, "box", *b)?;
}
Ok(())
}
struct Trace {
out: io::BufWriter<fs::File>,
calls: i32,
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{geometry::Vec3, position::BlockPos};
use horizon_world::{
entity_obstruction::EntityIdentity,
@@ -21,13 +22,6 @@ fn number(v: &Value) -> f64 {
fn vector(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn pos(p: BlockPos) -> String {
format!("{} {} {}", p.x, p.y, p.z)
}
@@ -181,9 +175,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
w.out,
"hit {} {:016x} {:016x} {:016x} {} {} {}",
r.miss,
bits(h.location.x),
bits(h.location.y),
bits(h.location.z),
f64_bits(h.location.x),
f64_bits(h.location.y),
f64_bits(h.location.z),
format!("{:?}", h.direction).to_lowercase(),
pos(h.block),
h.inside
@@ -1,4 +1,5 @@
//! Feature world transport retaining ordered mutations and partial failures.
use crate::support::common::tag;
use horizon_core::random::{LegacyRandom, RandomSource, XoroshiroRandom};
use horizon_world::{
DATA_VERSION,
@@ -135,17 +136,6 @@ fn fixture(
writeln!(out, "tail {}", random.next_long())?;
Ok(())
}
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
_ => panic!("invalid registry metadata"),
}
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = crate::args().nth(1).expect("private fixture directory");
let dir = Path::new(&arg);
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{geometry::Vec3, position::BlockPos};
use horizon_world::{
movement_restitution::{RestitutionInput, RestitutionWorld, restitute_movement},
@@ -18,19 +19,12 @@ fn single(v: &Value) -> f32 {
fn vector(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn vector_text(prefix: &str, v: Vec3) -> String {
format!(
"{prefix} {:016x} {:016x} {:016x}",
bits(v.x),
bits(v.y),
bits(v.z)
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
)
}
struct World<'a, W> {
@@ -102,7 +96,7 @@ impl<W: Write> RestitutionWorld for World<'_, W> {
p.x,
p.y,
p.z,
bits(fall)
f64_bits(fall)
))?;
if self.f["mutate"].as_bool().unwrap() {
self.velocity = Vec3::new(17.0, 18.0, 19.0);
@@ -1,4 +1,5 @@
//! Differential transport for replacement rules over pinned block identities.
use crate::support::common::tag;
use horizon_core::random::{LegacyRandom, RandomSource, XoroshiroRandom};
use horizon_world::{
DATA_VERSION,
@@ -41,17 +42,6 @@ fn fixture(
writeln!(out, "tail {}", random.next_long())?;
Ok(())
}
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
_ => panic!("invalid registry metadata"),
}
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = crate::args().nth(1).expect("private fixture directory");
let dir = Path::new(&arg);
@@ -1,4 +1,5 @@
//! Feature world transport retaining ordered mutations and partial failures.
use crate::support::common::tag;
use horizon_core::random::{LegacyRandom, RandomSource, XoroshiroRandom};
use horizon_world::{
DATA_VERSION,
@@ -159,17 +160,6 @@ fn fixture(
writeln!(out, "tail {}", random.next_long())?;
Ok(())
}
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
_ => panic!("invalid registry metadata"),
}
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = crate::args().nth(1).expect("private fixture directory");
let dir = Path::new(&arg);
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::damage_immunity::{DamageRule, ImmunityTag, ImmunityWorld};
use horizon_world::living_hurt::{HurtState, HurtTag, HurtWorld};
use horizon_world::{
@@ -84,19 +85,12 @@ impl FixtureAttributes for Live {
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
fn state(s: &HurtState<()>) -> String {
format!(
"{} {} {:08x} {} {} {} {}",
s.no_action_time,
s.cooldown,
bits(s.last_hurt),
f32_bits(s.last_hurt),
s.hurt_duration,
s.hurt_time,
s.last_source.is_some(),
@@ -208,7 +202,7 @@ impl HurtWorld for Env<'_> {
Ok(self.flag("component"))
}
fn apply_blocking(&mut self, _: &mut HurtState<()>, v: f32) -> io::Result<f32> {
self.event(&format!("blocking {:08x}", bits(v)))?;
self.event(&format!("blocking {:08x}", f32_bits(v)))?;
Ok(single(&self.op["blocked"]))
}
fn helmet_empty(&mut self, _: &mut HurtState<()>) -> io::Result<bool> {
@@ -216,7 +210,7 @@ impl HurtWorld for Env<'_> {
Ok(!self.flag("helmet"))
}
fn hurt_helmet(&mut self, _: &mut HurtState<()>, v: f32) -> io::Result<()> {
self.event(&format!("hurt-helmet {:08x}", bits(v)))
self.event(&format!("hurt-helmet {:08x}", f32_bits(v)))
}
fn actually_hurt(&mut self, _s: &mut HurtState<()>, _v: f32) -> io::Result<()> {
panic!("combat binding supplies actual inner damage")
@@ -228,7 +222,7 @@ impl HurtWorld for Env<'_> {
Ok(())
}
fn knockback(&mut self, _: &mut HurtState<()>, v: f32, b: bool) -> io::Result<()> {
self.event(&format!("knockback {:08x} {b}", bits(v)))
self.event(&format!("knockback {:08x} {b}", f32_bits(v)))
}
fn death_protection(&mut self, _: &mut HurtState<()>) -> io::Result<bool> {
self.event("tag bypasses_invulnerability")?;
@@ -252,7 +246,7 @@ impl HurtWorld for Env<'_> {
fn effects_on_hurt(&mut self, _: &mut HurtState<()>, v: f32) -> io::Result<()> {
self.event("effects")?;
for i in 0..self.op["effects"].as_u64().unwrap() {
self.event(&format!("effect {i} {:08x}", bits(v)))?;
self.event(&format!("effect {i} {:08x}", f32_bits(v)))?;
}
Ok(())
}
@@ -337,7 +331,7 @@ fn values(v: Option<&[FloatValue]>) -> String {
Some([]) => "empty".into(),
Some(v) => v
.iter()
.map(|v| format!("{}:{:08x}", v.id, bits(v.value)))
.map(|v| format!("{}:{:08x}", v.id, f32_bits(v.value)))
.collect::<Vec<_>>()
.join(","),
}
@@ -347,7 +341,7 @@ impl Observer for Env<'_> {
fn updated(&mut self, data: &mut SyncedFloats, id: u8) -> io::Result<()> {
self.event(&format!(
"updated {id} {:08x} {}",
bits(data.get(id).unwrap()),
f32_bits(data.get(id).unwrap()),
data.is_dirty()
))?;
if self.flag("pack_callback") {
@@ -393,7 +387,7 @@ impl<A: FixtureAttributes> ServerDamageEnvironment<A> for Env<'_> {
Ok(self.flag(&format!("bypass_{n}")))
}
fn hurt_armor(&mut self, a: &mut A, v: f32) -> io::Result<()> {
self.event(&format!("hurt-armor {:08x}", bits(v)))?;
self.event(&format!("hurt-armor {:08x}", f32_bits(v)))?;
if self.flag("break_armor") {
a.configure("minecraft:armor", number(&self.op["armor_after"]), None);
}
@@ -447,7 +441,7 @@ impl<A: FixtureAttributes> ServerDamageEnvironment<A> for Env<'_> {
}
fn record_damage(&mut self, v: f32) -> io::Result<()> {
self.event("tracker")?;
self.event(&format!("record {:08x}", bits(v)))?;
self.event(&format!("record {:08x}", f32_bits(v)))?;
self.recorded = v;
self.hit = true;
Ok(())
@@ -554,16 +548,16 @@ fn run<A: FixtureAttributes>(dir: &Path, output: &str) -> Result<(), Box<dyn std
e.out,
"state {} {:08x} {} {}",
state(&s),
bits(recorded),
f32_bits(recorded),
e.hit,
e.calls
)?;
writeln!(
e.out,
"storage {:08x} {:08x} {:08x} {} {} {} {}",
bits(data.get(ids.health).unwrap()),
bits(data.get(ids.absorption).unwrap()),
bits(food.exhaustion),
f32_bits(data.get(ids.health).unwrap()),
f32_bits(data.get(ids.absorption).unwrap()),
f32_bits(food.exhaustion),
data.is_dirty(),
data.item_dirty(ids.health).unwrap(),
data.item_dirty(ids.absorption).unwrap(),
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::{
attributes::{
Modifier, Operation,
@@ -24,20 +25,13 @@ fn single(v: &Value) -> f32 {
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
fn values(v: Option<&[FloatValue]>) -> String {
match v {
None => "none".into(),
Some([]) => "empty".into(),
Some(v) => v
.iter()
.map(|v| format!("{}:{:08x}", v.id, bits(v.value)))
.map(|v| format!("{}:{:08x}", v.id, f32_bits(v.value)))
.collect::<Vec<_>>()
.join(","),
}
@@ -69,7 +63,7 @@ impl Observer for Env<'_> {
fn updated(&mut self, data: &mut SyncedFloats, id: u8) -> io::Result<()> {
self.event(&format!(
"updated {id} {:08x} {}",
bits(data.get(id).unwrap()),
f32_bits(data.get(id).unwrap()),
data.is_dirty()
))?;
if self.flag("pack_callback") {
@@ -115,7 +109,7 @@ impl ServerDamageEnvironment for Env<'_> {
Ok(self.flag(&format!("bypass_{n}")))
}
fn hurt_armor(&mut self, a: &mut EntityAttributes, v: f32) -> io::Result<()> {
self.event(&format!("hurt-armor {:08x}", bits(v)))?;
self.event(&format!("hurt-armor {:08x}", f32_bits(v)))?;
if self.flag("break_armor") {
let id = a.catalog().id("minecraft:armor").unwrap();
a.edit(id, |a, o| {
@@ -174,7 +168,7 @@ impl ServerDamageEnvironment for Env<'_> {
}
fn record_damage(&mut self, v: f32) -> io::Result<()> {
self.event("tracker")?;
self.event(&format!("record {:08x}", bits(v)))?;
self.event(&format!("record {:08x}", f32_bits(v)))?;
self.recorded = v;
Ok(())
}
@@ -255,10 +249,10 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(
env.out,
"state {:08x} {:08x} {:08x} {:08x} {} {} {} {}",
bits(data.get(ids.health).unwrap()),
bits(data.get(ids.absorption).unwrap()),
bits(food.exhaustion),
bits(recorded),
f32_bits(data.get(ids.health).unwrap()),
f32_bits(data.get(ids.absorption).unwrap()),
f32_bits(food.exhaustion),
f32_bits(recorded),
data.is_dirty(),
data.item_dirty(ids.health).unwrap(),
data.item_dirty(ids.absorption).unwrap(),
@@ -3,6 +3,7 @@
//! (NoiseBasedChunkGenerator.getOrigin), as `seed x z chunk_x chunk_z` lines.
//!
//! usage: spawn_origin <client resource directory> <seed>...
use crate::support::common::tag;
use horizon_world::{
DATA_VERSION,
nbt::Tag,
@@ -14,17 +15,6 @@ use std::{fs, path::Path};
type Error = Box<dyn std::error::Error + Send + Sync>;
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
Value::Object(o) => {
Tag::Compound(o.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
_ => panic!("invalid registry metadata"),
}
}
fn registry(resources: &Path) -> Result<&'static BlockRegistry, Error> {
let facts: Value = serde_json::from_str(&fs::read_to_string(resources.join("facts.json"))?)?;
let states = facts["states"].as_array().ok_or("facts states")?;
@@ -1,3 +1,4 @@
use crate::support::common::tag;
use horizon_core::random::{LegacyRandom, RandomSource, WorldgenRandom, XoroshiroRandom};
use horizon_world::{
DATA_VERSION,
@@ -288,17 +289,6 @@ fn fixture(
writeln!(out, "tail {}", random.next_long())?;
Ok(())
}
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
_ => panic!("invalid registry metadata"),
}
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = crate::args().nth(1).expect("private fixture directory");
let dir = Path::new(&arg);
@@ -1,3 +1,4 @@
use crate::support::common::f64_hex;
use horizon_world::{
attribute_map::AttributeMap,
attributes::{AttributeError, Definition, Instance, Modifier, Observer, Operation},
@@ -38,16 +39,6 @@ enum Stop {
Null,
Bounds,
}
fn bits(v: f64) -> String {
format!(
"{:016x}",
if v.is_nan() {
f64::NAN.to_bits()
} else {
v.to_bits()
}
)
}
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
@@ -118,7 +109,7 @@ impl World {
format!(
"{id}:{}:{}:{}",
m.id(),
bits(m.amount()),
f64_hex(m.amount()),
m.operation() as u8
)
})
@@ -162,9 +153,9 @@ impl World {
let prefix = format!(
"instance {id} {} {} {} {}",
n.key.id,
bits(a.base_value()),
f64_hex(a.base_value()),
a.is_dirty(),
bits(a.cached_value())
f64_hex(a.cached_value())
);
let all = a.modifiers().to_vec();
let permanent = a.permanent_modifiers().to_vec();
@@ -469,7 +460,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
"value" => world
.handle(op["instance"].as_i64().unwrap())
.and_then(|h| h.ok_or(Stop::Null))
.map(|h| bits(world.instances[h.id].value.as_mut().unwrap().value())),
.map(|h| f64_hex(world.instances[h.id].value.as_mut().unwrap().value())),
_ => world.raw(&mut map, op).map(|()| "ok".into()),
};
world.logs.push(format!(
@@ -329,7 +329,7 @@ mod integration {
"value" => world
.handle(op["instance"].as_i64().unwrap())
.and_then(|h| h.ok_or(Stop::Null))
.map(|h| bits(world.instances[h.id].value.as_mut().unwrap().value())),
.map(|h| f64_hex(world.instances[h.id].value.as_mut().unwrap().value())),
_ => world.raw(&mut map, op).map(|()| "ok".into()),
};
world.logs.push(format!(
@@ -0,0 +1,49 @@
//! Number formats and JSON readers several probes share.
use horizon_core::position::BlockPos;
use horizon_world::nbt::Tag;
use serde_json::Value;
/// An f64's bits, every NaN as Java's canonical one (Double.doubleToLongBits).
pub fn f64_bits(v: f64) -> u64 {
if v.is_nan() {
f64::NAN.to_bits()
} else {
v.to_bits()
}
}
/// An f32's bits, every NaN as Java's canonical one (Float.floatToIntBits).
pub fn f32_bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
/// f64_bits as 16 hex digits.
pub fn f64_hex(v: f64) -> String {
format!("{:016x}", f64_bits(v))
}
/// Registry metadata from the oracle's JSON as NBT: strings, ints, lists and compounds.
pub fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
_ => panic!("invalid registry metadata"),
}
}
/// A block position from a JSON `[x, y, z]`.
pub fn position(v: &Value) -> BlockPos {
BlockPos::new(
v[0].as_i64().unwrap() as i32,
v[1].as_i64().unwrap() as i32,
v[2].as_i64().unwrap() as i32,
)
}
@@ -0,0 +1,85 @@
//! Shapes and boxes printed the same way by the collision probes.
use super::common::f64_bits;
use horizon_core::geometry::{Aabb, Axis, VoxelShape};
use std::io::{self, Write};
pub fn emit(out: &mut impl Write, shape: &VoxelShape) -> io::Result<()> {
writeln!(
out,
"shape {} {} {}",
shape.is_empty(),
shape.boxes().len(),
shape.is_cube()
)?;
for (axis, name) in Axis::ALL.into_iter().zip(["x", "y", "z"]) {
values(out, name, shape.coordinates(axis).iter().copied())?;
}
let axes = shape.cube_coordinate_axes();
writeln!(
out,
"axes {}",
u8::from(axes[0]) + 2 * u8::from(axes[1]) + 4 * u8::from(axes[2])
)?;
values(
out,
"extrema",
Axis::ALL
.map(|a| shape.min(a))
.into_iter()
.chain(Axis::ALL.map(|a| shape.max(a))),
)?;
match shape.bounds() {
Some(b) => box_values(out, "bounds", b)?,
None => writeln!(out, "bounds none")?,
}
for b in shape.boxes() {
box_values(out, "box", *b)?;
}
Ok(())
}
/// `label` and each value's bits in hex, NaN as Java's canonical one.
pub fn values(
out: &mut impl Write,
label: &str,
values: impl IntoIterator<Item = f64>,
) -> io::Result<()> {
write!(out, "{label}")?;
for v in values {
let bits = if v.is_nan() {
0x7ff8_0000_0000_0000
} else {
v.to_bits()
};
write!(out, " {bits:016x}")?;
}
writeln!(out)
}
pub fn box_values(out: &mut impl Write, label: &str, b: Aabb) -> io::Result<()> {
values(
out,
label,
[
b.min(Axis::X),
b.min(Axis::Y),
b.min(Axis::Z),
b.max(Axis::X),
b.max(Axis::Y),
b.max(Axis::Z),
],
)
}
/// `label` and the box's six bounds' bits in hex.
pub fn bounds(label: &str, b: Aabb) -> String {
format!(
"{label} {:016x} {:016x} {:016x} {:016x} {:016x} {:016x}",
f64_bits(b.min(Axis::X)),
f64_bits(b.min(Axis::Y)),
f64_bits(b.min(Axis::Z)),
f64_bits(b.max(Axis::X)),
f64_bits(b.max(Axis::Y)),
f64_bits(b.max(Axis::Z))
)
}
@@ -1,3 +1,4 @@
use crate::support::common::f32_bits;
use horizon_world::synced_floats::{DataError, FloatValue, Observer, SyncedFloats};
use serde_json::Value;
use std::{
@@ -8,13 +9,6 @@ use std::{
fn single(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
} else {
v.to_bits()
}
}
fn parse(v: &Value) -> Vec<FloatValue> {
v.as_array()
.unwrap()
@@ -31,7 +25,7 @@ fn values(v: Option<&[FloatValue]>) -> String {
Some([]) => "empty".into(),
Some(v) => v
.iter()
.map(|v| format!("{}:{:08x}", v.id, bits(v.value)))
.map(|v| format!("{}:{:08x}", v.id, f32_bits(v.value)))
.collect::<Vec<_>>()
.join(","),
}
@@ -59,7 +53,7 @@ impl Observer for Callback<'_> {
fn updated(&mut self, data: &mut SyncedFloats, id: u8) -> io::Result<()> {
self.event(&format!(
"updated {id} {:08x} {} {}",
bits(data.get(id).unwrap()),
f32_bits(data.get(id).unwrap()),
data.is_dirty(),
data.item_dirty(id).unwrap()
))?;
@@ -129,7 +123,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
),
"assign" => data.assign(&parse(&op["values"]), &mut cb),
"get" => data.get(id).map_err(DataError::UnknownId).and_then(|v| {
writeln!(cb.out, "get {:08x}", bits(v)).map_err(DataError::Observer)
writeln!(cb.out, "get {:08x}", f32_bits(v)).map_err(DataError::Observer)
}),
"pack" => writeln!(cb.out, "packed {}", values(data.take_dirty().as_deref()))
.map_err(DataError::Observer),
@@ -149,7 +143,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(
cb.out,
"state {id} {:08x} {} {}",
bits(data.get(*id).unwrap()),
f32_bits(data.get(*id).unwrap()),
data.item_dirty(*id).unwrap(),
data.is_default(*id).unwrap()
)?;
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{
geometry::Vec3,
position::BlockPos,
@@ -13,13 +14,6 @@ use std::{
fn n(v: &Value, k: &str) -> i32 {
v[k].as_i64().unwrap() as i32
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
struct World<'a, R> {
f: Value,
out: &'a mut dyn Write,
@@ -63,10 +57,10 @@ impl<R: RandomSource> World<'_, R> {
self.attempts,
self.changed,
self.riding,
bits(self.pos.x),
bits(self.pos.y),
bits(self.pos.z),
bits(self.fall),
f64_bits(self.pos.x),
f64_bits(self.pos.y),
f64_bits(self.pos.z),
f64_bits(self.fall),
self.grace,
self.impact
)
@@ -128,9 +122,9 @@ impl<R: RandomSource> TeleportConsumeWorld for World<'_, R> {
self.attempts += 1;
self.event(format!(
"teleport {} {} {}",
bits(p.x),
bits(p.y),
bits(p.z)
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z)
))?;
let at = n(self.config(), "success_at");
let success = at >= 0 && i >= at;
@@ -142,9 +136,9 @@ impl<R: RandomSource> TeleportConsumeWorld for World<'_, R> {
fn teleport_event(&mut self, l: i32, p: Vec3) -> Result<(), Self::Error> {
self.event(format!(
"game-event {l} {} {} {}",
bits(p.x),
bits(p.y),
bits(p.z)
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z)
))
}
fn is_fox(&self) -> bool {
@@ -153,9 +147,9 @@ impl<R: RandomSource> TeleportConsumeWorld for World<'_, R> {
fn teleport_sound(&mut self, l: i32, p: Vec3, fox: bool) -> Result<(), Self::Error> {
self.event(format!(
"sound {l} {fox} {} {} {}",
bits(p.x),
bits(p.y),
bits(p.z)
f64_bits(p.x),
f64_bits(p.y),
f64_bits(p.z)
))
}
fn block_position(&mut self) -> Result<BlockPos, Self::Error> {
@@ -1,4 +1,5 @@
//! Test transport for registry-backed noise-stage filling against vanilla doFill.
use crate::support::common::tag;
use horizon_core::{
density::{
Beardifier, JigsawJunction, RigidPiece, SamplerContext, StructureBounds, TerrainAdjustment,
@@ -67,17 +68,6 @@ impl TerrainBlockStates for Properties<'_> {
fn n(v: &Value) -> i32 {
v.as_i64().unwrap() as i32
}
fn tag(v: &Value) -> Tag {
match v {
Value::String(s) => Tag::String(s.as_str().into()),
Value::Number(i) => Tag::Int(i.as_i64().unwrap() as i32),
Value::Object(m) => {
Tag::Compound(m.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
}
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
_ => panic!("unsupported registry fixture value"),
}
}
fn structure(v: &Value) -> Beardifier {
let bounds = |v: &Value| {
StructureBounds::new(
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::geometry::Vec3;
use horizon_world::view_direction;
use serde_json::Value;
@@ -15,13 +16,6 @@ fn number(v: &Value) -> f64 {
fn vec(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
f64::NAN.to_bits()
} else {
v.to_bits()
}
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = crate::args().nth(1).unwrap();
let dir = Path::new(&arg);
@@ -32,22 +26,22 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
"acos" => writeln!(
out,
"angle {:016x}",
bits(view_direction::acos(number(&f["value"])))
f64_bits(view_direction::acos(number(&f["value"])))
)?,
"view" => {
let v = view_direction::view_vector(single(&f["pitch"]), single(&f["yaw"]));
writeln!(
out,
"view {:016x} {:016x} {:016x}",
bits(v.x),
bits(v.y),
bits(v.z)
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
)?;
}
"blocking" => writeln!(
out,
"angle {:016x}",
bits(view_direction::blocking_angle(
f64_bits(view_direction::blocking_angle(
vec(&f["source"]),
vec(&f["position"]),
single(&f["yaw"])
@@ -56,7 +50,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
"fallback" => writeln!(
out,
"angle {:016x}",
bits(view_direction::BLOCKING_FALLBACK_ANGLE)
f64_bits(view_direction::BLOCKING_FALLBACK_ANGLE)
)?,
_ => panic!("mode"),
}
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{
geometry::Vec3,
random::{LegacyRandom, RandomSource, XoroshiroRandom},
@@ -18,13 +19,6 @@ fn single(v: &Value) -> f32 {
fn vec(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
f64::NAN.to_bits()
} else {
v.to_bits()
}
}
fn float_bits(v: f32) -> u32 {
if v.is_nan() {
f32::NAN.to_bits()
@@ -33,7 +27,12 @@ fn float_bits(v: f32) -> u32 {
}
}
fn vector(v: Vec3) -> String {
format!("{:016x} {:016x} {:016x}", bits(v.x), bits(v.y), bits(v.z))
format!(
"{:016x} {:016x} {:016x}",
f64_bits(v.x),
f64_bits(v.y),
f64_bits(v.z)
)
}
struct World<'a, R> {
f: &'a Value,
@@ -1,5 +1,6 @@
use crate::support::shapes::{emit, values};
use horizon_core::geometry::{
Aabb, Axis, Vec3, VoxelShape,
Aabb, Vec3,
border::{BorderGeometry, BorderStatus},
};
use serde_json::Value;
@@ -11,70 +12,6 @@ use std::{
fn number(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn values(
out: &mut impl Write,
label: &str,
values: impl IntoIterator<Item = f64>,
) -> io::Result<()> {
write!(out, "{label}")?;
for v in values {
let bits = if v.is_nan() {
0x7ff8_0000_0000_0000
} else {
v.to_bits()
};
write!(out, " {bits:016x}")?;
}
writeln!(out)
}
fn box_values(out: &mut impl Write, label: &str, b: Aabb) -> io::Result<()> {
values(
out,
label,
[
b.min(Axis::X),
b.min(Axis::Y),
b.min(Axis::Z),
b.max(Axis::X),
b.max(Axis::Y),
b.max(Axis::Z),
],
)
}
fn emit(out: &mut impl Write, shape: &VoxelShape) -> io::Result<()> {
writeln!(
out,
"shape {} {} {}",
shape.is_empty(),
shape.boxes().len(),
shape.is_cube()
)?;
for (axis, name) in Axis::ALL.into_iter().zip(["x", "y", "z"]) {
values(out, name, shape.coordinates(axis).iter().copied())?;
}
let axes = shape.cube_coordinate_axes();
writeln!(
out,
"axes {}",
u8::from(axes[0]) + 2 * u8::from(axes[1]) + 4 * u8::from(axes[2])
)?;
values(
out,
"extrema",
Axis::ALL
.map(|a| shape.min(a))
.into_iter()
.chain(Axis::ALL.map(|a| shape.max(a))),
)?;
match shape.bounds() {
Some(b) => box_values(out, "bounds", b)?,
None => writeln!(out, "bounds none")?,
}
for b in shape.boxes() {
box_values(out, "box", *b)?;
}
Ok(())
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = crate::args().nth(1).expect("private fixture directory");
let dir = Path::new(&arg);
@@ -1,3 +1,4 @@
use crate::support::common::f64_bits;
use horizon_core::{
geometry::{Aabb, ShapeOp, Vec3, VoxelShape},
position::BlockPos,
@@ -15,13 +16,6 @@ fn number(v: &Value) -> f64 {
fn vector(v: &Value) -> Vec3 {
Vec3::new(number(&v[0]), number(&v[1]), number(&v[2]))
}
fn bits(v: f64) -> u64 {
if v.is_nan() {
0x7ff8000000000000
} else {
v.to_bits()
}
}
fn pos(p: BlockPos) -> String {
format!("{} {} {}", p.x, p.y, p.z)
}
@@ -185,9 +179,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
w.out,
"hit {} {:016x} {:016x} {:016x} {} {} {}",
r.miss,
bits(h.location.x),
bits(h.location.y),
bits(h.location.z),
f64_bits(h.location.x),
f64_bits(h.location.y),
f64_bits(h.location.z),
format!("{:?}", h.direction).to_lowercase(),
pos(h.block),
h.inside
+5 -4
View File
@@ -55,13 +55,14 @@ class ParityRunnerTests(unittest.TestCase):
with tempfile.TemporaryDirectory() as temp, mock.patch.object(parity, "ROOT", Path(temp)):
probe = Path(temp, "crates/w/examples/probe")
(probe / "support").mkdir(parents=True)
(probe / "a_fixture.rs").write_text("use crate::support::shared as s;")
(probe / "a_fixture.rs").write_text('mod integration { include!("d_fixture.rs"); }')
(probe / "d_fixture.rs").write_text("use crate::support::shared as s;")
for name in ("b_fixture.rs", "c_fixture.rs", "main.rs", "support/shared.rs", "support/other.rs"):
(probe / name).write_text("")
paths = [f"crates/w/examples/probe/{name}" for name in
("a_fixture.rs", "b_fixture.rs", "c_fixture.rs", "main.rs", "support/other.rs", "support/shared.rs")]
paths = [f"crates/w/examples/probe/{name}" for name in ("a_fixture.rs", "b_fixture.rs", "c_fixture.rs",
"d_fixture.rs", "main.rs", "support/other.rs", "support/shared.rs")]
self.assertEqual(parity.only_probes_run(["crates/w/src/lib.rs", *paths], {"a_fixture", "b_fixture"}),
["crates/w/src/lib.rs", *paths[:2], paths[3], paths[5]])
["crates/w/src/lib.rs", *paths[:2], *paths[3:5], paths[6]])
self.assertEqual(parity.only_probes_run(paths, set()), paths)
def test_java_sources_include_classes_pulled_from_the_sourcepath(self):
+13 -11
View File
@@ -482,19 +482,21 @@ def probes_run(commands):
def only_probes_run(paths, names):
"""A probe binary's dep-info lists every probe in it. Keep those the harness ran and the shared support
modules they name (support::<module>), so that editing one probe reruns only its own harnesses."""
"""A probe binary's dep-info lists every probe in it. Keep those the harness ran, the probes they include!
and the shared support modules they name (support::<module>), so that editing one probe reruns only its own
harnesses."""
if not names:
return paths
ran = [path for path in paths if (match := PROBE_SOURCE.search(path)) and not match.group(1) and match.group(2) in names]
used = "".join((ROOT / path).read_text(encoding="utf-8", errors="replace") for path in ran)
kept = []
for path in paths:
match = PROBE_SOURCE.search(path)
if not match or (match.group(1) and f"support::{match.group(2)}" in used) \
or (not match.group(1) and match.group(2) in (*names, "main")):
kept.append(path)
return kept
names, used = {*names, "main"}, ""
while True:
ran = [path for path in paths if (match := PROBE_SOURCE.search(path)) and not match.group(1) and match.group(2) in names]
used = "".join((ROOT / path).read_text(encoding="utf-8", errors="replace") for path in ran)
included = set(re.findall(r'include!\("(\w+)\.rs"\)', used)) - names
if not included:
break
names |= included
return [path for path in paths if not (match := PROBE_SOURCE.search(path))
or (f"support::{match.group(2)}" in used if match.group(1) else match.group(2) in names)]
def dependencies(trace, scope=None):