Added IsChildOf method to SceneGraph
This commit is contained in:
parent
ac217ffe97
commit
08b3cbafcd
|
@ -263,6 +263,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
// Error Handling
|
// Error Handling
|
||||||
|
|
||||||
if (!SHEntityManager::IsValidEID(entityID))
|
if (!SHEntityManager::IsValidEID(entityID))
|
||||||
{
|
{
|
||||||
SHLOG_ERROR("Entity {} is invalid! Unable to set parent of an invalid entity!", entityID)
|
SHLOG_ERROR("Entity {} is invalid! Unable to set parent of an invalid entity!", entityID)
|
||||||
|
@ -374,6 +375,8 @@ namespace SHADE
|
||||||
|
|
||||||
bool SHSceneGraph::RemoveNode(EntityID entityID) noexcept
|
bool SHSceneGraph::RemoveNode(EntityID entityID) noexcept
|
||||||
{
|
{
|
||||||
|
////////////////////////////////////////
|
||||||
|
// Error Handling
|
||||||
if (!SHEntityManager::IsValidEID(entityID))
|
if (!SHEntityManager::IsValidEID(entityID))
|
||||||
{
|
{
|
||||||
SHLOG_ERROR("Entity {} is invalid!", entityID)
|
SHLOG_ERROR("Entity {} is invalid!", entityID)
|
||||||
|
@ -386,6 +389,7 @@ namespace SHADE
|
||||||
SHLOG_ERROR("Entity {} does not exist in the scene!", entityID)
|
SHLOG_ERROR("Entity {} does not exist in the scene!", entityID)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
// Remove reference of current node from parent
|
// Remove reference of current node from parent
|
||||||
SHSceneNode* currentNode = NODE_ITER->second;
|
SHSceneNode* currentNode = NODE_ITER->second;
|
||||||
|
@ -412,6 +416,149 @@ namespace SHADE
|
||||||
ReleaseNode(node);
|
ReleaseNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SHSceneGraph::IsChildOf(EntityID entityID, SHSceneNode* targetNode) noexcept
|
||||||
|
{
|
||||||
|
////////////////////////////////////////
|
||||||
|
// Error Handling
|
||||||
|
|
||||||
|
if (!SHEntityManager::IsValidEID(entityID))
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Entity {} is invalid!", entityID)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NODE_ITER = entityNodeMap.find(entityID);
|
||||||
|
if (NODE_ITER == entityNodeMap.end())
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to check child!", entityID)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
|
// Handle self-checks
|
||||||
|
if (NODE_ITER->second == targetNode)
|
||||||
|
{
|
||||||
|
SHLOG_WARNING("Entity {} cannot be a child of itself!", entityID)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search for a matching target until the root
|
||||||
|
const SHSceneNode* CURRENT_TARGET = NODE_ITER->second->parent;
|
||||||
|
while (CURRENT_TARGET != root)
|
||||||
|
{
|
||||||
|
if (CURRENT_TARGET == targetNode)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
CURRENT_TARGET = CURRENT_TARGET->parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHSceneGraph::IsChildOf(SHSceneNode* node, SHSceneNode* targetNode) noexcept
|
||||||
|
{
|
||||||
|
if (!node || !targetNode)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Attempting to check for invalid scene nodes!")
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node == targetNode)
|
||||||
|
{
|
||||||
|
SHLOG_WARNING("Entity {} cannot be a child of itself!", node->entityID)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SHSceneNode* CURRENT_TARGET = node->parent;
|
||||||
|
while (CURRENT_TARGET != root)
|
||||||
|
{
|
||||||
|
if (CURRENT_TARGET == targetNode)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
CURRENT_TARGET = CURRENT_TARGET->parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHSceneGraph::IsChildOf(EntityID entityID, EntityID targetID) noexcept
|
||||||
|
{
|
||||||
|
////////////////////////////////////////
|
||||||
|
// Error Handling
|
||||||
|
|
||||||
|
if (!SHEntityManager::IsValidEID(entityID))
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Entity {} is invalid!", entityID)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SHEntityManager::IsValidEID(targetID))
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Entity {} is invalid!", targetID)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NODE_ITER = entityNodeMap.find(entityID);
|
||||||
|
if (NODE_ITER == entityNodeMap.end())
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to check child!", entityID)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto TARGET_ITER = entityNodeMap.find(targetID);
|
||||||
|
if (TARGET_ITER == entityNodeMap.end())
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to check child!", targetID)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
|
const SHSceneNode* CURRENT_TARGET = NODE_ITER->second->parent;
|
||||||
|
while (CURRENT_TARGET != root)
|
||||||
|
{
|
||||||
|
if (CURRENT_TARGET == TARGET_ITER->second)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
CURRENT_TARGET = CURRENT_TARGET->parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHSceneGraph::IsChildOf(SHSceneNode* node, EntityID targetID) noexcept
|
||||||
|
{
|
||||||
|
////////////////////////////////////////
|
||||||
|
// Error Handling
|
||||||
|
|
||||||
|
if (!SHEntityManager::IsValidEID(targetID))
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Entity {} is invalid!", targetID)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto TARGET_ITER = entityNodeMap.find(targetID);
|
||||||
|
if (TARGET_ITER == entityNodeMap.end())
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to check child!", targetID)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
|
const SHSceneNode* CURRENT_TARGET = node->parent;
|
||||||
|
while (CURRENT_TARGET != root)
|
||||||
|
{
|
||||||
|
if (CURRENT_TARGET == TARGET_ITER->second)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
CURRENT_TARGET = CURRENT_TARGET->parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void SHSceneGraph::Traverse (const UnaryFunction& function) const
|
void SHSceneGraph::Traverse (const UnaryFunction& function) const
|
||||||
{
|
{
|
||||||
TraverseAndInvokeFunction(root, function);
|
TraverseAndInvokeFunction(root, function);
|
||||||
|
|
|
@ -66,7 +66,6 @@ namespace SHADE
|
||||||
|
|
||||||
void SetParent (EntityID entityID, SHSceneNode* newParent) noexcept;
|
void SetParent (EntityID entityID, SHSceneNode* newParent) noexcept;
|
||||||
void SetParent (SHSceneNode* node, SHSceneNode* newParent) noexcept;
|
void SetParent (SHSceneNode* node, SHSceneNode* newParent) noexcept;
|
||||||
|
|
||||||
void SetParent (EntityID entityID, EntityID newParent) noexcept;
|
void SetParent (EntityID entityID, EntityID newParent) noexcept;
|
||||||
void SetParent (SHSceneNode* node, EntityID newParent) noexcept;
|
void SetParent (SHSceneNode* node, EntityID newParent) noexcept;
|
||||||
|
|
||||||
|
@ -79,6 +78,11 @@ namespace SHADE
|
||||||
bool RemoveNode (SHSceneNode* nodeToRemove) noexcept;
|
bool RemoveNode (SHSceneNode* nodeToRemove) noexcept;
|
||||||
void Reset () noexcept;
|
void Reset () noexcept;
|
||||||
|
|
||||||
|
bool IsChildOf (EntityID entityID, SHSceneNode* targetNode) noexcept;
|
||||||
|
bool IsChildOf (SHSceneNode* node, SHSceneNode* targetNode) noexcept;
|
||||||
|
bool IsChildOf (EntityID entityID, EntityID targetID) noexcept;
|
||||||
|
bool IsChildOf (SHSceneNode* node, EntityID targetID) noexcept;
|
||||||
|
|
||||||
void Traverse (const UnaryFunction& function) const;
|
void Traverse (const UnaryFunction& function) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue