Skip to main content

DynamicChunkContentManager

A class in Root.Township, Alta.Chunks.

Loads, saves and unloads the saved entities of one chunk: reads the chunk's save file (or the default save in Resources), spawns its entities, and writes them back on save or unload. Server side; created per chunk.

Constructors​

MemberWhat it is
DynamicChunkContentManager(Chunk chunk, bool isLogging = false)Creates a DynamicChunkContentManager from chunk and isLogging.

Fields​

11 private and internal fields
MemberWhat it is
private bool areEntitiesLoadedTrue once the chunk's entities have been loaded, until unload.
private CancellationTokenSource cancelLoadCancels the procedural static load when the chunk unloads early.
private Chunk chunkThe chunk this manager loads.
private IAltaFile chunkFileThe chunk's save file.
private bool isLoadingEntitiesTrue while entities are being spawned from the save.
private bool isLoggingTurns on extra info and debug logging for this chunk.
private Task<ValueTuple<bool, ChunkSaveFormat>> loadFileTaskThe running save file read, shared between callers.
private static Logger loggerNLog logger for this class.
private static UnclearedPower2ArrayPool<uint> poolShared array pool that unused save buffers go back to.
private INetworkScene sceneThe network scene the chunk belongs to.
private SpawnManager spawnManagerThe chunk's spawner, used to spawn and destroy entities.

Properties​

MemberWhat it is
static ChunkMatrix ActiveMatrix { get; set; }Offset matrix of the location chunk whose resource save is being loaded; loaders use it to move saved positions into place. Null otherwise.
override bool IsAllowingUnload { get; }False while entities are being loaded in.

Methods​

MemberWhat it is
override async Task Clear()Clears the chunk's content and deletes its save file and backup.
async Task<ValueTuple<bool, ChunkSaveFormat>> LoadFromFile()Loads the chunk save, sharing one read task between callers. Returns whether it came from a real save file, and the save.
async Task MergeWithResources(uint hash)Waits for the chunk to unload, then resets every saved object with the given prefab hash to the default save's copies and writes the file.
override async Task Save()Writes the chunk's current entities to its save file, unless it is still loading.
bool StartLoadingFromFile()Starts reading the save file early if it isn't loaded or loading yet. Returns true if it started.
override void UpdateIdentifier()Picks up the chunk's new save file after its identifier changes.
protected override async Task LoadInternal()Loads the procedural static content, the save, the procedural dynamic content and then the entities.
protected override async Task UnloadInternal()Saves and destroys the chunk's entities (or just destroys them if the scene has no save files).
protected override void WaitingToLoadForUnload()Cancels the running load when an unload is requested.
13 private and internal methods
MemberWhat it is
private ChunkSaveFormat CreateSave(bool isDestroying)Builds a new chunk save from the chunk's current entities (or embedded entities for the global chunk).
private void DestroyEntities()Destroys every prefab entity in the chunk without saving. Used on unload when the scene has no save files.
private SavedDynamicObject GetEmbeddedSave(NetworkEntity entity, uint hash)Serializes one entity into a saved object, or returns null if there was nothing to write.
private bool IsSaveValid(ChunkSaveFormat save)False when the save's version is older than the chunk's MinimumSaveVersion, so the default save is used instead.
private void LoadEntities(ChunkSaveFormat save, bool hasGenerated)Spawns every saved object in the save, runs load setup and server init on root entities, then puts them in the chunk. Skips unknown prefab hashes.
private async Task<ValueTuple<bool, ChunkSaveFormat>> LoadFromSaveOrResources()Reads the chunk's save file if valid; otherwise loads the default save Save/<chunk id> from Resources, or makes an empty one.
private void LoadSerializeEmbeddedEntity(SavedDynamicObject savedObject, ChunkVersioning chunkVersioning)Applies a saved object to the matching embedded scene entity, for the global chunk.
private void LoadSerializeEntity(SavedDynamicObject savedObject, ChunkVersioning chunkVersioning, ref NetworkEntity entity)Spawns an entity from a saved object's prefab hash (if not given one) and reads its saved data into it.
private void LoadSingle(SavedDynamicObject savedObject, ChunkVersioning chunkVersioning)Loads one saved object back into the chunk. Used when an unloaded-chunk entity has to be restored.
private void Merge(uint hash, ChunkSaveFormat current, ChunkSaveFormat resources = null)Removes every object with the given prefab hash from a save, then adds back the ones in the resources save.
private void SaveEmbedded(ChunkSaveFormat.Version version)Saves the global chunk's embedded (non-prefab) entities.
private void SaveEntities(ChunkSaveFormat.Version version, bool isDestroying)Saves each entity with save mode Base that is above y -15000; when destroying, also destroys all of the chunk's entities.
private async void UnloadSingle(NetworkEntity entity)Handles an entity entering this chunk while it is unloaded: saves it into the chunk save, or destroys it if it isn't saved.

Used in​

Members of other types that take, return or hold a DynamicChunkContentManager: