World sections
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
// server/worldgen_workers.ts). requests go nearest first, a worker has a couple at a time so priorities stay fresh, and what the
|
||||
// game stops wanting is dropped before it starts
|
||||
import type { RawChunk } from "@/common/generation.ts";
|
||||
import { ChunkColumn, Section, type SectionData } from "@/common/section.ts";
|
||||
import { WorldShape } from "@/common/world_shape.ts";
|
||||
import type { WorldgenBundle } from "@/common/worldgen_bundle.ts";
|
||||
import { chunk_key } from "@/common/utils.ts";
|
||||
|
||||
@@ -16,7 +18,8 @@ export type PoolToWorker =
|
||||
export type WorkerToPool =
|
||||
| { type: "ready" }
|
||||
| { type: "failed"; error: string }
|
||||
| { type: "chunk"; x: number; z: number; blocks: Uint32Array; spills: Int32Array; biomes: string[] }
|
||||
// a raw chunk's sections as their data, since what's sent between workers loses its class
|
||||
| { type: "chunk"; x: number; z: number; sections: SectionData[]; spills: Int32Array; biomes: string[] }
|
||||
| { type: "error"; x: number; z: number; error: string };
|
||||
|
||||
// the game's end of a channel to a worker
|
||||
@@ -45,6 +48,8 @@ interface Queued {
|
||||
|
||||
export class WorldgenPool {
|
||||
#bundle: WorldgenBundle;
|
||||
// what chunks it makes hold, from the bundle
|
||||
#shape: WorldShape;
|
||||
#slots: Slot[] = [];
|
||||
#queue = new Map<number, Queued>();
|
||||
// asked for by prefetch, kept when want() drops the rest
|
||||
@@ -60,6 +65,7 @@ export class WorldgenPool {
|
||||
|
||||
constructor(ports: WorkerPort[], bundle: WorldgenBundle) {
|
||||
this.#bundle = bundle;
|
||||
this.#shape = new WorldShape(bundle.shape);
|
||||
this.#ready = new Promise((resolve, reject) => this.#settle_ready = { resolve, reject });
|
||||
ports.forEach((port, index) => this.#attach(index, port));
|
||||
if (ports.length === 0) this.#settle_ready.resolve();
|
||||
@@ -160,10 +166,10 @@ export class WorldgenPool {
|
||||
const key = chunk_key(message.x, message.z);
|
||||
slot.in_flight.delete(key);
|
||||
this.generated++;
|
||||
const sections = message.sections.map((data) => new Section(data));
|
||||
this.on_chunk(message.x, message.z, {
|
||||
blocks: message.blocks,
|
||||
column: new ChunkColumn(message.x, message.z, this.#shape, sections, message.biomes),
|
||||
spills: message.spills,
|
||||
biomes: message.biomes,
|
||||
});
|
||||
this.#done(key);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user