SP3-5 ECS #27
|
@ -52,63 +52,20 @@ namespace SHADE
|
||||||
return entityHandle.GetIndex(entityID);
|
return entityHandle.GetIndex(entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityID SHEntityManager::CreateEntity(std::vector<uint32_t>const& 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<SHEntity>());
|
|
||||||
}
|
|
||||||
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<ComponentTypes>(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::vector<uint32_t>const& componentTypeIDs, EntityID desiredEID, std::string const& name, EntityID parentEID)
|
EntityID SHEntityManager::CreateEntity(std::vector<uint32_t>const& componentTypeIDs, EntityID desiredEID, std::string const& name, EntityID parentEID)
|
||||||
{
|
{
|
||||||
EntityID eID;
|
EntityID eID;
|
||||||
|
if (desiredEID == MAX_EID)
|
||||||
|
{
|
||||||
|
eID = entityHandle.GetNewHandle();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (entityHandle.ClaimHandle(desiredEID) == true)
|
if (entityHandle.ClaimHandle(desiredEID) == true)
|
||||||
eID = desiredEID;
|
eID = desiredEID;
|
||||||
else
|
else
|
||||||
eID = entityHandle.GetNewHandle();
|
eID = entityHandle.GetNewHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
EntityIndex eIndex = entityHandle.GetIndex(eID);
|
EntityIndex eIndex = entityHandle.GetIndex(eID);
|
||||||
|
|
|
@ -81,55 +81,21 @@ namespace SHADE
|
||||||
* EntityID of the new Entity
|
* EntityID of the new Entity
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
template<typename ...ComponentTypes>
|
template<typename ...ComponentTypes>
|
||||||
static std::enable_if_t<(... && std::is_base_of_v<SHComponent, ComponentTypes>), EntityID> CreateEntity(std::string const& name = "Default", EntityID parentEID = MAX_EID)
|
static std::enable_if_t<(... && std::is_base_of_v<SHComponent, ComponentTypes>), EntityID> CreateEntity(EntityID desiredEID = MAX_EID, 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<SHEntity>());
|
|
||||||
}
|
|
||||||
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<ComponentTypes>(eID),...);
|
|
||||||
|
|
||||||
/*if (entityHandle.IsValid(parentEID) == false)
|
|
||||||
{
|
|
||||||
entityVec[eIndex]->sceneNode.ConnectToRoot();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entityVec[eIndex]->SetParent(parentEID);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//TODO Link up with Scene graph
|
|
||||||
|
|
||||||
return eID;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename ...ComponentTypes>
|
|
||||||
static std::enable_if_t<(... && std::is_base_of_v<SHComponent, ComponentTypes>), EntityID> CreateEntity(EntityID desiredEID, std::string const& name = "Default", EntityID parentEID = MAX_EID)
|
|
||||||
{
|
{
|
||||||
EntityID eID;
|
EntityID eID;
|
||||||
|
if (desiredEID == MAX_EID)
|
||||||
|
{
|
||||||
|
eID = entityHandle.GetNewHandle();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (entityHandle.ClaimHandle(desiredEID) == true)
|
if (entityHandle.ClaimHandle(desiredEID) == true)
|
||||||
eID = desiredEID;
|
eID = desiredEID;
|
||||||
else
|
else
|
||||||
eID = entityHandle.GetNewHandle();
|
eID = entityHandle.GetNewHandle();
|
||||||
|
}
|
||||||
|
|
||||||
EntityIndex eIndex = entityHandle.GetIndex(eID);
|
EntityIndex eIndex = entityHandle.GetIndex(eID);
|
||||||
if (eIndex > entityVec.size())
|
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::vector<ComponentTypeID>const& componentTypeIDs,std::string const& name = "Default", EntityID parentEID = MAX_EID);
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* \brief
|
* \brief
|
||||||
|
@ -209,7 +160,7 @@ namespace SHADE
|
||||||
* \return
|
* \return
|
||||||
* EntityID of the new Entity
|
* EntityID of the new Entity
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static EntityID CreateEntity(std::vector<ComponentTypeID>const& componentTypeIDs, EntityID desiredEID, std::string const& name = "Default", EntityID parentEID = MAX_EID);
|
static EntityID CreateEntity(std::vector<ComponentTypeID>const& componentTypeIDs, EntityID desiredEID = MAX_EID, std::string const& name = "Default", EntityID parentEID = MAX_EID);
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* \brief
|
* \brief
|
||||||
|
|
Loading…
Reference in New Issue