Bläddra i källkod

Add perf component to test spawning at a configurable scale

Signed-off-by: AMZN-Olex <[email protected]>
AMZN-Olex 3 år sedan
förälder
incheckning
5ac0de6cf7

+ 2 - 3
Gem/Code/CMakeLists.txt

@@ -1,12 +1,11 @@
 #
 #
 # 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.
 # 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
 # SPDX-License-Identifier: Apache-2.0 OR MIT
 #
 #
 #
 #
 
 
-ly_get_list_relative_pal_filename(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME})
-#o3de_pal_dir(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} ${gem_restricted_path} ${gem_path} ${gem_parent_relative_path})
+o3de_pal_dir(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} "${gem_restricted_path}" "${gem_path}" "${gem_parent_relative_path}")
 
 
 ly_add_target(
 ly_add_target(
     NAME MultiplayerSample.Static STATIC
     NAME MultiplayerSample.Static STATIC

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

@@ -10,6 +10,7 @@
 #include <Components/PerfTest/NetworkTestComponent.h>
 #include <Components/PerfTest/NetworkTestComponent.h>
 #include <Multiplayer/IMultiplayer.h>
 #include <Multiplayer/IMultiplayer.h>
 #include <Multiplayer/Components/NetBindComponent.h>
 #include <Multiplayer/Components/NetBindComponent.h>
+#include <Multiplayer/Physics/PhysicsUtils.h>
 
 
 namespace MultiplayerSample
 namespace MultiplayerSample
 {
 {

+ 18 - 0
Gem/Code/Source/Components/PerfTest/NetworkTestSpawnerComponent.cpp

@@ -6,8 +6,10 @@
  */
  */
 
 
 #include <AzCore/Component/TransformBus.h>
 #include <AzCore/Component/TransformBus.h>
+#include <AzCore/Math/Random.h>
 #include <AzCore/Serialization/EditContext.h>
 #include <AzCore/Serialization/EditContext.h>
 #include <Components/PerfTest/NetworkTestSpawnerComponent.h>
 #include <Components/PerfTest/NetworkTestSpawnerComponent.h>
+#include <LmbrCentral/Shape/ShapeComponentBus.h>
 #include <Multiplayer/IMultiplayer.h>
 #include <Multiplayer/IMultiplayer.h>
 #include <Multiplayer/Components/NetBindComponent.h>
 #include <Multiplayer/Components/NetBindComponent.h>
 
 
@@ -15,6 +17,11 @@
 
 
 #pragma optimize("", off)
 #pragma optimize("", off)
 
 
+namespace LmbrCentral
+{
+    class BoxShapeComponent;
+}
+
 namespace MultiplayerSample
 namespace MultiplayerSample
 {
 {
     void NetworkTestSpawnerComponent::Reflect(AZ::ReflectContext* context)
     void NetworkTestSpawnerComponent::Reflect(AZ::ReflectContext* context)
@@ -38,6 +45,7 @@ namespace MultiplayerSample
                     ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
                     ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
                     ->DataElement(nullptr, &NetworkTestSpawnerComponent::m_enabled, "Enabled", "Enables spawning of test prefabs")
                     ->DataElement(nullptr, &NetworkTestSpawnerComponent::m_enabled, "Enabled", "Enables spawning of test prefabs")
                     ->DataElement(nullptr, &NetworkTestSpawnerComponent::m_spawnPeriod, "Spawn Period", "How often to spawn new prefab instance, in seconds")
                     ->DataElement(nullptr, &NetworkTestSpawnerComponent::m_spawnPeriod, "Spawn Period", "How often to spawn new prefab instance, in seconds")
+                        ->Attribute(AZ::Edit::Attributes::Suffix, " seconds")
                     ->DataElement(nullptr, &NetworkTestSpawnerComponent::m_maximumLiveCount, "Max Objects", 
                     ->DataElement(nullptr, &NetworkTestSpawnerComponent::m_maximumLiveCount, "Max Objects", 
                         "Maximum objects to keep alive, will delete older objects when the count goes above this value.")
                         "Maximum objects to keep alive, will delete older objects when the count goes above this value.")
                     ;
                     ;
@@ -47,6 +55,8 @@ namespace MultiplayerSample
 
 
     void NetworkTestSpawnerComponent::Activate()
     void NetworkTestSpawnerComponent::Activate()
     {
     {
+        m_randomDistribution = std::uniform_real_distribution<double>(-1000.f, 1000.f);
+
         if (const Multiplayer::NetBindComponent* netBindComponent = GetEntity()->FindComponent<Multiplayer::NetBindComponent>())
         if (const Multiplayer::NetBindComponent* netBindComponent = GetEntity()->FindComponent<Multiplayer::NetBindComponent>())
         {
         {
             if (netBindComponent->IsNetEntityRoleAuthority())
             if (netBindComponent->IsNetEntityRoleAuthority())
@@ -77,6 +87,14 @@ namespace MultiplayerSample
             {
             {
                 AZ::Transform t = GetEntity()->GetTransform()->GetWorldTM();
                 AZ::Transform t = GetEntity()->GetTransform()->GetWorldTM();
 
 
+                AZ::Vector3 randomPoint = AZ::Vector3::CreateZero();
+                using ShapeBus = LmbrCentral::ShapeComponentRequestsBus;
+                ShapeBus::EventResult(randomPoint, GetEntityId(), &ShapeBus::Events::GenerateRandomPointInside, AZ::RandomDistributionType::UniformReal);
+                if (!randomPoint.IsZero())
+                {
+                    t.SetTranslation(randomPoint);
+                }
+
                 PrefabCallbacks callbacks;
                 PrefabCallbacks callbacks;
                 callbacks.m_onActivateCallback = [this](
                 callbacks.m_onActivateCallback = [this](
                     AZStd::shared_ptr<AzFramework::EntitySpawnTicket>&& ticket,
                     AZStd::shared_ptr<AzFramework::EntitySpawnTicket>&& ticket,

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

@@ -7,6 +7,7 @@
 
 
 #pragma once
 #pragma once
 
 
+#include <random>
 #include <AzCore/Component/Component.h>
 #include <AzCore/Component/Component.h>
 #include <AzCore/Component/TickBus.h>
 #include <AzCore/Component/TickBus.h>
 #include <AzFramework/Spawnable/SpawnableEntitiesInterface.h>
 #include <AzFramework/Spawnable/SpawnableEntitiesInterface.h>
@@ -51,5 +52,7 @@ namespace MultiplayerSample
         float m_sinceLastSpawn = 0.f;
         float m_sinceLastSpawn = 0.f;
 
 
         AZStd::deque<AZStd::shared_ptr<AzFramework::EntitySpawnTicket>> m_spawnedObjects;
         AZStd::deque<AZStd::shared_ptr<AzFramework::EntitySpawnTicket>> m_spawnedObjects;
+
+        std::uniform_real_distribution<double> m_randomDistribution;
     };
     };
 }
 }

+ 16 - 34
Levels/SpawningPerfTest/SpawningPerfTest.prefab

@@ -20,8 +20,7 @@
                 "Id": 14126657869720434043,
                 "Id": 14126657869720434043,
                 "Child Entity Order": [
                 "Child Entity Order": [
                     "Entity_[1176639161715]",
                     "Entity_[1176639161715]",
-                    "Entity_[947961075516]",
-                    "Instance_[420009386512]/ContainerEntity"
+                    "Entity_[947961075516]"
                 ]
                 ]
             },
             },
             "Component_[15230859088967841193]": {
             "Component_[15230859088967841193]": {
@@ -572,7 +571,8 @@
                     "m_template": {
                     "m_template": {
                         "$type": "MultiplayerSample::NetworkTestSpawnerComponent",
                         "$type": "MultiplayerSample::NetworkTestSpawnerComponent",
                         "Enabled": true,
                         "Enabled": true,
-                        "Max Objects": 10
+                        "Max Objects": 1000,
+                        "Spawn Period": 0.009999999776482582
                     }
                     }
                 },
                 },
                 "Component_[194809454864350389]": {
                 "Component_[194809454864350389]": {
@@ -586,6 +586,19 @@
                         "$type": "NetBindComponent"
                         "$type": "NetBindComponent"
                     }
                     }
                 },
                 },
+                "Component_[4324228238802776895]": {
+                    "$type": "EditorBoxShapeComponent",
+                    "Id": 4324228238802776895,
+                    "BoxShape": {
+                        "Configuration": {
+                            "Dimensions": [
+                                50.0,
+                                50.0,
+                                1.0
+                            ]
+                        }
+                    }
+                },
                 "Component_[4995577444629330118]": {
                 "Component_[4995577444629330118]": {
                     "$type": "SelectionComponent",
                     "$type": "SelectionComponent",
                     "Id": 4995577444629330118
                     "Id": 4995577444629330118
@@ -610,36 +623,5 @@
                 }
                 }
             }
             }
         }
         }
-    },
-    "Instances": {
-        "Instance_[420009386512]": {
-            "Source": "Prefabs/Test_Net_Object.prefab",
-            "Patches": [
-                {
-                    "op": "replace",
-                    "path": "/ContainerEntity/Components/Component_[10875373432506593388]/Parent Entity",
-                    "value": "../Entity_[1146574390643]"
-                },
-                {
-                    "op": "replace",
-                    "path": "/ContainerEntity/Components/Component_[10875373432506593388]/Transform Data/Translate/0",
-                    "value": 2.2419509887695313
-                },
-                {
-                    "op": "replace",
-                    "path": "/ContainerEntity/Components/Component_[10875373432506593388]/Transform Data/Translate/1",
-                    "value": 3.4806900024414063
-                },
-                {
-                    "op": "replace",
-                    "path": "/ContainerEntity/Components/Component_[10875373432506593388]/Transform Data/Translate/2",
-                    "value": 3.210494041442871
-                },
-                {
-                    "op": "remove",
-                    "path": "/LinkId"
-                }
-            ]
-        }
     }
     }
 }
 }