Skip to main content

DomainController

A class in Root.Township, ATT.Domains.

Creates and destroys per-player domains: private copies of a location spawned in a row under the map. Server creates them; clients get the domain chunk registered by sync.

Constructors​

MemberWhat it is
DomainController()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

7 private and internal fields
MemberWhat it is
private float domainHeightY position domains are spawned at (default -200).
private readonly Dictionary<Domain, int> domainOffsetMapEach live domain and the slot index it was spawned at.
private static readonly Logger loggerNLog logger for this class.
private float spacingBetweenDomainsDistance along Z between domain slots (default 400).
private MethodSyncClass<LocationChunk> syncAddDomainToAddedChunksMethod sync (SyncE) that sends a new domain chunk to clients.
private MethodSyncClass<LocationChunk> syncRemoveDomainFromAddedChunksMethod sync (SyncD) that tells clients to drop a domain chunk.
private Domain universalDomainPrefabThe Domain prefab spawned for each player's domain.

Methods​

MemberWhat it is
async Task<Domain> CreateDomainForPlayer(IPlayer player)Server: creates a domain for the player, syncs its chunk to clients, clears its save, force-loads it and removes its entities.
void DeregisterDomain(Domain domain)Removes a domain from the offset map so its slot can be reused. Does not destroy it.
async Task DestroyDomain(Domain domain)Server: tells clients to drop the domain chunk, deregisters it, destroys the domain entity and clears the chunk's save.
Domain GetDomainForPlayer(IPlayer player)Returns the domain whose player is the given player, or null.
override void Initialize()Sets up the two method syncs used to add and remove domain chunks on clients.
override string ToString()Returns the object name and entity identifier.
5 private and internal methods
MemberWhat it is
private Domain CreateDomain(IPlayer player)Spawns universalDomainPrefab at the next free offset, assigns the player and registers its chunk as a location chunk.
private int GetDomainIndex(Domain domain)Returns the offset slot index a domain was given.
private int GetNextAvailableOffsetIndex()Returns the lowest slot index no domain is using.
private void SyncAddDomainToAddedChunks(IPlayer player, Stream stream, Chunk domainChunk)Sync handler: on clients, fixes the received domain chunk's bounds and registers it with LocationChunkHelper.
private void SyncRemoveDomainFromAddedChunks(IPlayer player, Stream stream, Chunk domainChunk)Sync handler: on clients, deregisters the received domain chunk from LocationChunkHelper.

Used in​

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