CoriEngine
Loading...
Searching...
No Matches
Cori::World::Entity Class Reference

Entities are the essential part of WorldSystem. More...

#include <Entity.hpp>

Public Member Functions

 Entity ()=default
 Entity (entt::handle handle)
template<typename T, typename... Args>
T & AddComponent (Args &&... args)
 Adds a component to the entity.
template<typename T, typename... Args>
T & ReplaceComponent (Args &&... args)
 Replaces the component with a newly created one.
template<typename T, typename... Args>
T & AddOrReplaceComponent (Args &&... args)
 Adds a component to the entity, or replaces it if the entity already has this component.
template<typename... T>
decltype(auto) GetComponents ()
 Retries the references to the requested components of the entity.
template<typename... T>
decltype(auto) GetComponents () const
 Retries the references to the requested components of the entity. Const variant.
template<typename T, typename... Args>
T & GetOrAddComponent (Args &&... args)
 Retries or adds a component to the entity.
template<typename... T>
bool HasComponents () const
 Checks if the entity has all the specified components.
template<typename... T>
entt::handle::size_type RemoveComponents ()
 Removes components from the entity if entity has them.
template<typename... T>
void EraseComponents ()
 Erases components from the entity without checking if the entity actually have them.
 operator bool () const
bool operator== (const Entity &other) const
bool operator!= (const Entity &other) const
bool IsValid () const
 Checks if the actual entity behind this handle is valid.
void SetActive (const bool state)
 Changes the activity state of the entity.
