Table of Contents

Class AutoSaveSystem<TSerializer>

Namespace
KeenEyes.Systems
Assembly
KeenEyes.Core.dll

A system that automatically saves the world state at configurable intervals.

public sealed class AutoSaveSystem<TSerializer> : SystemBase, ISystem, IDisposable, ISystemLifecycle where TSerializer : IComponentSerializer, IBinaryComponentSerializer

Type Parameters

TSerializer

The serializer type that implements both serialization interfaces.

Inheritance
AutoSaveSystem<TSerializer>
Implements
Inherited Members

Examples

// Create auto-save system with default config
var autoSave = new AutoSaveSystem<MySerializer>(serializer);
world.AddSystem(autoSave, SystemPhase.PostRender);

// Configure for more frequent saves
autoSave.Config = AutoSaveConfig.Frequent;

// Manually trigger a save
autoSave.SaveNow();

Remarks

The AutoSaveSystem monitors elapsed time and optionally entity changes to trigger automatic saves. It supports both full snapshots and delta (incremental) saves.

Delta saves are significantly smaller than full saves when few entities change between saves. The system automatically creates a new baseline after a configurable number of deltas to prevent long restoration chains.

This system requires the world to implement ISaveLoadCapability. The standard World class provides this capability.

Constructors

AutoSaveSystem(TSerializer, AutoSaveConfig?)

Creates a new auto-save system with the specified serializer.

public AutoSaveSystem(TSerializer serializer, AutoSaveConfig? config = null)

Parameters

serializer TSerializer

The component serializer for AOT-compatible serialization.

config AutoSaveConfig

Optional configuration. Uses default if not specified.

Properties

ChangesSinceLastSave

Gets the number of tracked entity changes (creations and destructions) since the last save.

public int ChangesSinceLastSave { get; }

Property Value

int

Remarks

This is the value compared against ChangeThreshold to drive the change-based auto-save trigger. It resets to zero after each successful save.

Config

Gets or sets the auto-save configuration.

public AutoSaveConfig Config { get; set; }

Property Value

AutoSaveConfig

CurrentDeltaSequence

Gets the current delta sequence number (0 if no saves have occurred).

public int CurrentDeltaSequence { get; }

Property Value

int

HasBaseline

Gets whether a baseline snapshot exists.

public bool HasBaseline { get; }

Property Value

bool

TimeSinceLastSave

Gets the time elapsed since the last save.

public float TimeSinceLastSave { get; }

Property Value

float

Methods

CreateNewBaseline()

Creates a new baseline snapshot, resetting the delta chain.

public SaveSlotInfo? CreateNewBaseline()

Returns

SaveSlotInfo

The save slot info for the new baseline.

Dispose(bool)

Releases resources used by this system.

protected override void Dispose(bool disposing)

Parameters

disposing bool

True if called from Dispose(), false if called from finalizer.

OnInitialize()

Called after the system is initialized with a world. Override to set up queries and resources.

protected override void OnInitialize()

Reset()

Resets the auto-save state, clearing any existing baseline.

public void Reset()

SaveNow()

Manually triggers an auto-save immediately.

public SaveSlotInfo? SaveNow()

Returns

SaveSlotInfo

The save slot info, or null if save failed.

Update(float)

Called each frame/tick to update the system.

public override void Update(float deltaTime)

Parameters

deltaTime float

Time elapsed since the last update in seconds.

Events

OnAutoSave

Event raised when an auto-save occurs.

public event Action<SaveSlotInfo>? OnAutoSave

Event Type

Action<SaveSlotInfo>

OnAutoSaveError

Event raised when an auto-save fails.

public event Action<Exception>? OnAutoSaveError

Event Type

Action<Exception>