WIP: feat(shared): store worldgen history per dimension and a world age in level.dat 7 #30

Draft
Serkyo wants to merge 5 commits from feat/level-v7 into feat/entity-chunk-lifecycle
Owner

What does this PR do?

This PR stacks on feat/entity-chunk-lifecycle, which is itself an open pull request. The diff below is against that branch, so it should be reviewed and merged after it.

I bumped level.dat to version 7 to close two gaps: the worldgen history was world-wide instead of per dimension, and the world had no clock.

  • WorldMetadata in crates/shared/src/save/level.rs now holds worldgen as a BTreeMap<DimensionId, WorldgenHistory>. The BTreeMap keeps the encoded order deterministic. worldgen_current, worldgen_entry and worldgen_versions take the dimension and return Option, and worldgen_dimensions iterates the map. No world-wide history accessor remains. Validation checks each dimension's current against its own history.
  • WorldMetadata also carries world_age_ticks: u64, with an accessor and a set_world_age_ticks setter that ignores a value below the stored one, so the age never moves backward.
  • WORLD_FORMAT_VERSION goes from 6 to 7. A version 6 record is refused with SaveError::UnsupportedVersion and there is no migrator.
  • build_generators in crates/server/src/main.rs returns generators keyed by (DimensionId, u32). A new nyelenor_generators helper picks out the syn:nyelenor entries and the current version for main, so ServerWorld's signature and world_server.rs are unchanged. I also moved the worldgen config read out of main into load_worldgen_config.
  • A new save::Level in crates/server/src/save/level_file.rs wraps the loaded metadata and its path. run_simulation calls Level::advance_tick once per simulation tick, so the age starts from the stored value and increments exactly once per tick. level.dat is written with the current age on every autosave and in shut_down. A failed write on shutdown is logged and returned after the world flush and player saves have run.
  • A new world gets one syn:nyelenor history entry built from the shipped config, and an age of 0.
  • inspect_save prints the world age and each dimension's history.
  • ADR-0014 is amended and docs/save_format.md documents the version 7 fields.

Why is this change necessary?

A world holds several dimensions, and a chunk's version stamp has to resolve against its own dimension's generator list. One world-wide history cannot express that, and a dimension that is not terrain at all has no use for Nyelenor's parameter sets. Keying the history and the generator registry on dimension fixes the shape of the format now, while only syn:nyelenor exists and no world lives off the dev machine.

The world also had no clock. Systems that need elapsed world time, such as weather, vegetation and off-screen catch-up, need one source. world_age_ticks is that source. Time of day is not stored; the system that owns day length derives it from the age.

Scope of Changes

server, shared, workspace

Testing

Automated, run on the whole workspace:

  • cargo fmt --all -- --check: clean.
  • cargo clippy --all-targets --all-features -- -D warnings: no issues.
  • cargo test --workspace --all-features --profile ci: all passed, including the shipped-asset golden digest test, which is not re-pinned.
  • cargo build -p shared --example inspect_save: builds.

New tests cover: a version 6 record is refused, per-dimension resolution and a dimension with no history, the world age round trip, a new world starting at age 0, a new world holding one syn:nyelenor history, and the_world_age_survives_a_restart_and_continues (age 40, save, reload, one more tick, save, reload, age 41).

Manual verification has not been done. Checklist for the maintainer:

  • Delete the dev world (version 6 is refused, which is intended), start the server, wait past one autosave, stop it with SIGINT, start it again, and confirm with cargo run -p shared --example inspect_save (it prints the default world) that world_age_ticks kept increasing across the restart and the worldgen map holds one syn:nyelenor entry.

Additional Context

Stacks on #24 (feat/entity-chunk-lifecycle); review that one first.

  • Breaking save format: a version 6 level.dat is refused, so existing dev worlds have to be deleted. ADR-0015 prescribes this and no migrator is added.
  • The first commit (feat(shared)) changes the shared API and does not build the server on its own. The server callers move in the second commit. The per-dimension history and the world age share that one commit because they ride on the same version bump, and splitting them would leave a commit at an intermediate shape that no version number describes.
  • I amended ADR-0014 instead of superseding it with a new ADR. The amendment changes where the history sits, not what it means or why the save owns it, so every rule in the ADR still holds inside each dimension.
  • Registering a Sanctuary or any second dimension and pinning a version are not part of this PR.
  • Level::advance_tick saturates at u64::MAX, which is unreachable at 20 ticks per second.

None.

Checklist

  • I have branched from dev (or a feature branch off dev) and my PR targets dev. (This branch is stacked on the open feat/entity-chunk-lifecycle, so the pull request targets that branch until it merges and then dev.)
  • I have kept my changes focused to a single concept.
  • I have added or updated documentation (/// doc comments for Rust) where necessary.
  • I have tested my changes and described any relevant automated or manual testing above.
### What does this PR do? This PR stacks on `feat/entity-chunk-lifecycle`, which is itself an open pull request. The diff below is against that branch, so it should be reviewed and merged after it. I bumped `level.dat` to version 7 to close two gaps: the worldgen history was world-wide instead of per dimension, and the world had no clock. - `WorldMetadata` in `crates/shared/src/save/level.rs` now holds `worldgen` as a `BTreeMap<DimensionId, WorldgenHistory>`. The `BTreeMap` keeps the encoded order deterministic. `worldgen_current`, `worldgen_entry` and `worldgen_versions` take the dimension and return `Option`, and `worldgen_dimensions` iterates the map. No world-wide history accessor remains. Validation checks each dimension's `current` against its own history. - `WorldMetadata` also carries `world_age_ticks: u64`, with an accessor and a `set_world_age_ticks` setter that ignores a value below the stored one, so the age never moves backward. - `WORLD_FORMAT_VERSION` goes from 6 to 7. A version 6 record is refused with `SaveError::UnsupportedVersion` and there is no migrator. - `build_generators` in `crates/server/src/main.rs` returns generators keyed by `(DimensionId, u32)`. A new `nyelenor_generators` helper picks out the `syn:nyelenor` entries and the current version for `main`, so `ServerWorld`'s signature and `world_server.rs` are unchanged. I also moved the worldgen config read out of `main` into `load_worldgen_config`. - A new `save::Level` in `crates/server/src/save/level_file.rs` wraps the loaded metadata and its path. `run_simulation` calls `Level::advance_tick` once per simulation tick, so the age starts from the stored value and increments exactly once per tick. `level.dat` is written with the current age on every autosave and in `shut_down`. A failed write on shutdown is logged and returned after the world flush and player saves have run. - A new world gets one `syn:nyelenor` history entry built from the shipped config, and an age of 0. - `inspect_save` prints the world age and each dimension's history. - ADR-0014 is amended and `docs/save_format.md` documents the version 7 fields. ### Why is this change necessary? A world holds several dimensions, and a chunk's version stamp has to resolve against its own dimension's generator list. One world-wide history cannot express that, and a dimension that is not terrain at all has no use for Nyelenor's parameter sets. Keying the history and the generator registry on dimension fixes the shape of the format now, while only `syn:nyelenor` exists and no world lives off the dev machine. The world also had no clock. Systems that need elapsed world time, such as weather, vegetation and off-screen catch-up, need one source. `world_age_ticks` is that source. Time of day is not stored; the system that owns day length derives it from the age. ### Scope of Changes server, shared, workspace ### Testing Automated, run on the whole workspace: - `cargo fmt --all -- --check`: clean. - `cargo clippy --all-targets --all-features -- -D warnings`: no issues. - `cargo test --workspace --all-features --profile ci`: all passed, including the shipped-asset golden digest test, which is not re-pinned. - `cargo build -p shared --example inspect_save`: builds. New tests cover: a version 6 record is refused, per-dimension resolution and a dimension with no history, the world age round trip, a new world starting at age 0, a new world holding one `syn:nyelenor` history, and `the_world_age_survives_a_restart_and_continues` (age 40, save, reload, one more tick, save, reload, age 41). Manual verification has not been done. Checklist for the maintainer: - [ ] Delete the dev world (version 6 is refused, which is intended), start the server, wait past one autosave, stop it with SIGINT, start it again, and confirm with `cargo run -p shared --example inspect_save` (it prints the `default` world) that `world_age_ticks` kept increasing across the restart and the worldgen map holds one `syn:nyelenor` entry. ### Additional Context Stacks on #24 (feat/entity-chunk-lifecycle); review that one first. - Breaking save format: a version 6 `level.dat` is refused, so existing dev worlds have to be deleted. ADR-0015 prescribes this and no migrator is added. - The first commit (`feat(shared)`) changes the shared API and does not build the server on its own. The server callers move in the second commit. The per-dimension history and the world age share that one commit because they ride on the same version bump, and splitting them would leave a commit at an intermediate shape that no version number describes. - I amended ADR-0014 instead of superseding it with a new ADR. The amendment changes where the history sits, not what it means or why the save owns it, so every rule in the ADR still holds inside each dimension. - Registering a Sanctuary or any second dimension and pinning a version are not part of this PR. - `Level::advance_tick` saturates at `u64::MAX`, which is unreachable at 20 ticks per second. ### Related Issues None. ### Checklist - [x] I have branched from `dev` (or a feature branch off `dev`) and my PR targets `dev`. (This branch is stacked on the open `feat/entity-chunk-lifecycle`, so the pull request targets that branch until it merges and then `dev`.) - [x] I have kept my changes focused to a single concept. - [x] I have added or updated documentation (`///` doc comments for Rust) where necessary. - [x] I have tested my changes and described any relevant automated or manual testing above.
All checks were successful
Auto Labeler / label-scope (pull_request_target) Successful in 2s
CLA Signed All authors have signed the CLA.
CLA Check / cla-check (pull_request_target) Successful in 2s
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/level-v7:feat/level-v7
git switch feat/level-v7

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch feat/entity-chunk-lifecycle
git merge --no-ff feat/level-v7
git switch feat/level-v7
git rebase feat/entity-chunk-lifecycle
git switch feat/entity-chunk-lifecycle
git merge --ff-only feat/level-v7
git switch feat/level-v7
git rebase feat/entity-chunk-lifecycle
git switch feat/entity-chunk-lifecycle
git merge --no-ff feat/level-v7
git switch feat/entity-chunk-lifecycle
git merge --squash feat/level-v7
git switch feat/entity-chunk-lifecycle
git merge --ff-only feat/level-v7
git switch feat/entity-chunk-lifecycle
git merge feat/level-v7
git push origin feat/entity-chunk-lifecycle
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Synvael/synvael!30
No description provided.