DragonECS provides two main types of entity collections for iterating and managing entities:
EcsSpan
A read-only, stack-allocated collection of entities. It is similar to ReadOnlySpan<int> and is returned by standard Where queries. It supports foreach and for iteration. It does not allow duplicate entities.
EcsGroup
A collection based on a Sparse Set, optimized for $O(1)$ additions, removals, and checks. Groups are managed by a pool within EcsWorld.
Key Operations for EcsGroup:
group.Add(entityID): Adds an entity.group.Has(entityID): Checks if an entity is in the group.group.Remove(entityID): Removes an entity.group.Dispose(): Returns the group to the pool.
Set Operations (implements ISet<int>):
Groups support set algebra (Union, Intersect, Except, SymmetricExcept, and Inverse) both in-place (e.g., groupA.UnionWith(groupB)) and by returning a new group (e.g., EcsGroup.Union(groupA, groupB)).
Querying into a Group:
Use _world.WhereToGroup(out TAspect aspect) to return an EcsReadonlyGroup.
// EcsSpan usage
EcsSpan es = _world.Where(out Aspect a);
foreach (var e in es) { /* ... */ }
// EcsGroup usage
EcsGroup group = EcsGroup.New(_world);
group.Add(entityID);
if (group.Has(entityID)) { /* ... */ }
group.Dispose();
// Set operations
groupA.UnionWith(groupB);
EcsGroup newGroup = EcsGroup.Intersect(groupA, groupB);