8#include "ColliderComponent.h"
14#include "InputComponent.h"
15#include "TransformComponent.h"
16#include "SpriteComponent.h"
21using ComponentBitSet = std::bitset<MAX_COMPONENTS>;
22using GroupBitSet = std::bitset<MAX_GROUPS>;
23using ComponentArray = std::array<Component*, MAX_COMPONENTS>;
60 manager(mManager) { };
86 return componentBitSet[getComponentTypeID<T>()];
91 template <
typename T,
typename...TArgs> T&
addComponent(TArgs&&...mArgs)
93 T* c(
new T(std::forward<TArgs>(mArgs)...));
95 std::unique_ptr<Component> uPtr{ c };
96 this->components.emplace_back(std::move(uPtr));
98 componentArray[getComponentTypeID<T>()] = c;
99 componentBitSet[getComponentTypeID<T>()] =
true;
107 auto ptr(componentArray[getComponentTypeID<T>()]);
108 return *
static_cast<T*
>(ptr);
114 std::vector<std::unique_ptr<Component>> components;
116 ComponentArray componentArray = {};
117 ComponentBitSet componentBitSet;
118 GroupBitSet groupBitSet;
Main class for any object in game, stores associations, labeling and components.
Definition Entity.h:35
void destroy()
Definition Entity.h:67
void addGroup(Group mGroup)
Definition Entity.cpp:17
GroupLabel
Used for rendering order (last is highest) or retrieving entities of group.
Definition Entity.h:46
@ MAPTILES
Entity using TileComponent.
@ COLLIDERS
Fixed collider entity, e.g. a wall.
@ PLAYERS
Primary entity in player controll.
bool hasComponent() const
Definition Entity.h:84
Entity(Manager &mManager)
Definition Entity.h:59
Manager & getManager()
Definition Entity.h:82
bool hasGroup(Group mGroup)
Definition Entity.cpp:12
T & getComponent() const
Definition Entity.h:105
std::bitset< MAX_GROUPS > getGroupBitSet()
Definition Entity.cpp:28
void delGroup(Group mGroup)
Definition Entity.cpp:23
T & addComponent(TArgs &&...mArgs)
Adds specified type as component and calls Component::init()
Definition Entity.h:91
bool isActive() const
Definition Entity.h:64
void update() const
Call each frame to update all components.
Definition Entity.cpp:7
Is responsible for managing all entities.
Definition Manager.h:23