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
| Member | What it is |
|---|
ChunkPhysicsResolver() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
6 private and internal fields
| Member | What it is |
|---|
private CancellationTokenSource cancelToken | Cancels the current run. |
private Transform center | Optional point used to order chunks by flat distance. Logs an error if missing. |
private bool isRunning | True while the loop is going. |
private bool isWaiting | True while waiting for a chunk to load fully. |
private static Logger logger | NLog logger for this class. |
private TaskCompletionSource<bool> waitingForPlayerstoLeave | Completed when the last player leaves. |
Methods
| Member | What 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
| Member | What 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. |