ComponentPool Class
Definition
Namespace: Brine2D.ECS
Stores all components of a specific type for a single scene-scoped EntityWorld. All access is game-thread-only via EntityWorld; no synchronization is required. Provides ArrayPool-based snapshots for zero-allocation iteration.
Type parameters
T
The component type.
Inheritance System.Object → ComponentPool\<T>
Remarks
\<b>Iteration order.\</b> The underlying storage is a System.Collections.Generic.Dictionary<>, whose enumeration order is unspecified and may vary between runs, runtime versions, and insertion sequences. Do not rely on iteration order for correctness. If your system applies cumulative effects where order affects the result \(e\.g\., damage stacking, collision priority\), sort the results explicitly or use a deterministic data structure.
| Methods | |
|---|---|
| All() | Returns all component entries as a materialized list. Allocates a new list on every call; for hot-path iteration prefer GetTypedSnapshot() + Brine2D.ECS.ComponentPool<>.ReturnTypedSnapshot\(System\.ValueTuple\{System\.Int64,@0\}\[\]\) directly. |
| GetEntityIdSnapshot() | Creates an ArrayPool snapshot of entity IDs only, for type-erased iteration. MUST call ReturnEntityIdSnapshot\(long\[\]\) in a finally block. |
| GetTypedSnapshot() | Creates a strongly-typed ArrayPool snapshot for iteration. Avoids the System.Array boxing round-trip of GetSnapshot. MUST call Brine2D.ECS.ComponentPool<>.ReturnTypedSnapshot\(System\.ValueTuple\{System\.Int64,@0\}\[\]\) in a finally block. |
| ReturnEntityIdSnapshot\(long\[\]\) | Returns an entity-ID snapshot to the ArrayPool. MUST be called after GetEntityIdSnapshot() to prevent memory leaks. |