makeGeneratorPool()
Run entity generators on a pool of workers, main-thread side. Generation is pure CPU work, so doing it here keeps the render thread free and spreads it across cores. Each worker runs serveGenerators with its own registry; the pool queues requests and hands each to the next free worker....
function makeGeneratorPool(opts: GeneratorPoolOptions): GeneratorPool;Defined in: engine/src/worker/pool.ts:240
Run entity generators on a pool of workers, main-thread side. Generation is pure CPU work, so
doing it here keeps the render thread free and spreads it across cores. Each worker runs
serveGenerators with its own registry; the pool queues requests and hands each to the
next free worker. Browser-only (needs Worker).
The queue is the app's to steer, and without options it is a plain FIFO: requests take a
priority and an AbortSignal, and the pool can pause(), resume() and reprioritise().
Which models matter first is the game's call; the pool only offers the controls.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts | GeneratorPoolOptions | spawn creates one worker; only the consumer's bundler can resolve its entry. |
Returns
The pool. Call destroy() when done; idle workers hold their memory.
Example
import { broadleafGenerator as oak } from "@voxolith/gen-tree";
const pool = makeGeneratorPool({
spawn: () => new Worker(new URL("./gen.worker.ts", import.meta.url), { type: "module" }),
});
try {
await pool.ready();
const trees = await pool.generateMany(
[1, 2, 3].map((seed) => ({ generator: oak.id, params: oak.defaults, seed })),
{ onDone: (done, total) => (info.textContent = `${done}/${total}`) },
);
} finally {
pool.destroy();
}
// Streaming: near models first, and drop the ones the player has walked away from.
const leave = new AbortController();
pool.generate(spec, { priority: -distance, signal: leave.signal }).catch(() => {});
pool.reprioritise((s) => -distanceTo(s));
leave.abort();makeChunkFillPool()
Fill ground chunks on a pool of workers, main-thread side: pass it as makeChunkedWorld's fill. Each worker runs serveChunks, gets init once, and fills the boxes it is sent. Requests go to the least busy worker, up to depth each, and queue in order beyond that; the chunked world keeps its own...
makeModelCache()
The model cache on any CacheStore: keys are prefixed with salt, entries are deflated, and maxBytes evicts by last use after each write. openModelCache is this on IndexedDB. Throws a RangeError on a maxBytes that is not a positive finite number, and warns about doubtful ones...