|
R-Type
Distributed multiplayer game engine in C++
|
Manages entities, their signatures and component type registrations. More...
#include <Registry.hpp>

Public Member Functions | |
| Registry () | |
| Construct a new Registry object. | |
| ~Registry () | |
| Destroy the Registry object and clear internal containers. | |
| Address | newEntity () |
| Create and register a new entity, returning its Address. | |
| template<typename T > | |
| void | setComponent (Address address, const T &component) |
| Set/add a component to an entity with its data. | |
| template<typename T > | |
| T & | getComponent (Address address) |
| Get a component from an entity. | |
| template<typename T > | |
| bool | hasComponent (Address address) |
| Check if an entity has a specific component. | |
| template<typename T > | |
| void | removeComponent (Address address) |
| Remove a component from an entity. | |
| template<typename T > | |
| void | addEntityProp (Address address) |
| Attach a component type T to an entity (set the component bit). | |
| void | destroyEntity (Address address) |
| Remove an entity and its Signature from the registry. | |
| Signature | getSignature (Address address) |
| Retrieve the Signature for a given entity address. | |
| template<typename... Components> | |
| std::vector< Address > | view () |
| Get all entities that have a specific set of components. | |
| std::vector< Address > | getEntitiesWithMask (Signature requiredMask) |
| Get all entities matching a specific component mask. | |
Private Member Functions | |
| Address | _generateAddress () |
| Signature | _registerComponent (ComponentType componentType) |
Private Attributes | |
| std::shared_mutex | _mutex |
| std::unordered_map< Address, Signature > | _signatures |
| Address | _nextAddress |
| std::priority_queue< Address, std::vector< Address >, std::greater< Address > > | _freeAddresses = {} |
| std::unordered_map< ComponentType, Signature > | _componentMap = {} |
| std::unordered_map< ComponentType, std::unordered_map< Address, std::any > > | _componentStorage = {} |
Manages entities, their signatures and component type registrations.
Responsibilities:
Notes:
Definition at line 68 of file Registry.hpp.
| ecs::Registry::Registry | ( | ) |
Construct a new Registry object.
Initializes internal maps. Addresses are generated sequentially and freed addresses are reused from a pool.
Definition at line 11 of file Registry.cpp.
| ecs::Registry::~Registry | ( | ) |
Destroy the Registry object and clear internal containers.
Definition at line 13 of file Registry.cpp.
References _componentMap, _componentStorage, and _signatures.
|
private |
Definition at line 19 of file Registry.cpp.
References _freeAddresses, and _nextAddress.
Referenced by newEntity().
|
private |
Definition at line 32 of file Registry.cpp.
References _componentMap, and N_MAX_COMPONENTS.
| void ecs::Registry::addEntityProp | ( | Address | address | ) |
Attach a component type T to an entity (set the component bit).
If the component type T is not yet registered, it will be registered automatically. If the component registration fails (component limit reached), no change is made.
| T | The component type to add. |
| address | The entity Address to which the component is added. |
| void ecs::Registry::destroyEntity | ( | Address | address | ) |
Remove an entity and its Signature from the registry.
| address | The Address of the entity to destroy. |
Definition at line 56 of file Registry.cpp.
References _componentStorage, _freeAddresses, _mutex, and _signatures.
Referenced by ecs::CollisionSystem::update().
| T & ecs::Registry::getComponent | ( | Address | address | ) |
Get a component from an entity.
| T | The component type to retrieve. |
| address | The entity Address. |
| std::runtime_error | if entity doesn't have the component. |
Referenced by ecs::BuffSystem::_applyBuffEffects(), ecs::MapSystem::_applyScrolling(), ecs::WeaponSystem::calculateProjectileTransform(), ecs::PrefabFactory::createOrbitalModule(), ecs::WeaponSystem::createProjectile(), ecs::WeaponSystem::fireChargedShot(), ecs::WeaponSystem::fireWeapon(), ecs::CollisionSystem::handleModuleEnemyCollision(), ecs::CollisionSystem::handleModuleProjectileCollision(), ecs::CollisionSystem::handlePickup(), ecs::CollisionSystem::handleProjectileCollision(), ecs::CollisionSystem::resolveWallCollision(), scripting::LuaSystemAdapter::update(), ecs::AISystem::update(), ecs::AnimationSystem::update(), ecs::BoundarySystem::update(), ecs::BuffSystem::update(), ecs::CollisionSystem::update(), ecs::HealthSystem::update(), ecs::MapSystem::update(), ecs::MovementSystem::update(), ecs::OrbitalSystem::update(), ecs::SpawnSystem::update(), ecs::WeaponSystem::update(), and ecs::OrbitalSystem::updateOrbitalPosition().
Get all entities matching a specific component mask.
Returns a vector of entity addresses that have all the components specified by the bitmask. This is the low-level filtering method used by systems for efficient entity queries.
| requiredMask | Bitmask of required components (from ComponentMask) |
Definition at line 79 of file Registry.cpp.
References _mutex, and _signatures.
Referenced by ecs::MapSystem::_applyScrolling(), scripting::LuaSystemAdapter::update(), ecs::AISystem::update(), ecs::AnimationSystem::update(), ecs::BoundarySystem::update(), ecs::CollisionSystem::update(), ecs::HealthSystem::update(), ecs::MapSystem::update(), ecs::MovementSystem::update(), ecs::OrbitalSystem::update(), and ecs::WeaponSystem::update().
Retrieve the Signature for a given entity address.
If the address is not present, a zero (empty) Signature is returned.
| address | The entity Address to query. |
Definition at line 70 of file Registry.cpp.
References _mutex, and _signatures.
Referenced by ecs::wrapper::Entity::isValid().
| bool ecs::Registry::hasComponent | ( | Address | address | ) |
Check if an entity has a specific component.
| T | The component type to check. |
| address | The entity Address. |
Referenced by ecs::BuffSystem::_applyBuffEffects(), ecs::MapSystem::_applyScrolling(), ecs::WeaponSystem::calculateProjectileTransform(), ecs::PrefabFactory::createOrbitalModule(), ecs::WeaponSystem::createProjectile(), ecs::WeaponSystem::fireChargedShot(), ecs::WeaponSystem::fireMultipleShots(), ecs::WeaponSystem::fireWeapon(), ecs::CollisionSystem::handleModuleEnemyCollision(), ecs::CollisionSystem::handleModuleProjectileCollision(), ecs::CollisionSystem::handlePickup(), ecs::CollisionSystem::handleProjectileCollision(), ecs::CollisionSystem::resolveWallCollision(), scripting::LuaSystemAdapter::update(), ecs::AISystem::update(), ecs::AnimationSystem::update(), ecs::BoundarySystem::update(), ecs::CollisionSystem::update(), ecs::HealthSystem::update(), ecs::WeaponSystem::update(), and ecs::OrbitalSystem::updateOrbitalPosition().
| Address ecs::Registry::newEntity | ( | ) |
Create and register a new entity, returning its Address.
A new unique Address is generated and an empty Signature (no components) is associated with it.
Definition at line 47 of file Registry.cpp.
References _generateAddress(), _mutex, and _signatures.
Referenced by ecs::SpawnSystem::_spawnEnemy(), ecs::PrefabFactory::createEnemy(), ecs::PrefabFactory::createEnemy(), ecs::PrefabFactory::createEnemyFromRegistry(), ecs::PrefabFactory::createHealthPack(), ecs::PrefabFactory::createPlayer(), ecs::PrefabFactory::createPowerUp(), ecs::PrefabFactory::createProjectile(), ecs::WeaponSystem::createProjectile(), and ecs::PrefabFactory::createWall().

| void ecs::Registry::removeComponent | ( | Address | address | ) |
Remove a component from an entity.
Removes the component data and updates the entity's signature.
| T | The component type to remove. |
| address | The entity Address. |
Referenced by ecs::BuffSystem::update().
| void ecs::Registry::setComponent | ( | Address | address, |
| const T & | component | ||
| ) |
Set/add a component to an entity with its data.
If the component type is not yet registered, it will be registered automatically. Updates the entity's signature and stores the component data.
| T | The component type to set. |
| address | The entity Address. |
| component | The component data to store. |
| std::runtime_error | if component limit is reached or entity doesn't exist. |
Referenced by ecs::SpawnSystem::_spawnEnemy(), ecs::PrefabFactory::createEnemy(), ecs::PrefabFactory::createEnemy(), ecs::PrefabFactory::createEnemyFromRegistry(), ecs::PrefabFactory::createHealthPack(), ecs::PrefabFactory::createOrbitalModule(), ecs::PrefabFactory::createPlayer(), ecs::PrefabFactory::createPowerUp(), ecs::PrefabFactory::createProjectile(), ecs::WeaponSystem::createProjectile(), ecs::PrefabFactory::createWall(), ecs::CollisionSystem::handlePickup(), ecs::BoundarySystem::update(), ecs::HealthSystem::update(), and ecs::OrbitalSystem::updateOrbitalPosition().
| std::vector< Address > ecs::Registry::view | ( | ) |
Get all entities that have a specific set of components.
Returns a vector of entity addresses that possess all the specified component types. This allows efficient iteration over entities matching a specific archetype.
| Components | The component types to filter by. |
Referenced by ecs::wrapper::ECSWorld::clear(), ecs::BuffSystem::update(), and ecs::SpawnSystem::update().
|
private |
Definition at line 81 of file Registry.hpp.
Referenced by _registerComponent(), and ~Registry().
|
private |
Definition at line 82 of file Registry.hpp.
Referenced by destroyEntity(), and ~Registry().
|
private |
Definition at line 80 of file Registry.hpp.
Referenced by _generateAddress(), and destroyEntity().
|
mutableprivate |
Definition at line 71 of file Registry.hpp.
Referenced by destroyEntity(), getEntitiesWithMask(), getSignature(), and newEntity().
|
private |
Definition at line 74 of file Registry.hpp.
Referenced by _generateAddress().
Definition at line 72 of file Registry.hpp.
Referenced by destroyEntity(), getEntitiesWithMask(), getSignature(), newEntity(), and ~Registry().