1 #ifndef RADIX_ENTITY_HPP
2 #define RADIX_ENTITY_HPP
54 entity(e), component(c) {}
69 entity(e), component(c) {}
84 entity(e), oldName(o) {}
90 manager(manager), id(id) {
116 void setName(
const std::string&);
121 template<
typename T,
typename... TArgs>
123 static_assert(std::is_base_of<Component, T>::value,
"T must be a Component");
124 if (hasComponent<T>()) {
127 T* result(
new T(*
this, std::forward<TArgs>(mArgs)...));
135 static_assert(std::is_base_of<Component, T>::value,
"T must be a Component");
136 return components[Component::getTypeId<T>()].
get() !=
nullptr;
141 static_assert(std::is_base_of<Component, T>::value,
"T must be a Component");
142 return *
reinterpret_cast<T*
>(components[Component::getTypeId<T>()].
get());
std::string name
Entity's name.
Definition: Entity.hpp:38
EntityId id
Entity (instance) identifier.
Definition: Entity.hpp:103
std::size_t ComponentTypeId
Definition: Component.hpp:11
Definition: GameController.hpp:7
Entity & entity
Definition: Entity.hpp:51
Definition: Entity.hpp:41
Definition: Logger.hpp:12
const std::string oldName
Definition: Entity.hpp:82
void clearComponents()
Definition: Entity.cpp:27
static constexpr StaticEventType Type
Definition: Entity.hpp:76
static _Log Log
Definition: Util.hpp:25
bool hasComponent() const
Definition: Entity.hpp:134
ECS entity, Component container It is created like this:
Definition: Entity.hpp:23
Component & component
Definition: Entity.hpp:52
T & getComponent() const
Definition: Entity.hpp:140
Entity(EntityManager &manager, EntityId id)
Definition: Entity.hpp:89
Definition: Entity.hpp:71
std::array< std::unique_ptr< Component >, Component::MaxId > components
Definition: Entity.hpp:119
static constexpr StaticEventTypeName TypeName
Definition: Entity.hpp:57
void addComponent(ComponentTypeId, Component *)
Definition: Entity.cpp:17
const EventTypeName getTypeName() const
Definition: Entity.hpp:43
const uint32_t StaticEventType
Definition: Event.hpp:10
ComponentRemovedEvent(Entity &e, Component &c)
Definition: Entity.hpp:68
Base class to create entity components.
Definition: Component.hpp:25
T & addComponent(TArgs &&...mArgs)
Definition: Entity.hpp:122
std::string EventTypeName
Definition: Event.hpp:13
const EventType getType() const
Definition: Entity.hpp:62
static constexpr StaticEventTypeName TypeName
Definition: Entity.hpp:72
Definition: Entity.hpp:56
uint32_t EntityId
Definition: Entity.hpp:16
ComponentAddedEvent(Entity &e, Component &c)
Definition: Entity.hpp:53
Manager and container of entities.
Definition: EntityManager.hpp:16
Component & component
Definition: Entity.hpp:67
static constexpr StaticEventType Type
Definition: Entity.hpp:61
static constexpr StaticEventTypeName TypeName
Definition: Entity.hpp:42
static constexpr TypeId MaxId
Definition: Component.hpp:36
ComponentTypeId TypeId
Definition: Component.hpp:35
bool operator!=(const Entity &o) const
Definition: Entity.hpp:108
const EventType getType() const
Definition: Entity.hpp:77
void removeComponent()
Definition: Entity.hpp:146
const EventTypeName getTypeName() const
Definition: Entity.hpp:58
static constexpr EventType TypeNameHash(StaticEventTypeName etn)
Definition: Event.hpp:16
EntityManager & manager
Definition: Entity.hpp:88
bool operator==(const Entity &o) const
Definition: Entity.hpp:105
~Entity()
Definition: Entity.hpp:93
void setName(const std::string &)
Definition: Entity.cpp:8
NameChangedEvent(Entity &e, const std::string &o)
Definition: Entity.hpp:83
const EventTypeName getTypeName() const
Definition: Entity.hpp:73
uint32_t EventType
Definition: Event.hpp:11
const char *const StaticEventTypeName
Definition: Event.hpp:12
const EventType getType() const
Definition: Entity.hpp:47
Entity & operator=(Entity &)=delete
std::string getName() const
Definition: Entity.hpp:113
Entity & entity
Definition: Entity.hpp:66
static constexpr StaticEventType Type
Definition: Entity.hpp:46
Entity & entity
Definition: Entity.hpp:81