4#include "component_array.hpp"
9#include <unordered_map>
11namespace acheron::ecs {
14 static inline ComponentID ID =
static_cast<ComponentID
>(-1);
20 class ComponentManager {
23 ComponentManager() : nextComponentID(0) {}
34 assert(ComponentType<T>::ID ==
static_cast<ComponentID
>(-1) &&
"Duplicate registration");
36 ComponentType<T>::ID = nextComponentID++;
37 componentArrays[ComponentType<T>::ID] = std::make_shared<ComponentArray<T>>();
50 assert(ComponentType<T>::ID !=
static_cast<ComponentID
>(-1) &&
"Component not registered");
51 return ComponentType<T>::ID;
64 GetComponentArray<T>()->InsertData(entity, component);
75 GetComponentArray<T>()->RemoveData(entity);
87 return GetComponentArray<T>()->GetData(entity);
99 return GetComponentArray<T>()->HasData(entity);
110 std::unordered_map<const char*, ComponentID> componentTypes;
111 std::unordered_map<ComponentID, std::shared_ptr<IComponentArray>> componentArrays;
112 ComponentID nextComponentID;
123 std::shared_ptr<ComponentArray<T>> GetComponentArray() {
125 return std::static_pointer_cast<ComponentArray<T>>(componentArrays[id]);
void RemoveComponent(Entity entity)
Removes a component and its data from an entity.
Definition component.hpp:74
T & GetComponent(Entity entity)
Get components data associated with an entity.
Definition component.hpp:86
void AddComponent(Entity entity, T component)
Adds a component and its data to an entity.
Definition component.hpp:63
bool HasComponent(Entity entity)
Checks if en entity has a component.
Definition component.hpp:98
void RegisterComponent()
Registers a component type creating a ComponentArray and an ID.
Definition component.hpp:33
ComponentID GetComponentID()
Gets the ID of a component.
Definition component.hpp:49
void EntityDespawned(Entity entity)
Remove components associated with an entity.
Definition component.cpp:5
Definition component.hpp:13