Table of Contents

Struct AabbClusterEnumerator

Namespace
Typhon.Engine
Assembly
Typhon.Engine.dll

Zero-allocation f32 AABB query enumerator over the per-cell cluster spatial index of a single archetype (issue #230 Phase 3). Shared between the game-facing generic entry point AABB<TBox>(in TBox, uint) and the engine-facing non-generic entry point QueryAabb(SpatialGrid, float, float, float, float, float, float, uint). Handles both 2D (AABB2F / BSphere2F) and 3D (AABB3F / BSphere3F) cluster storage tiers through a single state machine — the 3D overlap test is a strict superset of the 2D test, and 2D archetypes are queried with an infinite Z range that trivially passes the Z component of the overlap check.

public ref struct AabbClusterEnumerator
Inherited Members

Remarks

The state machine is three-phase per call to MoveNext(): (1) drain the current cluster's occupancy bits and test each entity's tight bounds against the query AABB (narrowphase), (2) advance to the next cluster in the current cell's Typhon.Engine.Internals.CellSpatialIndex and apply broadphase AABB + category mask filtering, (3) advance to the next cell in the query's overlap range and look up the archetype's per-cell slot.

Tier handling. The narrowphase branches on FieldType to unpack entity coordinates correctly: 2D fields write 4 doubles [minX, minY, maxX, maxY] via Typhon.Engine.Internals.SpatialMaintainer.ReadAndValidateBoundsFromPtr(System.Byte*,Typhon.Engine.SpatialFieldInfo,System.Span{System.Double},Typhon.Engine.Internals.SpatialNodeDescriptor) while 3D fields write 6 doubles [minX, minY, minZ, maxX, maxY, maxZ]. The storage layer (ClusterSpatialAabb / Typhon.Engine.Internals.CellSpatialIndex) uses unified 6-float storage, so the broadphase overlap test always runs in 3D and implicitly handles 2D via infinite Z sentinels.

Epoch scope. The caller must be inside an Typhon.Engine.Internals.EpochGuard scope; the enumerator creates a Typhon.Engine.Internals.ChunkAccessor<TStore> on the cluster segment to read entity bounds during the narrowphase pass. The accessor is lazily opened on the first broadphase hit to keep empty-result queries allocation-free.

Phase 3 history. Originally introduced as a nested ClusterSpatialQuery<TArch>.AABBEnumerator ref struct, hoisted out of the generic outer type as Aabb2fEnumerator during Phase 3 scaffolding, then unified to handle both 2D and 3D when the 3D-blocker scope discovery showed existing cluster archetypes depend on 3D bounds via the legacy per-entity tree.

Properties

Current

The most recently yielded result. Valid only after MoveNext() returns true.

public ClusterSpatialQueryResult Current { get; }

Property Value

ClusterSpatialQueryResult

Methods

Dispose()

Dispose the narrowphase accessor if one was opened. Called automatically by foreach on a ref struct that implements this method.

public void Dispose()

GetEnumerator()

Enumerator pattern: a ref struct enumerator is its own source.

public AabbClusterEnumerator GetEnumerator()

Returns

AabbClusterEnumerator

MoveNext()

Advance to the next matching entity. Returns false when the query is exhausted.

public bool MoveNext()

Returns

bool