diff --git a/astraweave-gameplay/src/types.rs b/astraweave-gameplay/src/types.rs index 6bc75959b4..2f2621f4f0 100644 --- a/astraweave-gameplay/src/types.rs +++ b/astraweave-gameplay/src/types.rs @@ -45,10 +45,8 @@ pub enum WeaveOpKind { RedirectWind, LowerWater, RaisePlatform, - /// W.2c.3 — freeze the water surface at `a`. **Presentation-only** today: a - /// valid weave that consumes the weather budget and carries `a` for the render - /// layer's freeze deformation. The truth-bearing freeze (walkable ice / buoyancy - /// block) is deferred to the post-surface-arc gameplay-truth-coupling phase. + /// W.2c.3 — freeze the water surface at `a`. A kept origin consumes one + /// weather op and inserts a static AABB from the compiled ice bounds. FreezeWater, } diff --git a/astraweave-gameplay/src/weaving.rs b/astraweave-gameplay/src/weaving.rs index 49853ce247..2b04b333e5 100644 --- a/astraweave-gameplay/src/weaving.rs +++ b/astraweave-gameplay/src/weaving.rs @@ -45,6 +45,18 @@ pub fn apply_weave_op( if matches!(op.kind, WeaveOpKind::CollapseBridge) && op.b.is_none() { anyhow::bail!("Collapse needs A->B"); } + let wind = if matches!(op.kind, WeaveOpKind::RedirectWind) { + let end = op.b.unwrap_or(op.a + vec3(1.0, 0.0, 0.0)); + Some( + wind_direction(op.a, end) + .ok_or_else(|| anyhow::anyhow!("weave origin is outside the island"))?, + ) + } else { + None + }; + if !legacy_geometry_kept(kind, &compiled) { + anyhow::bail!("weave origin is outside the island"); + } match op.kind { WeaveOpKind::ReinforcePath | WeaveOpKind::RaisePlatform | WeaveOpKind::CollapseBridge => { if budget.terrain_edits <= 0 { @@ -83,7 +95,9 @@ pub fn apply_weave_op( }); } if matches!(op.kind, WeaveOpKind::RedirectWind) { - let dir = (op.b.unwrap_or(op.a + vec3(1.0, 0.0, 0.0)) - op.a).normalize_or_zero(); + let Some(dir) = wind else { + anyhow::bail!("weave origin is outside the island"); + }; phys.set_wind(dir, 10.0); log("Weave: Wind redirected".into()); } @@ -147,6 +161,32 @@ pub fn apply_weave_op( Ok(consequence) } +fn wind_direction(from: glam::Vec3, to: glam::Vec3) -> Option { + let delta = to - from; + if !(delta.x.is_finite() && delta.y.is_finite() && delta.z.is_finite()) { + return None; + } + let len2 = delta.length_squared(); + if !len2.is_finite() || len2 == 0.0 { + return None; + } + let dir = delta.normalize_or_zero(); + if dir.length_squared() == 0.0 || !dir.is_finite() { + return None; + } + Some(dir) +} + +fn legacy_geometry_kept(kind: u8, compiled: &astraweave_weaving::CompiledOp) -> bool { + match kind { + 0 | 4 => compiled.fortify.is_some(), + 1 => compiled.collapse.is_some(), + 2 | 3 => compiled.write_count > 0, + 5 => compiled.ice_min_milli.is_some(), + _ => false, + } +} + #[cfg(test)] mod tests { use super::*; @@ -663,4 +703,448 @@ mod tests { "RedirectWind must decrement weather_ops by exactly 1" ); } + + #[test] + fn dropped_origin_does_not_spend_budget_or_return_a_consequence() { + let mut world = create_test_world(); + let mut physics = create_test_physics(); + let nav_src = vec![]; + let mut budget = create_test_budget(); + let op = WeaveOp { + kind: WeaveOpKind::FreezeWater, + a: vec3(1.0e20, f32::NAN, f32::INFINITY), + b: None, + budget_cost: 1, + }; + let mut logger = |_: String| {}; + let err = apply_weave_op( + &mut world, + &mut physics, + &nav_src, + &mut budget, + &op, + &mut logger, + ) + .expect_err("a dropped freeze must not succeed"); + assert!(err.to_string().contains("outside the island")); + assert_eq!(budget.weather_ops, 3); + assert_eq!(budget.terrain_edits, 5); + + let reinforce = WeaveOp { + kind: WeaveOpKind::ReinforcePath, + a: vec3(f32::NEG_INFINITY, 0.0, 0.0), + b: None, + budget_cost: 1, + }; + let err = apply_weave_op( + &mut world, + &mut physics, + &nav_src, + &mut budget, + &reinforce, + &mut logger, + ) + .expect_err("a dropped reinforce must not succeed"); + assert!(err.to_string().contains("outside the island")); + assert_eq!(budget.terrain_edits, 5); + } + + #[test] + fn far_collapse_endpoint_does_not_spend_budget() { + let mut world = create_test_world(); + let mut physics = create_test_physics(); + let nav_src = vec![]; + let mut budget = create_test_budget(); + let op = WeaveOp { + kind: WeaveOpKind::CollapseBridge, + a: vec3(0.0, 0.0, 0.0), + b: Some(vec3(1.0e20, 0.0, (i32::MAX as f32) / 1000.0)), + budget_cost: 1, + }; + let mut logger = |_: String| {}; + let err = apply_weave_op( + &mut world, + &mut physics, + &nav_src, + &mut budget, + &op, + &mut logger, + ) + .expect_err("a far collapse endpoint must not succeed"); + assert!(err.to_string().contains("outside the island")); + assert_eq!(budget.terrain_edits, 5); + } + + #[test] + fn non_finite_wind_endpoint_does_not_spend_weather() { + let mut world = create_test_world(); + let mut physics = create_test_physics(); + let nav_src = vec![]; + let mut budget = create_test_budget(); + let mut logger = |_: String| {}; + for endpoint in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY] { + let op = WeaveOp { + kind: WeaveOpKind::RedirectWind, + a: vec3(0.0, 0.0, 0.0), + b: Some(vec3(endpoint, 0.0, 1.0)), + budget_cost: 1, + }; + let err = apply_weave_op( + &mut world, + &mut physics, + &nav_src, + &mut budget, + &op, + &mut logger, + ) + .expect_err("a non-finite wind endpoint must not succeed"); + assert!(err.to_string().contains("outside the island")); + assert_eq!(budget.weather_ops, 3, "{endpoint}"); + } + physics.wind = vec3(3.0, 0.0, 0.0); + let huge = WeaveOp { + kind: WeaveOpKind::RedirectWind, + a: vec3(0.0, 0.0, 0.0), + b: Some(vec3(1.9e19, 0.0, 0.0)), + budget_cost: 1, + }; + let err = apply_weave_op( + &mut world, + &mut physics, + &nav_src, + &mut budget, + &huge, + &mut logger, + ) + .expect_err("a wind endpoint whose square overflows must not succeed"); + assert!(err.to_string().contains("outside the island")); + assert_eq!(budget.weather_ops, 3); + assert_eq!(physics.wind, vec3(3.0, 0.0, 0.0)); + } + + #[test] + fn weave_op_edges_fail_closed() { + #[derive(Clone, Copy)] + struct Case { + name: &'static str, + kind: WeaveOpKind, + a: [f32; 3], + b: Option<[f32; 3]>, + keep: bool, + } + let cases = [ + Case { + name: "reinforce origin", + kind: WeaveOpKind::ReinforcePath, + a: [0.0, 0.0, 0.0], + b: None, + keep: true, + }, + Case { + name: "reinforce floor -1.5", + kind: WeaveOpKind::ReinforcePath, + a: [-1.5, 0.0, 0.0], + b: None, + keep: true, + }, + Case { + name: "reinforce island edge", + kind: WeaveOpKind::ReinforcePath, + a: [2048.0, 0.0, -2048.0], + b: None, + keep: true, + }, + Case { + name: "reinforce just outside", + kind: WeaveOpKind::ReinforcePath, + a: [2049.0, 0.0, 0.0], + b: None, + keep: false, + }, + Case { + name: "reinforce negative floor edge", + kind: WeaveOpKind::ReinforcePath, + a: [-2047.1, 0.0, 0.0], + b: None, + keep: true, + }, + Case { + name: "reinforce past negative edge", + kind: WeaveOpKind::ReinforcePath, + a: [-2048.1, 0.0, 0.0], + b: None, + keep: false, + }, + Case { + name: "reinforce subnormal snaps to cell 0", + kind: WeaveOpKind::ReinforcePath, + a: [1e-45, 0.0, 0.0], + b: None, + keep: true, + }, + Case { + name: "reinforce nan", + kind: WeaveOpKind::ReinforcePath, + a: [f32::NAN, 0.0, 0.0], + b: None, + keep: false, + }, + Case { + name: "reinforce +inf", + kind: WeaveOpKind::ReinforcePath, + a: [f32::INFINITY, 0.0, 0.0], + b: None, + keep: false, + }, + Case { + name: "reinforce -inf", + kind: WeaveOpKind::ReinforcePath, + a: [f32::NEG_INFINITY, 0.0, 0.0], + b: None, + keep: false, + }, + Case { + name: "reinforce 1e20", + kind: WeaveOpKind::ReinforcePath, + a: [1.0e20, 0.0, 0.0], + b: None, + keep: false, + }, + Case { + name: "reinforce 2^31/1000", + kind: WeaveOpKind::ReinforcePath, + a: [(i32::MAX as f32) / 1000.0, 0.0, 0.0], + b: None, + keep: false, + }, + Case { + name: "raise origin", + kind: WeaveOpKind::RaisePlatform, + a: [1.0, 2.0, 3.0], + b: None, + keep: true, + }, + Case { + name: "raise nan y", + kind: WeaveOpKind::RaisePlatform, + a: [0.0, f32::NAN, 0.0], + b: None, + keep: false, + }, + Case { + name: "lower origin", + kind: WeaveOpKind::LowerWater, + a: [0.0, 0.0, 0.0], + b: None, + keep: true, + }, + Case { + name: "lower inf z", + kind: WeaveOpKind::LowerWater, + a: [0.0, 0.0, f32::INFINITY], + b: None, + keep: false, + }, + Case { + name: "freeze origin", + kind: WeaveOpKind::FreezeWater, + a: [1.0, 0.0, 1.0], + b: None, + keep: true, + }, + Case { + name: "freeze nan", + kind: WeaveOpKind::FreezeWater, + a: [f32::NAN, f32::NAN, f32::NAN], + b: None, + keep: false, + }, + Case { + name: "freeze 1e20", + kind: WeaveOpKind::FreezeWater, + a: [0.0, 1.0e20, 0.0], + b: None, + keep: false, + }, + Case { + name: "collapse segment", + kind: WeaveOpKind::CollapseBridge, + a: [0.0, 0.0, 0.0], + b: Some([10.0, 0.0, 10.0]), + keep: true, + }, + Case { + name: "collapse missing b", + kind: WeaveOpKind::CollapseBridge, + a: [0.0, 0.0, 0.0], + b: None, + keep: false, + }, + Case { + name: "collapse point", + kind: WeaveOpKind::CollapseBridge, + a: [2.0, 0.0, 2.0], + b: Some([2.0, 0.0, 2.0]), + keep: true, + }, + Case { + name: "collapse far b", + kind: WeaveOpKind::CollapseBridge, + a: [0.0, 0.0, 0.0], + b: Some([1.0e20, 0.0, 0.0]), + keep: false, + }, + Case { + name: "collapse nan b", + kind: WeaveOpKind::CollapseBridge, + a: [0.0, 0.0, 0.0], + b: Some([f32::NAN, 0.0, 1.0]), + keep: false, + }, + Case { + name: "collapse inf b", + kind: WeaveOpKind::CollapseBridge, + a: [0.0, 0.0, 0.0], + b: Some([0.0, f32::INFINITY, 0.0]), + keep: false, + }, + Case { + name: "collapse -inf b", + kind: WeaveOpKind::CollapseBridge, + a: [0.0, 0.0, 0.0], + b: Some([0.0, 0.0, f32::NEG_INFINITY]), + keep: false, + }, + Case { + name: "wind default +x", + kind: WeaveOpKind::RedirectWind, + a: [0.0, 0.0, 0.0], + b: None, + keep: true, + }, + Case { + name: "wind finite step", + kind: WeaveOpKind::RedirectWind, + a: [0.0, 0.0, 0.0], + b: Some([1.0, 0.0, 0.0]), + keep: true, + }, + Case { + name: "wind 1e-22", + kind: WeaveOpKind::RedirectWind, + a: [0.0, 0.0, 0.0], + b: Some([1e-22, 0.0, 0.0]), + keep: true, + }, + Case { + name: "wind zero", + kind: WeaveOpKind::RedirectWind, + a: [1.0, 2.0, 3.0], + b: Some([1.0, 2.0, 3.0]), + keep: false, + }, + Case { + name: "wind 1e-45", + kind: WeaveOpKind::RedirectWind, + a: [0.0, 0.0, 0.0], + b: Some([1e-45, 0.0, 0.0]), + keep: false, + }, + Case { + name: "wind 1e-30", + kind: WeaveOpKind::RedirectWind, + a: [0.0, 0.0, 0.0], + b: Some([0.0, 1e-30, 0.0]), + keep: false, + }, + Case { + name: "wind 1e-23", + kind: WeaveOpKind::RedirectWind, + a: [0.0, 0.0, 0.0], + b: Some([0.0, 0.0, 1e-23]), + keep: false, + }, + Case { + name: "wind 1.9e19", + kind: WeaveOpKind::RedirectWind, + a: [0.0, 0.0, 0.0], + b: Some([1.9e19, 0.0, 0.0]), + keep: false, + }, + Case { + name: "wind nan", + kind: WeaveOpKind::RedirectWind, + a: [0.0, 0.0, 0.0], + b: Some([f32::NAN, 0.0, 0.0]), + keep: false, + }, + Case { + name: "wind +inf", + kind: WeaveOpKind::RedirectWind, + a: [0.0, 0.0, 0.0], + b: Some([f32::INFINITY, 0.0, 0.0]), + keep: false, + }, + Case { + name: "wind -inf", + kind: WeaveOpKind::RedirectWind, + a: [0.0, 0.0, 0.0], + b: Some([f32::NEG_INFINITY, 0.0, 0.0]), + keep: false, + }, + Case { + name: "wind nan origin", + kind: WeaveOpKind::RedirectWind, + a: [f32::NAN, 0.0, 0.0], + b: Some([1.0, 0.0, 0.0]), + keep: false, + }, + ]; + for case in cases { + let mut world = create_test_world(); + let mut physics = create_test_physics(); + physics.wind = vec3(3.0, 0.0, 0.0); + let nav_src = vec![]; + let mut budget = create_test_budget(); + let op = WeaveOp { + kind: case.kind, + a: vec3(case.a[0], case.a[1], case.a[2]), + b: case.b.map(|p| vec3(p[0], p[1], p[2])), + budget_cost: 1, + }; + let mut logger = |_: String| {}; + let result = apply_weave_op( + &mut world, + &mut physics, + &nav_src, + &mut budget, + &op, + &mut logger, + ); + if case.keep { + assert!(result.is_ok(), "{}", case.name); + let weather = matches!( + case.kind, + WeaveOpKind::RedirectWind | WeaveOpKind::LowerWater | WeaveOpKind::FreezeWater + ); + if weather { + assert_eq!(budget.weather_ops, 2, "{}", case.name); + assert_eq!(budget.terrain_edits, 5, "{}", case.name); + } else { + assert_eq!(budget.terrain_edits, 4, "{}", case.name); + assert_eq!(budget.weather_ops, 3, "{}", case.name); + } + if matches!(case.kind, WeaveOpKind::RedirectWind) { + assert_ne!(physics.wind, vec3(3.0, 0.0, 0.0), "{}", case.name); + assert!(physics.wind.is_finite(), "{}", case.name); + assert!(physics.wind.length_squared() > 0.0, "{}", case.name); + } + } else { + assert!(result.is_err(), "{}", case.name); + assert_eq!(budget.terrain_edits, 5, "{}", case.name); + assert_eq!(budget.weather_ops, 3, "{}", case.name); + assert_eq!(physics.wind, vec3(3.0, 0.0, 0.0), "{}", case.name); + } + } + } } diff --git a/astraweave-weaving/src/eval.rs b/astraweave-weaving/src/eval.rs index 93ad2752f1..8b2f6540ed 100644 --- a/astraweave-weaving/src/eval.rs +++ b/astraweave-weaving/src/eval.rs @@ -7,8 +7,8 @@ use crate::field::{ encode_write, FieldWrite, NullField, Shape, SimField, WriteOp, CELL_MM, MAX_FIELD_WRITES, }; use crate::mod_queue::{ - WeaveCommand, WeaveNode, WeaveScratch, KIND_DECAY, KIND_DENSITY, KIND_GRAVITY, KIND_HEAT, - KIND_PHASE, KIND_VOLUME, KIND_WIND, MAX_WEAVE_COMMANDS, + WeaveCommand, WeaveNode, WeaveScratch, ISLAND_HALF_CELLS, KIND_DECAY, KIND_DENSITY, + KIND_GRAVITY, KIND_HEAT, KIND_PHASE, KIND_VOLUME, KIND_WIND, MAX_WEAVE_COMMANDS, }; use crate::templates::{builtin, writes_for, TEMPLATE_FREEZE}; use astraweave_nav::{NavChange, NavChangeKind}; @@ -230,6 +230,12 @@ fn store_writes(frame: &mut WeaveFrame, writes: &[FieldWrite]) -> u32 { } fn push_ice(frame: &mut WeaveFrame, tick: u64, seq: u32, origin: [i32; 3], radius: u8) { + debug_assert!( + origin + .iter() + .all(|cell| (-ISLAND_HALF_CELLS..=ISLAND_HALF_CELLS).contains(cell)), + "freeze origin is outside the island; queue_weave rejects it before writes are stored" + ); let radius = radius as i32; let min_milli = [ (origin[0] - radius) * CELL_MM, diff --git a/astraweave-weaving/src/field.rs b/astraweave-weaving/src/field.rs index 5f8e630608..eb4b616253 100644 --- a/astraweave-weaving/src/field.rs +++ b/astraweave-weaving/src/field.rs @@ -31,11 +31,33 @@ pub fn gravity_mm_s2(milli_g: i32) -> i32 { milli_g.saturating_mul(981) / 100 } -/// Nearest cell from metres. Truncates toward zero after scaling to millimetres. +/// Cell index from metres. Floors after scaling to millimetres (`div_euclid`), +/// so `-1.5` is cell `-2`, not `-1`. +/// +/// Returns `None` when `m` is not finite or `m * 1000` does not fit in `i32`. +/// The float-to-int cast saturates, so that range is rejected before the cast. /// The replay path passes cell coordinates and does not call this. -pub fn meters_to_cell(m: f32) -> i32 { - let milli = (m * 1000.0) as i32; - milli.div_euclid(CELL_MM) +pub fn meters_to_cell(m: f32) -> Option { + if !m.is_finite() { + return None; + } + let milli = m * 1000.0; + // `i32::MAX as f32` is `2^31`. `>` lets that value through and `as i32` + // saturates. The predecessor finite `f32` is `2147483520`, which fits. + if milli < i32::MIN as f32 || milli >= i32::MAX as f32 { + return None; + } + Some((milli as i32).div_euclid(CELL_MM)) +} + +/// `cell * CELL_MM` when the product fits in `i32`. Does not saturate. +pub fn cell_to_milli(cell: i32) -> Option { + cell.checked_mul(CELL_MM) +} + +/// Three cell coordinates scaled to millimetres, or `None` if any product overflows. +pub fn milli_corner(x: Option, y: Option, z: Option) -> Option<[i32; 3]> { + Some([cell_to_milli(x?)?, cell_to_milli(y?)?, cell_to_milli(z?)?]) } #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -233,6 +255,29 @@ impl SimField for TestSimField { mod tests { use super::*; + #[test] + fn meters_to_cell_rejects_non_finite_and_the_i32_edge() { + let positive = (i32::MAX as f32) / 1000.0; + assert!( + meters_to_cell(positive).is_none(), + "nearest f32 to 2^31/1000 ({positive}) must not saturate" + ); + let negative = (i32::MIN as f32) / 1000.0; + assert_eq!( + meters_to_cell(negative), + Some(-2_147_484), + "negative edge ({negative}) must stay negative and must not saturate" + ); + assert!(meters_to_cell(f32::NAN).is_none()); + assert!(meters_to_cell(f32::INFINITY).is_none()); + assert!(meters_to_cell(f32::NEG_INFINITY).is_none()); + assert_eq!(meters_to_cell(1.0), Some(1)); + assert_eq!(meters_to_cell(-1.5), Some(-2)); + let predecessor = f32::from_bits((i32::MAX as f32).to_bits() - 1); + assert_eq!(predecessor, 2_147_483_520.0); + assert!(predecessor < i32::MAX as f32); + } + #[test] fn gravity_conversion_matches_9810() { assert_eq!(gravity_mm_s2(WORLD_GRAVITY_MILLI_G), -9810); diff --git a/astraweave-weaving/src/legacy.rs b/astraweave-weaving/src/legacy.rs index 96561c2c38..5f299273f7 100644 --- a/astraweave-weaving/src/legacy.rs +++ b/astraweave-weaving/src/legacy.rs @@ -1,6 +1,7 @@ //! Compiles the six legacy ops into templates and director rectangles. -use crate::field::{meters_to_cell, FieldWrite, WriteOp}; +use crate::field::{meters_to_cell, milli_corner, FieldWrite, WriteOp}; +use crate::mod_queue::ISLAND_HALF_CELLS; use crate::templates::{ builtin, writes_for, MAX_NODES, TEMPLATE_DENSITY, TEMPLATE_FREEZE, TEMPLATE_LOWER_WATER, TEMPLATE_WIND, @@ -51,7 +52,9 @@ pub fn compile_legacy(kind: u8, points: LegacyPoints) -> CompiledOp { }; let tick = points.tick; let seq = points.seq; - let origin = [meters_to_cell(ax), meters_to_cell(ay), meters_to_cell(az)]; + let Some(origin) = cell_origin(ax, ay, az) else { + return empty_compiled(); + }; let mut compiled = CompiledOp { writes: writes_for(&builtin(TEMPLATE_DENSITY).unwrap(), origin, 1).0, write_count: 0, @@ -77,7 +80,10 @@ pub fn compile_legacy(kind: u8, points: LegacyPoints) -> CompiledOp { compiled.write_count = count; } 1 => { - if let (Some(bx), Some(bz)) = (bx, bz) { + if let (Some(bx), Some(by), Some(bz)) = (bx, by, bz) { + if cell_origin(bx, by, bz).is_none() { + return empty_compiled(); + } compiled.collapse = Some(DirectorCollapse { ax: ax as i32, ay: az as i32, @@ -85,9 +91,13 @@ pub fn compile_legacy(kind: u8, points: LegacyPoints) -> CompiledOp { by: bz as i32, }); } - let _ = by; } 2 => { + if let (Some(bx), Some(by), Some(bz)) = (bx, by, bz) { + if !wind_delta_fits(ax, ay, az, bx, by, bz) { + return empty_compiled(); + } + } let (mods, count) = writes_for(&builtin(TEMPLATE_WIND).unwrap(), origin, 1); compiled.writes = mods; compiled.write_count = count; @@ -110,31 +120,76 @@ pub fn compile_legacy(kind: u8, points: LegacyPoints) -> CompiledOp { compiled.writes = mods; compiled.write_count = count; let radius = template.ice_radius as i32; - let min_milli = [ - (origin[0] - radius) * crate::field::CELL_MM, - origin[1] * crate::field::CELL_MM, - (origin[2] - radius) * crate::field::CELL_MM, - ]; - let max_milli = [ - (origin[0] + radius + 1) * crate::field::CELL_MM, - (origin[1] + 1) * crate::field::CELL_MM, - (origin[2] + radius + 1) * crate::field::CELL_MM, - ]; - compiled.ice_min_milli = Some(min_milli); - compiled.ice_max_milli = Some(max_milli); - compiled.nav = Some(NavChange::new( - tick, - seq, - min_milli, - max_milli, - NavChangeKind::Weave, - )); + if let (Some(min_milli), Some(max_milli)) = ( + milli_corner( + origin[0].checked_sub(radius), + Some(origin[1]), + origin[2].checked_sub(radius), + ), + milli_corner( + origin[0] + .checked_add(radius) + .and_then(|cell| cell.checked_add(1)), + origin[1].checked_add(1), + origin[2] + .checked_add(radius) + .and_then(|cell| cell.checked_add(1)), + ), + ) { + compiled.ice_min_milli = Some(min_milli); + compiled.ice_max_milli = Some(max_milli); + compiled.nav = Some(NavChange::new( + tick, + seq, + min_milli, + max_milli, + NavChangeKind::Weave, + )); + } } _ => {} } compiled } +fn wind_delta_fits(ax: f32, ay: f32, az: f32, bx: f32, by: f32, bz: f32) -> bool { + let dx = bx - ax; + let dy = by - ay; + let dz = bz - az; + if !(dx.is_finite() && dy.is_finite() && dz.is_finite()) { + return false; + } + let len2 = dx * dx + dy * dy + dz * dz; + // Exact zero and squares that underflow to +0 (1e-45, 1e-30, 1e-23) + // have no direction. 1e-22 still has a positive square and is kept. + len2.is_finite() && len2 > 0.0 +} + +fn cell_origin(x: f32, y: f32, z: f32) -> Option<[i32; 3]> { + let origin = [meters_to_cell(x)?, meters_to_cell(y)?, meters_to_cell(z)?]; + if origin + .iter() + .all(|cell| (-ISLAND_HALF_CELLS..=ISLAND_HALF_CELLS).contains(cell)) + { + Some(origin) + } else { + None + } +} + +fn empty_compiled() -> CompiledOp { + let (writes, _) = writes_for(&builtin(TEMPLATE_DENSITY).unwrap(), [0, 0, 0], 1); + CompiledOp { + writes, + write_count: 0, + fortify: None, + collapse: None, + ice_min_milli: None, + ice_max_milli: None, + nav: None, + } +} + #[cfg(test)] mod tests { use super::*; @@ -176,4 +231,139 @@ mod tests { let rect = compiled.fortify.unwrap(); assert_eq!((rect.x0, rect.y0, rect.x1, rect.y1), (4, 4, 6, 6)); } + + #[test] + fn far_origin_does_not_saturate_into_a_milli_aabb() { + let compiled = compile_legacy( + 5, + LegacyPoints { + a: [1.0e20, 0.0, 0.0], + b: None, + tick: 4, + seq: 2, + }, + ); + assert_eq!(compiled.write_count, 0); + assert!(compiled.ice_min_milli.is_none()); + assert!(compiled.nav.is_none()); + let edge = compile_legacy( + 5, + LegacyPoints { + a: [ISLAND_HALF_CELLS as f32, 0.0, 0.0], + b: None, + tick: 1, + seq: 1, + }, + ); + let min = edge.ice_min_milli.unwrap(); + assert_eq!(min[0], (ISLAND_HALF_CELLS - 2) * crate::field::CELL_MM); + assert_eq!(min[1], 0); + } + + #[test] + fn non_finite_and_i32_edge_origins_drop_the_op() { + for origin in [ + f32::NAN, + f32::INFINITY, + f32::NEG_INFINITY, + (i32::MAX as f32) / 1000.0, + (i32::MIN as f32) / 1000.0, + ] { + let compiled = compile_legacy( + 5, + LegacyPoints { + a: [origin, 0.0, 0.0], + b: None, + tick: 1, + seq: 1, + }, + ); + assert_eq!(compiled.write_count, 0, "{origin}"); + assert!(compiled.ice_min_milli.is_none(), "{origin}"); + } + } + + #[test] + fn far_collapse_endpoint_is_rejected() { + let compiled = compile_legacy( + 1, + LegacyPoints { + a: [0.0, 0.0, 0.0], + b: Some([1.0e20, 0.0, 0.0]), + tick: 0, + seq: 0, + }, + ); + assert!(compiled.collapse.is_none()); + assert_eq!(compiled.write_count, 0); + let kept = compile_legacy( + 1, + LegacyPoints { + a: [0.0, 0.0, 0.0], + b: Some([10.0, 0.0, 10.0]), + tick: 0, + seq: 0, + }, + ); + let line = kept.collapse.unwrap(); + assert_eq!((line.ax, line.ay, line.bx, line.by), (0, 0, 10, 10)); + } + + #[test] + fn non_finite_wind_endpoint_drops_the_op() { + for endpoint in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY] { + let compiled = compile_legacy( + 2, + LegacyPoints { + a: [0.0, 0.0, 0.0], + b: Some([endpoint, 0.0, 1.0]), + tick: 0, + seq: 0, + }, + ); + assert_eq!(compiled.write_count, 0, "{endpoint}"); + } + let kept = compile_legacy( + 2, + LegacyPoints { + a: [0.0, 0.0, 0.0], + b: Some([1.0, 0.0, 0.0]), + tick: 0, + seq: 0, + }, + ); + assert!(kept.write_count > 0); + let tiny = compile_legacy( + 2, + LegacyPoints { + a: [0.0, 0.0, 0.0], + b: Some([1e-22, 0.0, 0.0]), + tick: 0, + seq: 0, + }, + ); + assert!(tiny.write_count > 0); + for underflow in [0.0_f32, 1e-45, 1e-30, 1e-23] { + let dropped = compile_legacy( + 2, + LegacyPoints { + a: [0.0, 0.0, 0.0], + b: Some([underflow, 0.0, 0.0]), + tick: 0, + seq: 0, + }, + ); + assert_eq!(dropped.write_count, 0, "{underflow}"); + } + let overflow = compile_legacy( + 2, + LegacyPoints { + a: [0.0, 0.0, 0.0], + b: Some([1.9e19, 0.0, 0.0]), + tick: 0, + seq: 0, + }, + ); + assert_eq!(overflow.write_count, 0); + } } diff --git a/astraweave-weaving/src/lib.rs b/astraweave-weaving/src/lib.rs index 552c233a08..5fccec4370 100644 --- a/astraweave-weaving/src/lib.rs +++ b/astraweave-weaving/src/lib.rs @@ -58,7 +58,7 @@ pub use field::{ }; pub use gameplay_qa::{load_bundled_scenario, run_scenario, FailureArtifact, RunOutcome}; pub use intents::{IntentProposer, WeaveIntent}; -pub use legacy::{compile_legacy, LegacyPoints}; +pub use legacy::{compile_legacy, CompiledOp, LegacyPoints}; pub use level::{Camera, LevelStats, Player, VeilweaverLevel}; pub use mod_queue::{ parse_template_toml, queue_weave, QueueError, WeaveCommand, WeaveScratch, WeaveTemplate, diff --git a/docs/architecture/gameplay.md b/docs/architecture/gameplay.md index 4c1e2cba83..90523b69c0 100644 --- a/docs/architecture/gameplay.md +++ b/docs/architecture/gameplay.md @@ -9,8 +9,8 @@ lifecycle_status: active integration_status: mixed summary: "Wired TYPES (QuestLog/Stats/Inventory->ui; BiomeRule/ResourceNode->terrain; Dialogue->audio), but combat (perform_attack_sweep), apply_weave_op & the Combat/Crafting/Quest plugins are example-only; water_movement.rs fully dormant. gameplay.md §1,§6" owns: [astraweave-gameplay] -doc_version: "1.3" -last_verified_commit: 1e306e13 +doc_version: "1.4" +last_verified_commit: 9403e3b6 --- # Architecture Trace: Gameplay System (Combat, Crafting, Veilweaver Slice, Weaving + Water Integration) @@ -21,9 +21,9 @@ last_verified_commit: 1e306e13 |---|---| | **System name** | Gameplay System (combat, crafting, quests/dialogue, Veilweaver slice/tutorial, in-crate weaving glue, water-movement logic) | | **Primary crates** | `astraweave-gameplay` (single crate) | -| **Document version** | 1.3 | -| **Last verified against commit** | `1e306e13` | -| **Last verified date** | 2026-10-15 | +| **Document version** | 1.4 | +| **Last verified against commit** | `9403e3b6` | +| **Last verified date** | 2026-10-20 | | **Status** | Active (mixed wiring: a subset of types are consumed by other engine crates; the ECS combat/craft/quest plugins, `perform_attack_sweep`, `apply_weave_op`, and `water_movement` are wired only by examples/the slice-runtime crate, not by an in-engine runtime caller) | | **Owner notes** | Generated by the architecture-trace campaign on 2026-06-24. The crate is a grab-bag of loosely-coupled gameplay-layer modules, not one cohesive pipeline; this trace documents each subsystem and its wiring honestly. | @@ -94,7 +94,7 @@ caller (example/test): apply_weave_op(w, phys, nav_src, &mut budget, &op, &mut l weaving.rs:11 role: match op.kind → either build a core DirectorPlan (Fortify/Collapse) or mutate PhysicsWorld directly (set_wind / clear_water), decrementing - the matching WeaveBudget field; FreezeWater is presentation-only (no truth) + the matching WeaveBudget field; FreezeWater adds a static ice AABB │ apply_director_plan(w, &mut core_budget, &plan, log) [core::validation:400] ▼ World terrain mutated (for terrain ops) and/or PhysicsWorld wind/water mutated @@ -105,10 +105,10 @@ Ok(WeaveConsequence{drop_multiplier, faction_disposition, weather_shift}) #### Stage detail **File:** `astraweave-gameplay/src/weaving.rs:11-150` -**Role:** Translates a positional `WeaveOp` into either a `astraweave_core::DirectorPlan` (`ReinforcePath`/`RaisePlatform` → `DirectorOp::Fortify`; `CollapseBridge` → `DirectorOp::Collapse`) applied via `apply_director_plan`, or a direct physics mutation (`RedirectWind` → `phys.set_wind`; `LowerWater` → `phys.clear_water`). Each arm bails if the relevant `WeaveBudget` field (`terrain_edits` or `weather_ops`) is `<= 0`, else decrements it by 1. `FreezeWater` (lines 94-105) is **presentation-only**: it consumes `weather_ops` and carries `op.a` for a render layer but makes **no** truth mutation (documented inline). +**Role:** Translates a positional `WeaveOp` into either a `astraweave_core::DirectorPlan` (`ReinforcePath`/`RaisePlatform` → `DirectorOp::Fortify`; `CollapseBridge` → `DirectorOp::Collapse`) applied via `apply_director_plan`, or a direct physics mutation (`RedirectWind` → `phys.set_wind`; `LowerWater` → `phys.clear_water`; `FreezeWater` → `phys.add_static_aabb` from the compiled ice bounds). Each arm bails if the relevant `WeaveBudget` field (`terrain_edits` or `weather_ops`) is `<= 0`, else decrements it by 1. A dropped origin bails before that spend. **Inputs:** `&mut World`, `&mut PhysicsWorld`, `&[Triangle]` nav source, `&mut WeaveBudget`, `&WeaveOp`, log closure. **Outputs:** `Result`. -**Notes:** Re-bakes a throwaway navmesh each call (`NavMesh::bake(nav_src, 0.5, 55.0)` → `_nav`, line 113) that is immediately discarded — a demo-pathing artifact. The actual W-series "weave gameplay producer" that turns these ops into render-side `WeaveInstance`s lives in `examples/weaving_playground/src/weave_producer.rs` (commit `3edf15e25`), **not** in this crate. +**Notes:** `nav_src` is unused. `apply_weave_op` does not bake a navmesh. The W-series weave gameplay producer that turns these ops into render-side `WeaveInstance`s lives in `examples/weaving_playground/src/weave_producer.rs` (commit `3edf15e25`), **not** in this crate. ### 2.C Veilweaver slice metadata → tutorial state @@ -172,7 +172,7 @@ WeaveTutorialState mutated (anchors stabilized, triggers active) | `astraweave-core` | `apply_director_plan` (`validation.rs:400`); `DirectorPlan`/`DirectorOp`/`DirectorBudget`/`Rect`/`IVec2`/`World`; ECS components `CHealth`/`CPos` | Terrain-edit plans; legacy world | `weaving.rs` builds a `DirectorPlan` and delegates terrain edits to core. `ecs.rs` reads/writes `CHealth`/`CPos`. | | `astraweave-ecs` | `World`, `App`, `Plugin`, `Query`/`Query2`, `Entity`, `Events` | Component queries, system registration, event drains | `ecs.rs` plugins register into `"simulation"`; `veilweaver_tutorial.rs` drains `Events`/`Events`. | | `astraweave-scene` | `world_partition::{Cell, CellComponentView, GridCoord}` | Designer-authored slice cell content | `veilweaver_slice.rs` parses typed component views from cells. | -| `astraweave-nav` | `NavMesh::bake`, `Triangle` | Nav source for weave re-bake (`weaving.rs:113`, discarded) and portal graph (`weave_portals.rs`) | | +| `astraweave-nav` | `Triangle` | Unused `nav_src` on `apply_weave_op`; portal graph in `weave_portals.rs` | `apply_weave_op` does not call `NavMesh::bake`. | | `astraweave-cinematics` | `CameraKey`, `Time` | Camera cue payload | `cutscenes.rs:151` builds a `CameraKey` inside `CutsceneState::tick`; dep added in the Unified Camera C.7.A chapter (Cargo.toml comment). | | Caller-supplied scalar | `WaterPlayerState::update(submersion, dt)` | `submersion: f32` | **No fluids/water-query dependency** — submersion is passed in. The crate has no `astraweave-fluids` dep (verified in `Cargo.toml`). | @@ -265,11 +265,11 @@ WeaveTutorialState mutated (anchors stabilized, triggers active) ### Decision: `FreezeWater` weave op is presentation-only - **Date:** 2026-06-24 (commit `3edf15e25`, W-series W.2c.3.2) -- **Status:** Accepted (in active code) +- **Status:** Superseded. `apply_weave_op` now places a static AABB from the compiled ice millimetre bounds (`phys.add_static_aabb`). That is a physics mutation. The 2026-06-24 "no physics change" sentence is not in force. - **Context:** The W-series surface arc needed water to deform from real fate-weaving casts without yet committing to gameplay-truth coupling. -- **Decision:** `WeaveOpKind::FreezeWater` (`types.rs:48-53`) consumes the weather budget and carries `op.a` for the render layer, with **no** physics/collision/traversal change (`weaving.rs:94-105`). `WeaveConsequence` arm returns `weather_shift: "frozen"`. +- **Decision:** `WeaveOpKind::FreezeWater` (`types.rs:48-53`) consumes the weather budget and carries `op.a` for the render layer. The later ice-bound path also inserts a static body. `WeaveConsequence` still returns `weather_shift: "frozen"`. - **Alternatives considered:** A truth-bearing freeze (walkable ice / buoyancy block) — explicitly deferred to a "post-surface-arc gameplay-truth-coupling phase" per the commit message and inline comments. -- **Consequences:** The enum is `#[non_exhaustive]`, so the variant addition is non-breaking. `astraweave-render` gains no dependency on gameplay (the producer translation lives in `examples/weaving_playground/src/weave_producer.rs`). +- **Consequences:** The enum is `#[non_exhaustive]`, so the variant addition is non-breaking. `astraweave-render` gains no dependency on gameplay (the producer translation lives in `examples/weaving_playground/src/weave_producer.rs`). Do not cite this decision as "FreezeWater performs no physics mutation." ### Decision: Player water-movement direction abandoned - **Date:** W-series W.1 (2026-06-21 era), commit `1a57fdd41` (recovery anchor `w0-pre-deprecation` — local-only since 2026-07-20, see `fluids.md` §0.5 recovery note) @@ -304,8 +304,8 @@ WeaveTutorialState mutated (anchors stabilized, triggers active) | 1 | `perform_attack_sweep` returns `None` for sweeps shorter than `1e-3` | Yes | Test `test_negligible_sweep_distance_returns_none` (`combat_physics.rs:591`) | | 2 | A parry blocks damage exactly once: it is consumed (`window=0.0, active=false`) on the hit it blocks | Yes | Tests `test_parry_blocks_damage`, `test_parry_window_zero_does_not_parry`, `test_parry_inactive_does_not_parry` (`combat_physics.rs`) | | 3 | Iframes block damage **without** being consumed | Yes | Test `test_iframes_block_damage` (`combat_physics.rs:393`) | -| 4 | `apply_weave_op` bails (no mutation) when the relevant budget field is `<= 0`, else decrements it by exactly 1 | Yes | Tests `*_no_budget`, `redirect_wind_budget_decrements`, `test_apply_weave_op_budget_depletion` (`weaving.rs`) | -| 5 | `FreezeWater` performs no truth mutation (consumes `weather_ops` only) | Partial | Doc-only (verified 2026-06-25). Enforced by the inline comment + budget decrement at `weaving.rs:94-105`; the `FreezeWater` arm provably contains no `w`/`phys` mutation. Confirmed there is **no** dedicated test asserting physics/world are unchanged — `mutation_tests.rs` has no `FreezeWater` truth-mutation test (only a budget-path test). | +| 4 | `apply_weave_op` bails (no mutation, no budget spend) when the relevant budget field is `<= 0`, when `compile_legacy` drops the op, and when a wind delta is zero or its square underflows. A kept op decrements the matching budget by exactly 1. `1e-22` is still a kept wind | Yes | `weaving.rs` `*_no_budget`, `redirect_wind_budget_decrements`, `test_apply_weave_op_budget_depletion`, `weave_op_edges_fail_closed` | +| 5 | `FreezeWater` consumes one `weather_ops` and, when the origin is kept, inserts one static AABB from `ice_min_milli`/`ice_max_milli`. It is not a no-physics op | Yes | `weaving.rs` `add_static_aabb` on the ice bounds. A dropped origin does not spend `weather_ops` (`dropped_origin_does_not_spend_budget_or_return_a_consequence`). | | 6 | `WaterPlayerState::update` clamps `submersion` to `[0,1]` before mode selection | Yes | `water_movement.rs:207`; tests `update_threshold_boundaries_exact` and others | | 7 | ECS `combat_system` uses Manhattan distance (`|dx|+|dy|`), not Euclidean | Yes | Tests `combat_distance_check_with_offset_positions`, `combat_system_distance_subtraction_matters` (`ecs.rs`) | | 8 | `CombatPlugin`/`CraftingPlugin`/`QuestPlugin` register into the `"simulation"` stage | Yes (inspect `ecs.rs:188-212`) | Doc-only | @@ -318,7 +318,7 @@ WeaveTutorialState mutated (anchors stabilized, triggers active) This crate is CPU gameplay logic; no GPU resources. Most paths are per-entity, per-tick scalar work. The only notable cost note recovered: -- **`apply_weave_op` re-bakes a navmesh per call** (`NavMesh::bake(nav_src, 0.5, 55.0)`, `weaving.rs:113`) and discards it. For the demo driver this is infrequent (player cast). [NEEDS VERIFICATION: whether this is ever called at tick frequency in any driver. Preserved 2026-06-25 — confirmed the only non-test caller is `examples/weaving_playground/src/main.rs` (no engine-runtime caller exists), but the per-frame vs on-keypress call frequency in that example was not traced; resolving requires reading the playground's input/update loop.] +- **`apply_weave_op` does not bake a navmesh.** `nav_src` is unused (`let _ = nav_src`). The earlier `NavMesh::bake(nav_src, 0.5, 55.0)` note is not the current function. - **W-series render-side water deformation** (the consumer of weave-op *positions*, in `astraweave-render`, not this crate) is measured at ~0.0005 ms/instance, full surface ~0.19–0.21 ms (commit `3edf15e25`). This is render-crate cost, included here only for cross-reference. No benchmarks live in this crate's runtime path beyond `benches/combat_pipeline` (declared in `Cargo.toml`). @@ -341,7 +341,7 @@ No benchmarks live in this crate's runtime path beyond `benches/combat_pipeline` - **Should the ECS combat/craft/quest plugins (`ecs.rs`) be considered the canonical gameplay ECS path, or are they superseded by `veilweaver_slice_runtime` / `astraweave-weaving` systems?** They currently have no production caller; their long-term role vs the slice-runtime's own systems is unresolved. - **Combat Path A vs Path B: which is canonical?** Both are example/test-driven. Is `perform_attack_sweep` intended for physics-integrated games and `combat_system` for grid/ECS games, or is one transitional? - **Does the gameplay-crate `weaving.rs` overlap intentionally with `astraweave-weaving`, or is one expected to absorb the other?** They are separate crates with overlapping vocabulary (§6); the relationship is not documented in a recovered source. -- **Is `apply_weave_op`'s per-call `NavMesh::bake` (then discard) intended, or demo residue?** (`weaving.rs:113`). +- **`apply_weave_op` does not bake a navmesh.** `nav_src` is unused. Closed 2026-10-21. - **`weave_portals.rs` / `weave_telemetry.rs` wiring:** no production caller surfaced in the §4 grep. Are these dormant, or driven by an example not exhaustively checked? *(Verification note 2026-06-25: exhaustive grep of `examples/`, `veilweaver_slice_runtime/`, and all `astraweave-*/src` for `weave_portals`/`weave_telemetry`/`PortalGraph`/`build_portals`/`string_pull`/`WeaveTelemetry` returns only `lib.rs` glob re-export + `mutation_tests.rs`; no example, runtime, or other-crate caller exists. §5 rows updated to "Dormant (tested only)". The remaining open question — whether they are forward-design or removable — is Andrew's call.)* - **Should `astraweave-terrain → astraweave-gameplay` (reverse dependency, via `BiomeRule`/`ResourceNode`/`spawn_resources`) be re-homed?** Flagged as an anomaly in `ARCHITECTURE_MAP.md`; not a defect, but a coupling worth noting. @@ -349,6 +349,8 @@ No benchmarks live in this crate's runtime path beyond `benches/combat_pipeline` ## 12. Maintenance Notes +**Revision 1.4 (2026-10-20):** `apply_weave_op` returns an error and does not spend budget when `compile_legacy` drops an origin. Invariant 4. Invariant 5 no longer says `FreezeWater` performs no physics mutation: a kept freeze inserts a static AABB. + **Update this doc when:** - Any Active file in §5 gains/loses a production caller (re-run the wired-vs-dormant grep — this is the doc's highest-value signal). - A new `WeaveOpKind` variant is added (touch §3, §7, and the `apply_weave_op`/`WeaveConsequence` match arms). @@ -371,7 +373,7 @@ No benchmarks live in this crate's runtime path beyond `benches/combat_pipeline` 2. **The headline behavioral functions are example-driven.** `perform_attack_sweep`, `apply_weave_op`, and the ECS combat/craft/quest plugins have no in-engine production caller. Adding a new one is a real integration step, not a no-op. 3. **`water_movement.rs` is dormant residue** from an abandoned plan — and it is NOT the W-series render water. Don't wire new water gameplay through it without first resolving §11. 4. **"Weave"/"Veilweaver"/"Quest"/"Combat"/"Anchor" each name two different things** across this crate and `astraweave-weaving`. Always qualify the crate. -5. **`FreezeWater` is presentation-only** (no truth mutation) by deliberate decision (§7). +5. **`FreezeWater` inserts a static ice AABB** when the origin is kept (§7). The 2026-06-24 presentation-only decision is superseded. **Files you'll most likely touch:** - `astraweave-gameplay/src/combat_physics.rs` (physics combat) diff --git a/docs/architecture/weaving.md b/docs/architecture/weaving.md index 51df209ef7..1a32737541 100644 --- a/docs/architecture/weaving.md +++ b/docs/architecture/weaving.md @@ -9,8 +9,8 @@ lifecycle_status: active integration_status: partial summary: "weave_tick is on main (#252). The greybox runs run_aravath_slice once at startup and reuses sword_hp (#275, #343). Replay case weaving still hashes NullField. local_sim is the local field." owns: [astraweave-weaving] -doc_version: "1.8" -last_verified_commit: fb1c8ec2 +doc_version: "1.9" +last_verified_commit: 9403e3b6 --- # Architecture Trace: Weaving / Fate-Weaving System (`astraweave-weaving`) @@ -21,9 +21,9 @@ last_verified_commit: fb1c8ec2 |---|---| | **System name** | Weaving / Fate-Weaving System (the Veilweaver signature mechanic) | | **Primary crates** | `astraweave-weaving` | -| **Document version** | 1.8 | -| **Last verified against commit** | `fb1c8ec2` | -| **Last verified date** | 2026-10-16 | +| **Document version** | 1.9 | +| **Last verified against commit** | `9403e3b6` | +| **Last verified date** | 2026-10-20 | | **Status** | The data-driven cast path is on main (#252). `Greybox::new` and `Greybox::open` run `run_aravath_slice` once. Each sword hit reuses that `sword_hp` and `cover_intact` (#275, #343). Required replay case `weaving` still hashes `NullField`. The local field is required case `local_sim` (#330). #253 is closed. Anchor-slice helpers are still plain functions. | | **Owner notes** | Built during the Veilweaver vertical-slice "Weeks 1-5" campaign (see `docs/journey/weeks/WEEK_*` and `docs/archive/projects/veilweaver/`). Naming is heavily overloaded across three independent "weaving" surfaces in the workspace — see §3 and §6. | @@ -378,7 +378,7 @@ This crate hosts **two distinct pipelines** that do not call each other. Both ar | 10 | Enemy patrol targets and wave spawn positions are a function of `(world_seed, draw_index, SIM_SYSTEM_ENEMY_PATROL \| SIM_SYSTEM_SPAWNER)`. Offsets are rejection samples in the disk (`disk_xz`); no `thread_rng` and no `sin`/`cos`. Active spawn ids are sorted before round-robin. | Yes | `enemy.rs`, `spawner.rs`; tests `patrol_target_is_bit_identical_for_the_same_seed`, `spawn_positions_are_bit_identical_for_the_same_seed`. | | 11 | `run_aravath_slice` is one resolve at `ARAVATH_SLICE_SEED`. The scripted and goal policies of `aravath_slice_sword` finish on the same SHA-256 trace. That digest is required case `gameplay_qa_aravath_slice`. | Yes | `gameplay_qa.rs` test `replay_aravath_slice_scenario`. `determinism-replay.yml` merges `replay-hash-gameplay-qa.json`. | | 12 | `weave_tick` does not allocate. Modifiers are stamped in command order. One reaction per cell. Freeze emits one ice AABB and one `NavChange` with `NavChangeKind::Weave` on the command's start tick. | Yes | `eval.rs`, `tests/no_alloc.rs`, `astraweave-core/tests/replay_hash.rs` case `weaving`. | -| 13 | `queue_weave` rejects an origin outside ±`ISLAND_HALF_CELLS` (2048) on any axis. It does not saturate. `parse_template_toml` rejects an id that does not fit `u16` before the cast (`template id {id} does not fit u16`). `0` and ids 1–7 are engine ids. In-range casts keep their bytes. | Yes | `mod_queue.rs` tests `origins_outside_the_island_are_rejected_without_saturation` and `parse_rejects_engine_ids_and_accepts_modifier_data`. | +| 13 | `queue_weave` rejects an origin outside ±`ISLAND_HALF_CELLS` (2048) on any axis. It does not saturate. `meters_to_cell` floors (`div_euclid`: `-1.5` is cell `-2`) and returns `None` when the metre value is non-finite or `m * 1000 >= i32::MAX as f32` (the finite `f32` before `2^31` is `2147483520`) or below `i32::MIN as f32`, before the float-to-int cast. `compile_legacy` drops the op when `a` or collapse endpoint `b` is outside that cube, and when a wind delta is non-finite or its square is not strictly positive (`1e-22` stays, `1e-23` and smaller underflow to 0). `push_ice` `debug_assert`s the island bound and then multiplies; it does not drop a sheet after writes are stored. `parse_template_toml` rejects an id that does not fit `u16` before the cast. `0` and ids 1–7 are engine ids. In-range casts keep their bytes. | Yes | `field.rs` `meters_to_cell_rejects_non_finite_and_the_i32_edge`. `legacy.rs` `far_origin_does_not_saturate_into_a_milli_aabb`, `non_finite_and_i32_edge_origins_drop_the_op`, `far_collapse_endpoint_is_rejected`, `non_finite_wind_endpoint_drops_the_op`. Gameplay `weave_op_edges_fail_closed`. | --- @@ -428,6 +428,7 @@ This is a pure-CPU logic crate; performance is benchmark-tracked but not a runti | Version | Date | Notes | |---|---|---| +| 1.9 | 2026-10-20 | `meters_to_cell` rejects a non-finite metre value, and any millimetre value at or above `i32::MAX as f32`, before the saturating cast. `compile_legacy` drops `a` or collapse `b` outside ±2048 cells. `push_ice` asserts the island bound instead of returning after writes are stored. `apply_weave_op` does not spend budget for a dropped op. In-range `weaving` bytes stay on the plain multiply. | | 1.8 | 2026-10-16 | Restamp `fb1c8ec2`. Summary, status, and the §4 greybox row match the startup cache. `weaving` still hashes `NullField`. | | 1.7 | 2026-10-16 | Restamp `1e275a9e`. Cargo consumers are the greybox, gameplay, scripting, security, the core replay test, `aravath_weave`, and the two older quest examples. | | 1.6 | 2026-10-16 | Greybox caller. `Combat::tick` calls `run_aravath_slice` and the window shows `Cover broke` when `cover_intact` is false. |