ChunkSync
A internal class in Root.Township, Alta.Chunks. Reach it through att-stubs' publicized assemblies or Harmony's AccessTools.
Server: spreads the spawning or despawning of one chunk's entities for one player over several frames. Started by PlayerEntitySyncServer; instances are pooled.
- Listed in World, chunks and saving
- Nested types
Set
Constructors
1 private and internal constructor
| Member | What it is |
|---|---|
private ChunkSync() | Creates a ChunkSync with default values. |
Fields
| Member | What it is |
|---|---|
static int SendCount | Most prefabs spawned or despawned per player per send (default 30). |
static float SendInterval | Seconds between sends to each player (default 0.1). |
12 private and internal fields
| Member | What it is |
|---|---|
private NetworkEntity[] cachedEntities | The chunk's entities, copied when the sync started. |
private Chunk chunk | The chunk being synced. |
private Action<ChunkSync> completeCallback | Called when the sync finishes or is stopped with callback. |
private static HashSet<Connection> disconnectedConnections | Connections that dropped during a pass, cleaned up after it. |
private int entityCount | Number of valid entries in cachedEntities. |
private static Logger logger | Logger for this class. |
private Player player | Backing field for Player. |
private static Dictionary<IPlayer, ChunkSync.Set> playerSyncs | Queued spawn and despawn syncs, and the next send time, for each player. |
private static Stack<ChunkSync> pool | Finished syncs kept for reuse. |
private int progress | Index of the next entity to send. |
private static AltaCoroutine running | Unused in this build. |
private ChunkSync.Set set | This sync's player queue in playerSyncs. |
Properties
| Member | What it is |
|---|---|
bool IsSpawning { get; private set; } | True when this sync spawns the chunk's entities, false when it despawns them. |
Player Player { get; } | The player the chunk is being synced to. |
Methods
| Member | What it is |
|---|---|
void ForceFinish() | Sends everything left in one go, ignoring the per-frame limit. |
static ChunkSync Start(Player player, ChunkEntityManager entities, bool isSpawning, Action<ChunkSync> completeCallback) | Takes a sync from the pool and starts it. The first call also starts the loop that drives all syncs. |
void Stop(bool isInvokingCallback = false) | Cancels the sync, optionally calling its complete callback first. |
10 private and internal methods
| Member | What it is |
|---|---|
private void InitializeAndStart(Player player, ChunkEntityManager entities, bool isSpawning, Action<ChunkSync> completeCallback) | Sets the sync up for a player and chunk, caches the entities (sorted by distance to the feet for Quest players) and queues it. |
private void Release() | Removes the sync from its player's queue, returns the entity array and puts the sync back in the pool. |
private static void RemoveConnectionsThatDisconnectedDuringSync() | For players that disconnected, stops all their queued syncs with callbacks and forgets them. |
private static void RemoveSync(Connection connection) | Disconnect handler; marks the connection so its syncs are cleaned up after the current pass. |
private bool Sync(Func<IChunker, int> syncMethod, ref int count) | Works through the cached entities with the given spawn or despawn method until the send limit is hit; finishes and releases when done. |
private static IEnumerator SyncAll() (iterator) | Coroutine that runs every frame: for each player whose send time has come, spawns first, then despawns with what is left of the limit. |
private int SyncDestroy(IChunker chunker) | Despawns one entity and its children for the player, if it is still in this chunk. Returns how many prefabs were sent. |
private static int SyncDestroying(int sentCount, List<ChunkSync> syncing) | Runs the queued despawn syncs for a player until the send limit is reached. |
private int SyncSpawn(IChunker chunker) | Spawns one entity and its children for the player, if it is still in this chunk. Returns how many prefabs were sent. |
private static int SyncSpawning(int sentCount, List<ChunkSync> syncing) | Runs the queued spawn syncs for a player until the send limit is reached. |
Used in
Members of other types that take, return or hold a ChunkSync: