Client side chunk sections

This commit is contained in:
2026-11-07 10:39:16 -03:00
parent 8e14e9842a
commit 71cbf901a5
19 changed files with 162 additions and 116 deletions
+3 -2
View File
@@ -8,6 +8,7 @@
import { Alea } from "@paulaboks/rng";
import { AIR, CHUNK_AREA, CHUNK_SIZE } from "@/common/constants.ts";
import { DEFAULT_SHAPE } from "@/common/world_shape.ts";
import { ChunkColumn } from "@/common/section.ts";
import { type BlockRegistry, EverythingRegistry } from "@/common/everything_registry.ts";
import { DEFAULT_MODEL } from "@/common/block_models.ts";
import { OctaveNoise2D, OctaveNoise3D, smoothstep } from "@/common/worldgen/noise.ts";
@@ -150,7 +151,7 @@ export class BenchTerrain {
return Math.min(TOP - 32, Math.round(height));
}
chunk(chunk_x: number, chunk_z: number): { blocks: Uint32Array; biomes: string[] } {
chunk(chunk_x: number, chunk_z: number): ChunkColumn {
const b = this.#blocks;
const blocks = new Uint32Array(LEVEL_SHAPE.volume);
const random = new Alea(`${SEED}_${chunk_x}_${chunk_z}`);
@@ -193,7 +194,7 @@ export class BenchTerrain {
}
this.#trees(chunk_x, chunk_z, set);
this.#features(set);
return { blocks, biomes: new Array(CHUNK_AREA).fill(b.biome) };
return ChunkColumn.from_flat(chunk_x, chunk_z, LEVEL_SHAPE, blocks, new Array(CHUNK_AREA).fill(b.biome));
}
#in_zone(x: number, z: number, margin: number) {
+1 -2
View File
@@ -261,8 +261,7 @@ export class RenderBenchmark {
const start = performance.now();
while (built < chunks.length && performance.now() - start < BUILD_MS_PER_FRAME) {
const [x, z] = chunks[built++];
const { blocks, biomes } = terrain.chunk(x, z);
this.#level.set_chunk(x, z, blocks, biomes);
this.#level.set_chunk(terrain.chunk(x, z));
}
this.#build_ms += performance.now() - start;
this.status = `building the level, ${Math.floor(built / chunks.length * 100)}%`;