49 template<
typename... Args>
66 for (
auto& cb :
m_onCreate) cb(entity, component);
77 if (!
has(entity))
return;
84 if (indexOfRemoved != indexOfLast) {
101 assert(
has(entity) &&
"Retrieving non-existent component.");
Template-based storage container for components of a specific type.
std::vector< std::function< void(Entity, T &)> > m_onCreate
Callbacks invoked when a component is created for an entity.
T & add_or_replace(Entity entity, Args &&... args)
Adds or replaces a component for an entity.
void on_destroy(std::function< void(Entity, T &)> cb)
Registers a callback to be invoked when a component is destroyed.
void remove(Entity entity)
Removes the component from an entity.
std::vector< std::function< void(Entity, T &)> > m_onDestroy
Callbacks invoked when a component is destroyed for an entity.
void entity_destroyed(Entity entity) override
Called by the Registry when an entity is destroyed.
std::vector< size_t > m_entityToIndex
Maps entity ID to the component storage index, or -1 if not present.
std::vector< Entity > m_indexToEntity
Maps component storage index to the entity that owns the component.
const std::vector< Entity > & get_entities() const
Returns the list of all entities that have this component type.
void on_create(std::function< void(Entity, T &)> cb)
Registers a callback to be invoked when a component is created.
std::vector< T > m_components
Dense array of component instances, cache-optimized for iteration.
bool has(Entity entity) const
Checks if the given entity has a component of type T.
T & get(Entity entity)
Retrieves a reference to the component for an entity.
Abstract base class for component storage implementations.
uint32_t Entity
Type alias representing a unique entity identifier in the ECS system.