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.
- Listed in World, chunks and saving
- Inherits or implements
ChunkContentManager - Documented in Chunk loading and saving
Constructors
| Member | What it is |
|---|---|
DynamicChunkContentManager(Chunk chunk, bool isLogging = false) | Creates a DynamicChunkContentManager from chunk and isLogging. |
Fields
11 private and internal fields
| Member | What it is |
|---|---|
private bool areEntitiesLoaded | True once the chunk's entities have been loaded, until unload. |
private CancellationTokenSource cancelLoad | Cancels the procedural static load when the chunk unloads early. |
private Chunk chunk | The chunk this manager loads. |
private IAltaFile chunkFile | The chunk's save file. |
private bool isLoadingEntities | True while entities are being spawned from the save. |
private bool isLogging | Turns on extra info and debug logging for this chunk. |
private Task<ValueTuple<bool, ChunkSaveFormat>> loadFileTask | The running save file read, shared between callers. |
private static Logger logger | NLog logger for this class. |
private static UnclearedPower2ArrayPool<uint> pool | Shared array pool that unused save buffers go back to. |
private INetworkScene scene | The network scene the chunk belongs to. |
private SpawnManager spawnManager | The chunk's spawner, used to spawn and destroy entities. |
Properties
| Member | What 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
| Member | What 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
| Member | What 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: