Class ArchetypeManager
- Namespace
- KeenEyes
- Assembly
- KeenEyes.Core.dll
Manages archetype lifecycle and entity-to-archetype mappings. Handles archetype creation, entity migration, and query matching.
public sealed class ArchetypeManager : IDisposable
- Inheritance
-
ArchetypeManager
- Implements
- Inherited Members
Remarks
The ArchetypeManager is the central coordinator for the archetype-based storage system. It maintains a mapping from ArchetypeId to Archetype instances and tracks which archetype each entity belongs to.
When an entity's component set changes, the ArchetypeManager handles the migration to a new archetype, copying shared components and updating all bookkeeping.
Constructors
ArchetypeManager(ComponentRegistry, ChunkPool?)
Manages archetype lifecycle and entity-to-archetype mappings. Handles archetype creation, entity migration, and query matching.
public ArchetypeManager(ComponentRegistry componentRegistry, ChunkPool? chunkPool = null)
Parameters
componentRegistryComponentRegistryThe component registry for type information.
chunkPoolChunkPoolOptional chunk pool for chunk reuse. If null, a new pool is created.
Remarks
The ArchetypeManager is the central coordinator for the archetype-based storage system. It maintains a mapping from ArchetypeId to Archetype instances and tracks which archetype each entity belongs to.
When an entity's component set changes, the ArchetypeManager handles the migration to a new archetype, copying shared components and updating all bookkeeping.
Properties
ArchetypeCount
Gets the number of archetypes.
public int ArchetypeCount { get; }
Property Value
Archetypes
Gets all archetypes in this manager.
public IReadOnlyList<Archetype> Archetypes { get; }
Property Value
ChunkPool
Gets the chunk pool used by this manager.
public ChunkPool ChunkPool { get; }
Property Value
EntityCount
Gets the number of entities tracked by this manager.
public int EntityCount { get; }
Property Value
Methods
Clear()
Clears all archetypes and entity locations, returning all chunks to the pool.
public void Clear()
Remarks
This method resets the archetype manager to its initial state while keeping the chunk pool for reuse. This is useful for scenarios like restoring from a snapshot where the world state needs to be cleared before recreation.
Unlike Dispose(), this method leaves the manager in a usable state.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetArchetype(ArchetypeId)
Gets an archetype by its ID, or null if it doesn't exist.
public Archetype? GetArchetype(ArchetypeId id)
Parameters
idArchetypeIdThe archetype identifier.
Returns
- Archetype
The archetype, or null.
GetMatchingArchetypes(QueryDescription)
Gets all archetypes that match the specified query.
public IEnumerable<Archetype> GetMatchingArchetypes(QueryDescription description)
Parameters
descriptionQueryDescriptionThe query description.
Returns
- IEnumerable<Archetype>
Matching archetypes.
GetOrCreateArchetype(ArchetypeId)
Gets or creates an archetype for the specified archetype ID.
public Archetype GetOrCreateArchetype(ArchetypeId id)
Parameters
idArchetypeIdThe archetype identifier.
Returns
- Archetype
The archetype for that ID.
GetOrCreateArchetype(IEnumerable<Type>)
Gets or creates an archetype for the specified component types.
public Archetype GetOrCreateArchetype(IEnumerable<Type> componentTypes)
Parameters
componentTypesIEnumerable<Type>The component types.
Returns
- Archetype
The archetype for those component types.
PreallocateArchetype(IEnumerable<Type>, int)
Pre-allocates an archetype for the specified component types with an initial capacity.
public Archetype PreallocateArchetype(IEnumerable<Type> componentTypes, int initialCapacity = 16)
Parameters
componentTypesIEnumerable<Type>The component types for this archetype.
initialCapacityintInitial capacity for entity storage. Defaults to 16.
Returns
- Archetype
The pre-allocated archetype.
Remarks
Pre-allocating archetypes is useful for reducing the number of archetype transitions when spawning many entities with the same component set. This is particularly effective when used with bundles.
If an archetype with these component types already exists, this method returns the existing archetype without creating a new one.
Events
ArchetypeCreated
Event raised when a new archetype is created. Used for cache invalidation in the query system.
public event Action<Archetype>? ArchetypeCreated