8#include "ColliderComponent.h"
15using ComponentBitSet = std::bitset<MAX_COMPONENTS>;
16using GroupBitSet = std::bitset<MAX_GROUPS>;
17using ComponentArray = std::array<Component*, MAX_COMPONENTS>;
64 manager(mManager) { };
96 return componentBitSet[getComponentTypeID<T>()];
101 template <
typename T,
typename...TArgs> T&
addComponent(TArgs&&...mArgs)
103 T* c(
new T(std::forward<TArgs>(mArgs)...));
105 std::unique_ptr<Component> uPtr{ c };
106 this->components.emplace_back(std::move(uPtr));
108 componentArray[getComponentTypeID<T>()] = c;
109 componentBitSet[getComponentTypeID<T>()] =
true;
117 auto ptr(componentArray[getComponentTypeID<T>()]);
118 return *
static_cast<T*
>(ptr);
124 std::vector<std::unique_ptr<Component>> components;
126 ComponentArray componentArray = {};
127 ComponentBitSet componentBitSet;
128 GroupBitSet groupBitSet;
Main class for any object in game, stores associations, labeling and components.
Definition Entity.h:29
void destroy()
Definition Entity.h:74
void addGroup(Group mGroup)
Definition Entity.cpp:22
GroupLabel
Used for rendering order (last is highest) or retrieving entities of group.
Definition Entity.h:40
@ MAPTILES
Entity using TileComponent.
@ COLLIDERS
Fixed collider entity, e.g. a wall.
@ PLAYERS
Primary entity in player controll.
bool hasComponent() const
Definition Entity.h:94
Entity(Manager &mManager)
Definition Entity.h:63
TeamLabel
Allows grouping entities by team association for hits, win conditions, etc.
Definition Entity.h:54
@ NONE
No team, should be skipped in any checks.
Manager & getManager()
Definition Entity.h:92
bool hasGroup(Group mGroup)
Definition Entity.cpp:17
T & getComponent() const
Definition Entity.h:115
std::bitset< MAX_GROUPS > getGroupBitSet()
Definition Entity.cpp:33
void setTeam(TeamLabel teamLabel)
Definition Entity.cpp:38
void delGroup(Group mGroup)
Definition Entity.cpp:28
T & addComponent(TArgs &&...mArgs)
Adds specified type as component and calls Component::init()
Definition Entity.h:101
void draw() const
Definition Entity.cpp:12
bool isActive() const
Definition Entity.h:71
TeamLabel getTeam()
Definition Entity.cpp:44
void update() const
Definition Entity.cpp:7
Is responsible for managing all entities.
Definition Manager.h:20