From 14eed4c7260acaa792d48c080f4349a7ffd0a52b Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Wed, 21 Sep 2022 18:30:20 +0800 Subject: [PATCH] Added missing active check in transform system --- .../src/Math/Transform/SHTransformSystem.cpp | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp index 6a1daff2..879c2d34 100644 --- a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp +++ b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp @@ -16,6 +16,8 @@ // Project Headers #include "Scene/SHSceneManager.h" #include "ECS_Base/Managers/SHComponentManager.h" +#include "ECS_Base/Managers/SHEntityManager.h" +#include "Tools/SHException.h" namespace SHADE { @@ -35,8 +37,8 @@ namespace SHADE void SHTransformSystem::Execute(double dt) noexcept { // Get the current scene graph to traverse and update - auto& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); - UpdateEntity(sceneGraph.GetRoot()); + const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); + UpdateEntity(SCENE_GRAPH.GetRoot()); } /*-----------------------------------------------------------------------------------*/ @@ -50,6 +52,20 @@ namespace SHADE for (const auto* child : node->GetChildren()) { + // Active states of entities should sync with scene nodes + const bool IS_NODE_ACTIVE = child->isActive; + + #ifdef _DEBUG + const bool IS_ENTITY_ACTIVE = SHEntityManager::GetEntityByID(child->GetEntityID())->GetActive(); + SHASSERT(IS_NODE_ACTIVE == IS_ENTITY_ACTIVE, "Entity and Node active states are not synced!") + #endif + + if (!IS_NODE_ACTIVE) + { + UpdateEntity(child); + continue; + } + const bool HAS_TRANSFORM = SHComponentManager::HasComponent(child->GetEntityID()); if (!HAS_TRANSFORM) continue; @@ -61,13 +77,14 @@ namespace SHADE UpdateEntity(child); + // Clear dirty flag after all children are updated childTransform->dirty = false; } } void SHTransformSystem::UpdateTransform(SHTransformComponent& tf, const SHTransformComponent* parent) { - SHMatrix localToWorld = SHMatrix::Identity; + SHMatrix localToWorld = SHMatrix::Identity; SHMatrix worldToLocal = SHMatrix::Identity; if (parent) @@ -103,7 +120,8 @@ namespace SHADE break; } - default: break; // Redundant + // Redundant + default: break; } tf.updateQueue.pop();