6#include "ComponentStorage.hpp"
7#include "VEX/VEX_export.h"
16 static uint32_t get_id_by_name(
const char* name);
19 static uint32_t get_id() {
20 static const uint32_t
id = get_id_by_name(
typeid(T).name());
45 uint32_t typeId = ComponentType::get_id<T>();
62 uint32_t typeId = ComponentType::get_id<T>();
88 if (Storage) Storage->entity_destroyed(entity);
99 template<
typename T,
typename... Args>
101 return get_storage<T>()->add_or_replace(entity, std::forward<Args>(args)...);
129 return (arr && arr->has(entity)) ? &arr->get(entity) :
nullptr;
139 return arr !=
nullptr && arr->has(entity);
Template-based storage container for components of a specific type.
Manages unique type IDs for component types in the ECS system.
Central registry for managing entities and their components in the ECS system.
std::vector< Entity > m_availableEntities
Pool of reusable entity IDs from destroyed entities.
Entity m_nextEntity
Counter for generating new entity IDs when the pool is empty.
void on_create(std::function< void(Entity, T &)> cb)
Registers a callback to be invoked when a component of type T is created.
ComponentStorage< T > * get_storage()
Retrieves or creates the storage for component type T.
bool has(Entity entity)
Checks if an entity has a component of type T.
ComponentStorage< T > * try_get_storage_internal()
Attempts to retrieve the storage for component type T without creating it.
T & add_or_replace(Entity entity, Args &&... args)
Adds or replaces a component for an entity.
T & get(Entity entity)
Retrieves a component from an entity.
void remove(Entity entity)
Removes a component from an entity.
void destroy(Entity entity)
Destroys an entity and all its associated components.
Entity create()
Creates a new entity.
std::vector< std::unique_ptr< IComponentStorage > > m_componentStorages
Array of component storages indexed by component type ID.
T * try_get(Entity entity)
Safely retrieves a component from an entity if it exists.
void on_destroy(std::function< void(Entity, T &)> cb)
Registers a callback to be invoked when a component of type T is destroyed.
uint32_t Entity
Type alias representing a unique entity identifier in the ECS system.