Quellcode durchsuchen

Added a workaround switch to avoid issues with deactivating network entities.

Olex Lozitskiy vor 3 Jahren
Ursprung
Commit
2fc2ec9540

+ 1 - 0
Gem/Code/Source/AutoGen/NetworkTestSpawnerComponent.AutoComponent.xml

@@ -12,6 +12,7 @@
 	<ComponentRelation Constraint="Required" HasController="false" Name="NetworkPrefabSpawnerComponent" Namespace="MultiplayerSample" Include="Source/Components/PerfTest/NetworkPrefabSpawnerComponent.h" />
 
 	<ArchetypeProperty Type="bool" Name="Enabled" Init="true" ExposeToEditor="true" Description="Enables spawning of test prefabs." />
+	<ArchetypeProperty Type="bool" Name="RespawnEnabled" Init="false" ExposeToEditor="true" Description="Deletes old instances and spawns new ones when at the maximum live count." />
 	<ArchetypeProperty Type="int" Name="MaxLiveCount" Init="100" ExposeToEditor="true" Description="Maximum objects to keep alive, will delete older objects when the count goes above this value." />
 	<ArchetypeProperty Type="int" Name="SpawnPerSecond" Init="10" ExposeToEditor="true" Description="How many prefabs to spawn per second." />
 

+ 2 - 1
Gem/Code/Source/Components/PerfTest/NetworkRandomImpulseComponent.cpp

@@ -40,7 +40,8 @@ namespace MultiplayerSample
 
             if (PhysX::RigidBodyComponent* body = GetEntity()->FindComponent<PhysX::RigidBodyComponent>())
             {
-                body->ApplyLinearImpulse(AZ::Vector3::CreateAxisZ(GetParent().GetHopForce()));
+                const AZ::Quaternion rotation = GetEntity()->GetTransform()->GetWorldRotationQuaternion();
+                body->ApplyLinearImpulse(rotation.TransformVector(AZ::Vector3::CreateAxisZ(GetParent().GetHopForce())));
             }
         }
     }

+ 38 - 31
Gem/Code/Source/Components/PerfTest/NetworkTestSpawnerComponent.cpp

