Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Entities::EntityContainer Class Reference

Owns entity lifetime and deferred destruction for a scene or subsystem. More...

#include <EntityContainer.h>

Collaboration diagram for Engine::Entities::EntityContainer:

Public Member Functions

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.

Protected Member Functions

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.

Private Attributes

std::vector< std::unique_ptr< Entity > > entities_
std::vector< Entity * > pendingDestroyEntities_
std::uint64_t revision_ = 0

Detailed Description

Owns entity lifetime and deferred destruction for a scene or subsystem.

Definition at line 20 of file EntityContainer.h.

Constructor & Destructor Documentation

◆ ~EntityContainer()

virtual Engine::Entities::EntityContainer::~EntityContainer ( )
virtual

Destroys all remaining container-owned entities.

Member Function Documentation

◆ 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
TEntity type to adopt.
Parameters
entityEntity 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
entityContainer-owned entity to destroy.

◆ destroyEntityImmediate()

void Engine::Entities::EntityContainer::destroyEntityImmediate ( Entity * entity)

Destroys an entity immediately.

Parameters
entityContainer-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
FuncCallable type accepting Entity*.
Parameters
funcCallback 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

Returns the container revision incremented by ownership changes.

Definition at line 111 of file EntityContainer.h.

References revision_.

◆ onEntityDestroyed()

virtual void Engine::Entities::EntityContainer::onEntityDestroyed ( Entity & entity)
protectedvirtual

Called before an entity is removed from the container.

Parameters
entityEntity being destroyed.

◆ onEntitySpawned()

virtual void Engine::Entities::EntityContainer::onEntitySpawned ( Entity & entity)
protectedvirtual

Called after an entity is adopted and before begin play.

Parameters
entityNewly spawned entity.

Referenced by adoptEntity().

Here is the caller graph for this function:

◆ reserve()

void Engine::Entities::EntityContainer::reserve ( std::size_t capacity)

Reserves entity storage capacity.

Parameters
capacityTarget 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
TEntity type to construct.
Parameters
argsArguments 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().

Here is the call graph for this function:

Member Data Documentation

◆ entities_

std::vector<std::unique_ptr<Entity> > Engine::Entities::EntityContainer::entities_
private

Definition at line 144 of file EntityContainer.h.

Referenced by adoptEntity(), and forEachEntity().

◆ pendingDestroyEntities_

std::vector<Entity *> Engine::Entities::EntityContainer::pendingDestroyEntities_
private

Definition at line 145 of file EntityContainer.h.

◆ revision_

std::uint64_t Engine::Entities::EntityContainer::revision_ = 0
private

Definition at line 146 of file EntityContainer.h.

Referenced by adoptEntity(), and getRevision().


The documentation for this class was generated from the following file:
  • /workspace/magerbeton/gl3-vulkan/code/Engine/include/Engine/Entity/EntityContainer.h