Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .github/workflows/determinism-replay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Branch protection is a repository setting. This workflow is the check it must require.
# `planner_pure` (WS-D0), `perception_world` (WS-D1), `gameplay_rng` (WS-D2),
# `fixed64`, `combat_resolve`, `destruction`, `gameplay_qa_aravath_slice`,
# `nav_reroute`, `causal_bridge`, `scripted_system` (WS-MOD), and `weaving`
# fail the compare job on any mismatch or if the case is missing. No path
# filter. cargo test has no retry loop (no-retry). Do not switch this job to
# nextest.
# `nav_reroute`, `causal_bridge`, `scripted_system` (WS-MOD), `weaving`,
# `traversal`, and `traversal_deformed` fail the compare job on any mismatch
# or if the case is missing. No path filter. cargo test has no retry loop
# (no-retry). Do not switch this job to nextest.

name: determinism-replay

Expand Down Expand Up @@ -71,6 +71,7 @@ jobs:
cargo test -p astraweave-weaving --lib gameplay_qa::tests::replay_aravath_slice_scenario -- --exact --nocapture
cargo test -p astraweave-causality --test replay_hash -- --nocapture
cargo test -p astraweave-scripting --test script_replay_hash -- --nocapture
cargo test -p astraweave-physics --test traversal_replay -- --nocapture

