Skip to main content

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.

Constructors​

MemberWhat it is
EntityManager(INetworkScene networkScene, bool isServer)Creates an EntityManager from networkScene and isServer.

Fields​

MemberWhat it is
const int MaximumEntitiesSize of the id table: 100000. Two ids in every 50 are reserved as markers, so fewer are usable.
12 private and internal fields
MemberWhat it is
private readonly SortedList<uint, NetworkEntityLink> clientSerializedPrivate: client side list of entities this client serializes to the server, by identifier.
private ClientSerializedEnumerable clientSerializedEnumerablePrivate: reusable enumerator over clientSerialized for GetClientSerialized.
private NetworkEntityLink[] entitiesPrivate: every link slot, indexed by entity identifier.
private const int FakeEntityDivisionPrivate constant 50: every 50th pair of link slots is a fake placeholder that never holds a real entity.
private readonly bool isServerPrivate: whether this manager runs on the server.
private int linkedListIterationCountPrivate: how many times link allocation has wrapped round the free list.
private readonly ILinkProvider linkProviderPrivate: where links come from. Always this manager.
private static readonly Logger loggerPrivate: logger for allocation and health messages.
private readonly INetworkScene networkScenePrivate: the scene these entities belong to.
private NetworkEntityLink nextSpawnPrivate: the next free link to hand out.
private static NetworkEntityLink[] preparedLinksPrivate static: a link array kept from a disposed manager so the next one can reuse it.
private readonly Dictionary<int, SerializedEnumerable> serializedEnumerablesPrivate: a reusable serialized entity enumerator per connection, for GetServerSerialized.

Methods​

MemberWhat 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
MemberWhat 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: