From ecd358a53e76a2d66f538d24975142900d1a0b1a Mon Sep 17 00:00:00 2001 From: AMZN-Olex <5432499+AMZN-Olex@users.noreply.github.com> Date: Thu, 7 Oct 2021 12:56:44 -0400 Subject: [PATCH] Cleaning up Signed-off-by: AMZN-Olex <5432499+AMZN-Olex@users.noreply.github.com> --- .../MultiplayerDebugHierarchyDebugger.cpp | 198 ------------------ .../Debug/MultiplayerDebugHierarchyDebugger.h | 55 ----- 2 files changed, 253 deletions(-) delete mode 100644 Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugHierarchyDebugger.cpp delete mode 100644 Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugHierarchyDebugger.h diff --git a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugHierarchyDebugger.cpp b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugHierarchyDebugger.cpp deleted file mode 100644 index 393f67474b..0000000000 --- a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugHierarchyDebugger.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#include "MultiplayerDebugHierarchyDebugger.h" - -#include -#include -#include -#include - -#if defined(IMGUI_ENABLED) -#include -#endif - -namespace Multiplayer -{ - MultiplayerDebugHierarchyReporter::MultiplayerDebugHierarchyReporter() - : m_updateDebugOverlay([this]() { UpdateDebugOverlay(); }, AZ::Name("UpdateHierarchyDebug")) - { - CollectHierarchyRoots(); - - AZ::EntitySystemBus::Handler::BusConnect(); - m_updateDebugOverlay.Enqueue(AZ::TimeMs{ 0 }, true); - } - - MultiplayerDebugHierarchyReporter::~MultiplayerDebugHierarchyReporter() - { - AZ::EntitySystemBus::Handler::BusDisconnect(); - } - - // -------------------------------------------------------------------------------------------- - void MultiplayerDebugHierarchyReporter::OnImGuiUpdate() - { -#if defined(IMGUI_ENABLED) - for (const auto& root : m_hierarchyRoots) - { - if (const auto* rootComponent = root.second.m_rootComponent) - { - if (rootComponent->IsHierarchicalRoot()) - { - const AZStd::vector& hierarchicalChildren = rootComponent->GetHierarchicalEntities(); - - if (ImGui::TreeNode(rootComponent->GetEntity()->GetName().c_str(), - "Hierarchy, Root entity name [%s]: %4zu members", - rootComponent->GetEntity()->GetName().c_str(), - hierarchicalChildren.size())) - { - ImGui::Separator(); - ImGui::Columns(4, "hierarchy_columns"); - ImGui::Text("EntityId"); - ImGui::NextColumn(); - ImGui::Text("NetEntityId"); - ImGui::NextColumn(); - ImGui::Text("Entity Name"); - ImGui::NextColumn(); - ImGui::Text("Role"); - ImGui::NextColumn(); - - ImGui::Separator(); - ImGui::Columns(4, "hierarchy child info"); - - bool firstEntity = true; - for (const AZ::Entity* entity : hierarchicalChildren) - { - ImGui::Text("%s", entity->GetId().ToString().c_str()); - ImGui::NextColumn(); - ImGui::Text("%u", GetMultiplayer()->GetNetworkEntityManager()->GetNetEntityIdById(entity->GetId())); - ImGui::NextColumn(); - ImGui::Text("%s", entity->GetName().c_str()); - ImGui::NextColumn(); - - if (firstEntity) - { - ImGui::Text("Root node"); - } - else if (entity->FindComponent()) - { - ImGui::Text("Inner root node"); - } - else if (entity->FindComponent()) - { - ImGui::Text("Child node"); - } - ImGui::NextColumn(); - - firstEntity = false; - } - - ImGui::Columns(1); - ImGui::TreePop(); - } - } - } - } -#endif - } - - - void MultiplayerDebugHierarchyReporter::UpdateDebugOverlay() - { - if (!m_hierarchyRoots.empty()) - { - if (m_debugDisplay == nullptr) - { - AzFramework::DebugDisplayRequestBus::BusPtr debugDisplayBus; - AzFramework::DebugDisplayRequestBus::Bind(debugDisplayBus, AzFramework::g_defaultSceneEntityDebugDisplayId); - m_debugDisplay = AzFramework::DebugDisplayRequestBus::FindFirstHandler(debugDisplayBus); - } - - const AZ::u32 stateBefore = m_debugDisplay->GetState(); - m_debugDisplay->SetColor(AZ::Colors::White); - - for (const auto& root : m_hierarchyRoots) - { - if (const auto* rootComponent = root.second.m_rootComponent) - { - if (rootComponent->IsHierarchicalRoot()) - { - const AZStd::vector& hierarchicalChildren = rootComponent->GetHierarchicalEntities(); - - azsprintf(m_statusBuffer, "Hierarchy [%s] %u members", rootComponent->GetEntity()->GetName().c_str(), - aznumeric_cast(hierarchicalChildren.size())); - - AZ::Vector3 entityPosition = rootComponent->GetEntity()->GetTransform()->GetWorldTranslation(); - constexpr bool centerText = true; - m_debugDisplay->DrawTextLabel(entityPosition, 1.0f, m_statusBuffer, centerText, 0, 0); - } - } - } - - m_debugDisplay->SetState(stateBefore); - } - } - - void MultiplayerDebugHierarchyReporter::OnEntityActivated(const AZ::EntityId& entityId) - { - if (const AZ::Entity* childEntity = AZ::Interface::Get()->FindEntity(entityId)) - { - if (auto* rootComponent = childEntity->FindComponent()) - { - HierarchyRootInfo info; - info.m_rootComponent = rootComponent; - rootComponent->BindNetworkHierarchyChangedEventHandler(info.m_changedEvent); - rootComponent->BindNetworkHierarchyLeaveEventHandler(info.m_leaveEvent); - - m_hierarchyRoots.insert(AZStd::make_pair(rootComponent, info)); - } - } - } - - void MultiplayerDebugHierarchyReporter::OnEntityDeactivated(const AZ::EntityId& entityId) - { - if (const AZ::Entity* childEntity = AZ::Interface::Get()->FindEntity(entityId)) - { - if (auto* rootComponent = childEntity->FindComponent()) - { - m_hierarchyRoots.erase(rootComponent); - } - } - } - - void MultiplayerDebugHierarchyReporter::CollectHierarchyRoots() - { - AZStd::vector gatheredEntries; - const AZ::Sphere awarenessSphere = AZ::Sphere(AZ::Vector3::CreateZero(), 1000.f); - AZ::Interface::Get()->GetDefaultVisibilityScene()->Enumerate(awarenessSphere, [&gatheredEntries](const AzFramework::IVisibilityScene::NodeData& nodeData) - { - gatheredEntries.reserve(gatheredEntries.size() + nodeData.m_entries.size()); - for (AzFramework::VisibilityEntry* visEntry : nodeData.m_entries) - { - if (visEntry->m_typeFlags & AzFramework::VisibilityEntry::TypeFlags::TYPE_Entity) - { - gatheredEntries.push_back(visEntry); - } - } - } - ); - - for (const AzFramework::VisibilityEntry* entry : gatheredEntries) - { - const AZ::Entity* entity = static_cast(entry->m_userData); - if (auto* rootComponent = entity->FindComponent()) - { - HierarchyRootInfo info; - info.m_rootComponent = rootComponent; - rootComponent->BindNetworkHierarchyChangedEventHandler(info.m_changedEvent); - rootComponent->BindNetworkHierarchyLeaveEventHandler(info.m_leaveEvent); - - m_hierarchyRoots.insert(AZStd::make_pair(rootComponent, info)); - } - } - } -} diff --git a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugHierarchyDebugger.h b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugHierarchyDebugger.h deleted file mode 100644 index 978664b96b..0000000000 --- a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugHierarchyDebugger.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#pragma once - -#include -#include -#include -#include - -namespace Multiplayer -{ - /** - * \brief Reports hierarchy information in the scene. - */ - class MultiplayerDebugHierarchyReporter - : public AZ::EntitySystemBus::Handler - { - public: - MultiplayerDebugHierarchyReporter(); - ~MultiplayerDebugHierarchyReporter() override; - - //! main update loop - void OnImGuiUpdate(); - - //! Draws hierarchy information over hierarchy root entities - void UpdateDebugOverlay(); - - //! EntitySystemBus overrides. - void OnEntityActivated(const AZ::EntityId& entityId) override; - void OnEntityDeactivated(const AZ::EntityId& entityId) override; - - private: - AZ::ScheduledEvent m_updateDebugOverlay; - - AzFramework::DebugDisplayRequests* m_debugDisplay = nullptr; - - struct HierarchyRootInfo - { - NetworkHierarchyRootComponent* m_rootComponent = nullptr; - NetworkHierarchyChangedEvent::Handler m_changedEvent; - NetworkHierarchyLeaveEvent::Handler m_leaveEvent; - }; - - AZStd::unordered_map m_hierarchyRoots; - void CollectHierarchyRoots(); - - char m_statusBuffer[100] = {}; - }; -}