3#include "Engine/Entity/Entity.h"
34 template <
class T,
typename... Args>
35 requires std::is_base_of_v<Entity, T> && std::is_constructible_v<T, Args...>
38 auto entity = std::make_unique<T>( std::forward<Args>( args )... );
49 requires std::is_base_of_v<Entity, T>
52 if ( entity ==
nullptr )
54 PLOGW <<
"Attempted to adopt a null entity.";
58 if ( entity->owningContainer_ !=
nullptr )
60 PLOGW <<
"Attempted to adopt an entity that already has an owning container.";
64 T * rawEntity = entity.get();
65 rawEntity->owningContainer_ =
this;
66 entities_.push_back( std::move( entity ) );
70 rawEntity->engineBeginPlay();
118 template<
typename Func>
123 if (entity !=
nullptr)
Owns entity lifetime and deferred destruction for a scene or subsystem.
void destroyEntity(Entity *entity)
Queues an entity for deferred destruction.
void destroyEntityImmediate(Entity *entity)
Destroys an entity immediately.
virtual void onEntitySpawned(Entity &entity)
Called after an entity is adopted and before begin play.
virtual void onEntityDestroyed(Entity &entity)
Called before an entity is removed from the container.
std::vector< std::unique_ptr< Entity > > entities_
void flushPendingEntityDestruction()
Destroys all entities queued for deferred destruction.
void reserve(std::size_t capacity)
Reserves entity storage capacity.
void forEachEntity(Func &&func) const
Invokes a callback for each live entity.
void cleanupEntities()
Destroys all container-owned entities and clears pending destruction.
std::vector< Entity * > pendingDestroyEntities_
T * adoptEntity(std::unique_ptr< T > entity)
Adopts an existing entity and starts its engine lifecycle.
std::uint64_t getRevision() const
Returns the container revision incremented by ownership changes.
virtual ~EntityContainer()
Destroys all remaining container-owned entities.
std::vector< Entity * > getEntities() const
Returns raw pointers to all live entities.
T * spawnEntity(Args &&... args)
Constructs and adopts an entity owned by this container.
The entity class is the base class of everything which is attached to a scene. If it is part of a sce...