4#include <unordered_map>
6#include "../Entity/entity.h"
38template <
typename Component>
56 template <
typename... Args>
57 Component*
emplace(
const Entity entity, Args &&...args);
59 typename std::vector<Component>::iterator
begin();
60 typename std::vector<Component>::iterator
end();
61 typename std::vector<Component>::const_iterator
begin()
const;
62 typename std::vector<Component>::const_iterator
end()
const;
112 std::vector<Component> components;
113 std::unordered_map<Entity, size_t> componentMap;
114 std::unordered_map<size_t, Entity> entityMap;
116 int lastReallocated = 0;
118 void onEntityDestroyed(Entity entity)
override;
Container for a specific Component type.
Definition: componentContainer.h:39
Entity getEntity(Component *component)
Get an Entity with this specific component.
Definition: componentContainer.inl:54
int getLastReallocated() override
Get the last time the component container resize the vector containing all the components.
Definition: componentContainer.h:109
bool hasComponent(const Entity entity)
Determine if an entity has this type of Component attached.
Definition: componentContainer.inl:49
int getActiveCnt()
Definition: componentContainer.h:101
std::vector< Component >::iterator begin()
Definition: componentContainer.inl:11
Component * emplace(const Entity entity, Args &&...args)
Emplace a component onto an entity. This created.
Definition: componentContainer.inl:24
Component * getComponent(const Entity entity)
Get a pointer to a Component attached to an entity.
Definition: componentContainer.inl:42
virtual ~ComponentContainer()
Destroy the Component Container object.
Definition: componentContainer.h:45
void removeComponent(const Entity entity)
Remove a component from an entity. This also allows the slot used for the component to be free to use...
Definition: componentContainer.inl:72
std::vector< Component >::iterator end()
Definition: componentContainer.inl:14
Generic container of components.
Definition: componentContainer.h:13
virtual int getLastReallocated()=0
Get the last time the container was changed. Useful for cacheing references from the container.
virtual ~IComponentContainer()=default
Destroy the IComponentContainer object.
virtual void onEntityDestroyed(Entity entity)=0
Handler for when an entity is deleted. This should remove the entity from the Container,...