Remove plans

This commit is contained in:
2026-10-11 01:26:51 -03:00
parent cd3b39c3d7
commit 44a39bf8ec
10 changed files with 50 additions and 15 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
// everything generating a chunk reads, as one plain object a worker can be sent: the seed, the generator, and each
// mod's data generation needs with its worldgen script's url. loading it registers the data in this realm and loads
// the scripts, which gives the same numeric block ids and the same generator as the game, so chunks come out the same
// block for block. see GENERATION.md
// block for block. tests/worldgen_bundle_test.ts checks it with the golden fixture
import type { ModData } from "./mod_loader.ts";
import { register_mod_data } from "./mod_loader.ts";
import { type BlockRegistry, EverythingRegistry } from "./everything_registry.ts";
+32 -5
View File
@@ -290,7 +290,10 @@ engine assets in `assets/`.
1. **Ids don't change.** Saves store blocks and items by string id, including inventories and chest contents.
2. **Terrain is identical, block for block.** A save only stores what players changed on top of generated terrain. If
the generator's output changes at all, every existing world silently changes with it.
the generator's output changes at all, every existing world silently changes with it. `tests/worldgen_golden_test.ts`
hashes 64 chunks for each of 3 seeds against `tests/fixtures/worldgen_golden.json`. A change meant to change
generation records it again (`deno test -A tests/worldgen_golden_test.ts -- --update`), and the worldgen fingerprint
(`ServerWorld.worldgen_fingerprint`) keeps chunks players saved as they were.
3. **Old saves are upgraded when loading.** The save format can change, as long as older saves load into the new shape.
`tests/fixtures/` keeps a save from each version.
4. **The protocol can change, with `PROTOCOL_VERSION`.** Clients on another version are turned away before anything else
@@ -315,6 +318,15 @@ How the server sends the world, like Minecraft Java since 1.20.2. The code is in
answers `chunk_batch_received { chunks_per_tick }`: as many chunks as fit in 7 ms a tick. Until the first answer
there's one batch of 9 in flight, after it up to 10. The server stops building chunks for a tick after 20 ms.
- **Changes.** `set_block` only goes to players that have the chunk.
- **Generation.** Chunks are generated in worldgen workers (`server/game/worldgen_worker.ts`), a few by default and
`WORLDGEN_WORKERS` on the dedicated server, 0 for none. Each tick the game asks them for what the nearest chunks each
player is waiting for are built from, nearest first, and only sends a chunk once they've made it; entities and players
in a chunk they haven't made yet wait for it, like Minecraft's in chunks that aren't loaded. Each worker gets the
worldgen bundle (`common/worldgen_bundle.ts`: the mods' data generation reads and their worldgen scripts), so it makes
the same chunks as the game. The host starts them, since the game has no permissions to (see
`server/worldgen_workers.ts`), and they talk to the game through ports. Whatever needs a chunk right away, like a mod
script reading a block somewhere far, still generates it on the game thread: `/tps` shows how many chunks that was in
the last minute. `tools/chunk_loading_bench.ts` measures a player arriving somewhere new.
## Phases
@@ -341,10 +353,11 @@ and dropped, containers clicked, players moving between chunks, entities.
rules become something `mods/bworld` sets, with the engine asking it on both sides so clients still predict breaking.
Check: all tests pass unchanged, and old saves still load.
**Phase 6: world generation.** Moved to data instead of a worldgen script, see [GENERATION.md](../GENERATION.md). The
golden fixture, the ore table, and the terrain, biomes, surface and water as data are done: the server refuses to start
without the `bworld:overworld` generator, and the fixture matches exactly. Trees are a code feature in bworld's worldgen
script.
**Phase 6: world generation.** Done, as data instead of a worldgen script with `register_terrain`: noises, density
functions, noise settings and biome sources in `mods/bworld/worldgen/` (see [Terrain](modding/worldgen/terrain.md)),
features that are code or data (bworld's trees and cacti are code, in its worldgen script), and generation in worldgen
workers (see [Chunk Streaming](#chunk-streaming)). The golden fixture checked every step made the same world block for
block, and the server refuses to start without the `bworld:overworld` generator.
**Done when** searching `client/`, `common/` and `server/` for `"bworld:` finds only `bworld:air`, removing
`mods/bworld` gives an engine that starts and says it needs a terrain generator, the base game uses no engine access,
@@ -362,3 +375,17 @@ and a world saved before any of this plays exactly the same.
- **Entities.** Mods can define simple animals, but there's no API for entity types with their own behavior, animations,
or natural spawning.
- **Hot reload.** Restarting the server and rejoining is the answer for now.
- **Biome rules or multi-noise?** Biome sources are ordered rules, which kept the old biomes exactly, but mods inserting
rules can step on each other in ways that are hard to see. Minecraft's multi-noise is easier to merge but would move
every biome border. A `minecraft:multi_noise` source could exist next to the rules, for mods and imported datapacks
that want it.
- **Should `register_terrain` stay?** It's still in the worldgen API, and only throws. Data covers bworld's terrain, but
a mod might want a generator that isn't density functions at all, like a flat or skyblock world. Keeping it means the
worldgen bundle also carries a terrain script, which workers can load the same way as features. Otherwise it goes.
- **Importing Minecraft's terrain.** Datapacks' noise settings assume a world from -64 to 320 and Minecraft's noises.
The formats are close enough that an importer could translate them, but the result wouldn't look like Minecraft's. Not
a goal for now.
- **Generation's loose ends.** The packaged desktop build hasn't been tried with the worldgen worker, which the desktop
task includes. In a world without land, the spawn search looks 32 chunks out on the game thread, which the server now
does at startup. Loading a save whose generation changed compares its chunks with the new generation on the game
thread.
+3 -1
View File
@@ -1,5 +1,7 @@
// the base game's trees, a feature that's code. biomes say which kinds grow and how often (their json's "trees"), this
// says what the kinds are. where they grow can't depend on which chunk generates first, so it only depends on the
// says what the kinds are. it isn't data features: each kind would need placers drawing random numbers in exactly
// the order grow_tree does, for the world to stay the same, to say what this already says. it runs after ores, which
// only replace stone, while trees only fill air or replace leaves, so that order changes nothing. where they grow can't depend on which chunk generates first, so it only depends on the
// seed: every CELL x CELL cell has one candidate spot and a random priority, and a candidate becomes a tree only if no
// other candidate within MIN_DISTANCE has a higher priority (then its biome may still say no). that spreads trees out
// like poisson disk sampling: never closer than MIN_DISTANCE, but without lining up in a grid. a tree is placed by the
+1 -1
View File
@@ -1,6 +1,6 @@
// generates chunks in worldgen workers (worldgen_worker.ts) instead of on the game's thread. the host starts the
// workers and gives the game a port to each, since the game has no permissions to start them itself (see
// GENERATION.md). requests go nearest first, a worker has a couple at a time so priorities stay fresh, and what the
// 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 type { WorldgenBundle } from "$/common/worldgen_bundle.ts";
+5 -1
View File
@@ -1,7 +1,11 @@
// the worldgen workers (game/worldgen_worker.ts), started by the host because the game worker has no permissions to
// start workers itself: Deno checks a new worker's code against its parent's permissions. each gets one end of a
// channel and the game the other, so the game talks to them directly. a worker that crashes is started again and the
// game is given its new port. see GENERATION.md
// game is given its new port.
// what else was tried, in Deno 2.9: a worker without permissions can start one from a data: url, but that one can't
// import a single engine file either, so it would have to be the whole worker bundled into one script. and giving the
// game read access to the code isn't enough: imports from jsr (like @paulaboks/rng) also want permission to import
// from jsr.io, which would let engine access mods in the game import code from the internet
const WORKER_URL = new URL("./game/worldgen_worker.ts", import.meta.url);
// a worker that keeps crashing isn't started again after this many times, the game generates without it
const MAX_RESTARTS = 5;
+1 -1
View File
@@ -1,6 +1,6 @@
// with a worldgen pool, chunks players are sent are generated in its workers: a player that teleports somewhere new
// gets every chunk around them, the same as the game would make them, without the game generating them itself. see
// GameServer.use_worldgen_pool and GENERATION.md
// GameServer.use_worldgen_pool
import { assert, assertEquals } from "@std/assert";
import { is_within_view } from "$/common/chunk_streaming.ts";
import { game_with_pool, load_view } from "./chunk_loading.ts";
+2 -2
View File
@@ -1,5 +1,5 @@
// how long generating chunks takes, for keeping generation fast as it moves to data, see GENERATION.md.
// deno task bench
// how long generating chunks takes, on one thread. moving the terrain from code to data was held to 15% slower here,
// and cost about 9% (144.5 to 157.7 ms on the machine it was measured on). deno task bench
import { generate_raw_chunk } from "$/common/generation.ts";
import { test_game } from "./helpers.ts";
+1 -1
View File
@@ -1,5 +1,5 @@
// the bundle is everything generation reads, so a worker sent it generates what the game does. see
// common/worldgen_bundle.ts and GENERATION.md
// common/worldgen_bundle.ts
import { assert, assertEquals } from "@std/assert";
import { EverythingRegistry } from "$/common/everything_registry.ts";
import { load_bundle } from "$/common/worldgen_bundle.ts";
+1 -1
View File
@@ -1,6 +1,6 @@
// world generation gives the same world block for block, release after release: a save only keeps what players
// changed, so any change to what generation makes changes every existing world (docs/modding_plan.md, rule 2).
// this generates chunks for a few seeds and compares them with tests/fixtures/worldgen_golden.json, see GENERATION.md.
// this generates chunks for a few seeds and compares them with tests/fixtures/worldgen_golden.json.
// after a change that's meant to change generation, record it again:
// deno test -A tests/worldgen_golden_test.ts -- --update
import { assertEquals } from "@std/assert";
+3 -1
View File
@@ -1,5 +1,7 @@
// 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.
// longest tick while they come in. ticks are paced like the game loop's, 50 ms apart. at view distance 16, 4 workers
// got all 1,021 chunks 4.7 times as fast as the game thread alone (5.1 s against 24.0), with no tick over 50 ms and
// nothing generated on the game thread.
// deno run -A tools/chunk_loading_bench.ts [workers=4] [view distance=16]
import { game_with_pool, load_view } from "../tests/chunk_loading.ts";