Skip to content
Merged
Prev Previous commit
Next Next commit
fix(nav): consume drained geometry notices on one NavChangeKind
NavChangeKind is Explosion, Brush, Detach, and Weave. The replay drains GeometryNotice values from DestructionWorld instead of building a second notice type. The workflow still requires planner_pure, perception_world, gameplay_rng, fixed64, combat_resolve, and nav_reroute.

Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
  • Loading branch information
cursoragent and lazyxeon committed Oct 15, 2026
commit 2b5bca6873fc63e032fdc24449975ed212927e9f
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions astraweave-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ astraweave-behavior = { workspace = true }
[dev-dependencies]
criterion = { workspace = true }
astraweave-ai = { workspace = true }
astraweave-destruction = { workspace = true }
astraweave-gameplay = { path = "../astraweave-gameplay" }
astraweave-math = { workspace = true }
astraweave-destruction = { workspace = true }
Expand Down
55 changes: 38 additions & 17 deletions astraweave-core/tests/replay_support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,50 @@ pub fn planner_pure_bytes() -> Vec<u8> {

pub fn nav_reroute_bytes() -> Vec<u8> {
use astraweave_ai::htn::{plan_route, AgentPlan, SpatialHooks};
use astraweave_nav::{bridge_and_ford, NavScratch};
use astraweave_destruction::command::{
Brush, BrushOp, BrushShape, CommandKind, DestructionCommand,
};
use astraweave_destruction::DestructionWorld;
use astraweave_nav::{bridge_and_ford, nav_change_from_geometry_notice, NavScratch};

let mut tiles = bridge_and_ford();
let mut scratch = NavScratch::new();
let hooks = SpatialHooks::none();
let mut world = DestructionWorld::new(0xA11C, 0);
world
.enqueue(DestructionCommand {
tick: 30,
seq: 0,
entity_id: 1,
kind: CommandKind::Brush(Brush {
shape: BrushShape::Box,
op: BrushOp::Subtract,
origin: [2_000, 0, 24_500],
radius: 7_499,
half_extents: [1, 1, 1],
strength: 1,
}),
})
.expect("enqueue bridge collapse");
let mut out = Vec::new();
for tick in 0..60u64 {
if tick == 30 {
// Same shape `drain_geometry_notices` publishes for a collapse
// (reason 2). The destruction crate is not on this branch.
let notice = astraweave_nav::GeometryNotice {
tick,
x0: -1_000,
y0: -1_000,
z0: 17_000,
x1: 5_000,
y1: 1_000,
z1: 31_999,
reason: astraweave_nav::NOTICE_COLLAPSE,
};
let change = astraweave_nav::nav_change_from_geometry_notice(&notice, 0)
.expect("collapse notice");
tiles.mark(change);
world.tick();
let empty = astraweave_destruction::GeometryNotice {
tick: 0,
x0: 0,
y0: 0,
z0: 0,
x1: 0,
y1: 0,
z1: 0,
reason: 0,
};
let mut notices = [empty; 8];
let count = world.drain_geometry_notices(&mut notices);
for (seq, notice) in notices[..count].iter().enumerate() {
if let Some(change) = nav_change_from_geometry_notice(notice, seq as u32) {
tiles.mark(change);
}
}
let committed = tiles.commit_tick() as u32;
let mut budget = 64u32;
Expand Down
1 change: 1 addition & 0 deletions astraweave-nav/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"

[dependencies]
anyhow = { workspace = true }
astraweave-destruction = { workspace = true }
glam = { workspace = true }

[dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions astraweave-nav/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ use glam::Vec3;
use std::fmt;

mod tiles;
pub use astraweave_destruction::GeometryNotice;
pub use tiles::{
bridge_and_ford, nav_change_from_geometry_notice, nav_change_from_kind, BreachSite, CoverSite,
GeometryNotice, NavChange, NavChangeKind, NavScratch, NavTiles, TileSideBuffer,
FRAME_BUDGET_MS, NOTICE_BRUSH, NOTICE_COLLAPSE, NOTICE_WEAVE, TILE_COMMITS_PER_TICK,
TILE_SIZE_M,
NavChange, NavChangeKind, NavScratch, NavTiles, TileSideBuffer, FRAME_BUDGET_MS, NOTICE_BRUSH,
NOTICE_COLLAPSE, NOTICE_WEAVE, TILE_COMMITS_PER_TICK, TILE_SIZE_M,
};

#[cfg(test)]
Expand Down
51 changes: 16 additions & 35 deletions astraweave-nav/src/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//! once at the edge and call [`nav_change_from_kind`].

use crate::Triangle;
use astraweave_destruction::GeometryNotice;
use glam::Vec3;

/// World span of one tile, in meters.
Expand Down Expand Up @@ -45,28 +46,11 @@ pub enum NavChangeKind {
Weave,
}

/// Reason bytes published by `DestructionWorld::drain_geometry_notices`.
/// Reason bytes published by [`astraweave_destruction::DestructionWorld::drain_geometry_notices`].
pub const NOTICE_BRUSH: u8 = 1;
pub const NOTICE_COLLAPSE: u8 = 2;
pub const NOTICE_WEAVE: u8 = 3;

/// Same fields as `astraweave_destruction::GeometryNotice`.
///
/// That crate lives on `feat/destruction` and is not in this branch. Callers
/// copy a drained notice into this struct and pass it to
/// [`nav_change_from_geometry_notice`]. Bounds are copied as published.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct GeometryNotice {
pub tick: u64,
pub x0: i32,
pub y0: i32,
pub z0: i32,
pub x1: i32,
pub y1: i32,
pub z1: i32,
pub reason: u8,
}

/// One walkable-region invalidation, in milli-units.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct NavChange {
Expand Down Expand Up @@ -100,8 +84,8 @@ impl NavChange {
///
/// Reason 1 is a brush, 2 is a collapse (`Detach`), 3 is a weave. Any other
/// reason is ignored. `seq` is the drain index so two notices in one tick
/// stay ordered. `drain_geometry_notices` is the producer on the destruction
/// branch; this crate does not depend on that crate until both share a commit.
/// stay ordered. `notice` is a value drained from
/// [`astraweave_destruction::DestructionWorld::drain_geometry_notices`].
#[must_use]
pub const fn nav_change_from_geometry_notice(
notice: &GeometryNotice,
Expand Down Expand Up @@ -1233,7 +1217,8 @@ mod tests {
#[test]
fn tile_isolation_keeps_the_other_hash() {
let mut tiles = bridge_and_ford();
let before = tiles.slot_hash(2, 0).expect("decoy tile");
let before = tiles.slot_hash(2, 0);
assert!(before.is_some(), "decoy tile");
tiles.mark(nav_change_from_kind(
NavChangeKind::Detach,
30,
Expand All @@ -1242,7 +1227,7 @@ mod tests {
[5_000, 1_000, 31_999],
));
let _ = tiles.commit_tick();
assert_eq!(tiles.slot_hash(2, 0), Some(before));
assert_eq!(tiles.slot_hash(2, 0), before);
}

#[test]
Expand Down Expand Up @@ -1386,7 +1371,7 @@ mod tests {

#[test]
fn geometry_notice_reasons_map_and_unknown_is_dropped() {
let brush = GeometryNotice {
let brush = astraweave_destruction::GeometryNotice {
tick: 4,
x0: 1,
y0: 2,
Expand All @@ -1396,29 +1381,25 @@ mod tests {
z1: 6,
reason: NOTICE_BRUSH,
};
let mapped = nav_change_from_geometry_notice(&brush, 2).expect("brush");
assert_eq!(mapped.kind, NavChangeKind::Brush);
assert_eq!(mapped.seq, 2);
assert_eq!(mapped.min_milli, [1, 2, 3]);
let mapped = nav_change_from_geometry_notice(&brush, 2);
assert_eq!(mapped.map(|change| change.kind), Some(NavChangeKind::Brush));
assert_eq!(mapped.map(|change| change.seq), Some(2));
assert_eq!(mapped.map(|change| change.min_milli), Some([1, 2, 3]));
let collapse = GeometryNotice {
reason: NOTICE_COLLAPSE,
..brush
};
assert_eq!(
nav_change_from_geometry_notice(&collapse, 0)
.expect("collapse")
.kind,
NavChangeKind::Detach
nav_change_from_geometry_notice(&collapse, 0).map(|change| change.kind),
Some(NavChangeKind::Detach)
);
let weave = GeometryNotice {
reason: NOTICE_WEAVE,
..brush
};
assert_eq!(
nav_change_from_geometry_notice(&weave, 0)
.expect("weave")
.kind,
NavChangeKind::Weave
nav_change_from_geometry_notice(&weave, 0).map(|change| change.kind),
Some(NavChangeKind::Weave)
);
let unknown = GeometryNotice { reason: 9, ..brush };
assert!(nav_change_from_geometry_notice(&unknown, 0).is_none());
Expand Down