engine/ecs/EntityManager.ixx File
Central manager for entity lifecycle and component storage. More...
Included Headers
#include <cassert>
#include <generator>
#include <memory>
#include <ranges>
#include <vector>
#include <helios/helios_config.h>
#include <helios.engine.ecs.ComponentOpsRegistry>
#include <helios.engine.ecs.EntityHandle>
#include <helios.engine.ecs.EntityRegistry>
#include <helios.engine.ecs.ComponentOps>
#include <helios.engine.ecs.Traits>
#include <helios.engine.ecs.SparseSet>
#include <helios.core.data>
#include <helios.engine.ecs.types>
Namespaces Index
| namespace | helios |
| namespace | engine |
|
Main engine module aggregating core infrastructure and game systems. More... | |
| namespace | ecs |
|
Core Entity-Component-System architecture. More... | |
Classes Index
| class | EntityManager |
|
Manages entities and their associated components. More... | |
Description
Central manager for entity lifecycle and component storage.
File Listing
The file content with the documentation metadata removed is:
28export namespace helios::engine::ecs {
67 class EntityManager {
78 EntityRegistry& registry_;
92 explicit EntityManager(EntityRegistry& registry, size_t capacity = ENTITY_MANAGER_DEFAULT_CAPACITY)
104 [[nodiscard]] EntityHandle create() {
115 [[nodiscard]] bool isValid(const EntityHandle handle) const noexcept {
116 return registry_.isValid(handle);
127 return registry_.isValid(handle(entityId));
141 [[nodiscard]] bool destroy(const EntityHandle handle) {
143 if (!registry_.isValid(handle)) {
152 const auto typeId = ComponentTypeId{i};
154 if (const auto& ops = helios::engine::ecs::ComponentOpsRegistry::ops(typeId); ops.onRemove) {
159 components_[i]->remove(handle.entityId);
162 registry_.destroy(handle);
178 [[nodiscard]] T* get(const EntityHandle handle) const {
183 const auto entityId = handle.entityId;
184 const auto typeId = ComponentTypeId::id<T>().value();
186 auto* sparseSet = static_cast<SparseSet<T>*>(components_[typeId].get());
199 [[nodiscard]] SparseSet<T>* getSparseSet() {
201 const auto typeId = ComponentTypeId::id<T>().value();
207 return static_cast<SparseSet<T>*>(components_[typeId].get());
218 [[nodiscard]] const SparseSet<T>* getSparseSet() const {
220 const auto typeId = ComponentTypeId::id<T>().value();
226 return static_cast<SparseSet<T>*>(components_[typeId].get());
240 [[nodiscard]] bool has(const EntityHandle handle) const {
241 if (!registry_.isValid(handle)) {
245 const auto typeId = ComponentTypeId::id<T>().value();
248 return components_[typeId]->contains(handle.entityId);
262 [[nodiscard]] bool has(const EntityHandle handle, const helios::engine::ecs::types::ComponentTypeId typeId) const {
263 if (!registry_.isValid(handle)) {
267 const auto tvalue = typeId.value();
270 return components_[tvalue]->contains(handle.entityId);
284 void enable(const EntityHandle handle, const helios::engine::ecs::types::ComponentTypeId typeId) const {
296 void disable(const EntityHandle handle, const helios::engine::ecs::types::ComponentTypeId typeId) const {
307 void enable(const EntityHandle handle, const helios::engine::ecs::types::ComponentTypeId typeId, const bool enable) const {
317 const auto& ops = helios::engine::ecs::ComponentOpsRegistry::ops(typeId);
319 if (enable && ops.enable) {
321 } else if (!enable && ops.disable) {
344 T* emplace(const EntityHandle handle, Args&& ...args) {
346 if (!registry_.isValid(handle)) {
350 const auto entityId = handle.entityId;
352 const auto typeId = ComponentTypeId::id<T>().value();
362 auto* sparseSet = static_cast<SparseSet<T>*>(components_[typeId].get());
384 T* emplaceOrGet(const EntityHandle handle, Args&& ...args) {
386 if (!registry_.isValid(handle)) {
390 auto* raw = emplace<T>(handle, std::forward<Args>(args)...);
392 if (!raw) {
417 bool remove(const EntityHandle& handle) {
423 const auto typeId = ComponentTypeId::id<T>();
428 const auto& ops = helios::engine::ecs::ComponentOpsRegistry::ops(typeId);
434 return components_[typeId.value()]->remove(handle.entityId);
445 componentTypeIds(const EntityHandle handle) const {
446 if (!registry_.isValid(handle)) {
451 if (components_[i] && components_[i]->contains(handle.entityId)) {
452 co_yield ComponentTypeId{i};
467 void clone(const EntityHandle source, const EntityHandle target) {
473 for (auto typeId : componentTypeIds(source)) {
475 if (!has(target, typeId)) {
477 const auto& ops = ComponentOpsRegistry::ops(typeId);
479 const void* sourceCmp = raw(source, typeId);
498 [[nodiscard]] void* raw(const EntityHandle handle, const helios::engine::ecs::types::ComponentTypeId typeId ) const {
513 [[nodiscard]] EntityHandle handle(const EntityId entityId) const {
514 return EntityHandle{entityId, registry_.version(entityId)};
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.