Skip to main content

ChunkPhysicsResolver

A class in Root.Township, the global namespace.

Server: after bootup, force-loads each location chunk (not cave layers) in turn, nearest to center first, lets physics settle, then saves and unloads it. Only runs while no players are online.

Constructors​

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

Fields​

6 private and internal fields
MemberWhat it is
private CancellationTokenSource cancelTokenCancels the current run.
private Transform centerOptional point used to order chunks by flat distance. Logs an error if missing.
private bool isRunningTrue while the loop is going.
private bool isWaitingTrue while waiting for a chunk to load fully.
private static Logger loggerNLog logger for this class.
private TaskCompletionSource<bool> waitingForPlayerstoLeaveCompleted when the last player leaves.

Methods​

MemberWhat it is
override void InitializeAsServer(SpawnData spawnData)Server: starts the resolver once server bootup is finished, if the component is enabled.
void Restart()Makes a new cancel token and starts the loop if it isn't running.
void Stop()Cancels the run; it ends at its next check.
5 private and internal methods
MemberWhat it is
private void OnDestroy()Server: cancels the run and unhooks the player event.
private async void ResolveChunkPhysicsAsync()The main loop: per chunk, waits for an empty server, loads it, waits 1 to 30 seconds by entity count, unloads and saves.
private void StartAfterBootup()Starts the run unless a server wipe is under way, and stops it when one begins.
private void StopWaiting(Chunk chunk)Handler for a chunk finishing loading; ends the wait.
private void WaitForLastPlayer(Player obj)Handler for a player leaving; continues the loop once the server is empty.