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>;
52 manager(mManager) { };
54 void update(uint_fast16_t diffTime)
const;
65#ifndef DOXYGEN_SHOULD_SKIP_THIS
66 bool hasGroup(Group mGroup);
67 void addGroup(Group mGroup);
68 void delGroup(Group mGroup);
69 std::bitset<MAX_GROUPS> getGroupBitSet();
77 return componentBitSet[getComponentTypeID<T>()];
83 template <
typename T,
typename...TArgs> T&
addComponent(TArgs&&...mArgs)
85 T* c(
new T(std::forward<TArgs>(mArgs)...));
87 std::shared_ptr<Component> uPtr{ c };
88 this->components.at(getComponentTypeID<T>()) = std::move(uPtr);
90 componentArray[getComponentTypeID<T>()] = c;
91 componentBitSet[getComponentTypeID<T>()] =
true;
102 auto ptr(componentArray[getComponentTypeID<T>()]);
103 return *
static_cast<T*
>(ptr);
110 return std::static_pointer_cast<T>(components.at(getComponentTypeID<T>()));
116 std::array<std::shared_ptr<Component>, MAX_COMPONENTS> components;
118 ComponentArray componentArray = {};
119 ComponentBitSet componentBitSet;
120 GroupBitSet groupBitSet;
void destroy()
Definition Entity.h:59
GroupLabel
Some premade Entity groups used to avoid checking all entities for everything all of the time.
Definition Entity.h:39
@ PROJECTILE
Not used.
Definition Entity.h:43
@ POWERUPS
Not used.
Definition Entity.h:45
@ MAPTILES
Entity using TileComponent, internal use only.
Definition Entity.h:40
@ HEARTS
Not used.
Definition Entity.h:44
@ COLLIDERS
Fixed collider entity, e.g. a wall.
Definition Entity.h:42
@ PLAYERS
Primary entity in player control, used to be able to interact with pickupables.
Definition Entity.h:41
bool hasComponent() const
Definition Entity.h:75
Entity(Manager &mManager)
Definition Entity.h:51
Manager & getManager()
Definition Entity.h:73
T & getComponent() const
Access a specific component of an entity.
Definition Entity.h:100
T & addComponent(TArgs &&...mArgs)
Adds specified type as component and calls its CONSTRUCTOR.
Definition Entity.h:83
bool isActive() const
Definition Entity.h:56
std::shared_ptr< T > getComponentAsPointer() const
Access a specific component of an entity as a pointer.
Definition Entity.h:108
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