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

The entity class is the base class of everything which is attached to a scene. If it is part of a scene it is an entity. More...

#include <Entity.h>

Inheritance diagram for Engine::Entities::Entity:
Collaboration diagram for Engine::Entities::Entity:

Public Member Functions

 Entity ()
 Creates an entity in the constructed lifecycle state.
 ~Entity () override
 Destroys the entity and owned logic components.
void enableTick (bool enable)
 Enables or disables ticking for this entity.
void setTickPriority (int32_t priority)
 Sets the tick ordering priority for this entity.
int32_t getTickPriority () const
 Returns the tick ordering priority for this entity.
void tick (double deltaTime) override
 Executes every frame if tick is enabled.
void destroy ()
 Tells the scene to destroy this Entity.
void destroyImmediate ()
 Destroys this entity immediately through its owning container.
EntityContainer * getOwningContainer () const
 Returns the container that owns this entity.
bool isPendingDestroy () const
 Returns whether this entity has been queued for destruction.
bool isPlaying () const
 Returns whether this entity has begun play and has not ended play.
template<typename T, typename... Args>
requires std::is_base_of_v<Components::Logic, T> && std::is_constructible_v<T, Args...>
T * addComponent (Args &&... args)
 Adds a component to the entity. Checks for uniqueness if the component defines 'static constexpr bool IsUnique = true;'.
template<typename T>
requires std::is_base_of_v<Components::Logic, T>
T * getComponent () const
 Returns the first component of type T found.
template<typename T>
requires std::is_base_of_v<Components::Logic, T>
std::vector< T * > getComponents () const
 Returns all components of type T.
void removeComponent (Components::Logic *component)
 Removes a specific component instance.
template<typename T>
requires std::is_base_of_v<Components::Logic, T>
bool removeFirstComponent ()
 Removes the first component of type T found.
template<typename T>
requires std::is_base_of_v<Components::Logic, T>
bool hasComponent () const
 Checks if a component of type T exists.
const std::vector< std::unique_ptr< Components::Logic > > & getAllComponents () const
 Gets all components on this entity.
bool canTick () const
 Tells you if the entity can execute its tick function.
bool canEverTick () const
 Tells if this entity can ever tick.
entt::entity getEcsEntity () const
 Gets the ECS entity handle for this Entity.
Public Member Functions inherited from Engine::Core::ITickable
virtual ~ITickable ()=default
 Destroys a tickable object.
virtual void preTick ()
 Function which executes immediately before the execution of ITickable::preTick()
virtual void postTick ()
 Function which executes immediately after the execution of ITickable::postTick()

Protected Member Functions

virtual void onEngineBeginPlay ()
 Hook called when the engine begins play for this entity.
virtual void onEngineEndPlay ()
 Hook called when the engine ends play for this entity.
virtual void onEngineDestroyed ()
 Hook called when the entity is being destroyed by the engine lifecycle.

Protected Attributes

std::vector< std::unique_ptr< Components::Logic > > components_
 List of all logical components.
entt::entity data_ = entt::null
 ECS entity handle associated with this entity.
bool allowTicking_ = false
 Whether ticking is currently enabled.
int32_t tickPriority_ = 0
 Priority used to order entity ticks.

Private Types

enum class  LifecycleState {
  Constructed ,
  Playing ,
  PendingDestroy ,
  Destroying ,
  Destroyed
}

Private Member Functions

void engineBeginPlay ()
void engineEndPlay ()
bool isDestroyingOrDestroyed () const

Private Attributes

EntityContainer * owningContainer_ = nullptr
LifecycleState lifecycleState_ = LifecycleState::Constructed

Detailed Description

The entity class is the base class of everything which is attached to a scene. If it is part of a scene it is an entity.

Definition at line 18 of file Entity.h.

Member Enumeration Documentation

◆ LifecycleState

