From 578f384808fe1f5fe26fed136cb033e2104e8490 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Thu, 10 Nov 2022 10:24:09 +0800 Subject: [PATCH] Removed redundant overloads to restrict potential bad function calls --- SHADE_Engine/src/Scene/SHSceneGraph.cpp | 105 ------------------------ SHADE_Engine/src/Scene/SHSceneGraph.h | 6 +- 2 files changed, 1 insertion(+), 110 deletions(-) diff --git a/SHADE_Engine/src/Scene/SHSceneGraph.cpp b/SHADE_Engine/src/Scene/SHSceneGraph.cpp index e2bd58e2..6240b7bf 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraph.cpp +++ b/SHADE_Engine/src/Scene/SHSceneGraph.cpp @@ -244,21 +244,6 @@ namespace SHADE SHEventManager::BroadcastEvent(EVENT_DATA, SH_SCENEGRAPH_CHANGE_PARENT_EVENT); } - void SHSceneGraph::SetParent(SHSceneNode* node, SHSceneNode* newParent) noexcept - { - const SHSceneGraphChangeParentEvent EVENT_DATA - { - .node = node - , .oldParent = node->parent - , .newParent = newParent ? newParent : root - }; - - if (newParent == nullptr) - newParent = root; - - ChangeParent(node, newParent); - } - void SHSceneGraph::SetParent(EntityID entityID, EntityID newParent) noexcept { //////////////////////////////////////// @@ -304,38 +289,6 @@ namespace SHADE SHEventManager::BroadcastEvent(EVENT_DATA, SH_SCENEGRAPH_CHANGE_PARENT_EVENT); } - void SHSceneGraph::SetParent(SHSceneNode* node, EntityID newParent) noexcept - { - //////////////////////////////////////// - // Error Handling - - if (!SHEntityManager::IsValidEID(newParent)) - { - SHLOG_ERROR("Parent Entity {} is invalid! Unable to set Entity {}'s parent!", newParent, node->entityID) - return; - } - - auto PARENT_ITER = entityNodeMap.find(newParent); - if (PARENT_ITER == entityNodeMap.end()) - { - SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to parent to Entity {}", newParent, node->entityID) - return; - } - //////////////////////////////////////// - - const SHSceneGraphChangeParentEvent EVENT_DATA - { - .node = node - , .oldParent = node->parent - , .newParent = PARENT_ITER->second - }; - - ChangeParent(node, PARENT_ITER->second); - - SHEventManager::BroadcastEvent(EVENT_DATA, SH_SCENEGRAPH_CHANGE_PARENT_EVENT); - } - - /*-----------------------------------------------------------------------------------*/ /* Public Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ @@ -456,32 +409,6 @@ namespace SHADE 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 { //////////////////////////////////////// @@ -527,38 +454,6 @@ namespace SHADE 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 { TraverseAndInvokeFunction(root, function); diff --git a/SHADE_Engine/src/Scene/SHSceneGraph.h b/SHADE_Engine/src/Scene/SHSceneGraph.h index 494f480e..5747be7b 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraph.h +++ b/SHADE_Engine/src/Scene/SHSceneGraph.h @@ -65,9 +65,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ void SetParent (EntityID entityID, SHSceneNode* newParent) noexcept; - void SetParent (SHSceneNode* node, SHSceneNode* newParent) noexcept; void SetParent (EntityID entityID, EntityID newParent) noexcept; - void SetParent (SHSceneNode* node, EntityID newParent) noexcept; /*---------------------------------------------------------------------------------*/ /* Function Members */ @@ -79,9 +77,7 @@ namespace SHADE 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; + bool IsChildOf (EntityID entityID, EntityID targetID) noexcept; void Traverse (const UnaryFunction& function) const;