@@ -26,7 +26,10 @@ namespace MultiplayerSample
 
     void NetworkTestSpawnerComponentController::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
     {
-        m_tickEvent.Enqueue(AZ::TimeMs{ 0 }, true);
+        if (GetParent().GetNetworkPrefabSpawnerComponent())
+        {
+            m_tickEvent.Enqueue(AZ::TimeMs{ 0 }, true);
+        }
 
         m_currentCount = 0;
         m_accumulatedTime = 0.f;
@@ -46,44 +49,48 @@ namespace MultiplayerSample
         {
             m_accumulatedTime = 0.f;
 
-            if (NetworkPrefabSpawnerComponent* spawner = GetParent().GetNetworkPrefabSpawnerComponent())
-            {
-                AZ::Vector3 randomPoint = AZ::Vector3::CreateZero();
-                // ShapeComponentRequestsBus is designed in such a way that it's very difficult to use direct component interface instead of the EBus
-                using ShapeBus = LmbrCentral::ShapeComponentRequestsBus;
-                ShapeBus::EventResult(randomPoint, GetParent().GetEntityId(), &ShapeBus::Events::GenerateRandomPointInside,
-                    AZ::RandomDistributionType::UniformReal);
+            AZ::Vector3 randomPoint = AZ::Vector3::CreateZero();
+            // ShapeComponentRequestsBus is designed in such a way that it's very difficult to use direct component interface instead of the EBus
+            using ShapeBus = LmbrCentral::ShapeComponentRequestsBus;
+            ShapeBus::EventResult(randomPoint, GetParent().GetEntityId(), &ShapeBus::Events::GenerateRandomPointInside,
+                AZ::RandomDistributionType::UniformReal);
 
-                AZ::Transform t = GetEntity()->GetTransform()->GetWorldTM();
-                if (!randomPoint.IsZero())
-                {
-                    t.SetTranslation(randomPoint);
+            AZ::Transform t = GetEntity()->GetTransform()->GetWorldTM();
+            if (!randomPoint.IsZero())
+            {
+                t.SetTranslation(randomPoint);
 
-                    // Create a random orientation for fun.
-                    float randomAngles[3];
-                    randomAngles[0] = aznumeric_cast<float>(GetNetworkRandomComponentController()->GetRandomUint64() % 180);
-                    randomAngles[1] = aznumeric_cast<float>(GetNetworkRandomComponentController()->GetRandomUint64() % 180);
-                    randomAngles[2] = aznumeric_cast<float>(GetNetworkRandomComponentController()->GetRandomUint64() % 180);
-                    t.SetRotation(AZ::Quaternion::CreateFromEulerAnglesDegrees(AZ::Vector3::CreateFromFloat3(randomAngles)));
-                }
+                // Create a random orientation for fun.
+                float randomAngles[3];
+                randomAngles[0] = aznumeric_cast<float>(GetNetworkRandomComponentController()->GetRandomUint64() % 180);
+                randomAngles[1] = aznumeric_cast<float>(GetNetworkRandomComponentController()->GetRandomUint64() % 180);
+                randomAngles[2] = aznumeric_cast<float>(GetNetworkRandomComponentController()->GetRandomUint64() % 180);
+                t.SetRotation(AZ::Quaternion::CreateFromEulerAnglesDegrees(AZ::Vector3::CreateFromFloat3(randomAngles)));
+            }
 
-                PrefabCallbacks callbacks;
-                callbacks.m_onActivateCallback = [this](
-                    AZStd::shared_ptr<AzFramework::EntitySpawnTicket>&& ticket,
-                    [[maybe_unused]] AzFramework::SpawnableConstEntityContainerView view)
-                {
-                    m_spawnedObjects.push_back(move(ticket));
-                };
+            PrefabCallbacks callbacks;
+            callbacks.m_onActivateCallback = [this](
+                AZStd::shared_ptr<AzFramework::EntitySpawnTicket>&& ticket,
+                [[maybe_unused]] AzFramework::SpawnableConstEntityContainerView view)
+            {
+                m_spawnedObjects.push_back(move(ticket));
+            };
 
-                spawner->SpawnDefaultPrefab(t, callbacks);
-            }
+            GetParent().GetNetworkPrefabSpawnerComponent()->SpawnDefaultPrefab(t, callbacks);
 
             m_currentCount++;
 
-            if (m_currentCount > GetParent().GetMaxLiveCount())
+            if (m_currentCount >= GetParent().GetMaxLiveCount())
             {
-                m_spawnedObjects.pop_front(); // this destroys the prefab instance for this ticket
-                --m_currentCount;
+                if (GetParent().GetRespawnEnabled())
+                {
+                    m_spawnedObjects.pop_front(); // this destroys the prefab instance for this ticket
+                    --m_currentCount;
+                }
+                else
+                {
+                    m_tickEvent.RemoveFromQueue();
+                }
             }
         }
     }

+ 5 - 4
Levels/SpawningPerfTest/SpawningPerfTest.prefab

@@ -525,8 +525,9 @@
                     "m_template": {
                         "$type": "MultiplayerSample::NetworkTestSpawnerComponent",
                         "Enabled": true,
-                        "MaxLiveCount": 1000,
-                        "SpawnPerSecond": 10
+                        "RespawnEnabled": false,
+                        "MaxLiveCount": 20,
+                        "SpawnPerSecond": 5
                     }
                 },
                 "Component_[12075594064273029366]": {
@@ -602,8 +603,8 @@
                     "BoxShape": {
                         "Configuration": {
                             "Dimensions": [
-                                50.0,
-                                50.0,
+                                5.0,
+                                5.0,
                                 1.0
                             ]
                         }