Skip to main content

SavingSystem

A static class in Root.Township, Alta.Saving.

Static core of entity saving: maps each savable type to its versioned save data classes (from [SaveStructure]), writes and reads them with sizes and migrates old versions to the latest.

Fields​

4 private and internal fields
MemberWhat it is
private static readonly Type ISavableTypeThe open ISavable<> type, used to check each savable implements its latest data version.
private static Logger loggerNLog logger for this class.
private static Dictionary<Type, SavingSystem.SavingSetup> savingSetupsSaving setup for each savable type.
private static Dictionary<uint, SavingSystem.SavingSetup> savingTypesSaving setup for each type hash.

Properties​

MemberWhat it is
static bool IsLoadingPlayerSave { get; set; }True while a player character is loading its save; heat sources check it.
static ChunkVersioning LatestChunkVersioning { get; private set; }Latest version of every save type, written with new saves.

Methods​

MemberWhat it is
static SavingSystem.SavingSetup GetSetupOfData(SaveData data)Gets the saving setup for a save data object from its [SaveStructure] type.
static bool Load(Stream stream, ChunkVersioning chunkVersioning, uint hash, out SaveData data)Reads one block by its hash; the entity overloads find or add the component and apply the data. Returns false if the hash is unknown.
static T ReadBasic<T>(uint[] data, int bytes, ChunkVersioning versioning)Reads a BasicSaveData object from raw data with the given versioning.
static void ReadMissing(Stream stream)Skips a block whose type isn't known, using its stored size.
static void Reinitialize()Rebuilds the setups from every [SaveStructure] class in this game assembly only, then the latest versioning.
static List<ISavingContext> Serialize(ChunkVersioning chunkVersioning, NetworkEntity networkEntity, Stream stream, ISerializeChildren childrenSerializer, bool isAccumulatingContexts = false)Writes or reads all savable blocks of an entity or one savable, each tagged by type hash and ended by a 0.
static void Serialize(ChunkVersioning chunkVersioning, Stream stream, ISavableSaveBase savable)Writes or reads all savable blocks of an entity or one savable, each tagged by type hash and ended by a 0.
static void SerializeEmpty(Stream stream, ChunkVersioning chunkVersioning)Reads past all blocks of an entity without applying them.
static ValueTuple<int, uint[]> WriteBasic<T>(T data)Writes a BasicSaveData object to raw data with the latest versioning.
5 private and internal methods
MemberWhat it is
private static bool Load(Stream stream, ChunkVersioning chunkVersioning, NetworkEntity networkEntity, uint hash, ISerializeChildren childrenSerializer, bool isAccumulatingContexts, ref List<ISavingContext> contexts)Reads one block by its hash; the entity overloads find or add the component and apply the data. Returns false if the hash is unknown.
private static bool Load(Stream stream, ChunkVersioning chunkVersioning, ISavableSaveBase savable, uint hash, ISerializeChildren childrenSerializer)Reads one block by its hash; the entity overloads find or add the component and apply the data. Returns false if the hash is unknown.
private static SaveData Migrate(SavingSystem.SavingSetup setup, Stream stream, uint version, ChunkVersioning versioning)Reads data written in an old version and calls Migrate step by step up to the latest. Returns null if a step fails.
private static SaveData Read(Stream stream, ISavableSaveBase savable, SavingSystem.SavingSetup setup, uint version, ChunkVersioning versioning)Reads one sized block and migrates it, then skips or backtracks if the bits read don't match the stored size, logging an error.
private static void Write(Stream stream, ISavableSaveBase savable, SavingSystem.SavingSetup setup, ISerializeChildren childrenSerializer)Writes one savable's latest save data, preceded by its size in bits; logs an error on failure.