Struct ClusterEnumerator<TArch>
Iterates active clusters for an archetype. Owns a Typhon.Engine.Internals.ChunkAccessor<TStore> — must be disposed.
public ref struct ClusterEnumerator<TArch> where TArch : class
Type Parameters
TArch
- Inherited Members
Remarks
Supports foreach via GetEnumerator().
Non-empty guarantee: the enumerator always yields clusters with OccupancyBits != 0 (i.e. LiveCount >= 1). Empty clusters can exist
in ActiveClusterIds during the fence's deferred-drain window — between Migrate (last slot released) and Finalize (chunk freed) — but
MoveNext() filters them out so callers never observe a drained cluster.
Usage:
foreach (var cluster in ants.GetClusterEnumerator())
{
var positions = cluster.GetSpan<Position>(Ant.Position);
ulong bits = cluster.OccupancyBits; // guaranteed non-zero
while (bits != 0)
{
int slot = BitOperations.TrailingZeroCount(bits);
bits &= bits - 1;
// ...
}
}
Properties
Current
Get the current cluster ref.
public ClusterRef<TArch> Current { get; }
Property Value
- ClusterRef<TArch>
CurrentChunkId
The chunk ID of the current cluster. Available after MoveNext() returns true.
public int CurrentChunkId { get; }
Property Value
Methods
Dispose()
Release the ChunkAccessors.
public void Dispose()
GetEnumerator()
Enable foreach.
public ClusterEnumerator<TArch> GetEnumerator()
Returns
- ClusterEnumerator<TArch>
MarkCurrentDirty()
Mark all occupied slots in the current cluster as dirty. Call this after writing to component data via
GetSpan<T>(Comp<T>) — the direct cluster path does not set dirty bits automatically.
Without this call, DetectClusterMigrations and the WAL tick fence will not see the changes.
public void MarkCurrentDirty()
MarkSlotDirty(int)
Mark a single slot in the current cluster as dirty. More precise than MarkCurrentDirty() — use when only specific entities changed (e.g., after a cell-boundary crossing check). The slot index is the bit position from the OccupancyBits TZCNT loop.
public void MarkSlotDirty(int slotIndex)
Parameters
slotIndexint
MoveNext()
Advance to the next active cluster in the range, skipping drained clusters (OccupancyBits == 0) left in
ActiveClusterIds by the fence's deferred-drain window. Guarantees Current.OccupancyBits != 0 when returning true.
public bool MoveNext()