Skip to main content

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.

Constructors​

1 private and internal constructor
MemberWhat it is
private ChunkSync()Creates a ChunkSync with default values.

Fields​

MemberWhat it is
static int SendCountMost prefabs spawned or despawned per player per send (default 30).
static float SendIntervalSeconds between sends to each player (default 0.1).
12 private and internal fields
MemberWhat it is
private NetworkEntity[] cachedEntitiesThe chunk's entities, copied when the sync started.
private Chunk chunkThe chunk being synced.
private Action<ChunkSync> completeCallbackCalled when the sync finishes or is stopped with callback.
private static HashSet<Connection> disconnectedConnectionsConnections that dropped during a pass, cleaned up after it.
private int entityCountNumber of valid entries in cachedEntities.
private static Logger loggerLogger for this class.
private Player playerBacking field for Player.
private static Dictionary<IPlayer, ChunkSync.Set> playerSyncsQueued spawn and despawn syncs, and the next send time, for each player.
private static Stack<ChunkSync> poolFinished syncs kept for reuse.
private int progressIndex of the next entity to send.
private static AltaCoroutine runningUnused in this build.
private ChunkSync.Set setThis sync's player queue in playerSyncs.

Properties​

MemberWhat 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​

MemberWhat 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
MemberWhat 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: