WIP: feat(server): load, save and unload entities with their chunk #24
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
scope/assets
scope/client
scope/networking
scope/renderer
scope/scripting
scope/server
scope/shared
scope/workspace
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Synvael/synvael!24
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/entity-chunk-lifecycle"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What does this PR do?
I gave the entity region store a caller. Persistent non-player entities now load, save and unload with the chunk they stand in.
region_actor.rs: the save actor also owns the entity region files underentities/, in a map separate from the chunk regions. It has entity read and write requests (a write with an empty list removes the record), andFlushflushes entity regions as well as chunk regions. Entity requests share the actor's queue with chunk requests, so a record written on eviction is read back by that chunk's next load.entity_file.rs:loadrejects a record holding an entity outside its own chunk, and a newmergeadds entities to the stored record of a chunk whose record was not read, replacing by id and keeping every other stored entity.build_recordstays the only place a record is built, so players are never included. Thedead_codeexpectation is gone.world_server.rs: aLoadjob also reads the chunk's entity record and returns it with the chunk.reconcilenow reports the chunks it loaded (with their entity lists) and the chunks it evicted throughStreamStats. A record that fails to decode is logged, the chunk loads with no entities, and its stored record is left alone on eviction.entity_store.rs:EntityStorespawns loaded entities withPersistentId,EntityKindandPosition, writes a chunk's record throughbuild_recordand despawns its entities on eviction, and tracks which chunks have a non-empty stored record so that a chunk whose last entity left gets its record removed.autosave_entitieswrites every resident chunk whose entity set or positions changed, andsave_all_entitieswrites everything on stop. Each write reports its outcome back, and a failed write is retried on the next pass.main.rs: wiring only.stream_chunkshands its stats to the store,sync_entitiesruns after it in the schedule, the autosave block callsautosave_entitiesbefore the flush, and shutdown callssave_all_entitiesbefore the final flush.save.rsmodule doc now describes the incremental flush as the common path and the whole-file rewrite as the fallback.docs/save_format.mddescribes entity regions on the save actor, the entity read in the load pipeline, and when records are written.Why is this change necessary?
The entity region store and the persistent entity id already existed, but nothing called them, so an entity that was in a chunk when the chunk left memory would have been lost. A chunk that holds a persistent entity also has to be written back whatever its voxel diff, and a chunk whose last entity left has to have its record removed, otherwise the departed entity comes back on the next load. Entity regions live on the save actor so their reads and writes are ordered with the chunk requests on the same thread. No non-player entity kind exists yet, so the round trip is covered by tests that spawn a test entity carrying
PersistentId,EntityKindandPosition.Scope of Changes
server, workspace
Testing
Automated, all run on this branch:
cargo fmt --all -- --check: clean.cargo clippy --all-targets --all-features -- -D warnings: clean.cargo test -p server: 109 passed, 0 failed.cargo test --workspace --all-features --profile ci: all suites passed, 0 failed.cargo deny check: advisories, bans, licenses and sources ok.The new tests in
tests/entity_store.rsandtests/region_actor.rscover: an entity evicted and reloaded keeps itsEntityId, kind and position and is despawned in between; a chunk holding only a player gets no entity record; moving the only entity out of a chunk removes the old chunk's record; a chunk whose voxels equal the baseline but which holds an entity still gets its record written; an entity that moved before an autosave is found at its new position when the entity region is read from disk; and failed writes are retried and reported by the flush.Manual: not run. Maintainer to run it: start the server, join, walk out of the view radius and back, then quit. Expect no entity-record errors in the server log and an empty
entities/directory in the world, since no non-player entity exists and players never land there.Additional Context
SYNEandSYNRkeep their versions and no migrator is added.crates/serverand one doc, and is a single concept in seven commits.nettests in parallel ondevcan fail intermittently because they share a trust store. They passed here.Related Issues
None.
Checklist
dev(or a feature branch offdev) and my PR targetsdev.///doc comments for Rust) where necessary.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.