From d5ad5d95965266ecc1cca41d11537b7206afff81 Mon Sep 17 00:00:00 2001 From: karlberg Date: Mon, 3 May 2021 21:20:40 -0700 Subject: [PATCH] Removing some more ebus dependencies within the vis system --- .../AzCore/AzCore/Component/Component.cpp | 3 ++- Code/Framework/AzCore/AzCore/Component/Entity.cpp | 2 +- .../AzFramework/Components/TransformComponent.cpp | 10 ++++++---- .../AzFramework/Visibility/EntityBoundsUnionBus.h | 4 ++++ .../EntityVisibilityBoundsUnionSystem.cpp | 7 +------ .../Visibility/EntityVisibilityBoundsUnionSystem.h | 5 +---- .../ToolsComponents/TransformComponent.cpp | 14 ++++++++------ 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Component/Component.cpp b/Code/Framework/AzCore/AzCore/Component/Component.cpp index f1e8aa1fb0..f336b9e1a1 100644 --- a/Code/Framework/AzCore/AzCore/Component/Component.cpp +++ b/Code/Framework/AzCore/AzCore/Component/Component.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -173,7 +174,7 @@ namespace AZ //========================================================================= void ComponentDescriptor::ReleaseDescriptor() { - EBUS_EVENT(ComponentApplicationBus, UnregisterComponentDescriptor, this); + AZ::Interface::Get()->UnregisterComponentDescriptor(this); delete this; } } // namespace AZ diff --git a/Code/Framework/AzCore/AzCore/Component/Entity.cpp b/Code/Framework/AzCore/AzCore/Component/Entity.cpp index 656fc5938f..6796bccb2b 100644 --- a/Code/Framework/AzCore/AzCore/Component/Entity.cpp +++ b/Code/Framework/AzCore/AzCore/Component/Entity.cpp @@ -112,7 +112,7 @@ namespace AZ { EBUS_EVENT(EntitySystemBus, OnEntityDestruction, m_id); EBUS_EVENT_ID(m_id, EntityBus, OnEntityDestruction, m_id); - EBUS_EVENT(ComponentApplicationBus, RemoveEntity, this); + AZ::Interface::Get()->RemoveEntity(this); m_stateEvent.Signal(State::Init, State::Destroying); } diff --git a/Code/Framework/AzFramework/AzFramework/Components/TransformComponent.cpp b/Code/Framework/AzFramework/AzFramework/Components/TransformComponent.cpp index 910d6749af..866f0cc6d2 100644 --- a/Code/Framework/AzFramework/AzFramework/Components/TransformComponent.cpp +++ b/Code/Framework/AzFramework/AzFramework/Components/TransformComponent.cpp @@ -11,10 +11,12 @@ */ #include +#include #include #include #include #include +#include #include #include @@ -694,8 +696,7 @@ namespace AzFramework } #endif - AZ::Entity* parentEntity = nullptr; - EBUS_EVENT_RESULT(parentEntity, AZ::ComponentApplicationBus, FindEntity, parentEntityId); + AZ::Entity* parentEntity = AZ::Interface::Get()->FindEntity(parentEntityId); AZ_Assert(parentEntity, "We expect to have a parent entity associated with the provided parent's entity Id."); if (parentEntity) { @@ -744,8 +745,7 @@ namespace AzFramework m_parentId = parentId; if (m_parentId.IsValid()) { - AZ::Entity* parentEntity = nullptr; - AZ::ComponentApplicationBus::BroadcastResult(parentEntity, &AZ::ComponentApplicationBus::Events::FindEntity, m_parentId); + AZ::Entity* parentEntity = AZ::Interface::Get()->FindEntity(m_parentId); m_parentActive = parentEntity && (parentEntity->GetState() == AZ::Entity::State::Active); m_onNewParentKeepWorldTM = isKeepWorldTM; @@ -832,6 +832,8 @@ namespace AzFramework EBUS_EVENT_PTR(m_notificationBus, AZ::TransformNotificationBus, OnTransformChanged, m_localTM, m_worldTM); m_transformChangedEvent.Signal(m_localTM, m_worldTM); + + AZ::Interface::Get()->OnTransformUpdated(GetEntity()); } void TransformComponent::ComputeWorldTM() diff --git a/Code/Framework/AzFramework/AzFramework/Visibility/EntityBoundsUnionBus.h b/Code/Framework/AzFramework/AzFramework/Visibility/EntityBoundsUnionBus.h index 99c575e3c9..b607759260 100644 --- a/Code/Framework/AzFramework/AzFramework/Visibility/EntityBoundsUnionBus.h +++ b/Code/Framework/AzFramework/AzFramework/Visibility/EntityBoundsUnionBus.h @@ -40,6 +40,10 @@ namespace AzFramework //! also be called explicitly (e.g. For testing purposes). virtual void ProcessEntityBoundsUnionRequests() = 0; + //! Notifies the EntityBoundsUnion system that an entities transform has been modified. + //! @param entity the entity whose transform has been modified. + virtual void OnTransformUpdated(AZ::Entity* entity) = 0; + protected: virtual ~IEntityBoundsUnion() = default; }; diff --git a/Code/Framework/AzFramework/AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.cpp b/Code/Framework/AzFramework/AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.cpp index c03ab8b78d..f9c24b82db 100644 --- a/Code/Framework/AzFramework/AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.cpp +++ b/Code/Framework/AzFramework/AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.cpp @@ -28,7 +28,6 @@ namespace AzFramework { AZ::Interface::Register(this); IEntityBoundsUnionRequestBus::Handler::BusConnect(); - AZ::TransformNotificationBus::Router::BusRouterConnect(); AZ::TickBus::Handler::BusConnect(); AZ::Interface::Get()->RegisterEntityActivatedEventHandler(m_entityActivatedEventHandler); @@ -39,7 +38,6 @@ namespace AzFramework { AZ::TickBus::Handler::BusDisconnect(); IEntityBoundsUnionRequestBus::Handler::BusDisconnect(); - AZ::TransformNotificationBus::Router::BusRouterDisconnect(); AZ::Interface::Unregister(this); } @@ -156,13 +154,10 @@ namespace AzFramework m_entityBoundsDirty.clear(); } - void EntityVisibilityBoundsUnionSystem::OnTransformChanged(const AZ::Transform&, const AZ::Transform&) + void EntityVisibilityBoundsUnionSystem::OnTransformUpdated(AZ::Entity* entity) { AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::AzFramework); - const AZ::EntityId entityId = *AZ::TransformNotificationBus::GetCurrentBusId(); - AZ::Entity* entity = AZ::Interface::Get()->FindEntity(entityId); - // update the world transform of the visibility bounds union if (auto instance_it = m_entityVisibilityBoundsUnionInstanceMapping.find(entity); instance_it != m_entityVisibilityBoundsUnionInstanceMapping.end()) diff --git a/Code/Framework/AzFramework/AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.h b/Code/Framework/AzFramework/AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.h index 27304a57b1..808f834ebc 100644 --- a/Code/Framework/AzFramework/AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.h +++ b/Code/Framework/AzFramework/AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.h @@ -24,7 +24,6 @@ namespace AzFramework //! Provide a unified hook between entities and the visibility system. class EntityVisibilityBoundsUnionSystem : public IEntityBoundsUnionRequestBus::Handler - , private AZ::TransformNotificationBus::Router , private AZ::TickBus::Handler { public: @@ -37,6 +36,7 @@ namespace AzFramework void RefreshEntityLocalBoundsUnion(AZ::EntityId entityId) override; AZ::Aabb GetEntityLocalBoundsUnion(AZ::EntityId entityId) const override; void ProcessEntityBoundsUnionRequests() override; + void OnTransformUpdated(AZ::Entity* entity) override; private: struct EntityVisibilityBoundsUnionInstance @@ -55,9 +55,6 @@ namespace AzFramework // TickBus overrides ... void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; - // TransformNotificationBus overrides ... - void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override; - void UpdateVisibilitySystem(AZ::Entity* entity, EntityVisibilityBoundsUnionInstance& instance); EntityVisibilityBoundsUnionInstanceMapping m_entityVisibilityBoundsUnionInstanceMapping; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.cpp index 459d3022ad..81c9ebaaec 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.cpp @@ -9,7 +9,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ -#pragma optimize ("", off) + #include "AzToolsFramework_precompiled.h" #include "TransformComponent.h" @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -262,6 +263,8 @@ namespace AzToolsFramework AZ::TransformNotificationBus::Event( GetEntityId(), &TransformNotification::OnTransformChanged, localTM, worldTM); m_transformChangedEvent.Signal(localTM, worldTM); + + AZ::Interface::Get()->OnTransformUpdated(GetEntity()); } } @@ -930,15 +933,14 @@ namespace AzToolsFramework { return nullptr; } - - AZ::Entity* pEntity = nullptr; - EBUS_EVENT_RESULT(pEntity, AZ::ComponentApplicationBus, FindEntity, otherEntityId); - if (!pEntity) + + AZ::Entity* entity = AZ::Interface::Get()->FindEntity(otherEntityId); + if (!entity) { return nullptr; } - return pEntity->FindComponent(); + return entity->FindComponent(); } AZ::TransformInterface* TransformComponent::GetParent()