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
Dispose is load-bearing for writes (#1531, PS-10): a cluster whose ClusterRef<TArch> handed out writable memory
(GetSpan, Get) has its page recorded when the enumerator leaves it — by MoveNext(), or by Dispose() for the last
one. A hand-driven loop that stops early without disposing leaves that page unrecorded, and a write in it can be lost at eviction.
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.
Own pending work (CLUSTERWALK-04): an enumerator created through a Transaction never yields an entity that transaction destroyed and has not committed — MoveNext() takes each cluster's occupancy minus those slots, and skips a cluster it leaves empty — exactly as the transaction's point access and queries treat it. A destroy made mid-walk applies from the next cluster. Another transaction's uncommitted destroy hides nothing. Entities the transaction spawned and has not committed are NOT yielded: they hold no slot data until PUBLISH (point access and queries see them).
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>
Remarks
Scoped to this enumerator: the ref reports writes through memory it hands out back to it (#1531).
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, and clusters holding only the walking transaction's own pending destroys
(CLUSTERWALK-04). Guarantees Current.OccupancyBits != 0 when returning true.
public bool MoveNext()