Owns entity lifetime and deferred destruction for a scene or subsystem.
More...
#include <EntityContainer.h>
|
| virtual | ~EntityContainer () |
| | Destroys all remaining container-owned entities.
|
template<class T, typename... Args>
requires std::is_base_of_v<Entity, T> && std::is_constructible_v<T, Args...> |
| T * | spawnEntity (Args &&... args) |
| | Constructs and adopts an entity owned by this container.
|
template<class T>
requires std::is_base_of_v<Entity, T> |
| T * | adoptEntity (std::unique_ptr< T > entity) |
| | Adopts an existing entity and starts its engine lifecycle.
|
| void | destroyEntity (Entity *entity) |
| | Queues an entity for deferred destruction.
|
| void | destroyEntityImmediate (Entity *entity) |
| | Destroys an entity immediately.
|
| void | flushPendingEntityDestruction () |
| | Destroys all entities queued for deferred destruction.
|
| void | cleanupEntities () |
| | Destroys all container-owned entities and clears pending destruction.
|
| void | reserve (std::size_t capacity) |
| | Reserves entity storage capacity.
|
| std::vector< Entity * > | getEntities () const |
| | Returns raw pointers to all live entities.
|
| std::uint64_t | getRevision () const |
| | Returns the container revision incremented by ownership changes.
|
| template<typename Func> |
| void | forEachEntity (Func &&func) const |
| | Invokes a callback for each live entity.
|
Owns entity lifetime and deferred destruction for a scene or subsystem.
Definition at line 20 of file EntityContainer.h.
◆ ~EntityContainer()
| virtual Engine::Entities::EntityContainer::~EntityContainer |
( |
| ) |
|
|
virtual |
Destroys all remaining container-owned entities.
◆ adoptEntity()
template<class T>
requires std::is_base_of_v<
Entity, T>
| T * Engine::Entities::EntityContainer::adoptEntity |
( |
std::unique_ptr< T > | entity | ) |
|
|
inline |
Adopts an existing entity and starts its engine lifecycle.
- Template Parameters
-
- Parameters
-
| entity | Entity instance to take ownership of. |
- Returns
- Pointer to the adopted entity, or nullptr if adoption fails.
Definition at line 50 of file EntityContainer.h.
References entities_, onEntitySpawned(), and revision_.
Referenced by spawnEntity().
◆ cleanupEntities()
| void Engine::Entities::EntityContainer::cleanupEntities |
( |
| ) |
|
Destroys all container-owned entities and clears pending destruction.
◆ destroyEntity()
| void Engine::Entities::EntityContainer::destroyEntity |
( |
Entity * | entity | ) |
|
Queues an entity for deferred destruction.
- Parameters
-
| entity | Container-owned entity to destroy. |
◆ destroyEntityImmediate()
| void Engine::Entities::EntityContainer::destroyEntityImmediate |
( |
Entity * | entity | ) |
|
Destroys an entity immediately.
- Parameters
-
| entity | Container-owned entity to destroy. |
◆ flushPendingEntityDestruction()
| void Engine::Entities::EntityContainer::flushPendingEntityDestruction |
( |
| ) |
|
Destroys all entities queued for deferred destruction.
◆ forEachEntity()
template<typename Func>
| void Engine::Entities::EntityContainer::forEachEntity |
( |
Func && | func | ) |
const |
|
inline |
Invokes a callback for each live entity.
- Template Parameters
-
| Func | Callable type accepting Entity*. |
- Parameters
-
| func | Callback invoked for each entity. |
Definition at line 119 of file EntityContainer.h.
References entities_.
◆ getEntities()
| std::vector< Entity * > Engine::Entities::EntityContainer::getEntities |
( |
| ) |
const |
|
nodiscard |
Returns raw pointers to all live entities.
◆ getRevision()
| std::uint64_t Engine::Entities::EntityContainer::getRevision |
( |
| ) |
const |
|
inlinenodiscard |
◆ onEntityDestroyed()
| virtual void Engine::Entities::EntityContainer::onEntityDestroyed |
( |
Entity & | entity | ) |
|
|
protectedvirtual |
Called before an entity is removed from the container.
- Parameters
-
| entity | Entity being destroyed. |
◆ onEntitySpawned()
| virtual void Engine::Entities::EntityContainer::onEntitySpawned |
( |
Entity & | entity | ) |
|
|
protectedvirtual |
Called after an entity is adopted and before begin play.
- Parameters
-
| entity | Newly spawned entity. |
Referenced by adoptEntity().
◆ reserve()
| void Engine::Entities::EntityContainer::reserve |
( |
std::size_t | capacity | ) |
|
Reserves entity storage capacity.
- Parameters
-
| capacity | Target entity capacity. |
◆ spawnEntity()
template<class T, typename... Args>
requires std::is_base_of_v<
Entity, T> && std::is_constructible_v<T, Args...>
| T * Engine::Entities::EntityContainer::spawnEntity |
( |
Args &&... | args | ) |
|
|
inline |
Constructs and adopts an entity owned by this container.
- Template Parameters
-
| T | Entity type to construct. |
- Parameters
-
| args | Arguments forwarded to T's constructor. |
- Returns
- Pointer to the spawned entity, or nullptr if adoption fails.
Definition at line 36 of file EntityContainer.h.
References adoptEntity().
◆ entities_
| std::vector<std::unique_ptr<Entity> > Engine::Entities::EntityContainer::entities_ |
|
private |
◆ pendingDestroyEntities_
| std::vector<Entity *> Engine::Entities::EntityContainer::pendingDestroyEntities_ |
|
private |
◆ revision_
| std::uint64_t Engine::Entities::EntityContainer::revision_ = 0 |
|
private |
The documentation for this class was generated from the following file: