Caves
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { CHUNK_AREA, CHUNK_SIZE } from "@/common/constants.ts";
|
||||
import { carve_chunk } from "@/common/worldgen/carvers.ts";
|
||||
import { WorldShape } from "@/common/world_shape.ts";
|
||||
|
||||
const shape = new WorldShape({ min_y: -64, max_y: 320, sky_light: true });
|
||||
const carvers = [{ probability: 1, min_y: 0, max_y: 40 }];
|
||||
|
||||
Deno.test("carvers cut tunnels that carry on across chunk borders", () => {
|
||||
assertEquals(carve_chunk("seed", [], 0, 0, shape), undefined, "no carvers, nothing to cut");
|
||||
const west = carve_chunk("seed", carvers, 0, 0, shape)!;
|
||||
const east = carve_chunk("seed", carvers, 1, 0, shape)!;
|
||||
assertEquals(west, carve_chunk("seed", carvers, 0, 0, shape), "same chunk, same tunnels");
|
||||
// a cell on the border cut in both chunks
|
||||
let joined = false;
|
||||
for (let y = 0; y < shape.height; y++) {
|
||||
for (let z = 0; z < CHUNK_SIZE; z++) {
|
||||
const row = y * CHUNK_AREA + z * CHUNK_SIZE;
|
||||
if (west[row + CHUNK_SIZE - 1] && east[row]) joined = true;
|
||||
}
|
||||
}
|
||||
assert(joined, "a tunnel crosses from one chunk into the next");
|
||||
assert(west.subarray(0, CHUNK_AREA).every((cut) => !cut), "the world's bottom layer stays");
|
||||
});
|
||||
Vendored
+384
-384
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user