- name: Merge replay hashes
run: |
Expand All @@ -82,17 +83,18 @@ jobs:
const combat = JSON.parse(fs.readFileSync(path.join(root, "replay-hash-combat.json"), "utf8"));
const gameplay = JSON.parse(fs.readFileSync(path.join(root, "replay-hash-gameplay-qa.json"), "utf8"));
const causal = JSON.parse(fs.readFileSync(path.join(root, "replay-hash-causal.json"), "utf8"));
const traversal = JSON.parse(fs.readFileSync(path.join(root, "replay-hash-traversal.json"), "utf8"));
const seen = new Set(core.map((row) => row.case));
const merged = core.slice();
for (const row of combat.concat(gameplay, causal)) {
for (const row of combat.concat(gameplay, causal, traversal)) {
if (seen.has(row.case)) {
console.error(`duplicate replay case ${row.case}`);
process.exit(1);
}
seen.add(row.case);
merged.push(row);
}
const required = ["planner_pure", "perception_world", "gameplay_rng", "fixed64", "combat_resolve", "destruction", "gameplay_qa_aravath_slice", "nav_reroute", "causal_bridge", "scripted_system", "weaving"];
const required = ["planner_pure", "perception_world", "gameplay_rng", "fixed64", "combat_resolve", "destruction", "gameplay_qa_aravath_slice", "nav_reroute", "causal_bridge", "scripted_system", "weaving", "traversal", "traversal_deformed"];
const names = new Set(merged.map((row) => row.case));
for (const name of required) {
if (!names.has(name)) {
Expand Down Expand Up @@ -131,7 +133,7 @@ jobs:
import sys
from pathlib import Path

required = {"planner_pure", "perception_world", "gameplay_rng", "fixed64", "combat_resolve", "destruction", "gameplay_qa_aravath_slice", "nav_reroute", "causal_bridge", "scripted_system", "weaving"}
required = {"planner_pure", "perception_world", "gameplay_rng", "fixed64", "combat_resolve", "destruction", "gameplay_qa_aravath_slice", "nav_reroute", "causal_bridge", "scripted_system", "weaving", "traversal", "traversal_deformed"}
root = Path("replay-artifacts")
files = sorted(root.glob("*/replay-hash.json"))
print(f"artifacts: {[str(p) for p in files]}")
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion aravath_runtime/golden/replay.hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9b607d1a840ecd64
b663da52ea1d566e
236 changes: 236 additions & 0 deletions aravath_runtime/src/course.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
//! Scripted traversal course for the Aravath greybox.
//!
//! The voxel island is unchanged. This course is a deterministic probe script
//! the sim can run without a GPU: a step, a vault, a mantle, a climb that
//! prefers a handhold, a non-climbable puzzle volume, a pool, a slide, a
//! crawl, a wall-run, and a glide. Geometry flags live on the probes.

use astraweave_physics::traversal::{
step, ProbeFrame, TraversalBody, TraversalInput, TraversalMode, CLIMB_SPEED,
};
use glam::Vec3;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CourseBeat {
Step,
Vault,
Mantle,
ClimbMarkup,
PuzzleWall,
Swim,
Slide,
Crawl,
WallRun,
Glide,
Ledge,
Shimmy,
}

pub fn run_course() -> Vec<CourseBeat> {
let mut seen = Vec::new();
let mut body = TraversalBody::default();

let mut step_probe = ProbeFrame::plane(0.0);
step_probe.step_height = Some(0.25);
step(
&mut body,
TraversalInput {
move_y: 1.0,
..TraversalInput::default()
},
&step_probe,
0,
);
if (body.pos.y - 0.25).abs() < 1e-2 {
seen.push(CourseBeat::Step);
}

body = TraversalBody::default();
let mut vault = ProbeFrame::plane(0.0);
vault.vault_to = Some(Vec3::new(1.0, 0.6, 0.0));
step(
&mut body,
TraversalInput {
move_y: 1.0,
..TraversalInput::default()
},
&vault,
1,
);
if body.mode == TraversalMode::Vault {
seen.push(CourseBeat::Vault);
}

body = TraversalBody::default();
let mut mantle = ProbeFrame::plane(0.0);
mantle.mantle_to = Some(Vec3::new(0.5, 1.5, 0.0));
step(
&mut body,
TraversalInput {
move_y: 1.0,
..TraversalInput::default()
},
&mantle,
2,
);
if body.mode == TraversalMode::Mantle {
seen.push(CourseBeat::Mantle);
}

body = TraversalBody::default();
let mut climb = ProbeFrame::plane(0.0);
climb.climb_point = Some(Vec3::new(0.0, 1.0, 0.4));
climb.markup_point = Some(Vec3::new(0.0, 1.6, 0.0));
climb.climb_normal = Some(Vec3::new(0.0, 0.1, 1.0));
step(
&mut body,
TraversalInput {
climb: true,
..TraversalInput::default()
},
&climb,
3,
);
if body.mode == TraversalMode::Climb && (body.pos.y - 1.6).abs() < 1e-3 {
seen.push(CourseBeat::ClimbMarkup);
}
climb.ledge_point = Some(Vec3::new(0.2, 2.0, 0.0));
step(&mut body, TraversalInput::default(), &climb, 11);
if body.mode == TraversalMode::LedgeHang {
seen.push(CourseBeat::Ledge);
}
step(
&mut body,
TraversalInput {
move_x: 1.0,
..TraversalInput::default()
},
&climb,
12,
);
if body.mode == TraversalMode::Shimmy {
seen.push(CourseBeat::Shimmy);
}
let _ = CLIMB_SPEED;

body = TraversalBody::default();
climb.climbability = astraweave_physics::traversal::Climbability::NonClimbable;
climb.markup_point = None;
step(
&mut body,
TraversalInput {
climb: true,
..TraversalInput::default()
},
&climb,
4,
);
if body.mode != TraversalMode::Climb {
seen.push(CourseBeat::PuzzleWall);
}

body = TraversalBody::default();
let mut pool = ProbeFrame::plane(0.0);
pool.water_surface = Some(1.4);
step(&mut body, TraversalInput::default(), &pool, 5);
step(&mut body, TraversalInput::default(), &pool, 6);
if body.mode == TraversalMode::Swim {
seen.push(CourseBeat::Swim);
}

body = TraversalBody::default();
step(
&mut body,
TraversalInput {
move_y: 1.0,
sprint: true,
crouch: true,
..TraversalInput::default()
},
&ProbeFrame::plane(0.0),
7,
);
if body.mode == TraversalMode::Slide {
seen.push(CourseBeat::Slide);
}

body = TraversalBody::default();
step(
&mut body,
TraversalInput {
prone: true,
..TraversalInput::default()
},
&ProbeFrame::plane(0.0),
8,
);
if body.mode == TraversalMode::Prone {
seen.push(CourseBeat::Crawl);
}

body = TraversalBody::default();
body.mode = TraversalMode::Air;
body.vel = Vec3::new(6.0, 1.0, 0.0);
body.pos.y = 2.0;
let mut wall = ProbeFrame::plane(0.0);
wall.support = false;
wall.wall_normal = Some(Vec3::new(1.0, 0.0, 0.0));
step(
&mut body,
TraversalInput {
move_y: 1.0,
..TraversalInput::default()
},
&wall,
9,
);
if body.mode == TraversalMode::WallRun {
seen.push(CourseBeat::WallRun);
}

body = TraversalBody::default();
body.mode = TraversalMode::Air;
body.pos.y = 6.0;
let mut air = ProbeFrame::plane(0.0);
air.support = false;
step(
&mut body,
TraversalInput {
glide: true,
move_y: 1.0,
..TraversalInput::default()
},
&air,
10,
);
if body.mode == TraversalMode::Glide {
seen.push(CourseBeat::Glide);
}

seen
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn course_hits_every_beat() {
let beats = run_course();
let expected = [
CourseBeat::Step,
CourseBeat::Vault,
CourseBeat::Mantle,
CourseBeat::ClimbMarkup,
CourseBeat::Ledge,
CourseBeat::Shimmy,
CourseBeat::PuzzleWall,
CourseBeat::Swim,
CourseBeat::Slide,
CourseBeat::Crawl,
CourseBeat::WallRun,
CourseBeat::Glide,
];
assert_eq!(beats, expected);
}
}
70 changes: 70 additions & 0 deletions aravath_runtime/src/ik.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//! Presentation-only two-bone IK. The sim never reads these joint positions.

use glam::Vec3;

/// Move the middle joint so the end reaches `target` when the chain can.
/// Returns `(mid, end)`.
pub fn solve_two_bone(root: Vec3, mid: Vec3, end: Vec3, target: Vec3) -> (Vec3, Vec3) {
let len_ab = (mid - root).length().max(1e-4);
let len_bc = (end - mid).length().max(1e-4);
let mut to_target = target - root;
let reach = len_ab + len_bc;
let dist = to_target.length();
if dist < 1e-4 {
return (mid, root);
}
if dist >= reach {
let dir = to_target / dist;
let new_mid = root + dir * len_ab;
let new_end = root + dir * reach;
return (new_mid, new_end);
}
to_target = to_target / dist;
let adjacent = (len_ab * len_ab - len_bc * len_bc + dist * dist) / (2.0 * dist);
let height_sq = (len_ab * len_ab - adjacent * adjacent).max(0.0);
let height = height_sq.sqrt();
let pole = {
let bend = (mid - root).cross(to_target);
if bend.length_squared() < 1e-6 {
Vec3::Y
} else {
bend.normalize()
}
};
let new_mid = root + to_target * adjacent + pole * height;
let new_end = target;
(new_mid, new_end)
}

/// Pelvis lift so a foot planted at `ground_y` meets the hip chain.
pub fn foot_ground_offset(hip_y: f32, foot_y: f32, ground_y: f32) -> f32 {
let plant = ground_y - foot_y;
if hip_y + plant < ground_y {
ground_y - hip_y
} else {
plant
}
}

#[cfg(test)]
mod tests {
use super::*;
use glam::Vec3;

#[test]
fn hand_ik_reaches_the_climb_anchor() {
let root = Vec3::new(0.0, 1.4, 0.0);
let mid = Vec3::new(0.2, 1.2, 0.1);
let end = Vec3::new(0.4, 1.0, 0.2);
let target = Vec3::new(0.3, 1.5, 0.4);
let (_mid, solved) = solve_two_bone(root, mid, end, target);
let gap = (solved - target).length();
assert!(gap < 1e-3, "hand missed the anchor by {gap}");
}

#[test]
fn foot_ik_lifts_to_the_ground_sample() {
let offset = foot_ground_offset(1.0, 0.0, 0.2);
assert!((offset - 0.2).abs() < 1e-4);
}
}
2 changes: 2 additions & 0 deletions aravath_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ const _: () = assert!(
pub mod assets;
pub mod bridge_agent;
pub mod combat;
pub mod course;
pub mod detmath;
pub mod figure;
pub mod frame_budget;
pub mod ground;
pub mod hud;
pub mod ik;
pub mod island;
pub mod locomotion;
pub mod motor;
Expand Down
Loading
Loading