Workers for chunk generation !

This commit is contained in:
2026-10-11 01:15:14 -03:00
parent 3d2b235f64
commit cd3b39c3d7
24 changed files with 1119 additions and 91 deletions
+33
View File
@@ -14,6 +14,7 @@ import { Options } from "$/client/options.ts";
import type { Client } from "$/client/client.ts";
import type { ModListing } from "$/common/mod_loader.ts";
import { copy_dir, test_game } from "./helpers.ts";
import { game_with_pool } from "./chunk_loading.ts";
const [MAJOR, MINOR] = GAME_VERSION.split(".");
const THIS_MINOR = `~${MAJOR}.${MINOR}.0`;
@@ -121,6 +122,38 @@ Deno.test("a worldgen mod hooks the terrain in engine.common", async () => {
assert(plain.world.get_block_id(8, 10, 8) !== "bworld:water");
});
Deno.test({
name: "a worldgen mod's hook reaches the worldgen workers too, since each loads the worldgen scripts",
sanitizeOps: false,
sanitizeResources: false,
fn: async () => {
const dir = mods_dir((dir) =>
write_mod(dir, "flat_sea", {
worldgen: [
"worldgen.ts",
`import { engine, hook } from "bworld/engine";
export function setup() {
hook(engine.common.OverworldTerrain.prototype, "density", { replace: () => -1 });
}`,
],
})
);
// it's all sea, so no spawn search
const t = await game_with_pool(1, "engine-access-flat-sea-pool", dir, false);
try {
const around: [number, number][] = [];
for (let x = -1; x <= 1; x++) for (let z = -1; z <= 1; z++) around.push([x, z]);
await t.pool!.prefetch(around);
const fallbacks = t.game.world.fallbacks;
assertEquals(t.game.world.get_block_id(8, 10, 8), "bworld:water");
assertEquals(t.game.world.fallbacks, fallbacks, "the worker made it, not the game");
} finally {
t.close();
Deno.removeSync(dir, { recursive: true });
}
},
});
Deno.test("a client mod hooks LocalPlayer from its .bmod", async () => {
const dir = Deno.makeTempDirSync({ prefix: "bworld_engine_" });
write_mod(dir, "floaty", {