OGL Engine 1.2.0-dev
Loading...
Searching...
No Matches
entity.hpp
Go to the documentation of this file.
1
7#pragma once
8
9#include "../defs.hpp"
10#include "registry.hpp"
11#include "componentstorage.hpp"
12
13#include <set>
14
15namespace Engine::ECS {
19 class Entity {
20 private:
22 EntityID mID;
24 Registry* mRegistry;
25
26 public:
33 Entity(EntityID id = -1, Registry* registry = nullptr);
39 EntityID GetID() const;
40
52 bool IsValid() const;
53
59 std::string ToString() const;
60
66 Registry& GetRegistry() const;
67
74 void AddTag(std::string tag);
83 bool HasTag(std::string tag);
84
94 template<typename T, typename... Args>
95 T& AddComponent(Args&&... args) {
96 mRegistry->AddComponent<T>(mID, std::forward<Args>(args)...);
97 T& component = mRegistry->GetComponent<T>(mID);
98 if constexpr(requires(T t, Entity e) { t.SetEntity(e); }) {
99 component.SetEntity(*this);
100 }
101
102 return component;
103 }
104
111 template<typename T>
113 mRegistry->RemoveComponent<T>(mID);
114 }
115
123 template<typename T>
125 return mRegistry->GetComponent<T>(mID);
126 }
127
135 template<typename T>
136 std::vector<T*> GetComponents() {
137 return mRegistry->GetComponents<T>(mID);
138 }
139
146 template<typename T>
148 return mRegistry->HasComponent<T>(mID);
149 }
150
156 void AddChild(EntityID childID);
157
163 void SetParent(EntityID parentID);
164
170 void RemoveChild(EntityID childID);
171
176 void RemoveParent();
177 };
178}
void RemoveChild(EntityID childID)
Supprime le lien avec l'entité enfant donnée.
Definition entity.cpp:51
void AddChild(EntityID childID)
Ajoute l'identifiant donné comme "enfant".
Definition entity.cpp:43
EntityID GetID() const
Retourne l'identifiant EntityID de cette.
Definition entity.cpp:31
T & GetComponent()
Retourne le premier composant de type T associé à cette entité
Definition entity.hpp:124
void SetParent(EntityID parentID)
Ajoute l'identifiant donné comme "parent".
Definition entity.cpp:47
Entity(EntityID id=-1, Registry *registry=nullptr)
Construit une nouvelle entité
Definition entity.cpp:5
void RemoveParent()
Supprime le lien reliant cette entité à son parent.
Definition entity.cpp:55
std::vector< T * > GetComponents()
Retourne le tableau de composants de type T associé à cette entité
Definition entity.hpp:136
bool HasComponent()
Vérifie si l'entité possède le component demandé
Definition entity.hpp:147
T & AddComponent(Args &&... args)
Ajoute un component de type T au registre, référencé sous l'entityID de cette entité
Definition entity.hpp:95
void AddTag(std::string tag)
Ajoute un tag à l'entité actuelle.
Definition entity.cpp:35
std::string ToString() const
Renvoie une chaine de caractères qui représente cette entité
Definition entity.cpp:7
Registry & GetRegistry() const
Renvoie le registre parent de cet entité
Definition entity.cpp:23
bool IsValid() const
Renvoie true si l'entité est valide, false sinon.
Definition entity.cpp:27
void RemoveComponent()
Supprime le composant de type T référencé par l'EntityID de cette entité
Definition entity.hpp:112
bool HasTag(std::string tag)
Check si l'entité possède un tag.
Definition entity.cpp:39
Classe Registre qui stocke des composants et gère l'attribution des IDs d'entités.
Definition registry.hpp:32
Définit des types de données utilisés dans le moteur.
Definition component.hpp:11
std::uint32_t EntityID
Définition de type pour mieux identifier les EntityID.
Definition defs.hpp:13
Définit le rôle du Registre dans l'architecture ECS.