Definition at line 15 of file entity.h.
◆ Entity() [1/3]
◆ Entity() [2/3]
ecs::Entity::Entity |
( |
const Entity & | | ) |
|
|
delete |
No copy constructor or assignment operator to prevent copying.
◆ Entity() [3/3]
ecs::Entity::Entity |
( |
Entity && | | ) |
|
|
default |
Move constructor and assignment operator to allow moving entities.
◆ AddComponent()
template<typename T , typename... Args>
std::shared_ptr< T > ecs::Entity::AddComponent |
( |
Args &&... | args | ) |
|
|
inline |
Add a component of type T to the entity. If the component already exists, it returns the existing component.
- Template Parameters
-
- Parameters
-
args | Arguments to construct the component. |
- Returns
- A shared pointer to the added or existing component.
Definition at line 49 of file entity.h.
49 {
50 static_assert(std::is_base_of<Component, T>::value, "T must derive from Component");
51
53
54
55 if (m_Components.find(typeID) != m_Components.end()) {
56 return std::static_pointer_cast<T>(m_Components[typeID]);
57 }
58
59
60 auto component = std::make_shared<T>(std::forward<Args>(args)...);
61 m_Components[typeID] = component;
62
63
64 component->Initialize();
65
66 return component;
67 }
std::type_index ComponentTypeID
ComponentTypeID GetComponentTypeID()
◆ GetComponent()
template<typename T >
std::shared_ptr< T > ecs::Entity::GetComponent |
( |
| ) |
|
|
inline |
Get a component of type T from the entity.
- Template Parameters
-
- Returns
- A shared pointer to the component if it exists, nullptr otherwise.
Definition at line 75 of file entity.h.
75 {
76 static_assert(std::is_base_of<Component, T>::value, "T must derive from Component");
77
79
80 auto it = m_Components.find(typeID);
81 if (it != m_Components.end()) {
82 return std::static_pointer_cast<T>(it->second);
83 }
84
85 return nullptr;
86 }
◆ GetID()
Get the unique identifier for the entity.
- Returns
- The unique ID of the entity.
Definition at line 39 of file entity.h.
◆ HasComponent()
template<typename T >
bool ecs::Entity::HasComponent |
( |
| ) |
const |
|
inline |
Check if the entity has a component of type T.
- Template Parameters
-
- Returns
- true if the entity has the component, false otherwise.
Definition at line 94 of file entity.h.
94 {
95 static_assert(std::is_base_of<Component, T>::value, "T must derive from Component");
96
98 return m_Components.find(typeID) != m_Components.end();
99 }
◆ RemoveComponent()
template<typename T >
void ecs::Entity::RemoveComponent |
( |
| ) |
|
|
inline |
Remove a component of type T from the entity.
- Template Parameters
-
Definition at line 106 of file entity.h.
106 {
107 static_assert(std::is_base_of<Component, T>::value, "T must derive from Component");
108
110 auto it = m_Components.find(typeID);
111
112 if (it != m_Components.end()) {
113 m_Components.erase(it);
114 }
115 }
◆ UpdateComponents()
void ecs::Entity::UpdateComponents |
( |
float | deltaTime | ) |
|
|
inline |
Update all components of the entity.
- Parameters
-
Definition at line 121 of file entity.h.
121 {
122 for (auto& [typeID, component] : m_Components) {
123 component->Update(deltaTime);
124 }
125 }
The documentation for this class was generated from the following file:
- enginecustom/src/inc/system/ecs/entity.h