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
+4 -2
View File
@@ -12,7 +12,8 @@ import {
} from "@/common/everything_registry.ts";
import { block_from_json, block_to_json, type BlockJson, validate_block } from "@/common/mod_data.ts";
import { cube_face_texture } from "@/common/block_models.ts";
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE } from "@/common/constants.ts";
import { CHUNK_AREA, CHUNK_SIZE } from "@/common/constants.ts";
import { DEFAULT_SHAPE } from "@/common/world_shape.ts";
import { get_state_value, set_state_value } from "@/common/utils.ts";
import { cell_index, corner_height, fluid_quads, type FluidCell } from "@/client/workers/fluid_mesh.ts";
import { TERRAIN_VERTEX_BYTES } from "@/client/workers/chunk_messages.ts";
@@ -172,6 +173,7 @@ async function mesh(blocks: [number, number, number, string, number?][]) {
const worker = new Worker(new URL("../client/workers/chunk_worker.ts", import.meta.url).href, { type: "module" });
worker.postMessage({
type: "init",
shape: DEFAULT_SHAPE,
// with the registry's gaps, like the client sends it
blocks_registry: registry.map((block) => JSON.parse(JSON.stringify(block))),
models: {},
@@ -179,7 +181,7 @@ async function mesh(blocks: [number, number, number, string, number?][]) {
image: { width: 1024, height: 1024 },
visuals: [],
});
const chunks = Array.from({ length: 9 }, () => new Uint32Array(CHUNK_AREA * CHUNK_HEIGHT));
const chunks = Array.from({ length: 9 }, () => new Uint32Array(DEFAULT_SHAPE.volume));
for (const [x, y, z, id, level] of blocks) {
const chunk = x < 0 ? chunks[3] : chunks[4];
chunk[y * CHUNK_AREA + z * CHUNK_SIZE + ((x + CHUNK_SIZE) % CHUNK_SIZE)] = ids[id] | ((level ?? 0) << 16);