Skip to main content

PlayerChunkManager

A class in Root.Township, the global namespace.

Tracks which location chunk a player is in and which chunks they have loaded. The server works it out from position and sends it; clients apply what they receive. One per Player.

Constructors​

MemberWhat it is
PlayerChunkManager(Player player)Creates a PlayerChunkManager from player.

Fields​

MemberWhat it is
protected static Logger loggerNLog logger for chunk errors and moves.
protected Player playerThe player this manager tracks.
5 private and internal fields
MemberWhat it is
private IChunkLoader chunkLoaderDecides which chunks load around the player.
private static HashSet<Chunk> dynamicListShared scratch set of chunks the player should be in.
private static HashSet<Chunk> staticListShared scratch set of chunks sent to the client to force-load.
private MethodSyncStruct<ChunksToSync> syncChunksNetwork message that sends chunk state to the player.
private HashSet<Chunk> tempListScratch set used when diffing loaded chunks.

Properties​

MemberWhat it is
LocationChunk Chunk { get; private set; }The location chunk the player is in now, or null after leaving.

Events​

MemberWhat it is
event Action<LocationChunk> ChunkChangedRaised when Chunk changes. HandleLeave raises it with the old chunk.

Methods​

MemberWhat it is
void HandleLeave()Removes the player from all loaded chunks and clears Chunk.
void LoadChunkAt(LocationChunk newChunk, Vector3 position)Server: reloads chunks for a position and logs an error if it doesn't land in the expected chunk.
5 private and internal methods
MemberWhat it is
private void HandleChunkSync(IPlayer p, Stream stream, ChunksToSync arguments)Writes or reads current and loaded chunks. Clients force-load the listed chunks, unload others, and update Chunk.
private void LoadChunksFromPosition(PlayerController playerController, Vector3 oldPosition, Vector3 position, LocomotionFunction function)Server: hooked to the locomotion PositionChanged event; calls LoadFromPosition.
private void LoadFromPosition(Vector3 position)Server: finds the chunk at a position, updates the player's chunk lists, and sends the result. No chunk sends them to respawn.
private void PlayerControllerSet(Player player, PlayerController playerController)On a new body: clients pick the chunk from position; the server hooks position changes.
private void SetLoader(PlatformTarget platformTarget)Picks the chunk loader for the player's platform: normal for PC, optimised for Quest.

Used in​

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