Workers for chunk generation !
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// how fast a player arriving somewhere new gets the chunks around them, with worldgen workers and without, and the
|
||||
// longest tick while they come in. ticks are paced like the game loop's, 50 ms apart.
|
||||
// deno run -A tools/chunk_loading_bench.ts [workers=4] [view distance=16]
|
||||
import { game_with_pool, load_view } from "../tests/chunk_loading.ts";
|
||||
|
||||
const workers = Number(Deno.args[0] ?? 4);
|
||||
const distance = Number(Deno.args[1] ?? 16);
|
||||
|
||||
for (const count of [0, workers]) {
|
||||
const t = await game_with_pool(count, "bench-seed");
|
||||
// like the real server: a tick only builds chunks for 20 ms, and monsters spawn
|
||||
t.game.chunk_send_budget_ms = 20;
|
||||
t.game.do_mob_spawning = true;
|
||||
t.game.view_distance = distance;
|
||||
t.join(1, "alice");
|
||||
t.send(1, { type: "view_distance", distance });
|
||||
const player = t.game.players()[0];
|
||||
// what's around spawn first, so the teleport is all that's measured
|
||||
await load_view(t, 1, 50);
|
||||
const fallbacks = t.game.world.fallbacks;
|
||||
t.game.world.fallback_callers = new Map();
|
||||
t.game.teleport(player, 10_000.5, 150, 3_000.5);
|
||||
const { chunks, longest_tick, ms } = await load_view(t, 1, 50);
|
||||
console.log(
|
||||
`${count === 0 ? "game thread" : `${count} workers`}: ${chunks.size} chunks in ${(ms / 1000).toFixed(1)} s, ` +
|
||||
`longest tick ${longest_tick.toFixed(0)} ms, ${
|
||||
t.game.world.fallbacks - fallbacks
|
||||
} generated on the game thread`,
|
||||
Object.fromEntries(t.game.world.fallback_callers),
|
||||
);
|
||||
t.close();
|
||||
}
|
||||
Deno.exit(0);
|
||||
Reference in New Issue
Block a user