|
| T & | insert (Entity e, T component) |
| | adds a component for an Entity, growing the sparse array if necessary
|
| T & | replace (Entity e, T component) |
| | replaces a component with new data
|
| T & | get (Entity e) |
| | returns a reference to the Entity's component
|
|
const T & | get (Entity e) const |
| T * | try_to_get (Entity e) |
| | tries to get a component and returns nullptr if one does not exist
|
| void | remove (Entity e) override |
| | removes an Entity's component from this pool, if it is currently present
|
| bool | has (Entity e) const override |
| | checks whether an Entity currently has a component stored in this pool
|
| size_t | get_size () const override |
| | return the number of Entities currently stored in this pool
|
| const std::vector< Entity > & | get_entities () const override |
| | returns the dense array of entities currently stored in this pool
|
| size_t | get_index (Entity e) const override |
| | Returns the index of the specified Entity.
|
| void | swap_entities (Entity e1, Entity e2) override |
| | Swaps e1 with e2 in _dense, _entities, and _sparse.
|
template<typename T>
class Imago::ECS::SparseSet< T >
SparseSet concrete class templated to a component type, acts as Imago ECS's component pool.
Packed, cache friendly storage for one component type. SparseSet<T> stores every entity's T component contiguously in memory, with no gaps. This allows iterating every instance of T to be a straight linear scan with no pointer chasing and no skipped/empty slots. Lookups, insertions, and removals are all O(1), implemented via three parallel arrays:
- _sparse maps an entitiy's raw index to its slot in _dense/_entities
- _dense is the packed component data itself
- _entities is the packed entities, parallel to _dense, used to patch _sparse after a swap-and-pop removal
- Template Parameters
-
| T | the component type stored in the pool. |