Class ComponentPoolBase
Namespace: KenseiECS
Untyped part of a component pool: the sparse set of entity indices. World stores pools of every component type as this base so it can walk masks and remove components without knowing T. Operations that bypass World bookkeeping (Clear, AddDefault, CopyTo) are internal — calling them directly would desynchronize masks and filters.
public abstract class ComponentPoolBaseInheritance
Derived
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Properties
AllocatedBytes
Approximate bytes held by this pool's arrays.
public long AllocatedBytes { get; }Property Value
ComponentSize
Size of one component in bytes, or 0 when it holds references and cannot be measured.
public abstract int ComponentSize { get; }Property Value
ComponentType
Component type stored in this pool.
public Type ComponentType { get; }Property Value
Count
Number of components in the pool.
public int Count { get; }Property Value
DenseCapacity
Length of the dense arrays.
public int DenseCapacity { get; }Property Value
RawEntities
Dense entity index array — parallel to the typed data array. Valid range is 0..Count.
public int[] RawEntities { get; }Property Value
int[]
ReservedComponents
Components this pool is reserved for: the highest count passed to Reserve(), 0 while it was not reserved (the obsolete Reserve() does not count). A reserved pool covers ReservedEntities with its sparse array, and the filters whose Inc types are all reserved take their reserve from it (ReservedCount).
public int ReservedComponents { get; }Property Value
SparseCapacity
Length of the sparse array (grows with the highest entity index that ever had this component).
public int SparseCapacity { get; }Property Value
TypeIndex
Unique type index of the component stored in this pool.
public int TypeIndex { get; }Property Value
Methods
Has(int)
Check if entity has this component. O(1).
public bool Has(int entityIndex)Parameters
entityIndex int
Returns
Remove(int)
Remove component. O(1) via swap-remove. No-op if the entity does not have it.
public abstract void Remove(int entityIndex)Parameters
entityIndex int
Reserve(int)
Reserve this pool for the peak of its type: count components fit without further growth, on any entity slot below ReservedEntities (or below count, when that is larger). The dense arrays (entities, data, change versions when tracked) get exactly count slots and the sparse array covers the reserved entity slots — also after a later ReserveEntities(), which extends it. Every filter whose Inc types are now all reserved is reserved with them (ReservedCount). Never shrinks; a repeated call only raises ReservedComponents. Allocates; call at load time.
public void Reserve(int count)Parameters
count int
Number of components to have room for. 0 does nothing.
Remarks
Reserve the types whose count changes during play. A type that is not reserved costs nothing up front and grows on demand: its first component on a high entity index grows its sparse array to that index, a larger count grows its dense arrays. A singleton created at load needs no reserve.
The cost is count × (4 bytes + the component size, + 4 when change versions are tracked) for the dense side and 4 bytes per reserved entity slot for the sparse side, plus 4 bytes per slot and per matching entity for each filter it completes.
Like growth during Add, a Reserve that grows the dense arrays moves the components to new arrays: a ref from Get/Add/Modify and the RawData and [`RawEntities`](KenseiECS.ComponentPoolBase.md#KenseiECS_ComponentPoolBase_RawEntities) arrays taken before it no longer reach the pool, and neither does a [`Entities`](KenseiECS.Filter.md#KenseiECS_Filter_Entities) span of a filter it grows. A running foreach over a filter is not affected. If an allocation fails (`OutOfMemoryException`), the pool keeps working (with arrays grown before the failure) and its reserve, and that of the filters over its type, is not raised. Under KENSEI_DEBUG growth past the reserve is counted in [`GrowthsAfterReserve`](KenseiECS.World.md#KenseiECS_World_GrowthsAfterReserve).
Exceptions
When count is negative.
When the pool's world was destroyed.
When an array of the pool or of a filter it reserves cannot be allocated; the pool keeps working and its reserve is not raised, so a repeated call tries again.
