From 85a63cec1fc8f734317699c62cfe97563872fbc0 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Thu, 8 Sep 2022 12:06:29 +0800 Subject: [PATCH] #comment removed two CreateEntity function overloads and added a default value to desired EID instead --- .../ECS_Base/System/SHEntityManager.cpp | 65 +++------------- .../Engine/ECS_Base/System/SHEntityManager.h | 75 ++++--------------- 2 files changed, 24 insertions(+), 116 deletions(-) diff --git a/SHADE_Engine/src/Engine/ECS_Base/System/SHEntityManager.cpp b/SHADE_Engine/src/Engine/ECS_Base/System/SHEntityManager.cpp index 4aa38112..240c0b32 100644 --- a/SHADE_Engine/src/Engine/ECS_Base/System/SHEntityManager.cpp +++ b/SHADE_Engine/src/Engine/ECS_Base/System/SHEntityManager.cpp @@ -52,63 +52,20 @@ namespace SHADE return entityHandle.GetIndex(entityID); } - EntityID SHEntityManager::CreateEntity(std::vectorconst& componentTypeIDs, std::string const& name,EntityID parentEID) - { - EntityID eID = entityHandle.GetNewHandle(); - EntityIndex eIndex = entityHandle.GetIndex(eID); - if (eIndex > entityVec.size()) - { - assert("FATAL ERROR: EntityIndex out of range in Entity Creation"); - } - else if (eIndex == entityVec.size()) - { - entityVec.emplace_back(std::make_unique()); - } - else - { - if (!entityVec[eIndex]) - { - //There is still an entity stored there.Something went wrong - assert("FATAL ERROR: Entity Creation error. Entity Index Conflict"); - } - - //Reset it to a newly constructed entity - entityVec[eIndex].reset(new SHEntity()); - } - - - entityVec[eIndex]->entityID = eID; - entityVec[eIndex]->name = name; - for (auto& id : componentTypeIDs) - { - SHComponentManager::AddComponent(eID, id); - } - - //(SHComponentManager::AddComponent(eID), ...); - /*if (entityHandle.IsValid(parentEID) == false) - { - entityVec[eIndex]->sceneNode.ConnectToRoot(); - } - else - { - entityVec[eIndex]->SetParent(parentEID); - }*/ - - - //TODO Link to Scene graph. - - return eID; - - } - EntityID SHEntityManager::CreateEntity(std::vectorconst& componentTypeIDs, EntityID desiredEID, std::string const& name, EntityID parentEID) { - EntityID eID ; - - if (entityHandle.ClaimHandle(desiredEID) == true) - eID = desiredEID; - else + EntityID eID; + if (desiredEID == MAX_EID) + { eID = entityHandle.GetNewHandle(); + } + else + { + if (entityHandle.ClaimHandle(desiredEID) == true) + eID = desiredEID; + else + eID = entityHandle.GetNewHandle(); + } EntityIndex eIndex = entityHandle.GetIndex(eID); diff --git a/SHADE_Engine/src/Engine/ECS_Base/System/SHEntityManager.h b/SHADE_Engine/src/Engine/ECS_Base/System/SHEntityManager.h index 11e896d5..7afece52 100644 --- a/SHADE_Engine/src/Engine/ECS_Base/System/SHEntityManager.h +++ b/SHADE_Engine/src/Engine/ECS_Base/System/SHEntityManager.h @@ -81,55 +81,21 @@ namespace SHADE * EntityID of the new Entity ***************************************************************************/ template - static std::enable_if_t<(... && std::is_base_of_v), EntityID> CreateEntity(std::string const& name = "Default", EntityID parentEID = MAX_EID) - { - EntityID eID = entityHandle.GetNewHandle(); - EntityIndex eIndex = entityHandle.GetIndex(eID); - if (eIndex > entityVec.size()) - { - assert("FATAL ERROR: EntityIndex out of range in Entity Creation"); - } - else if (eIndex == entityVec.size()) - { - entityVec.emplace_back(std::make_unique()); - } - else - { - if (!entityVec[eIndex]) - { - //There is still an entity stored there.Something went wrong - assert("FATAL ERROR: Entity Creation error. Entity Index Conflict"); - } - - //Reset it to a newly constructed entity - entityVec[eIndex].reset(new SHEntity()); - } - entityVec[eIndex]->entityID = eID; - entityVec[eIndex]->name = name; - (SHComponentManager::AddComponent(eID),...); - - /*if (entityHandle.IsValid(parentEID) == false) - { - entityVec[eIndex]->sceneNode.ConnectToRoot(); - } - else - { - entityVec[eIndex]->SetParent(parentEID); - }*/ - - //TODO Link up with Scene graph - - return eID; - } - - template - static std::enable_if_t<(... && std::is_base_of_v), EntityID> CreateEntity(EntityID desiredEID, std::string const& name = "Default", EntityID parentEID = MAX_EID) + static std::enable_if_t<(... && std::is_base_of_v), EntityID> CreateEntity(EntityID desiredEID = MAX_EID, std::string const& name = "Default", EntityID parentEID = MAX_EID) { EntityID eID; - if (entityHandle.ClaimHandle(desiredEID) == true) - eID = desiredEID; - else + if (desiredEID == MAX_EID) + { eID = entityHandle.GetNewHandle(); + } + else + { + if (entityHandle.ClaimHandle(desiredEID) == true) + eID = desiredEID; + else + eID = entityHandle.GetNewHandle(); + } + EntityIndex eIndex = entityHandle.GetIndex(eID); if (eIndex > entityVec.size()) { @@ -179,21 +145,6 @@ namespace SHADE - /************************************************************************** - * \brief - * Create Entity using a vector of ComponentTypeIDs. - * \param componentTypeIDs - * Vector of ComponentTypeIDs. This assumes that CreateSparseSet is called - * for these ComponentTypes. - * \param name - * Name of the Entity (this is not unique) - * \param parentEID - * The entity ID of the parent. This does not call UpdateHierarchy hence - * the parent of the entity is not updated until UpdateHierarchy is called. - * \return - * EntityID of the new Entity - ***************************************************************************/ - static EntityID CreateEntity(std::vectorconst& componentTypeIDs,std::string const& name = "Default", EntityID parentEID = MAX_EID); /************************************************************************** * \brief @@ -209,7 +160,7 @@ namespace SHADE * \return * EntityID of the new Entity ***************************************************************************/ - static EntityID CreateEntity(std::vectorconst& componentTypeIDs, EntityID desiredEID, std::string const& name = "Default", EntityID parentEID = MAX_EID); + static EntityID CreateEntity(std::vectorconst& componentTypeIDs, EntityID desiredEID = MAX_EID, std::string const& name = "Default", EntityID parentEID = MAX_EID); /************************************************************************** * \brief