Class Archetype
- Namespace
- KeenEyes
- Assembly
- KeenEyes.Core.dll
An archetype stores all entities that share the same set of component types. Entities are stored in fixed-size chunks for cache-friendly iteration and reduced GC pressure.
public sealed class Archetype : IDisposable
- Inheritance
-
Archetype
- Implements
- Inherited Members
Remarks
Each archetype maintains a list of ArchetypeChunk instances, each holding up to a fixed number of entities. This chunked storage enables:
- Cache-friendly iteration (chunks sized for L2 cache)
- Chunk pooling for reduced allocations
- Potential parallel processing of different chunks
When an entity's component set changes (via Add or Remove), the entity must migrate to a different archetype. The ArchetypeManager handles these transitions.
Properties
ChunkCount
Gets the number of chunks in this archetype.
public int ChunkCount { get; }
Property Value
Chunks
Gets all chunks in this archetype.
public IReadOnlyList<ArchetypeChunk> Chunks { get; }
Property Value
ComponentTypes
Gets the component types in this archetype.
public IReadOnlyList<Type> ComponentTypes { get; }
Property Value
Count
Gets the number of entities in this archetype.
public int Count { get; }
Property Value
Entities
Gets all entities in this archetype.
public IEnumerable<Entity> Entities { get; }
Property Value
- IEnumerable<Entity>
Id
Gets the unique identifier for this archetype.
public ArchetypeId Id { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetByEntity<T>(Entity)
Gets a reference to a component for an entity.
public ref T GetByEntity<T>(Entity entity) where T : struct, IComponent
Parameters
entityEntity
Returns
- T
Type Parameters
T
GetChunkReadOnlySpan<T>(int)
Gets a readonly span of components from a specific chunk.
public ReadOnlySpan<T> GetChunkReadOnlySpan<T>(int chunkIndex) where T : struct, IComponent
Parameters
chunkIndexint
Returns
- ReadOnlySpan<T>
Type Parameters
T
GetChunkSpan<T>(int)
Gets a span of components from a specific chunk for efficient iteration.
public Span<T> GetChunkSpan<T>(int chunkIndex) where T : struct, IComponent
Parameters
chunkIndexintThe chunk index.
Returns
- Span<T>
A span over component values in that chunk.
Type Parameters
TThe component type.
GetEntity(int)
Gets the entity at the specified global index.
public Entity GetEntity(int globalIndex)
Parameters
globalIndexint
Returns
- Entity
GetEntityIndex(Entity)
Gets the global index of an entity in this archetype.
public int GetEntityIndex(Entity entity)
Parameters
entityEntity
Returns
GetEntityLocation(Entity)
Gets the entity location (chunk index and index within chunk).
public (int ChunkIndex, int IndexInChunk) GetEntityLocation(Entity entity)
Parameters
entityEntity
Returns
GetReadOnlySpan<T>()
Gets a readonly span of components. Note: With chunked storage, this only returns the first chunk's span.
[Obsolete("Use GetChunkReadOnlySpan for chunked archetypes. This method only returns the first chunk.")]
public ReadOnlySpan<T> GetReadOnlySpan<T>() where T : struct, IComponent
Returns
- ReadOnlySpan<T>
Type Parameters
T
GetReadonly<T>(int)
Gets a readonly reference to a component.
public ref readonly T GetReadonly<T>(int globalIndex) where T : struct, IComponent
Parameters
globalIndexint
Returns
- T
Type Parameters
T
GetSpan<T>()
Gets a span of components for efficient iteration. Note: With chunked storage, this only returns the first chunk's span. For full iteration, use chunk-based methods.
[Obsolete("Use GetChunkSpan for chunked archetypes. This method only returns the first chunk.")]
public Span<T> GetSpan<T>() where T : struct, IComponent
Returns
- Span<T>
Type Parameters
T
Get<T>(int)
Gets a reference to a component for the entity at the specified global index.
public ref T Get<T>(int globalIndex) where T : struct, IComponent
Parameters
globalIndexint
Returns
- T
Type Parameters
T
Has(Type)
Checks if this archetype contains a specific component type.
public bool Has(Type type)
Parameters
typeType
Returns
Has<T>()
Checks if this archetype contains a specific component type.
public bool Has<T>() where T : struct, IComponent
Returns
Type Parameters
T
Set<T>(int, in T)
Sets a component value at the specified global index.
public void Set<T>(int globalIndex, in T component) where T : struct, IComponent
Parameters
globalIndexintcomponentT
Type Parameters
T
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.