Send chunks to players connected to server

This commit is contained in:
2026-09-28 11:14:40 -03:00
parent 677ad8115a
commit ded9a7e5d0
26 changed files with 920 additions and 357 deletions
+3 -8
View File
@@ -6,6 +6,7 @@ import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.
import { Frustum } from "$/client/rendering/frustum.ts";
import { group_faces_camera } from "$/client/rendering/level_renderer.ts";
import { FACE_GROUPS, type LayerMesh, TERRAIN_VERTEX_BYTES } from "$/client/workers/chunk_messages.ts";
import { decode_level_chunk } from "$/common/chunk_streaming.ts";
import { test_game } from "./helpers.ts";
// the matrix the renderer makes for a camera, see update_camera in client/renderer/core.ts
@@ -29,12 +30,10 @@ Deno.test("the frustum keeps what's in front of the camera and drops what's behi
assert(!frustum.intersects_box(-8, 60, -1100, 8, 80, -1090), "past the far plane");
});
// real chunks from the chunk worker, meshed the way the client does it
// real chunks as the server sends them, meshed the way the client does it
async function mesh_chunks(radius: number) {
const { game } = await test_game("mods", undefined, "culling-seed");
const blocks = EverythingRegistry.get_registry<BlockRegistry>("blocks");
const block_ids: Record<string, number> = {};
blocks.forEach((b, nid) => block_ids[b.id] = nid);
const worker = new Worker(new URL("../client/workers/chunk_worker.ts", import.meta.url).href, { type: "module" });
// deno-lint-ignore no-explicit-any
const replies = new Map<string, (message: any) => void>();
@@ -53,19 +52,15 @@ async function mesh_chunks(radius: number) {
worker.postMessage({
type: "init",
blocks_registry: JSON.parse(JSON.stringify(blocks)),
block_ids,
models: {},
textures_info: { "engine:missing": { x: 0, y: 0 } },
image: { width: 1024, height: 1024 },
worldgen_scripts: [],
ores: game.recipes.ores,
});
const generated = new Map<string, Uint32Array>();
for (let x = -radius - 1; x <= radius + 1; x++) {
for (let z = -radius - 1; z <= radius + 1; z++) {
const reply = await ask({ type: "generate", chunk_x: x, chunk_z: z, seed: "culling-seed" }, "generated");
generated.set(`${x},${z}`, reply.blocks);
generated.set(`${x},${z}`, decode_level_chunk(game.world.level_chunk(x, z)).blocks);
}
}
const meshes = [];