3D biomes

This commit is contained in:
2026-11-07 12:13:43 -03:00
parent b726ce9695
commit 22191d260c
53 changed files with 874 additions and 316 deletions
+17 -2
View File
@@ -3,7 +3,8 @@
// the golden fixture's hashes, shared by the tests that check generation against it: worldgen_golden_test.ts,
// worldgen_bundle_test.ts and worldgen_pool_test.ts. hashed by name, since numeric ids move whenever a block is added
import { AIR, ID_MASK } from "@/common/constants.ts";
import { AIR, CHUNK_AREA, ID_MASK } from "@/common/constants.ts";
import { BIOME_CELL_HEIGHT, type ChunkColumn } from "@/common/section.ts";
import type { RawChunk } from "@/common/generation.ts";
import { AIR_ID } from "@/common/protocol.ts";
import { sha256 } from "@/common/utils.ts";
@@ -41,7 +42,21 @@ export function raw_hash(raw: RawChunk, name: (value: number) => string): Promis
for (let i = 0; i < raw.spills.length; i += 4) {
spills.push(raw.spills[i], raw.spills[i + 1], raw.spills[i + 2], name(raw.spills[i + 3]));
}
return hash(blocks_text(raw.column.to_flat(), name), JSON.stringify(spills), raw.column.biomes.join(","));
return hash(blocks_text(raw.column.to_flat(), name), JSON.stringify(spills), biomes_text(raw.column));
}
// each column's biome, x then z, then every biome cell's when any isn't its column's, so a world whose biomes don't
// change with height hashes as it did before biomes had heights
function biomes_text(column: ChunkColumn) {
const { min_y, max_y } = column.shape;
const at = (i: number, y: number) => column.biome_at(column.x * 16 + (i & 15), y, column.z * 16 + (i >> 4));
const columns = Array.from({ length: CHUNK_AREA }, (_, i) => at(i, min_y));
const cells: string[] = [];
for (let y = min_y; y < max_y; y += BIOME_CELL_HEIGHT) {
for (let i = 0; i < CHUNK_AREA; i++) cells.push(at(i, y));
}
const flat = cells.every((biome, i) => biome === columns[i % CHUNK_AREA]);
return flat ? columns.join(",") : `${columns.join(",")}|${cells.join(",")}`;
}
// what the fixture's "final" is: the chunk with its neighbors' spills