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
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ assets/aravath/**/*.jpg filter=lfs diff=lfs merge=lfs -text
assets/aravath/**/*.gltf text eol=lf
assets/aravath/**/*.tsv text eol=lf
assets/aravath/**/*.md text eol=lf
# Hashed text assets must stay LF on every OS. Windows autocrlf rewrites
# pine-forest glTF and the manifest check then fails.
*.gltf text eol=lf
*.glsl text eol=lf
*.obj text eol=lf
*.mtl text eol=lf
*.usda text eol=lf
*.hdr binary
*.ktx2 binary
18 changes: 13 additions & 5 deletions .github/workflows/determinism-replay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# `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), `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.
# `traversal`, `traversal_deformed`, `worldgen_columns`, and `deformed_chunk`
# 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 @@ -43,6 +44,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v5

- name: Fetch Aravath nature models
run: git lfs pull --include "assets/aravath/models/nature/*.glb"

- name: Rust CI setup
uses: ./.github/actions/rust-ci-setup
with:
Expand All @@ -64,6 +68,9 @@ jobs:
;;
esac

- name: Fetch Aravath nature models
run: git lfs pull --include "assets/aravath/models/nature/*.glb"

- name: Replay hash
run: |
cargo test -p astraweave-core --test replay_hash -- --nocapture
Expand All @@ -72,6 +79,7 @@ jobs:
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
cargo test -p astraweave-terrain --test worldgen_hash -- --nocapture

- name: Merge replay hashes
run: |
Expand All @@ -94,7 +102,7 @@ jobs:
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", "traversal", "traversal_deformed"];
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", "worldgen_columns", "deformed_chunk"];
const names = new Set(merged.map((row) => row.case));
for (const name of required) {
if (!names.has(name)) {
Expand Down Expand Up @@ -133,7 +141,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", "traversal", "traversal_deformed"}
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", "worldgen_columns", "deformed_chunk"}
root = Path("replay-artifacts")
files = sorted(root.glob("*/replay-hash.json"))
print(f"artifacts: {[str(p) for p in files]}")
Expand Down
4 changes: 4 additions & 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 aravath_runtime/src/figure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ impl Figure {
indices: primitive.indices.clone(),
albedo_image: None,
texture_source_hint: None,
..Default::default()
},
color: primitive.color,
});
Expand Down
42 changes: 17 additions & 25 deletions aravath_runtime/src/ground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use std::collections::{HashMap, HashSet};

use astraweave_physics::{Layers, PhysicsWorld};
use astraweave_render::mesh::{CpuMesh, MeshVertex as RenderVertex};
use astraweave_terrain::{ChunkCoord, ChunkMesh, DualContouring, MeshVertex, Voxel, VoxelGrid};
use astraweave_terrain::{
ChunkCoord, ChunkMesh, ColumnStream, DualContouring, MeshVertex, Voxel, VoxelGrid,
};
use glam::{Vec2, Vec3, Vec4};

use crate::island::{self, biome_at, column_material, Biome, MAT_WOOD};
Expand Down Expand Up @@ -62,6 +64,7 @@ pub struct Ground {
mesher: DualContouring,
bodies: HashMap<ChunkCoord, u64>,
generated: HashSet<ChunkCoord>,
stream: ColumnStream,
scatter: HashMap<ChunkCoord, Vec<PropSpot>>,
/// Chunk the ring was built around, plus the radius. A settled player
/// whose grid is clean skips the set rebuild.
Expand All @@ -85,6 +88,7 @@ impl Ground {
mesher: DualContouring::new(),
bodies: HashMap::new(),
generated: HashSet::new(),
stream: ColumnStream::new(),
scatter: HashMap::new(),
stream_key: None,
}
Expand All @@ -107,32 +111,19 @@ impl Ground {
if self.stream_key == Some(key) && self.grid.dirty_chunks().is_empty() {
return Vec::new();
}
let mut keep = HashSet::new();
for dz in -radius..=radius {
for dx in -radius..=radius {
if dx.abs().max(dz.abs()) > radius {
continue;
}
let coord = ChunkCoord::new(center.x + dx, 0, center.z + dz);
keep.insert(coord);
if self.generated.insert(coord) {
fill_height_chunk(&mut self.grid, coord);
self.reapply_edits(coord);
self.scatter.insert(coord, scatter_chunk(coord));
}
}
// ColumnStream is the loaded set. Island columns still fill the
// voxels, so the #205 heightfield stays the one the replay hashes.
let delta = self.stream.around(center.x, center.z, radius);
for &(x, z) in delta.added() {
let coord = ChunkCoord::new(x, 0, z);
self.generated.insert(coord);
fill_height_chunk(&mut self.grid, coord);
self.reapply_edits(coord);
self.scatter.insert(coord, scatter_chunk(coord));
}
let mut stale: Vec<ChunkCoord> = self
.generated
.iter()
.copied()
.filter(|coord| coord.y == 0 && !keep.contains(coord))
.collect();
// HashSet iteration follows the process hasher. Removal order is part
// of the physics step, so it has to be the same on every run.
sort_coords(&mut stale);
let mut removed = Vec::new();
for coord in stale {
for &(x, z) in delta.removed() {
let coord = ChunkCoord::new(x, 0, z);
self.generated.remove(&coord);
self.scatter.remove(&coord);
self.grid.remove_chunk(coord);
Expand Down Expand Up @@ -613,6 +604,7 @@ fn chunk_parts(mesh: &ChunkMesh) -> Vec<ChunkPart> {
indices,
albedo_image: None,
texture_source_hint: None,
..CpuMesh::default()
},
});
}
Expand Down
1 change: 1 addition & 0 deletions aravath_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod hud;
pub mod ik;
pub mod island;
pub mod locomotion;
pub mod materials;
pub mod motor;
pub mod play_input;
pub mod player;
Expand Down
127 changes: 127 additions & 0 deletions aravath_runtime/src/materials.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//! Voxel materials 1–5 sample the pine-forest Poly Haven set.
//!
//! `diff` / `nor_gl` / `arm` are converted with `astraweave_render::pbr_maps`
//! into [`astraweave_render::ModelSurfaceMaps`]. KayKit props stay on the
//! greybox colored-mesh path.

use std::path::{Path, PathBuf};

use anyhow::{bail, Context, Result};

use crate::assets;

/// One material after the Poly Haven ARM split.
pub struct VoxelSurface {
pub width: u32,
pub height: u32,
pub albedo: Vec<u8>,
pub normal: Vec<u8>,
pub metallic_roughness: Vec<u8>,
pub occlusion: Vec<u8>,
}

/// Stone, dirt (road), grass, sand, wood.
pub fn material_slug(material: u16) -> &'static str {
match material {
2 => "rocky_trail",
3 => "forest_ground_04",
4 => "coast_land_rocks_01",
5 => "pine_bark",
_ => "aerial_rocks_01",
}
}

/// Build engine maps from already-decoded RGBA8 images of the same size.
pub fn maps_from_polyhaven(
diff: &[u8],
nor_gl: &[u8],
arm: &[u8],
width: u32,
height: u32,
) -> VoxelSurface {
let (metallic_roughness, occlusion) = astraweave_render::pbr_maps::split_polyhaven_arm(arm);
let normal = astraweave_render::pbr_maps::nor_gl_unchanged(nor_gl);
VoxelSurface {
width,
height,
albedo: diff.to_vec(),
normal,
metallic_roughness,
occlusion,
}
}

pub fn pine_forest_dir() -> PathBuf {
let beside = assets::exe_dir().join("assets/terrain/polyhaven/pine_forest");
if beside.is_dir() {
return beside;
}
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../assets/terrain/polyhaven/pine_forest")
}

pub fn load_slug(slug: &str) -> Result<VoxelSurface> {
let dir = pine_forest_dir();
let diff = read_rgba(&dir.join(format!("{slug}_diff_2k.jpg")))?;
let nor = read_rgba(&dir.join(format!("{slug}_nor_gl_2k.jpg")))?;
let arm = read_rgba(&dir.join(format!("{slug}_arm_2k.jpg")))?;
if diff.0 != nor.0 || diff.1 != nor.1 || diff.0 != arm.0 || diff.1 != arm.1 {
bail!("{slug} maps are not the same size");
}
Ok(maps_from_polyhaven(&diff.2, &nor.2, &arm.2, diff.0, diff.1))
}

fn read_rgba(path: &Path) -> Result<(u32, u32, Vec<u8>)> {
let meta = std::fs::metadata(path).with_context(|| format!("open {}", path.display()))?;
if !meta.is_file() || meta.len() == 0 || meta.len() > assets::MAX_TEXTURE_BYTES {
bail!("texture {} is missing or too large", path.display());
}
let image = image::ImageReader::open(path)
.with_context(|| format!("open {}", path.display()))?
.with_guessed_format()
.context("guess texture format")?
.decode()
.with_context(|| format!("decode {}", path.display()))?
.into_rgba8();
let width = image.width();
let height = image.height();
if width == 0
|| height == 0
|| width > assets::MAX_TEXTURE_EDGE
|| height > assets::MAX_TEXTURE_EDGE
{
bail!("texture {} has an invalid size", path.display());
}
Ok((width, height, image.into_raw()))
}

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

#[test]
fn polyhaven_arm_feeds_the_engine_layout() {
let surface =
maps_from_polyhaven(&[1, 2, 3, 255], &[9, 8, 7, 255], &[10, 80, 250, 255], 1, 1);
assert_eq!(surface.albedo, vec![1, 2, 3, 255]);
assert_eq!(surface.normal, vec![9, 8, 7, 255]);
assert_eq!(surface.metallic_roughness, vec![250, 80, 0, 255]);
assert_eq!(surface.occlusion, vec![10, 10, 10, 255]);
assert_eq!(material_slug(1), "aerial_rocks_01");
assert_eq!(material_slug(2), "rocky_trail");
assert_eq!(material_slug(3), "forest_ground_04");
assert_eq!(material_slug(4), "coast_land_rocks_01");
assert_eq!(material_slug(5), "pine_bark");
}

#[test]
fn pine_forest_2k_maps_are_vendored() {
let dir = pine_forest_dir();
for material in 1..=5 {
let slug = material_slug(material);
for role in ["diff", "nor_gl", "arm"] {
let path = dir.join(format!("{slug}_{role}_2k.jpg"));
assert!(path.is_file(), "missing {}", path.display());
}
}
}
}
3 changes: 3 additions & 0 deletions aravath_runtime/src/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl NodeActor {
indices,
albedo_image: None,
texture_source_hint: None,
..Default::default()
})
}

Expand Down Expand Up @@ -241,6 +242,7 @@ pub fn load_colored(path: &Path) -> Result<Vec<ColoredMesh>> {
indices: prim_indices,
albedo_image: None,
texture_source_hint: None,
..Default::default()
},
color: primitive
.material()
Expand Down Expand Up @@ -302,6 +304,7 @@ pub fn load_rigid(path: &Path) -> Result<TexturedMesh> {
indices,
albedo_image: None,
texture_source_hint: None,
..Default::default()
},
albedo: rgba_from_images(&images),
})
Expand Down
Loading
Loading