EntityManager
A class in Root.Township, Alta.Networking.Internal.
Owns the table of network entity ids for a scene: hands out free ids, maps ids to entities and lists what needs serializing. One per network scene.
- Listed in Networking and servers
- Inherits or implements
ILinkProvider,IEntityManager,IDisposable - Documented in Finding entities
Constructors
| Member | What it is |
|---|---|
EntityManager(INetworkScene networkScene, bool isServer) | Creates an EntityManager from networkScene and isServer. |
Fields
| Member | What it is |
|---|---|
const int MaximumEntities | Size of the id table: 100000. Two ids in every 50 are reserved as markers, so fewer are usable. |
12 private and internal fields
| Member | What it is |
|---|---|
private readonly SortedList<uint, NetworkEntityLink> clientSerialized | Private: client side list of entities this client serializes to the server, by identifier. |
private ClientSerializedEnumerable clientSerializedEnumerable | Private: reusable enumerator over clientSerialized for GetClientSerialized. |
private NetworkEntityLink[] entities | Private: every link slot, indexed by entity identifier. |
private const int FakeEntityDivision | Private constant 50: every 50th pair of link slots is a fake placeholder that never holds a real entity. |
private readonly bool isServer | Private: whether this manager runs on the server. |
private int linkedListIterationCount | Private: how many times link allocation has wrapped round the free list. |
private readonly ILinkProvider linkProvider | Private: where links come from. Always this manager. |
private static readonly Logger logger | Private: logger for allocation and health messages. |
private readonly INetworkScene networkScene | Private: the scene these entities belong to. |
private NetworkEntityLink nextSpawn | Private: the next free link to hand out. |
private static NetworkEntityLink[] preparedLinks | Private static: a link array kept from a disposed manager so the next one can reuse it. |
private readonly Dictionary<int, SerializedEnumerable> serializedEnumerables | Private: a reusable serialized entity enumerator per connection, for GetServerSerialized. |
Methods
| Member | What it is |
|---|---|
void CheckHealth(Logger logger) | Logs counts of used, empty, reserved and broken id slots. |
void ChunkEmbedded(IEnumerable<NetworkEntity> embeddedEntities) | Puts embedded entities in the scene's global chunk. |
void Dispose() | Frees every slot and keeps the table for the next scene to reuse. |
void Empty(NetworkEntityLink link) | Frees an id slot. |
void Fill(NetworkEntityLink link, NetworkEntity entity) | Puts an entity in an id slot. |
uint ForceRegisterEntity(NetworkEntity entity) | Puts an entity in the next free id slot (returns the id, 0 on failure) or in a given id slot. |
void ForceRegisterEntity(NetworkEntity entity, uint identifier) | Puts an entity in the next free id slot (returns the id, 0 on failure) or in a given id slot. |
IEnumerable<EntitySerializer> GetClientSerialized(int start = 0) | Client: the serializers of entities the client sends, starting at an index. |
NetworkEntity GetEntity(uint identifier) | Finds an entity by id, or null. |
NetworkEntity GetEntityWithSerializer(uint identifier, out EntitySerializer serializer) | Finds an entity by id and also gives its serializer. |
IEnumerable<EntitySerializer> GetServerSerialized(int connectionId, int start) | Server: the serializers to visit for one connection, starting at an index. |
void InitializeAsServer(IEnumerable<NetworkEntity> embeddedEntities) | Server: initializes each embedded entity with default spawn data. |
IEnumerable<NetworkEntity> IterateEntities() (iterator) | Every live entity in id order. |
void MarkSerialized(NetworkEntity entity, EntitySerializer serializer) | Marks an entity as having a serializer, so it is included in sync passes. |
void RegisterEmbedded(IEnumerable<NetworkEntity> embeddedEntities) | Gives each embedded scene entity without an id a new one and initializes it. |
void SerializeAsClient(NetworkEntity entity) | Adds an entity to the list the client sends to the server, until it's destroyed. |
void SyncSceneEntity(uint embeddedIndex, uint identifier, uint[] embedded) | Client: gives an embedded scene entity the id the server uses for it. |
3 private and internal methods
| Member | What it is |
|---|---|
private NetworkEntityLink Alta.Networking.Internal.ILinkProvider.GetLink(uint identifier) | Returns the link slot for an identifier, straight from the array. |
private NetworkEntityLink Alta.Networking.Internal.ILinkProvider.GetNextLink() | Walks the free list to the next empty, non fake link. A full link found there counts as corruption and quits the server. |
private void PrepareLinkedEntityList() | Private: builds the 100000 link slots and their free list, or reuses the array kept by the last Dispose. |
Used in
Members of other types that take, return or hold a EntityManager: