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.
- Listed in Global namespace: P
Constructors
| Member | What it is |
|---|---|
PlayerChunkManager(Player player) | Creates a PlayerChunkManager from player. |
Fields
| Member | What it is |
|---|---|
protected static Logger logger | NLog logger for chunk errors and moves. |
protected Player player | The player this manager tracks. |
5 private and internal fields
| Member | What it is |
|---|---|
private IChunkLoader chunkLoader | Decides which chunks load around the player. |
private static HashSet<Chunk> dynamicList | Shared scratch set of chunks the player should be in. |
private static HashSet<Chunk> staticList | Shared scratch set of chunks sent to the client to force-load. |
private MethodSyncStruct<ChunksToSync> syncChunks | Network message that sends chunk state to the player. |
private HashSet<Chunk> tempList | Scratch set used when diffing loaded chunks. |
Properties
| Member | What it is |
|---|---|
LocationChunk Chunk { get; private set; } | The location chunk the player is in now, or null after leaving. |
Events
| Member | What it is |
|---|---|
event Action<LocationChunk> ChunkChanged | Raised when Chunk changes. HandleLeave raises it with the old chunk. |
Methods
| Member | What 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
| Member | What 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: