12using Component = std::uint32_t;
13enum class ComponentType : Component
19 TRANSFORM = POSITION | SCALE | ROTATION,
22 BOX_COLLIDER2D = 1u << 6u,
31template<
typename T, Component C>
37 components_.resize(entityInitNmb);
87 std::vector<T> components_;
90template <
typename T, Component C>
98 auto newSize = components_.size();
103 while (entity >= newSize)
105 newSize = newSize + newSize / 2;
107 components_.resize(newSize);
109 entityManager_.AddComponent(entity, C);
112template <
typename T, Component C>
116 gpr_warn(entityManager_.HasComponent(entity, C),
"Entity has not the removing component");
117 entityManager_.RemoveComponent(entity, C);
120template <
typename T, Component C>
124 gpr_warn(entityManager_.HasComponent(entity, C),
"Entity has not the requested component");
125 return components_[entity];
128template <
typename T, Component C>
132 gpr_warn(entityManager_.HasComponent(entity, C),
"Entity has not the requested component");
133 return components_[entity];
136template <
typename T, Component C>
140 gpr_warn(entityManager_.HasComponent(entity, C),
"Entity has not the requested component");
141 components_[entity] = value;
144template <
typename T, Component C>
150template <
typename T, Component C>
153 components_ = components;
ComponentManager is a class that owns Component in a contiguous array. Component indexing is done wit...
Definition: component.h:33
void SetComponent(Entity entity, const T &value)
SetComponent is a method that sets a new value of the Component of an Entity.
Definition: component.h:137
virtual void RemoveComponent(Entity entity)
RemoveComponent is a method that unsets the flag C in the EntityManager.
Definition: component.h:113
T & GetComponent(Entity entity)
GetComponent is a method that gets a reference to a Component given the Entity.
Definition: component.h:129
const T & GetComponent(Entity entity) const
GetComponent is a method that gets a constant reference to a Component given the Entity.
Definition: component.h:121
const std::vector< T > & GetAllComponents() const
GetAllComponents is a method that returns the internal array of components.
Definition: component.h:145
virtual void AddComponent(Entity entity)
AddComponent is a method that sets the flag C in the EntityManager and resize if need the components_...
Definition: component.h:91
void CopyAllComponents(const std::vector< T > &components)
CopyAllComponents is a method that changes the internal components array by copying a newly provided ...
Definition: component.h:151
Manages the entities in an array using bitwise operations to know if it has components.
Definition: entity.h:35
constexpr Entity INVALID_ENTITY
INVALID_ENTITY is a constant that define an invalid Entity.
Definition: entity.h:26
std::uint32_t Entity
Entity is the type used to define an game world entity. An Entity is just an index,...
Definition: entity.h:17