4#include <unordered_map>
21 virtual size_t size()
const = 0;
51 data[it->second] = std::move(comp);
55 data.push_back(std::move(comp));
77 size_t index = it->second;
78 size_t last =
data.size() - 1;
105 if (it ==
entityToIndex.end())
throw std::runtime_error(
"Component not found");
106 return data[it->second];
121 size_t size()
const override {
return data.size(); }
Template class storing components contiguously in memory for optimal cache usage.
Definition ComponentStorage.hpp:41
void remove(Entity e)
Removes the component from an entity.
Definition ComponentStorage.hpp:73
void add(Entity e, T comp)
Adds a component to an entity.
Definition ComponentStorage.hpp:48
void removeEntity(Entity e) override
Polymorphic interface to remove entity component.
Definition ComponentStorage.hpp:94
std::vector< T > data
Contiguous array of component instances.
Definition ComponentStorage.hpp:146
size_t size() const override
Returns the size of the storage.
Definition ComponentStorage.hpp:121
const std::vector< Entity > & getEntities() const override
Retrieves all entities with this component.
Definition ComponentStorage.hpp:113
auto entityBegin()
Gets start iterator of stored entity list.
Definition ComponentStorage.hpp:137
auto begin()
Gets start iterator of stored component data.
Definition ComponentStorage.hpp:127
auto entityEnd()
Gets end iterator of stored entity list.
Definition ComponentStorage.hpp:142
bool has(Entity e) const
Checks if an entity possesses this component.
Definition ComponentStorage.hpp:65
T & get(Entity e)
Retrieves the component associated with an entity.
Definition ComponentStorage.hpp:103
auto end()
Gets end iterator of stored component data.
Definition ComponentStorage.hpp:132
std::unordered_map< Entity, size_t > entityToIndex
Mapping for quick entity component lookup.
Definition ComponentStorage.hpp:150
std::vector< Entity > entities
Entity mapping matching data array order.
Definition ComponentStorage.hpp:148
Lightweight identifier representing a game object in the Entity Component System.
Definition Entity.hpp:11
Polymorphic base interface for all component storage types, allowing untyped manipulation of componen...
Definition ComponentStorage.hpp:12
virtual void removeEntity(Entity e)=0
Removes the component associated with the given entity.
virtual ~IStorage()=default
Virtual destructor.
virtual const std::vector< Entity > & getEntities() const =0
Returns list of entities mapped to components.
virtual size_t size() const =0
Returns the number of component instances stored.
static ufbxi_noinline ufbxi_aa_node index
Definition ufbx.cpp:4444