Class ComponentArray<T>
- Namespace
- KeenEyes
- Assembly
- KeenEyes.Core.dll
Typed component storage for an archetype, using pooled arrays for efficiency. Stores components contiguously in memory for cache-friendly iteration.
public sealed class ComponentArray<T> : IComponentArray, IDisposable where T : struct, IComponent
Type Parameters
TThe component type to store.
- Inheritance
-
ComponentArray<T>
- Implements
- Inherited Members
Constructors
ComponentArray()
Creates a new component array with default capacity.
public ComponentArray()
ComponentArray(int)
Creates a new component array with the specified initial capacity.
public ComponentArray(int initialCapacity)
Parameters
initialCapacityintThe initial capacity.
Properties
Capacity
Gets the capacity of the array.
public int Capacity { get; }
Property Value
ComponentType
Gets the component type stored in this array.
public Type ComponentType { get; }
Property Value
Count
Gets the number of components stored.
public int Count { get; }
Property Value
Methods
Add(in T)
Adds a component to the array.
public int Add(in T component)
Parameters
componentTThe component to add.
Returns
- int
The index where the component was added.
AddBoxed(object)
Adds a component from a boxed value.
public int AddBoxed(object value)
Parameters
valueobjectThe boxed component value to add.
Returns
- int
The index where the component was added.
AsReadOnlySpan()
Gets a readonly span over the valid components in this array.
public ReadOnlySpan<T> AsReadOnlySpan()
Returns
- ReadOnlySpan<T>
A readonly span of the components.
AsSpan()
Gets a span over the valid components in this array.
public Span<T> AsSpan()
Returns
- Span<T>
A span of the components.
Clear()
Clears all components from this array.
public void Clear()
CopyTo(int, IComponentArray)
Copies a component from this array to another array. Used during entity migration between archetypes.
public void CopyTo(int sourceIndex, IComponentArray destination)
Parameters
sourceIndexintThe index in this array.
destinationIComponentArrayThe destination array.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetBoxed(int)
Gets the boxed component value at the specified index.
public object GetBoxed(int index)
Parameters
indexintThe index of the component.
Returns
- object
The boxed component value.
Remarks
This method boxes the component and should only be used for debugging or serialization scenarios. For performance-critical code, use the typed GetRef(int) method.
GetReadonly(int)
Gets a readonly reference to the component at the specified index.
public ref readonly T GetReadonly(int index)
Parameters
indexintThe index of the component.
Returns
- T
A readonly reference to the component.
GetRef(int)
Gets a reference to the component at the specified index.
public ref T GetRef(int index)
Parameters
indexintThe index of the component.
Returns
- T
A reference to the component.
RemoveAtSwapBack(int)
Removes the component at the specified index by swapping with the last element.
public void RemoveAtSwapBack(int index)
Parameters
indexintThe index to remove.
Set(int, in T)
Sets the component value at the specified index.
public void Set(int index, in T component)
Parameters
indexintThe index.
componentTThe new component value.
SetBoxed(int, object)
Sets the component value at the specified index from a boxed value.
public void SetBoxed(int index, object value)