Server authority

This commit is contained in:
2026-09-24 19:34:07 -03:00
parent 1bef94ce0c
commit 79faa556de
75 changed files with 2247 additions and 1632 deletions
+3 -32
View File
@@ -4,7 +4,7 @@ import type { BlockRegistry } from "$/common/everything_registry.ts";
import type { SpriteRegion } from "$/common/constants.ts";
import type { Texture } from "../renderer/types.ts";
import type { FromChunkWorker, ToChunkWorker } from "./chunk_messages.ts";
import { generate_chunk } from "../generation.ts";
import { generate_raw_chunk } from "$/common/generation.ts";
const pad = 0.5;
@@ -311,37 +311,8 @@ function post(message: FromChunkWorker, transfer: Transferable[]) {
}
function generate(chunk_x: number, chunk_z: number, seed: string) {
const blocks = new Uint32Array(CHUNK_SIZE * CHUNK_SIZE * CHUNK_HEIGHT);
const spills: number[] = [];
generate_chunk(
{
add_block(block) {
const nid = block_ids[block.id];
if (nid === undefined || block.y < 0 || block.y >= CHUNK_HEIGHT) {
return;
}
const block_chunk_x = Math.floor(block.x / CHUNK_SIZE);
const block_chunk_z = Math.floor(block.z / CHUNK_SIZE);
if (block_chunk_x !== chunk_x || block_chunk_z !== chunk_z) {
spills.push(block.x, block.y, block.z, nid);
return;
}
const lx = block.x - chunk_x * CHUNK_SIZE;
const lz = block.z - chunk_z * CHUNK_SIZE;
blocks[block.y * CHUNK_SIZE * CHUNK_SIZE + lz * CHUNK_SIZE + lx] = nid;
},
},
chunk_x,
chunk_z,
seed,
);
const spills_array = new Int32Array(spills);
post({ type: "generated", chunk_x, chunk_z, blocks, spills: spills_array }, [
blocks.buffer,
spills_array.buffer,
]);
const { blocks, spills } = generate_raw_chunk(chunk_x, chunk_z, seed, block_ids);
post({ type: "generated", chunk_x, chunk_z, blocks, spills }, [blocks.buffer, spills.buffer]);
}
function make_chunk_mesh(