Client side chunk sections
This commit is contained in:
@@ -13,7 +13,8 @@
|
||||
// y in a region counts from the bottom of the world, 0 is the dimension's min_y. in a dimension without sky light
|
||||
// there's only block light
|
||||
|
||||
import { AIR, CHUNK_AREA, CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
|
||||
import { AIR, CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
|
||||
import type { Section } from "@/common/section.ts";
|
||||
import type { WorldShapeJson } from "@/common/world_shape.ts";
|
||||
|
||||
export const REGION_SIZE = CHUNK_SIZE * 3;
|
||||
@@ -50,21 +51,23 @@ export class LightRegion {
|
||||
this.block_light = new Uint8Array(volume);
|
||||
}
|
||||
|
||||
// the 3x3 chunks around the one being meshed, going +x then +z, starting at -x -z. missing ones are void
|
||||
fill(chunks: (Uint32Array | null)[]) {
|
||||
// the 3x3 chunks around the one being meshed, going +x then +z, starting at -x -z, by section. missing ones are
|
||||
// void
|
||||
fill(chunks: (Section[] | null)[]) {
|
||||
for (let i = 0; i < 9; i++) {
|
||||
const source = chunks[i];
|
||||
const origin = Math.floor(i / 3) * CHUNK_SIZE * REGION_SIZE + (i % 3) * CHUNK_SIZE;
|
||||
for (let y = 0; y < this.height; y++) {
|
||||
const section = source?.[y >> 4];
|
||||
for (let z = 0; z < CHUNK_SIZE; z++) {
|
||||
const to = y * REGION_LAYER + origin + z * REGION_SIZE;
|
||||
if (!source) {
|
||||
this.blocks.fill(REGION_VOID, to, to + CHUNK_SIZE);
|
||||
if (!section?.blocks) {
|
||||
this.blocks.fill(section ? section.value & ID_MASK : REGION_VOID, to, to + CHUNK_SIZE);
|
||||
continue;
|
||||
}
|
||||
const from = y * CHUNK_AREA + z * CHUNK_SIZE;
|
||||
const from = ((y & 15) << 8) | (z << 4);
|
||||
for (let x = 0; x < CHUNK_SIZE; x++) {
|
||||
this.blocks[to + x] = source[from + x] & ID_MASK;
|
||||
this.blocks[to + x] = section.blocks[from + x] & ID_MASK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user