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) { };
62 void update(uint_fast16_t diffTime)
const;
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::shared_ptr<Component> uPtr{ c };
96 this->components.at(getComponentTypeID<T>()) = 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);
111 template <
typename T> std::shared_ptr<T> getComponentAsPointer()
const
113 return std::static_pointer_cast<T>(components.at(getComponentTypeID<T>()));
119 std::array<std::shared_ptr<Component>, MAX_COMPONENTS> components;
121 ComponentArray componentArray = {};
122 ComponentBitSet componentBitSet;
123 GroupBitSet groupBitSet;
void destroy()
Definition Entity.h:67
void addGroup(Group mGroup)
Definition Entity.cpp:19
GroupLabel
Used for rendering order (last is highest) or retrieving entities of group.
Definition Entity.h:46
@ PROJECTILE
Definition Entity.h:51
@ POWERUPS
Definition Entity.h:53
@ MAPTILES
Entity using TileComponent.
Definition Entity.h:47
@ HEARTS
Definition Entity.h:52
@ COLLIDERS
Fixed collider entity, e.g. a wall.
Definition Entity.h:50
@ PLAYERS
Primary entity in player controll.
Definition Entity.h:48
@ ENEMIES
Definition Entity.h:49
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:14
T & getComponent() const
<
Definition Entity.h:105
std::bitset< MAX_GROUPS > getGroupBitSet()
Definition Entity.cpp:30
void delGroup(Group mGroup)
Definition Entity.cpp:25
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(uint_fast16_t diffTime) const
Call each frame to update all components.
Definition Entity.cpp:7
Is responsible for managing all entities.
Definition Manager.h:23