Преглед на файлове

Addressing CR feedback

Signed-off-by: AMZN-Olex <[email protected]>
AMZN-Olex преди 3 години
родител
ревизия
a11fda4209

+ 19 - 0
Gem/Code/Include/NetworkPrefabSpawnerInterface.h

@@ -32,8 +32,27 @@ namespace MultiplayerSample
         AZ_RTTI(NetworkPrefabSpawnerRequests, "{82e5cfb5-6a1a-4bd1-b48d-cd817474d611}");
         virtual ~NetworkPrefabSpawnerRequests() = default;
 
+        /**
+         * \brief Spawn a prefab given its asset path at a specified transform.
+         * \param worldTm Where to spawn the instance.
+         * \param assetPath Path to .spawnable asset to spawn from.
+         * \param callbacks Optional structure for pre-activate and post-activate callbacks.
+         */
         virtual void SpawnPrefab(const AZ::Transform& worldTm, const char* assetPath, PrefabCallbacks callbacks) = 0;
+
+        /**
+         * \brief Spawn a prefab from spawnable asset at a specified transform.
+         * \param worldTm Where to spawn the instance.
+         * \param asset .spawnable asset to spawn from.
+         * \param callbacks Optional structure for pre-activate and post-activate callbacks.
+         */
         virtual void SpawnPrefabAsset(const AZ::Transform& worldTm, const AZ::Data::Asset<AzFramework::Spawnable>& asset, PrefabCallbacks callbacks) = 0;
+
+        /**
+         * \brief Spawn a prefab instance from spawnable asset assigned in the spawner component. See @NetworkPrefabSpawnerComponent.
+         * \param worldTm Where to spawn the instance.
+         * \param callbacks Optional structure for pre-activate and post-activate callbacks.
+         */
         virtual void SpawnDefaultPrefab(const AZ::Transform& worldTm, PrefabCallbacks callbacks) = 0;
     };
 

+ 2 - 2
Gem/Code/Source/AutoGen/NetworkTestComponent.AutoComponent.xml → Gem/Code/Source/AutoGen/NetworkRandomImpulseComponent.AutoComponent.xml

@@ -1,11 +1,11 @@
 <?xml version="1.0"?>
 
 <Component
-	Name="NetworkTestComponent"
+	Name="NetworkRandomImpulseComponent"
 	Namespace="MultiplayerSample"
 	OverrideComponent="false"
 	OverrideController="true"
-	OverrideInclude="Source/Components/PerfTest/NetworkTestComponent.h"
+	OverrideInclude="Source/Components/PerfTest/NetworkRandomImpulseComponent.h"
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 
 	<ArchetypeProperty Type="bool" Name="EnableHopping" Init="true" ExposeToEditor="true" Description="Enables occasional hops." />

+ 47 - 0
Gem/Code/Source/Components/PerfTest/NetworkRandomImpulseComponent.cpp

@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) Contributors to the Open 3D Engine Project
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+
+#include <RigidBodyComponent.h>
+#include <Components/PerfTest/NetworkRandomImpulseComponent.h>
+
+namespace MultiplayerSample
+{
+    NetworkRandomImpulseComponentController::NetworkRandomImpulseComponentController(NetworkRandomImpulseComponent& parent)
+        : NetworkRandomImpulseComponentControllerBase(parent)
+        , m_tickEvent{ [this] { TickEvent(); }, AZ::Name{ "NetworkRandomImpulseComponent" } }
+    {
+    }
+
+    void NetworkRandomImpulseComponentController::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
+    {
+        if (GetParent().GetEnableHopping())
+        {
+            m_tickEvent.Enqueue(AZ::TimeMs{ 0 }, true);
+            m_accumulatedTime = 0.f;
+        }
+    }
+
+    void NetworkRandomImpulseComponentController::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
+    {
+    }
+
+    void NetworkRandomImpulseComponentController::TickEvent()
+    {
+        const float deltaTime = static_cast<float>(m_tickEvent.TimeInQueueMs()) / 1000.f;
+        m_accumulatedTime += deltaTime;
+
+        if (m_accumulatedTime > GetParent().GetHopPeriod())
+        {
+            m_accumulatedTime = 0.f;
+
+            if (PhysX::RigidBodyComponent* body = GetEntity()->FindComponent<PhysX::RigidBodyComponent>())
+            {
+                body->ApplyLinearImpulse(AZ::Vector3::CreateAxisZ(GetParent().GetHopForce()));
+            }
+        }
+    }
+}

