Skip to main content

StreamerManager

A class in Root.Township, the global namespace.

Singleton (Instance) that loads and unloads chunk prefabs within a per-frame time budget and saves the world, including the server's timed auto save.

Constructors​

MemberWhat it is
StreamerManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
static StreamerManager InstanceThe active manager; a second copy destroys itself.
6 private and internal fields
MemberWhat it is
private CancellationTokenSource cancelCurrentCancels the running save when an instant save starts.
private Task currentThe save task in progress, or null.
private bool isAutoSavingWhether the auto save loop should keep running.
private static Logger loggerNLog logger for save progress and errors.
private float minutesBetweenAutoSavesMinutes between auto saves, from the server config.
private float streamingMillisecondsAllowanceBacking field for StreamingTimeAllowanceMilliseconds (2 ms by default).

Properties​

MemberWhat it is
static List<IAutoSave> AutoSavingBehaviours { get; }Objects whose AutoSave runs after the chunks are saved, such as GameTaskManager and PerPlayerManager.
float StreamingTimeAllowanceMilliseconds { get; }Per-frame time budget in milliseconds for chunk streaming and spread-out saving.

Methods​

MemberWhat it is
async Task SaveWorld(bool isInstant)Saves every chunk, the auto save behaviours and all players, then flushes files and backs up changed remote files. An instant save blocks and cancels a running one.
void StartAutoSave()Server: starts the auto save loop if the server config turns auto saving on. Called by ServerHandler.
5 private and internal methods
MemberWhat it is
private async void AutoSave()Server: loop that waits the configured minutes and saves the world, skipping while a wipe or another save is running.
private void OnDestroy()Stops the auto save loop.
private void OnEnable()Sets Instance, or destroys this copy if one already exists.
private async Task SaveWorld(bool isInstant, CancellationToken cancellationToken)Saves every chunk, the auto save behaviours and all players, then flushes files and backs up changed remote files. An instant save blocks and cancels a running one.
private void Update()Loads and unloads chunk prefabs within the time budget.