From a369c26a280d2226b82f4ae510701c823aec69e6 Mon Sep 17 00:00:00 2001 From: stiffly Date: Mon, 7 Mar 2016 14:19:22 +0100 Subject: [PATCH] Blend tree nodes can now exist without transform components, without the game crashing. --- include/Engine/Editor/EditorSystem.h | 1 + src/Engine/Editor/EditorSystem.cpp | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/Engine/Editor/EditorSystem.h b/include/Engine/Editor/EditorSystem.h index 655ac9b9..a6d3e759 100644 --- a/include/Engine/Editor/EditorSystem.h +++ b/include/Engine/Editor/EditorSystem.h @@ -47,6 +47,7 @@ private: // Utility functions EntityWrapper importEntity(EntityWrapper parent, boost::filesystem::path filePath); void setWidgetMode(EditorGUI::WidgetMode mode); + bool IsAnyParentMissingTransform(EntityID entityID); // GUI callbacks void OnEntitySelected(EntityWrapper entity); diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index f9cdde0b..f66cd01c 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -4,7 +4,7 @@ #include "Editor/EditorWidgetSystem.h" #include "Core/EntityFile.h" -EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame* renderFrame) +EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame* renderFrame) : System(params) , m_Renderer(renderer) , m_RenderFrame(renderFrame) @@ -14,7 +14,7 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame m_EditorWorldSystemPipeline->AddSystem(0); m_EditorWorldSystemPipeline->AddSystem(0, m_Renderer); m_EditorWorldSystemPipeline->AddSystem(1, m_Renderer, m_RenderFrame); - + m_EditorCamera = importEntity(EntityWrapper(m_EditorWorld, EntityID_Invalid), "Schema/Entities/Empty.xml"); m_ActualCamera = m_EditorCamera; m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Transform"); @@ -70,7 +70,11 @@ void EditorSystem::Update(double dt) m_EditorGUI->Draw(); m_EditorStats->Draw(actualDelta); + if (IsAnyParentMissingTransform(m_CurrentSelection.ID)) { + return; + } if (m_CurrentSelection.Valid() && m_Widget.Valid()) { + (glm::vec3&)m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection); if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) { (glm::vec3&)m_Widget["Transform"]["Orientation"] = Transform::AbsoluteOrientationEuler(m_CurrentSelection); @@ -78,7 +82,6 @@ void EditorSystem::Update(double dt) (glm::vec3&)m_Widget["Transform"]["Orientation"] = glm::vec3(0, 0, 0); } } - m_EditorWorldSystemPipeline->Update(actualDelta); ComponentWrapper& cameraTransform = m_EditorCamera["Transform"]; @@ -202,6 +205,9 @@ bool EditorSystem::OnMousePress(const Events::MousePress& e) bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e) { if (m_CurrentSelection.Valid()) { + if (IsAnyParentMissingTransform(m_CurrentSelection.ID)) { + return false; + } if (m_WidgetSpace == EditorGUI::WidgetSpace::Global) { glm::quat parentOrientation; EntityWrapper parent = m_CurrentSelection.Parent(); @@ -301,3 +307,15 @@ void EditorSystem::setWidgetMode(EditorGUI::WidgetMode mode) m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection.World, m_CurrentSelection.ID); } + +bool EditorSystem::IsAnyParentMissingTransform(EntityID entityID) +{ + EntityWrapper entity(m_World, entityID); + while (entity.Parent().Valid()) { + if (!entity.HasComponent("Transform")) { + return true; + } + entity = entity.Parent(); + } + return false; +}