Nui Engine
A game engine framework
Loading...
Searching...
No Matches
Nui::ECS::Entity Class Reference

Class to represent an entity in an ECS Context. More...

#include <Entity.h>

Public Types

using ComponentMap = std::unordered_map<TypeIndex, std::unique_ptr<Internal::ComponentContainerBase>>
 Maps component type indices to unique pointers to component containers.
 

Public Member Functions

 Entity (Context *context, U64 id)
 Constructs a new entity in the given ECS Context with the given id.
 
 ~Entity ()
 Destroys the entity and all its components.
 
ContextGetContext () const noexcept
 Gets the ECS context associated with the entity.
 
U64 GetId () const noexcept
 Gets the ID of the entity.
 
bool IsPendingDestroy () const noexcept
 Whether the entity has pending destruction.
 
template<typename T >
bool Has () const
 Whether the entity has a component of the given type.
 
template<typename T , typename U , typename... Types>
bool Has () const
 Whether the entity has components of the given types.
 
template<typename T , typename... Args>
ComponentHandle< T > Add (Args &&... args)
 Adds a component to the entity.
 
template<typename T >
ComponentHandle< T > Get ()
 Gets a component from the entity.
 
template<typename T >
bool Remove ()
 Gets a component from the entity.
 
void RemoveAll ()
 Removes all components from the entity.
 
template<typename... Types>
bool With (typename std::common_type< std::function< void(ComponentHandle< Types >...)> >::type func)
 Executes a function on a set of component handles if the entity has components of the specified types.
 

Static Public Attributes

static constexpr U64 InvalidId = 0
 Invalid entity ID.
 

Friends

class Context
 

Detailed Description

Class to represent an entity in an ECS Context.

Constructor & Destructor Documentation

◆ Entity()

Nui::ECS::Entity::Entity ( Context * context,
U64 id )
inline

Constructs a new entity in the given ECS Context with the given id.

Parameters
contextPointer to the ECS Context
idID of the entity

Member Function Documentation

◆ Add()

template<typename T , typename ... Args>
ComponentHandle< T > Nui::ECS::Entity::Add ( Args &&... args)
inline

Adds a component to the entity.

Template Parameters
TType of the component
...ArgsArguments to pass to the constructor
Parameters
...argsArguments to pass to the constructor
Returns
Handle to the added (or updated) component

◆ Get()

template<typename T >
ComponentHandle< T > Nui::ECS::Entity::Get ( )
inline

Gets a component from the entity.

Template Parameters
TType of the component
Returns
Handle to the component

◆ GetContext()

Context * Nui::ECS::Entity::GetContext ( ) const
inlinenoexcept

Gets the ECS context associated with the entity.

Returns
Pointer to the ECS context

◆ GetId()

U64 Nui::ECS::Entity::GetId ( ) const
inlinenoexcept

Gets the ID of the entity.

Returns
ID of the entity

◆ Has() [1/2]

template<typename T >
bool Nui::ECS::Entity::Has ( ) const
inline

Whether the entity has a component of the given type.

Template Parameters
TType of the component
Returns
True if the entity has the component

◆ Has() [2/2]

template<typename T , typename U , typename... Types>
bool Nui::ECS::Entity::Has ( ) const
inline

Whether the entity has components of the given types.

Template Parameters
TFirst Component
VSecond Component
...TypesRemaining Components
Returns
True if the entity has all the specified components

◆ IsPendingDestroy()

bool Nui::ECS::Entity::IsPendingDestroy ( ) const
inlinenoexcept

Whether the entity has pending destruction.

Returns
True if the entity has pending destruction

◆ Remove()

template<typename T >
bool Nui::ECS::Entity::Remove ( )
inline

Gets a component from the entity.

Template Parameters
TType of the component
Returns
Handle to the component

◆ With()

template<typename... Types>
bool Nui::ECS::Entity::With ( typename std::common_type< std::function< void(ComponentHandle< Types >...)> ,
::type func )
inline

Executes a function on a set of component handles if the entity has components of the specified types.

Template Parameters
...TypesTypes of components
Parameters
viewFunction to execute
Returns
True if the entity has all the specified components

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