From 4b1fe9b10b8e1daaaf2ae39fc7fda85335d70f05 Mon Sep 17 00:00:00 2001 From: karlberg Date: Thu, 6 May 2021 17:35:48 -0700 Subject: [PATCH] Fix a comment and minor optimization to the server to client replication window --- .../EntityVisibilityBoundsUnionSystem.cpp | 2 +- .../ServerToClientReplicationWindow.cpp | 14 +++++++------- .../ServerToClientReplicationWindow.h | 11 +++++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Code/Framework/AzFramework/AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.cpp b/Code/Framework/AzFramework/AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.cpp index f9c24b82db..f019039d16 100644 --- a/Code/Framework/AzFramework/AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.cpp +++ b/Code/Framework/AzFramework/AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.cpp @@ -71,7 +71,7 @@ namespace AzFramework { AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::AzFramework); - // ignore any entity that might activate which does not have a TransformComponent + // ignore any entity that might deactivate which does not have a TransformComponent if (entity->GetTransform() == nullptr) { return; diff --git a/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.cpp b/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.cpp index abcb1e62ab..c54a610de2 100644 --- a/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.cpp +++ b/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.cpp @@ -56,6 +56,8 @@ namespace Multiplayer ServerToClientReplicationWindow::ServerToClientReplicationWindow(NetworkEntityHandle controlledEntity, const AzNetworking::IConnection* connection) : m_controlledEntity(controlledEntity) + , m_entityActivatedEventHandler([this](AZ::Entity* entity) { OnEntityActivated(entity); }) + , m_entityDeactivatedEventHandler([this](AZ::Entity* entity) { OnEntityDeactivated(entity); }) , m_connection(connection) , m_lastCheckedSentPackets(connection->GetMetrics().m_packetsSent) , m_lastCheckedLostPackets(connection->GetMetrics().m_packetsLost) @@ -74,7 +76,9 @@ namespace Multiplayer //} m_updateWindowEvent.Enqueue(sv_ClientReplicationWindowUpdateMs, true); - AZ::EntitySystemBus::Handler::BusConnect(); + + AZ::Interface::Get()->RegisterEntityActivatedEventHandler(m_entityActivatedEventHandler); + AZ::Interface::Get()->RegisterEntityDeactivatedEventHandler(m_entityDeactivatedEventHandler); } bool ServerToClientReplicationWindow::ReplicationSetUpdateReady() @@ -205,10 +209,8 @@ namespace Multiplayer //} } - void ServerToClientReplicationWindow::OnEntityActivated(const AZ::EntityId& entityId) + void ServerToClientReplicationWindow::OnEntityActivated(AZ::Entity* entity) { - AZ::Entity* entity = AZ::Interface::Get()->FindEntity(entityId); - ConstNetworkEntityHandle entityHandle(entity, GetNetworkEntityTracker()); NetBindComponent* netBindComponent = entityHandle.GetNetBindComponent(); if (netBindComponent != nullptr) @@ -236,10 +238,8 @@ namespace Multiplayer } } - void ServerToClientReplicationWindow::OnEntityDeactivated(const AZ::EntityId& entityId) + void ServerToClientReplicationWindow::OnEntityDeactivated(AZ::Entity* entity) { - AZ::Entity* entity = AZ::Interface::Get()->FindEntity(entityId); - ConstNetworkEntityHandle entityHandle(entity, GetNetworkEntityTracker()); NetBindComponent* netBindComponent = entityHandle.GetNetBindComponent(); if (netBindComponent != nullptr) diff --git a/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.h b/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.h index 423334476e..55a6a4b56e 100644 --- a/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.h +++ b/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.h @@ -27,7 +27,6 @@ namespace Multiplayer class ServerToClientReplicationWindow : public IReplicationWindow - , public AZ::EntitySystemBus::Handler { public: @@ -56,11 +55,8 @@ namespace Multiplayer //! @} private: - //! EntitySystemBus interface - //! @{ - void OnEntityActivated(const AZ::EntityId&) override; - void OnEntityDeactivated(const AZ::EntityId&) override; - //! @} + void OnEntityActivated(AZ::Entity* entity); + void OnEntityDeactivated(AZ::Entity* entity); //void CollectControlledEntitiesRecursive(ReplicationSet& replicationSet, EntityHierarchyComponent::Authority& hierarchyController); //void OnAddFilteredEntity(NetEntityId filteredEntityId); @@ -79,6 +75,9 @@ namespace Multiplayer NetworkEntityHandle m_controlledEntity; AZ::TransformInterface* m_controlledEntityTransform = nullptr; + AZ::EntityActivatedEvent::Handler m_entityActivatedEventHandler; + AZ::EntityDeactivatedEvent::Handler m_entityDeactivatedEventHandler; + //FilteredEntityComponent::Authority* m_controlledFilteredEntityComponent = nullptr; //NetBindComponent* m_controlledNetBindComponent = nullptr;