Vesper 0.5.1
Vesper is short form for the Latin word for "Bat", as Vesper is designed to be small, lightweight, and easily handle things like particles and flocking behaviors in accordance with the nature of bats. \n It is meant to be a particle simulation, VFX editor, and CAN be used secondarily as a small game engine.
GitHub | Vesper Updates | Creator
Loading...
Searching...
No Matches
Vesper::Entity Class Reference

Represents an entity in a scene. More...

#include <Entity.h>

Public Member Functions

 Entity ()=default
 Entity (entt::entity handle, Scene *scene)
 Constructs an Entity with the given handle and scene.
 Entity (const Entity &other)=default
 Copy constructor for Entity.
template<typename T>
bool HasComponent () const
template<typename T, typename... Args>
T & AddComponent (Args &&... args)
template<typename T, typename... Args>
T & AddOrReplaceComponent (Args &&... args)
template<typename T>
T & GetComponent ()
template<typename T, typename... Args>
T & GetOrAddComponent (Args &&... args)
template<typename T>
void RemoveComponent ()
const UUIDGetID ()
const std::string & GetName ()
 operator bool () const
 operator entt::entity () const
 operator uint32_t () const
bool operator== (const Entity &other) const
bool operator!= (const Entity &other) const

Private Attributes

entt::entity m_EntityID {entt::null}
 The unique identifier of the entity within the scene.
Scenem_Scene = nullptr
 Pointer to the scene that contains the entity.

Detailed Description

Represents an entity in a scene.

Contains a handle to an entity (entt::entity) in a scene and provides methods to manipulate its components.

Constructor & Destructor Documentation

◆ Entity() [1/3]

Vesper::Entity::Entity ( )
default

◆ Entity() [2/3]

Vesper::Entity::Entity ( entt::entity handle,
Scene * scene )

Constructs an Entity with the given handle and scene.

Parameters
handleThe handle to the entity.
sceneThe scene to which the entity belongs.
7 : m_EntityID(handle), m_Scene(scene)
8 {
9 }
entt::entity m_EntityID
The unique identifier of the entity within the scene.
Definition Entity.h:126
Scene * m_Scene
Pointer to the scene that contains the entity.
Definition Entity.h:128

References Entity(), and m_Scene.

Referenced by Entity().

◆ Entity() [3/3]

Vesper::Entity::Entity ( const Entity & other)
default

Copy constructor for Entity.

Member Function Documentation

◆ AddComponent()

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

Adds a component of type T to the entity with the provided arguments Otherwise, asserts if the entity already has the component.

Template Parameters
TThe type of component to add.
ArgsThe types of arguments to forward to the component's constructor.
Parameters
argsThe arguments to forward to the component's constructor.
Returns
A reference to the newly added component.
46 {
47 VZ_CORE_ASSERT(!HasComponent<T>(), "Entity already has component!");
48 T& component = m_Scene->m_Registry.emplace<T>(m_EntityID, std::forward<Args>(args)...);
49 m_Scene->OnComponentAdded<T>(*this, component);
50 return component;
51 }
#define VZ_CORE_ASSERT(x,...)
Definition Asserts.h:20
bool HasComponent() const
Definition Entity.h:33
@ T
Definition KeyCodes.h:57

◆ AddOrReplaceComponent()

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

Adds or replaces a component of type T to the entity with the provided arguments.

Template Parameters
TThe type of component to add or replace.
ArgsThe types of arguments to forward to the component's constructor.
Parameters
argsThe arguments to forward to the component's constructor.
Returns
A reference to the newly added or replaced component.
61 {
62 return m_Scene->m_Registry.emplace_or_replace<T>(m_EntityID, std::forward<Args>(args)...);
63 }

◆ GetComponent()

template<typename T>
T & Vesper::Entity::GetComponent ( )
inline

Retrieves a reference to the component of type T attached to the entity if it exists. Otherwise, asserts.

Template Parameters
TThe type of component to retrieve.
Returns
A reference to the component.
71 {
72 VZ_CORE_ASSERT(HasComponent<T>(), "Entity does not have component!");
73 return m_Scene->m_Registry.get<T>(m_EntityID);
74 }

◆ GetID()

const UUID & Vesper::Entity::GetID ( )
inline

Retrieves a const reference to the UUID of the entity.

Returns
A const reference to the UUID of the entity.
105 {
106 return GetComponent<UUIDComponent>().ID;
107 }
T & GetComponent()
Definition Entity.h:70

◆ GetName()

const std::string & Vesper::Entity::GetName ( )
inline

Retrieves a const reference to the name of the entity.

Returns
A const reference to the name of the entity.
113 {
114 return GetComponent<NameComponent>().Name;
115 }

◆ GetOrAddComponent()

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

Retrieves a reference to the component of type T attached to the entity if it exists. Otherwise, adds the component with the provided arguments and returns it.

Template Parameters
TThe type of component to add.
ArgsThe types of arguments to forward to the component's constructor.
Parameters
argsThe arguments to forward to the component's constructor.
Returns
A reference to the newly added component.
84 {
85 if (HasComponent<T>())
86 return GetComponent<T>();
87 else
88 return AddComponent<T>(std::forward<Args>(args)...);
89 }
T & AddComponent(Args &&... args)
Definition Entity.h:45

◆ HasComponent()

template<typename T>
bool Vesper::Entity::HasComponent ( ) const
inline

Checks if the entity has a component of type T.

Template Parameters
TThe type of component to check for.
Returns
true if the entity has the component, false otherwise.
34 {
35 return m_Scene->m_Registry.all_of<T>(m_EntityID);
36 }

◆ operator bool()

Vesper::Entity::operator bool ( ) const
inline
118{ return m_EntityID != entt::null; }

◆ operator entt::entity()

Vesper::Entity::operator entt::entity ( ) const
inline
119{ return m_EntityID; }

◆ operator uint32_t()

Vesper::Entity::operator uint32_t ( ) const
inline
120{ return (uint32_t)m_EntityID; }

◆ operator!=()

bool Vesper::Entity::operator!= ( const Entity & other) const
inline
122{ return !(*this == other); }

◆ operator==()

bool Vesper::Entity::operator== ( const Entity & other) const
inline
121{ return m_EntityID == other.m_EntityID && m_Scene == other.m_Scene; }

◆ RemoveComponent()

template<typename T>
void Vesper::Entity::RemoveComponent ( )
inline

Removes the component of type T from the entity if it exists. Otherwise, asserts.

Template Parameters
TThe type of component to remove.
96 {
97 VZ_CORE_ASSERT(HasComponent<T>(), "Entity does not have component!");
98 m_Scene->m_Registry.remove<T>(m_EntityID);
99 }

Member Data Documentation

◆ m_EntityID

entt::entity Vesper::Entity::m_EntityID {entt::null}
private

The unique identifier of the entity within the scene.

126{entt::null};

◆ m_Scene

Scene* Vesper::Entity::m_Scene = nullptr
private

Pointer to the scene that contains the entity.

Referenced by Entity().


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