enum class Engine::Entities::Entity::LifecycleState
strongprivate
Enumerator
Constructed 
Playing 
PendingDestroy 
Destroying 
Destroyed 

Definition at line 239 of file Entity.h.

Constructor & Destructor Documentation

◆ Entity()

Engine::Entities::Entity::Entity ( )

Creates an entity in the constructed lifecycle state.

◆ ~Entity()

Engine::Entities::Entity::~Entity ( )
override

Destroys the entity and owned logic components.

Member Function Documentation

◆ addComponent()

template<typename T, typename... Args>
requires std::is_base_of_v<Components::Logic, T> && std::is_constructible_v<T, Args...>
T * Engine::Entities::Entity::addComponent ( Args &&... args)
inline

Adds a component to the entity. Checks for uniqueness if the component defines 'static constexpr bool IsUnique = true;'.

Template Parameters
TThe type of component to add (must derive from LogicComponent).
ArgsArguments to forward to the component constructor.
Returns
Pointer to the added (or existing unique) component.

Definition at line 88 of file Entity.h.

References components_, getComponent(), and isPlaying().

Referenced by Engine::Entities::Actor::addComponent(), Engine::Entities::Actor::addComponentWithSceneEntityFirstNodeRest(), and Engine::Entities::Actor::~Actor().

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

◆ canEverTick()

bool Engine::Entities::Entity::canEverTick ( ) const
nodiscard

Tells if this entity can ever tick.

Returns
true if it can ever tick

◆ canTick()

bool Engine::Entities::Entity::canTick ( ) const
nodiscard

Tells you if the entity can execute its tick function.

Returns
true if it can tick

◆ destroy()

void Engine::Entities::Entity::destroy ( )

Tells the scene to destroy this Entity.

◆ destroyImmediate()

void Engine::Entities::Entity::destroyImmediate ( )

Destroys this entity immediately through its owning container.

◆ enableTick()

void Engine::Entities::Entity::enableTick ( bool enable)

Enables or disables ticking for this entity.

Parameters
enabledisable or enable ticking

◆ engineBeginPlay()

void Engine::Entities::Entity::engineBeginPlay ( )
private

◆ engineEndPlay()

void Engine::Entities::Entity::engineEndPlay ( )
private

◆ getAllComponents()

const std::vector< std::unique_ptr< Components::Logic > > & Engine::Entities::Entity::getAllComponents ( ) const
inlinenodiscard

Gets all components on this entity.

Returns
Read-only reference to the component list.

Definition at line 189 of file Entity.h.

References components_.

◆ getComponent()

template<typename T>
requires std::is_base_of_v<Components::Logic, T>
T * Engine::Entities::Entity::getComponent ( ) const
inline

Returns the first component of type T found.

Returns
Pointer to component or nullptr if not found.

Definition at line 116 of file Entity.h.

References components_.

Referenced by addComponent(), and hasComponent().

Here is the caller graph for this function:

◆ getComponents()

template<typename T>
requires std::is_base_of_v<Components::Logic, T>
std::vector< T * > Engine::Entities::Entity::getComponents ( ) const
inline

Returns all components of type T.

Returns
Vector of pointers to components of type T.

Definition at line 131 of file Entity.h.

References components_.

◆ getEcsEntity()

entt::entity Engine::Entities::Entity::getEcsEntity ( ) const
inlinenodiscard

Gets the ECS entity handle for this Entity.

Returns
The entt::entity handle.

Definition at line 209 of file Entity.h.

References data_.

◆ getOwningContainer()

EntityContainer * Engine::Entities::Entity::getOwningContainer ( ) const
nodiscard

Returns the container that owns this entity.

References EntityContainer.

Here is the call graph for this function:

◆ getTickPriority()

int32_t Engine::Entities::Entity::getTickPriority ( ) const
inlinenodiscard

Returns the tick ordering priority for this entity.

Definition at line 45 of file Entity.h.

References tickPriority_.

