Save all generated chunks instead of only chunks that were changed
This commit is contained in:
@@ -5,16 +5,17 @@ with ores (data) and features (a worldgen script).
|
||||
|
||||
## Determinism
|
||||
|
||||
A save only keeps what players changed on top of the generated terrain. Everything else is generated again whenever a
|
||||
chunk loads, so a chunk has to come out **exactly the same every time**. If it doesn't, blocks players broke reappear
|
||||
and their builds end up half buried.
|
||||
Every chunk is saved whole once it's generated, like Minecraft, so a saved chunk never changes when generation does.
|
||||
Generation still has to come out **exactly the same every time**: a chunk is generated more than once, since what a
|
||||
feature writes into a neighbor is generated again when that neighbor is (even years later, next to a saved chunk). If it
|
||||
isn't the same, trees are cut off at chunk borders.
|
||||
|
||||
- **Never use `Math.random`, `Date`, `performance.now` or anything else that changes between runs.** Use the chunk's
|
||||
`rng` and noise helpers, which are seeded from the world's seed.
|
||||
- Don't keep state between chunks. Chunks generate in any order, and in several worldgen workers at once, each with its
|
||||
own copy of the worldgen scripts (and the game generates a few itself).
|
||||
- Adding or removing a mod's features is safe for chunks that haven't been generated yet, but changes existing worlds'
|
||||
untouched terrain the next time it loads.
|
||||
- Adding or removing a mod's features only changes chunks that haven't been generated yet, with seams where they meet
|
||||
saved ones.
|
||||
|
||||
## The Passes
|
||||
|
||||
|
||||
@@ -247,8 +247,8 @@ filler down to its `filler_depth`. Everything else is stone.
|
||||
## Changing the Base Game's Terrain
|
||||
|
||||
A mod can add biomes to it, but can't replace its files yet: an id defined by two mods is an error. Anything that
|
||||
changes the terrain changes untouched land in existing worlds, the same as adding a [feature](index.md#features). The
|
||||
worldgen fingerprint keeps chunks players changed as they were.
|
||||
changes the terrain changes land not generated yet in existing worlds, the same as adding a
|
||||
[feature](index.md#features). Every chunk generated is saved, so what's been generated stays as it was.
|
||||
|
||||
[Engine access](../misc/engine.md) mods can hook `engine.common.OverworldTerrain`, whose `density` and `cave` are called
|
||||
for every cell corner.
|
||||
|
||||
@@ -289,11 +289,11 @@ engine assets in `assets/`.
|
||||
### Rules That Keep Existing Worlds Working
|
||||
|
||||
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. `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.
|
||||
2. **Terrain doesn't change by accident.** Every chunk generated is saved whole, like Minecraft, so a change to
|
||||
generation only shows in chunks not generated yet, with seams where they meet saved ones.
|
||||
`tests/worldgen_golden_test.ts` hashes 64 chunks for each of 3 seeds against `tests/fixtures/worldgen_golden.json`,
|
||||
so it's never a surprise. A change meant to change generation records it again
|
||||
(`deno test -A tests/worldgen_golden_test.ts -- --update`).
|
||||
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
|
||||
@@ -387,5 +387,5 @@ and a world saved before any of this plays exactly the same.
|
||||
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.
|
||||
does at startup. Saved chunks are read on the game thread, which waits for the host (see `read_chunk` in
|
||||
`server/game/worker.ts`): much faster than generating them, but Minecraft reads them ahead instead.
|
||||
|
||||
Reference in New Issue
Block a user