Skip to main content

PlayerEntitySyncServer

A class in Root.Township, Alta.Chunks.

Server: the server half of a chunk's entity sync. It spawns and despawns the chunk's entities for players as they load and unload the chunk, spreading the work out over time with ChunkSync.

Constructors​

MemberWhat it is
PlayerEntitySyncServer(Chunk chunk)Creates a PlayerEntitySyncServer from chunk.

Fields​

3 private and internal fields
MemberWhat it is
private readonly Dictionary<Player, ChunkSync> gradualSyncThe ChunkSync in progress for each player.
private bool isAllowingLoadTrue while the chunk's content is loaded, so entities may be spawned for players.
private static readonly Logger loggerNLog logger for this class.

Properties​

MemberWhat it is
bool ShouldBeLoaded { get; }True while the chunk has players in it or a gradual sync is still running.

Events​

MemberWhat it is
event Action ReadyForUnloadRaised when no players are in the chunk and no syncs are running, so the chunk can unload.

Methods​

MemberWhat it is
void FinishAllSyncs()Forces every gradual sync still in progress to finish at once.
void HandleParentChange(IChunker chunker)Re-spawns a chunker for the right players after its parent changes, and despawns it for players who should no longer see it.
9 private and internal methods
MemberWhat it is
private void BeginEntityAdded(IChunkedEntity entity)Runs when an entity joins the chunk. Starts spawning it for every player in the chunk, if the chunk is loaded.
private void BeginEntityRemoved(IChunkedEntity entity)Runs when an entity leaves the chunk. Despawns it for players who don't also have its new chunk loaded.
private void LoadForPlayer(Player player)Runs when a player is added to the chunk. Starts spawning its entities for them, and tells them it loaded if the chunk auto-syncs.
private void OnChunkLoaded(Chunk chunk)Runs when the chunk's content loads. Allows loading and starts syncing for players already in the chunk.
private void OnChunkUnloaded(Chunk chunk)Runs when the chunk's content unloads. Stops new entities from being spawned for players.
private void StartSync(Player player, bool isSpawning)Starts a gradual spawn or despawn of the chunk's entities for one player. Global chunks finish it straight away.
private void StopSync(Player player)Stops and forgets any sync running for the player.
private void SyncFinished(ChunkSync sync)Callback when a player's gradual sync ends. Raises ReadyForUnload if nothing keeps the chunk loaded.
private void UnloadForPlayer(Player player)Runs when a player is removed from the chunk. Tells them it unloaded and starts despawning its entities for them.

Used in​

Members of other types that take, return or hold a PlayerEntitySyncServer: