Drop the chunk palette; chunks are plain u16 tile arrays
The 64-entry per-chunk palette was a wire-format artifact and capped a chunk at 64 distinct tiles. A Chunk is now Box<[u16; 1024]> with flags derived from the id on lookup — the same layout a binary on-disk format would use. Map path becomes the first CLI argument; assets/map_large is a generated 256×256 stress map (loads in ~0.5 ms release). The snapshot test takes SNAPSHOT_MAP. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
5a055c048d
commit
1d14076468
+5
-9
@@ -9,7 +9,7 @@ mod sim;
|
||||
|
||||
pub use sim::Sim;
|
||||
|
||||
use chunk::{Chunk, TileDef, TileFlags};
|
||||
use chunk::Chunk;
|
||||
use map::TileMap;
|
||||
use world::World;
|
||||
|
||||
@@ -99,8 +99,8 @@ pub fn tile_collidable(tile_id: u16) -> bool {
|
||||
|
||||
/// Build a world from a loaded tile map. The map's top-left tile sits at world (0, 0); the
|
||||
/// map is sliced into 32×32 chunks. Tiles inside a loaded chunk but outside the authored map
|
||||
/// become an invisible solid border (id 0, collidable), so the walkable world edge sits flush
|
||||
/// with the visible map rim instead of with the larger chunk boundary.
|
||||
/// get id 0 (solid, see `tile_collidable`), so the walkable world edge sits flush with the
|
||||
/// visible map rim instead of with the larger chunk boundary.
|
||||
pub fn load_world(map: &TileMap) -> World {
|
||||
let mut w = World::new();
|
||||
let max_cx = (map.width.saturating_sub(1) >> 5) as i16;
|
||||
@@ -109,12 +109,8 @@ pub fn load_world(map: &TileMap) -> World {
|
||||
for cx in 0..=max_cx {
|
||||
let chunk = Chunk::generate(|lx, ly| {
|
||||
let (wx, wy) = world::local_to_tile(cx, cy, lx, ly);
|
||||
if wx < 0 || wy < 0 || wx >= map.width as i16 || wy >= map.height as i16 {
|
||||
return TileDef { tile_id: 0, flags: TileFlags(TileFlags::COLLIDABLE) };
|
||||
}
|
||||
let id = map.tile(wx, wy);
|
||||
TileDef { tile_id: id, flags: map::tile_flags(id) }
|
||||
}).expect("palette overflow during world gen");
|
||||
map.tile(wx, wy) // 0 outside the map
|
||||
});
|
||||
w.set_chunk(cx, cy, chunk);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user