EntityWorld Class
Default implementation of IEntityWorld. Uses a deferred operations pattern. Structural changes (create/destroy) are queued during frame execution and applied at frame boundaries. Targets 1,000-10,000+ entities with a straightforward mental model.
internal class EntityWorld : Brine2D.ECS.IEntityWorld, System.IDisposable
Inheritance System.Object → EntityWorld
Implements IEntityWorld, System.IDisposable
| Methods | |
|---|---|
| AddSystem<T>(Action<T>) | Adds a system to this world, automatically creating it with dependency injection. Systems that implement IUpdateSystem are added to the update pipeline. Systems that implement IFixedUpdateSystem are added to the fixed update pipeline. Systems that implement IRenderSystem are added to the render pipeline. Systems can implement multiple interfaces. |
| Clear() | Clears all entities and systems from the world. Entities are destroyed in a single pass (no deferred round-trip), then all internal state is reset. The world remains usable after this call. |
| ClearEntities() | Destroys all entities but keeps systems intact. Use for scene resets where the system pipeline should remain unchanged. |
| CreateEntity(string) | Creates a new entity and queues it for initialization. |
| CreateEntity<T>(string) | Creates a new entity and queues it for initialization. |
| Dispose() | Releases all internal references, runs entity lifecycle callbacks, and disposes systems. Called automatically by the DI scope when the scene is unloaded. Entities receive OnDestroy() so cleanup logic (event unsubscription, behavior detach, etc.) runs even without an explicit Clear() call. |
| DisposeAndClearSystems() | Disposes all systems and clears all pipelines. Systems that implement multiple pipeline interfaces are disposed exactly once. |
| GetEntitiesWithComponent<T>() | |
| GetEntitiesWithComponents<T1,T2>() | |
| GetEntityByName(string) | |
| GetPoolsAssignableTo(Type) | Returns all non-empty pools whose component type is assignable to componentType. Used by queries for polymorphic iteration. |
| GetPoolsAssignableTo(Type, List<IComponentPool>) | Populates result with all non-empty pools whose component type is assignable to componentType. Caller owns the list and can reuse it across rebuilds to avoid per-call allocation. |
| GetTotalPoolCount(Type) | Returns the combined entity count across all pools whose component type is assignable to componentType (including itself). |
| PruneTypeHierarchy(Type) | Removes concreteType from the type hierarchy index. Mirror of RegisterTypeHierarchy(Type); called when a pool is emptied and removed so that the hierarchy does not accumulate stale entries. |
| RegisterTypeHierarchy(Type) | Registers concreteType in the type hierarchy index under itself and every ancestor up to (but not including) Component. Called once when a new pool is created. |
| RemoveSystem(ISystem) | Removes a system from this world. If the system implements multiple pipeline interfaces it will be removed from all. Disposal is deferred until the next Brine2D.ECS.EntityWorld.ProcessDeferredOperations call so that systems are never disposed while the update/render loop is iterating. |
| RemoveSystem<T>() | Removes a system of the specified type from this world. If the system implements multiple pipeline interfaces it will be removed from all. |
| TeardownEntities() | Shared entity teardown used by both Clear() and Dispose(). Flushes pending changes, runs OnDestroy() on every entity, and resets all entity-related state. |
| UnregisterCachedQuery(ICachedQuery) | Removes a cached query from the invalidation index. Called by CachedEntityQuery<T1>.Dispose() and its siblings so that queries removed mid-scene (e.g., when a system is unregistered) stop receiving invalidation notifications and are eligible for GC. |