+ 29 - 0
Gem/Code/Source/Components/PerfTest/NetworkRandomImpulseComponent.h

@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) Contributors to the Open 3D Engine Project
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+
+#pragma once
+
+#include <Source/AutoGen/NetworkRandomImpulseComponent.AutoComponent.h>
+
+namespace MultiplayerSample
+{
+    class NetworkRandomImpulseComponentController
+        : public NetworkRandomImpulseComponentControllerBase
+    {
+    public:
+        NetworkRandomImpulseComponentController(NetworkRandomImpulseComponent& parent);
+
+        void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
+        void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
+        
+    private:
+        float m_accumulatedTime = 0.f;
+
+        AZ::ScheduledEvent m_tickEvent;
+        void TickEvent();
+    };
+}

+ 0 - 46
Gem/Code/Source/Components/PerfTest/NetworkTestComponent.cpp

@@ -1,46 +0,0 @@
-/*
- * Copyright (c) Contributors to the Open 3D Engine Project
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
-
-#include <RigidBodyComponent.h>
-#include <Components/PerfTest/NetworkTestComponent.h>
-
-namespace MultiplayerSample
-{
-    NetworkTestComponentController::NetworkTestComponentController(NetworkTestComponent& parent)
-        : NetworkTestComponentControllerBase(parent)
-    {
-    }
-
-    void NetworkTestComponentController::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
-    {
-        if (GetParent().GetEnableHopping())
-        {
-            m_accumulatedTime = 0.f;
-            AZ::TickBus::Handler::BusConnect();
-        }
-    }
-
-    void NetworkTestComponentController::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
-    {
-        AZ::TickBus::Handler::BusDisconnect();
-    }
-
-    void NetworkTestComponentController::OnTick(float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
-    {
-        m_accumulatedTime += deltaTime;
-
-        if (m_accumulatedTime > GetParent().GetHopPeriod())
-        {
-            m_accumulatedTime = 0.f;
-
-            if (PhysX::RigidBodyComponent* body = GetEntity()->FindComponent<PhysX::RigidBodyComponent>())
-            {
-                body->ApplyLinearImpulse(AZ::Vector3::CreateAxisZ(GetParent().GetHopForce()));
-            }
-        }
-    }
-}

+ 0 - 33
Gem/Code/Source/Components/PerfTest/NetworkTestComponent.h

@@ -1,33 +0,0 @@
-/*
- * Copyright (c) Contributors to the Open 3D Engine Project
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
-
-#pragma once
-
-#include <AzCore/Component/TickBus.h>
-#include <Source/AutoGen/NetworkTestComponent.AutoComponent.h>
-
-namespace MultiplayerSample
-{
-    class NetworkTestComponentController
-        : public NetworkTestComponentControllerBase
-        , public AZ::TickBus::Handler
-    {
-    public:
-        NetworkTestComponentController(NetworkTestComponent& parent);
-
-        void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
-        void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
-
-        //! AZ::TickBus overrides.
-        //! @{
-        void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
-        //! }@
-
-    private:
-        float m_accumulatedTime = 0.f;
-    };
-}

+ 4 - 3
Gem/Code/Source/Components/PerfTest/NetworkTestSpawnerComponent.cpp

@@ -20,12 +20,13 @@ namespace MultiplayerSample
 {
     NetworkTestSpawnerComponentController::NetworkTestSpawnerComponentController(NetworkTestSpawnerComponent& parent)
         : NetworkTestSpawnerComponentControllerBase(parent)
+        , m_tickEvent{ [this] { TickEvent(); }, AZ::Name{ "NetworkTestSpawnerComponent" } }
     {
     }
 
     void NetworkTestSpawnerComponentController::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
     {
-        AZ::TickBus::Handler::BusConnect();
+        m_tickEvent.Enqueue(AZ::TimeMs{ 0 }, true);
 
         m_currentCount = 0;
         m_accumulatedTime = 0.f;
@@ -34,11 +35,11 @@ namespace MultiplayerSample
 
     void NetworkTestSpawnerComponentController::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
     {
-        AZ::TickBus::Handler::BusDisconnect();
     }
 
-    void NetworkTestSpawnerComponentController::OnTick(float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
+    void NetworkTestSpawnerComponentController::TickEvent()
     {
+        const float deltaTime = static_cast<float>(m_tickEvent.TimeInQueueMs()) / 1000.f;
         m_accumulatedTime += deltaTime;
 
         if (m_accumulatedTime > 1.0f / aznumeric_cast<float>(GetParent().GetSpawnPerSecond()))

+ 3 - 7
Gem/Code/Source/Components/PerfTest/NetworkTestSpawnerComponent.h

@@ -7,7 +7,6 @@
 
 #pragma once
 
-#include <AzCore/Component/TickBus.h>
 #include <AzFramework/Spawnable/SpawnableEntitiesInterface.h>
 #include <Source/AutoGen/NetworkTestSpawnerComponent.AutoComponent.h>
 
@@ -15,7 +14,6 @@ namespace MultiplayerSample
 {
     class NetworkTestSpawnerComponentController
         : public NetworkTestSpawnerComponentControllerBase
-        , public AZ::TickBus::Handler
     {
     public:
         NetworkTestSpawnerComponentController(NetworkTestSpawnerComponent& parent);
@@ -23,16 +21,14 @@ namespace MultiplayerSample
         void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
         void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
 
-        //! AZ::TickBus overrides.
-        //! @{
-        void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
-        //! }@
-
     private:
         int m_currentCount = 0;
         float m_accumulatedTime = 0.f;
         float m_sinceLastSpawn = 0.f;
 
         AZStd::deque<AZStd::shared_ptr<AzFramework::EntitySpawnTicket>> m_spawnedObjects;
+
+        AZ::ScheduledEvent m_tickEvent;
+        void TickEvent();
     };
 }

+ 1 - 1
Gem/Code/Source/MultiplayerSampleModule.cpp

@@ -9,7 +9,7 @@
 #include <AzCore/Module/Module.h>
 #include <Components/ExampleFilteredEntityComponent.h>
 #include <Components/PerfTest/NetworkPrefabSpawnerComponent.h>
-#include <Components/PerfTest/NetworkTestComponent.h>
+#include <Components/PerfTest/NetworkRandomImpulseComponent.h>
 #include <Components/PerfTest/NetworkTestSpawnerComponent.h>
 #include <Source/AutoGen/AutoComponentTypes.h>
 

+ 3 - 3
Gem/Code/multiplayersample_files.cmake

@@ -17,7 +17,7 @@ set(FILES
     Source/AutoGen/NetworkStressTestComponent.AutoComponent.xml
     Source/AutoGen/NetworkPlayerMovementComponent.AutoComponent.xml
     Source/AutoGen/NetworkTestSpawnerComponent.AutoComponent.xml
-    Source/AutoGen/NetworkTestComponent.AutoComponent.xml
+    Source/AutoGen/NetworkRandomImpulseComponent.AutoComponent.xml
     Source/Components/ExampleFilteredEntityComponent.h
     Source/Components/ExampleFilteredEntityComponent.cpp
     Source/Components/NetworkAiComponent.cpp
@@ -36,8 +36,8 @@ set(FILES
     Source/Components/NetworkSimplePlayerCameraComponent.h
     Source/Components/PerfTest/NetworkPrefabSpawnerComponent.cpp
     Source/Components/PerfTest/NetworkPrefabSpawnerComponent.h
-    Source/Components/PerfTest/NetworkTestComponent.cpp
-    Source/Components/PerfTest/NetworkTestComponent.h
+    Source/Components/PerfTest/NetworkRandomImpulseComponent.cpp
+    Source/Components/PerfTest/NetworkRandomImpulseComponent.h
     Source/Components/PerfTest/NetworkTestSpawnerComponent.cpp
     Source/Components/PerfTest/NetworkTestSpawnerComponent.h
     Source/Components/NetworkStressTestComponent.cpp