World shape for dimension

This commit is contained in:
2026-11-06 22:49:43 -03:00
parent 7458a2d42a
commit 818ce22dd6
60 changed files with 749 additions and 349 deletions
+10 -9
View File
@@ -186,7 +186,7 @@ interface Entry {
// a level's visuals
export class Visuals {
// by chunk_key, then the block's index in its chunk
// by chunk_key, then the block's index in its chunk counted from y 0, see #entry
#chunks = new Map<number, Map<number, Entry>>();
#level: VisualsLevel;
// baked once per level, since a level's mods don't change
@@ -213,15 +213,16 @@ export class Visuals {
yield* this.#fluid_groups;
}
// the blocks with visuals a chunk was meshed with, as pairs of the block's index in the chunk and its value. visuals
// for blocks that are gone or changed go, and new ones are made. the chunk's light came with its mesh, so the ones
// that stay take it
meshed(chunk_x: number, chunk_z: number, found: Uint32Array) {
// the blocks with visuals a chunk was meshed with, as pairs of the block's index in the chunk (from min_y, the
// bottom of the world) and its value. visuals for blocks that are gone or changed go, and new ones are made. the
// chunk's light came with its mesh, so the ones that stay take it
meshed(chunk_x: number, chunk_z: number, min_y: number, found: Uint32Array) {
const key = chunk_key(chunk_x, chunk_z);
const old = this.#chunks.get(key) ?? new Map<number, Entry>();
const kept = new Map<number, Entry>();
for (let i = 0; i < found.length; i += 2) {
const index = found[i];
const local = found[i];
const index = local + min_y * CHUNK_AREA;
const value = found[i + 1];
const entry = old.get(index);
old.delete(index);
@@ -231,9 +232,9 @@ export class Visuals {
continue;
}
if (entry) this.#delete(entry);
const x = chunk_x * CHUNK_SIZE + (index % CHUNK_SIZE);
const z = chunk_z * CHUNK_SIZE + Math.floor(index / CHUNK_SIZE) % CHUNK_SIZE;
const made = this.#create(x, Math.floor(index / CHUNK_AREA), z, value);
const x = chunk_x * CHUNK_SIZE + (local % CHUNK_SIZE);
const z = chunk_z * CHUNK_SIZE + Math.floor(local / CHUNK_SIZE) % CHUNK_SIZE;
const made = this.#create(x, min_y + Math.floor(local / CHUNK_AREA), z, value);
if (made) kept.set(index, made);
}
for (const entry of old.values()) this.#delete(entry);