bool IsActiveLocally () const
 Checks if the entity is active locally (doesn't have InactiveLocallyFlag), just a convenience function.
bool IsActiveGlobally () const
 Checks if the entity is active locally (doesn't have InactiveGloballyFlag), just a convenience function.
uint32_t GetID () const
 Gets the entity ID.
uint32_t GetVersion () const
 Gets the entity version.
uint64_t GetEUID () const
 Gets the EUID (entity unique ID). A combination of entity ID and version, it is unique for every entity.
uint32_t GetOwnerSceneID () const
 Retries the ID of the owner scene. You can get the actual SceneHandle by providing SceneManager with this ID (method: GetHandle).
std::string GetDebugData (bool showUUID=false) const
 Gets the debuting string for logging.
std::expected< void, Core::CoriError<> > SetParent (Entity parent)
 Links the entity to a parent entity.
std::expected< std::vector< Entity >, Core::CoriError<> > GetSiblings () const
 Creates and returns a vector containing all entity siblings.
std::expected< Entity, Core::CoriError<> > GetParent () const
 Retries the parent entity of the entity if any.
std::expected< std::vector< Entity >, Core::CoriError<> > GetChildren () const
 Creates and returns a vector containing all entity children (does not include grandchildren and so on, not recursive).
std::expected< Entity, Core::CoriError<> > FindChildByName (const char *name) const
 Finds a children entity by name.
std::expected< Entity, Core::CoriError<> > FindChildByName (const std::string_view name) const
 Finds a children entity by name.
std::expected< Entity, Core::CoriError<> > FindChildByName (const std::string &name) const
 Finds a children entity by name.
void DestroyChildren ()
 Destroys all children (and they grandchildren) that the entity has.
entt::entity GetRawEntity () const
 Gets a raw entt::entity if you need to interact with entt directly.
entt::handle GetRawHandle () const
 Gets a raw entt::handle if you need to interact with entt directly.
void PrintHierarchy () const
 Prints the full entity hierarchy tree in the console.
std::string_view GetName () const
 Retrieves the name of the entity.
void SetName (const std::string &name)
 Changes the entity name.
void UnlinkFromParent ()
 Unlinks the entity from its parent if it has one.

Protected Member Functions

void UpdateInactivityFlagsRecursive (entt::entity parent, bool parentIsActive)

Friends

class Scene

Detailed Description

Entities are the essential part of WorldSystem.

Entities can have a parent-children hierarchy that is represented by a left-child right-sibling binary tree internally.
Instance of Entity class does not control a lifetime of an actual entity, it lifetime is controlled by the Scene. Through this class you interact with an actual entity, it is sort of a now-owning handle.

Definition at line 25 of file Entity.hpp.

Constructor & Destructor Documentation

◆ Entity() [1/2]

Cori::World::Entity::Entity ( )
default

◆ Entity() [2/2]

Cori::World::Entity::Entity ( entt::handle handle)
inline

Definition at line 29 of file Entity.hpp.

Member Function Documentation

◆ AddComponent()

template<typename T, typename... Args>
T & Cori::World::Entity::AddComponent ( Args &&... args)
inline

Adds a component to the entity.

Template Parameters
TType of component to add.
ArgsDeduced automatically, no need to specify.
Parameters
argsArguments passed to the component constructor.
Returns
A reference to the newly created component.

Definition at line 39 of file Entity.hpp.

◆ AddOrReplaceComponent()

template<typename T, typename... Args>
T & Cori::World::Entity::AddOrReplaceComponent ( Args &&... args)
inline

Adds a component to the entity, or replaces it if the entity already has this component.

Template Parameters
TType of component to add or replace.
ArgsDeduced automatically, no need to specify.
Parameters
argsArguments passed to the component constructor.
Returns
A reference to the newly created or replaced component.

Definition at line 63 of file Entity.hpp.

◆ DestroyChildren()

void Cori::World::Entity::DestroyChildren ( )

Destroys all children (and they grandchildren) that the entity has.

Definition at line 106 of file Entity.cpp.

Here is the call graph for this function:

◆ EraseComponents()

template<typename... T>
void Cori::World::Entity::EraseComponents ( )
inline

Erases components from the entity without checking if the entity actually have them.

Template Parameters
TComponents to erase.
Warning
This method is dangerous, call it only when you absolutely sure that the entity has all the components you're trying to erase, if at least one component is absent it will cause a crash.

Definition at line 144 of file Entity.hpp.

◆ FindChildByName() [1/3]

std::expected< Entity, Core::CoriError<> > Cori::World::Entity::FindChildByName ( const char * name) const
nodiscard

Finds a children entity by name.

Parameters
nameName of the children to find.
Returns
Expected object with child entity with the specified name, or CoriError<> on failure.

Definition at line 94 of file Entity.cpp.

Here is the call graph for this function:

◆ FindChildByName() [2/3]

std::expected< Entity, Core::CoriError<> > Cori::World::Entity::FindChildByName ( const std::string & name) const
nodiscard

Finds a children entity by name.

Parameters
nameName of the children to find.
Returns
Expected object with child entity with the specified name, or CoriError<> on failure.

Definition at line 102 of file Entity.cpp.

Here is the call graph for this function:

◆ FindChildByName() [3/3]

std::expected< Entity, Core::CoriError<> > Cori::World::Entity::FindChildByName ( const std::string_view name) const
nodiscard

Finds a children entity by name.

Parameters
nameName of the children to find.
Returns
Expected object with child entity with the specified name, or CoriError<> on failure.

Definition at line 98 of file Entity.cpp.

Here is the call graph for this function:

◆ GetChildren()

std::expected< std::vector< Entity >, Core::CoriError<> > Cori::World::Entity::GetChildren ( ) const
nodiscard

Creates and returns a vector containing all entity children (does not include grandchildren and so on, not recursive).

Returns
Expected object with a vector of all children, or CoriError<> on failure.

Definition at line 90 of file Entity.cpp.

Here is the call graph for this function:

◆ GetComponents() [1/2]

template<typename... T>
decltype(auto) Cori::World::Entity::GetComponents ( )
inlinenodiscard

Retries the references to the requested components of the entity.

Template Parameters
TTypes of components to retrieve.
Note
When retrieving multiple components use structured binding. Also make sure you use receive by reference not by value.
Returns
References to the requested component(s).

Definition at line 74 of file Entity.hpp.

Here is the call graph for this function:

◆ GetComponents() [2/2]

template<typename... T>
decltype(auto) Cori::World::Entity::GetComponents ( ) const
inlinenodiscard

Retries the references to the requested components of the entity. Const variant.

Template Parameters
TTypes of components to retrieve.
Note
When retrieving multiple components use structured binding. Also make sure you use receive by const reference not by value.
Returns
References to the requested component(s).

Definition at line 92 of file Entity.hpp.

Here is the call graph for this function:

◆ GetDebugData()

std::string Cori::World::Entity::GetDebugData ( bool showUUID = false) const
nodiscard

Gets the debuting string for logging.

Parameters
showUUIDWhether to include UUID in the debugging string.
Returns
Formated debugging string.

Definition at line 65 of file Entity.cpp.

Here is the call graph for this function:

◆ GetEUID()

uint64_t Cori::World::Entity::GetEUID ( ) const
inlinenodiscard

Gets the EUID (entity unique ID). A combination of entity ID and version, it is unique for every entity.

Returns
EUID.

Definition at line 205 of file Entity.hpp.

Here is the call graph for this function:

◆ GetID()

uint32_t Cori::World::Entity::GetID ( ) const
inlinenodiscard

Gets the entity ID.

Returns
Entity ID.
Note
Entity IDs can be reused, to differentiate one entity from the other, you need to compare entity ID and entity version. To get a unique entity ID use GetEUID() method.

Definition at line 189 of file Entity.hpp.

◆ GetName()

std::string_view Cori::World::Entity::GetName ( ) const
nodiscard

Retrieves the name of the entity.

Returns
A view to the current entity name.

Definition at line 114 of file Entity.cpp.

Here is the call graph for this function:

◆ GetOrAddComponent()

template<typename T, typename... Args>
T & Cori::World::Entity::GetOrAddComponent ( Args &&... args)
inline

Retries or adds a component to the entity.

Template Parameters
TType of component to retrieve or add if absent.
ArgsDeduced automatically, no need to specify.
Parameters
argsArguments passed to the component constructor in case of addition of the component.
Returns
Reference to the added or received component.

Definition at line 112 of file Entity.hpp.

◆ GetOwnerSceneID()

uint32_t Cori::World::Entity::GetOwnerSceneID ( ) const
inlinenodiscard

Retries the ID of the owner scene. You can get the actual SceneHandle by providing SceneManager with this ID (method: GetHandle).

Returns
Owner SceneID.

Definition at line 213 of file Entity.hpp.

Here is the call graph for this function:

◆ GetParent()

std::expected< Entity, Core::CoriError<> > Cori::World::Entity::GetParent ( ) const
nodiscard

Retries the parent entity of the entity if any.

Returns
Expected object with the parent entity, or CoriError<> on failure.

Definition at line 82 of file Entity.cpp.

Here is the call graph for this function:

◆ GetRawEntity()

entt::entity Cori::World::Entity::GetRawEntity ( ) const
inlinenodiscard

Gets a raw entt::entity if you need to interact with entt directly.

Returns
Underlying entt::entity.
Warning
Use at your own risk and only if you know what you're doing.

Definition at line 280 of file Entity.hpp.

◆ GetRawHandle()

entt::handle Cori::World::Entity::GetRawHandle ( ) const
inlinenodiscard

Gets a raw entt::handle if you need to interact with entt directly.

Returns
Underlying entt::handle.
Warning
Use at your own risk and only if you know what you're doing.

Definition at line 287 of file Entity.hpp.

◆ GetSiblings()

std::expected< std::vector< Entity >, Core::CoriError<> > Cori::World::Entity::GetSiblings ( ) const
nodiscard

Creates and returns a vector containing all entity siblings.

Returns
Expected object with a vector of siblings, or CoriError<> on failure.

Definition at line 86 of file Entity.cpp.

Here is the call graph for this function:

◆ GetVersion()

uint32_t Cori::World::Entity::GetVersion ( ) const
inlinenodiscard

Gets the entity version.

Returns
Entity version.

Definition at line 197 of file Entity.hpp.

◆ HasComponents()

template<typename... T>
bool Cori::World::Entity::HasComponents ( ) const
inlinenodiscard

Checks if the entity has all the specified components.

Template Parameters
TComponents to check the presence of.
Returns
True if the entity has all the components, false if at least one is absent.

Definition at line 122 of file Entity.hpp.

◆ IsActiveGlobally()

bool Cori::World::Entity::IsActiveGlobally ( ) const
nodiscard

Checks if the entity is active locally (doesn't have InactiveGloballyFlag), just a convenience function.

Returns
True if it doesn't have InactiveGloballyFlag, false otherwise.

Definition at line 61 of file Entity.cpp.

Here is the call graph for this function:

◆ IsActiveLocally()

bool Cori::World::Entity::IsActiveLocally ( ) const
nodiscard

Checks if the entity is active locally (doesn't have InactiveLocallyFlag), just a convenience function.

Returns
True if it doesn't have InactiveLocallyFlag, false otherwise.

Definition at line 57 of file Entity.cpp.

Here is the call graph for this function:

◆ IsValid()

bool Cori::World::Entity::IsValid ( ) const
inlinenodiscard

Checks if the actual entity behind this handle is valid.

Returns
True if valid, false otherwise.

Definition at line 161 of file Entity.hpp.

◆ operator bool()

Cori::World::Entity::operator bool ( ) const
inlineexplicit

Definition at line 148 of file Entity.hpp.

◆ operator!=()

bool Cori::World::Entity::operator!= ( const Entity & other) const
inline

Definition at line 153 of file Entity.hpp.

Here is the call graph for this function:

◆ operator==()

bool Cori::World::Entity::operator== ( const Entity & other) const
inline

Definition at line 150 of file Entity.hpp.

Here is the call graph for this function:

◆ PrintHierarchy()

void Cori::World::Entity::PrintHierarchy ( ) const

Prints the full entity hierarchy tree in the console.

Definition at line 110 of file Entity.cpp.

Here is the call graph for this function:

◆ RemoveComponents()

template<typename... T>
entt::handle::size_type Cori::World::Entity::RemoveComponents ( )
inline

Removes components from the entity if entity has them.

Template Parameters
TComponents to remove.
Note
Removes the components only if the entity has it, it's safe to try to remove a component that the entity doesn't have.
Returns
Amount of components removed.

Definition at line 133 of file Entity.hpp.

◆ ReplaceComponent()

template<typename T, typename... Args>
T & Cori::World::Entity::ReplaceComponent ( Args &&... args)
inline

Replaces the component with a newly created one.

Template Parameters
TType of component to replace.
ArgsDeduced automatically, no need to specify.
Parameters
argsArguments passed to the component constructor.
Returns
A reference to the replaced component.

Definition at line 51 of file Entity.hpp.

◆ SetActive()

void Cori::World::Entity::SetActive ( const bool state)

Changes the activity state of the entity.

Parameters
stateActivity state to set.

When deactivating the entity a InactiveLocallyFlag and InactiveGloballyFlag are assigned to it, it this entity has any children a InactiveGloballyFlag will be added to the whole children tree recursively (to the grandchildren, grand-grandchildren and so on).

Definition at line 7 of file Entity.cpp.

Here is the call graph for this function:

◆ SetName()

void Cori::World::Entity::SetName ( const std::string & name)

Changes the entity name.

Parameters
nameName to change to.

Definition at line 122 of file Entity.cpp.

Here is the call graph for this function:

◆ SetParent()

std::expected< void, Core::CoriError<> > Cori::World::Entity::SetParent ( Entity parent)

Links the entity to a parent entity.

Parameters
parentParent entity to link the entity to.
Returns
Expected object with void on success or CoriError<> on failure.

Definition at line 78 of file Entity.cpp.

Here is the call graph for this function:

◆ UnlinkFromParent()

void Cori::World::Entity::UnlinkFromParent ( )

Unlinks the entity from its parent if it has one.

Definition at line 143 of file Entity.cpp.

Here is the call graph for this function:

◆ UpdateInactivityFlagsRecursive()

void Cori::World::Entity::UpdateInactivityFlagsRecursive ( entt::entity parent,
bool parentIsActive )
protected

Definition at line 151 of file Entity.cpp.

Here is the call graph for this function:

◆ Scene

friend class Scene
friend

Definition at line 319 of file Entity.hpp.


The documentation for this class was generated from the following files: