Meshing and lighting per section

This commit is contained in:
2026-11-07 11:41:21 -03:00
parent 71cbf901a5
commit b726ce9695
21 changed files with 736 additions and 544 deletions
+11 -16
View File
@@ -4,14 +4,10 @@
// monsters spawning on their own in the dark near players, like undergarden's rotwalkers, see natural_spawner.ts and
// mods/undergarden/worldgen/spawns.json
import { assert, assertEquals } from "@std/assert";
import { CHUNK_SIZE } from "@/common/constants.ts";
import { CHUNK_AREA, CHUNK_SIZE } from "@/common/constants.ts";
import { decode_level_chunk } from "@/common/chunk_streaming.ts";
import {
block_light_emission,
block_light_opacity,
BlockRegistry,
EverythingRegistry,
} from "@/common/everything_registry.ts";
import { BlockRegistry, EverythingRegistry, light_tables } from "@/common/everything_registry.ts";
import { ChunkColumn, column_heights } from "@/common/section.ts";
import { LightRegion, REGION_LAYER, REGION_SIZE, REGION_VOID } from "@/client/workers/lighting.ts";
import { create_entity } from "@/server/game/entity/entity_types.ts";
import { Mob } from "@/server/game/entity/mob.ts";
@@ -78,22 +74,21 @@ Deno.test("the server's light is the same as what clients work out", async () =>
world.set_block(x0 + 3, FLOOR + 1, x0 + 3, "bworld:light");
world.set_block(x0 + 12, ROOF, x0 + 12, "cubi:air");
const blocks = EverythingRegistry.get_registry<BlockRegistry>("blocks");
const opacity = new Uint8Array(REGION_VOID + 1);
const emission = new Uint8Array(REGION_VOID + 1);
blocks.forEach((block, nid) => {
opacity[nid] = block_light_opacity(block);
emission[nid] = block_light_emission(block);
});
// the 3x3 chunks lit whole, like the client lights sections
const { opacity, emission } = light_tables(EverythingRegistry.get_registry<BlockRegistry>("blocks"));
opacity[REGION_VOID] = 15;
const region = new LightRegion(world.shape);
const chunks = [];
const sky = [];
for (let dz = -1; dz <= 1; dz++) {
for (let dx = -1; dx <= 1; dx++) {
chunks.push(decode_level_chunk(world.level_chunk(CHUNK + dx, CHUNK + dz)).sections);
const { sections, biomes } = decode_level_chunk(world.level_chunk(CHUNK + dx, CHUNK + dz));
chunks.push(sections);
const column = new ChunkColumn(CHUNK + dx, CHUNK + dz, world.shape, sections, biomes);
sky.push(column_heights(column, opacity).slice(CHUNK_AREA));
}
}
region.fill(chunks);
region.fill(chunks, sky, world.shape.min_y);
region.compute({ opacity, emission });
const check = (x: number, y: number, z: number) => {