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
+6 -5
View File
@@ -3,9 +3,9 @@
// ticks blocks asked for some ticks ahead, see ServerWorld.schedule_tick. kept by chunk and grouped by when they're due,
// so a tick costs nothing until it's due, and a chunk with none due is passed over with one comparison
import { CHUNK_SIZE } from "@/common/constants.ts";
import { CHUNK_AREA, CHUNK_SIZE } from "@/common/constants.ts";
import { chunk_key } from "@/common/utils.ts";
import { index_in_chunk } from "./world.ts";
import { HIGHEST_Y, LOWEST_Y } from "@/common/world_shape.ts";
// the most that run in one tick. the rest run first the next
export const MAX_SCHEDULED_TICKS = 65536;
@@ -26,7 +26,7 @@ export interface ScheduledTick {
readonly key: number;
// counts up with every tick scheduled, so of ticks with the same key the first scheduled runs first
readonly order: number;
// nid * 65536 + index in chunk, which is one per block, see ChunkTicks.waiting
// the block's numeric id and place in its chunk, which is one per block, see block_key and ChunkTicks.waiting
readonly block: number;
}
@@ -137,7 +137,8 @@ function run_order(a: ScheduledTick, b: ScheduledTick) {
return a.key - b.key || a.order - b.order;
}
// a block's place in its chunk, under 65536 since chunks are 256 tall, with its numeric id above
// a block's place in its chunk with its numeric id above, the same whatever the dimension's height. under 2^40
function block_key(x: number, y: number, z: number, chunk_x: number, chunk_z: number, nid: number) {
return nid * 65536 + index_in_chunk(x, y, z, chunk_x, chunk_z);
const column = (z - chunk_z * CHUNK_SIZE) * CHUNK_SIZE + (x - chunk_x * CHUNK_SIZE);
return (nid * (HIGHEST_Y - LOWEST_Y) + y - LOWEST_Y) * CHUNK_AREA + column;
}