◆ hasComponent()

template<typename T>
requires std::is_base_of_v<Components::Logic, T>
bool Engine::Entities::Entity::hasComponent ( ) const
inline

Checks if a component of type T exists.

Returns
true if found.

Definition at line 181 of file Entity.h.

References getComponent().

Here is the call graph for this function:

◆ isDestroyingOrDestroyed()

bool Engine::Entities::Entity::isDestroyingOrDestroyed ( ) const
nodiscardprivate

◆ isPendingDestroy()

bool Engine::Entities::Entity::isPendingDestroy ( ) const
nodiscard

Returns whether this entity has been queued for destruction.

◆ isPlaying()

bool Engine::Entities::Entity::isPlaying ( ) const
nodiscard

Returns whether this entity has begun play and has not ended play.

Referenced by addComponent().

Here is the caller graph for this function:

◆ onEngineBeginPlay()

virtual void Engine::Entities::Entity::onEngineBeginPlay ( )
protectedvirtual

Hook called when the engine begins play for this entity.

Reimplemented in Engine::Entities::Actor.

◆ onEngineDestroyed()

virtual void Engine::Entities::Entity::onEngineDestroyed ( )
protectedvirtual

Hook called when the entity is being destroyed by the engine lifecycle.

Reimplemented in Engine::Entities::Actor.

◆ onEngineEndPlay()

virtual void Engine::Entities::Entity::onEngineEndPlay ( )
protectedvirtual

Hook called when the engine ends play for this entity.

Reimplemented in Engine::Entities::Actor.

◆ removeComponent()

void Engine::Entities::Entity::removeComponent ( Components::Logic * component)
inline

Removes a specific component instance.

Parameters
componentPointer to the component to remove.

Definition at line 145 of file Entity.h.

References components_.

◆ removeFirstComponent()

template<typename T>
requires std::is_base_of_v<Components::Logic, T>
bool Engine::Entities::Entity::removeFirstComponent ( )
inline

Removes the first component of type T found.

Returns
true if a component was removed, false otherwise.

Definition at line 162 of file Entity.h.

References components_.

◆ setTickPriority()

void Engine::Entities::Entity::setTickPriority ( int32_t priority)

Sets the tick ordering priority for this entity.

Parameters
priorityTick priority value.

◆ tick()

void Engine::Entities::Entity::tick ( double deltaTime)
overridevirtual

Executes every frame if tick is enabled.

Parameters
deltaTimetime between the last frame and this frame

Reimplemented from Engine::Core::ITickable.

Member Data Documentation

◆ allowTicking_

bool Engine::Entities::Entity::allowTicking_ = false
protected

Whether ticking is currently enabled.

Definition at line 219 of file Entity.h.

◆ components_

std::vector<std::unique_ptr<Components::Logic> > Engine::Entities::Entity::components_
protected

List of all logical components.

Definition at line 215 of file Entity.h.

Referenced by addComponent(), getAllComponents(), getComponent(), getComponents(), removeComponent(), and removeFirstComponent().

◆ data_

entt::entity Engine::Entities::Entity::data_ = entt::null
protected

ECS entity handle associated with this entity.

Definition at line 217 of file Entity.h.

Referenced by Engine::Entities::Actor::addComponent(), Engine::Entities::Actor::addComponentWithSceneEntityFirstNodeRest(), and getEcsEntity().

◆ lifecycleState_

LifecycleState Engine::Entities::Entity::lifecycleState_ = LifecycleState::Constructed
private

Definition at line 254 of file Entity.h.

◆ owningContainer_

EntityContainer* Engine::Entities::Entity::owningContainer_ = nullptr
private

Definition at line 253 of file Entity.h.

◆ tickPriority_

int32_t Engine::Entities::Entity::tickPriority_ = 0
protected

Priority used to order entity ticks.

Definition at line 220 of file Entity.h.

Referenced by getTickPriority().


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