From 11c219701e4cb547fa5c466796e33ff84a57efb2 Mon Sep 17 00:00:00 2001 From: jckand-amzn Date: Fri, 12 Nov 2021 15:47:18 -0600 Subject: [PATCH 01/13] Initial check-in of in-memory prefab creation helpers for Dynamic Vegetation tests Signed-off-by: jckand-amzn --- .../editor_entity_utils.py | 4 +- .../DynVegUtils_TempPrefabCreationWorks.py | 90 +++++++++++++++++++ .../dyn_veg/TestSuite_Periodic_Optimized.py | 22 +++++ .../editor_dynveg_test_helper.py | 55 +++++++++++- 4 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py create mode 100644 AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/TestSuite_Periodic_Optimized.py diff --git a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py index 9e857ed8bc..aee8846afe 100644 --- a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py +++ b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py @@ -132,6 +132,7 @@ class EditorEntity: def __init__(self, id: azlmbr.entity.EntityId): self.id: azlmbr.entity.EntityId = id + self.components: List[EditorComponent] = [] # Creation functions @classmethod @@ -258,6 +259,7 @@ class EditorEntity: :return: Component object of newly added component. """ component = self.add_components([component_name])[0] + self.components.append(component) return component def add_components(self, component_names: list) -> List[EditorComponent]: @@ -279,7 +281,7 @@ class EditorEntity: ), f"Failure: Could not add component: '{new_comp.get_component_name()}' to entity: '{self.get_name()}'" new_comp.id = add_component_outcome.GetValue()[0] components.append(new_comp) - + self.components.append(new_comp) return components def get_components_of_type(self, component_names: list) -> List[EditorComponent]: diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py new file mode 100644 index 0000000000..d684d7eb02 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py @@ -0,0 +1,90 @@ +""" +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 +""" + + +def DynVegUtils_TempPrefabCreationWorks(): + """ + Summary: + An existing level is opened. Each Prefab setup to be spawned by Dynamic Vegetation tests is created in memory and + validated against existing components/mesh assignments. A spawner is then created with the temporary prefabs to ensure + proper functionality with Dynamic Vegetation components. + + Expected Behavior: + Temporary prefabs contain the expected components/assets. Instances plant as expected in the assigned area. + + Test Steps: + 1) Open an existing level + 2) Create each of the necessary temporary prefabs, and validate the component/mesh setups + 3) Create a Vegetation Layer Spawner setup using the temporary prefabs as Prefab Instance Spawner types + 4) Create a surface to plant on and validate instance counts + 5) Verify expected instance counts + + Note: + - This test file must be called from the Open 3D Engine Editor command terminal + - Any passed and failed tests are written to the Editor.log file. + Parsing the file or running a log_monitor are required to observe the test results. + + :return: None + """ + + import os + + import azlmbr.editor as editor + import azlmbr.legacy.general as general + import azlmbr.bus as bus + import azlmbr.math as math + + import editor_python_test_tools.hydra_editor_utils as hydra + from largeworlds.large_worlds_utils import editor_dynveg_test_helper as dynveg + from editor_python_test_tools.utils import Report, Tracer + from editor_python_test_tools.utils import TestHelper as helper + from editor_python_test_tools.prefab_utils import Prefab, PrefabInstance, get_prefab_file_path + + with Tracer() as error_tracer: + # Create dictionary for prefab filenames and paths to create using helper function + mesh_prefabs = { + "PinkFlower": os.path.join("assets", "objects", "foliage", "grass_flower_pink.azmodel"), + "PurpleFlower": os.path.join("assets", "objects", "foliage", "grass_flower_purple.azmodel"), + "1m_Cube": os.path.join("objects", "_primitives", "_box_1x1.azmodel"), + "CedarTree": os.path.join("assets", "objects", "foliage", "cedar.azmodel"), + "Bush": os.path.join("assets", "objects", "foliage", "bush_privet_01.azmodel"), + } + + # 1) Open an existing simple level + helper.init_idle() + helper.open_level("Prefab", "Base") + + # 2) Create a Dynamic Vegetation surface in preparation of prefab creation + center_point = math.Vector3(0.0, 0.0, 0.0) + dynveg.create_surface_entity("Planting Surface", center_point, 128.0, 128.0, 1.0) + + # 3) Create each of the Mesh asset prefabs and validate that the prefab created successfully + for prefab_filename, asset_path in mesh_prefabs.items(): + prefab_created = ( + f"Temporary {prefab_filename} prefab created successfully", + f"Failed to create temporary {prefab_filename} prefab" + ) + prefab = dynveg.create_temp_mesh_prefab(asset_path, prefab_filename) + Report.result(prefab_created, helper.wait_for_condition(lambda: PrefabInstance.is_valid(prefab[1]), 3.0)) + + # 4) Assign the temp prefab to the prefab instance spawner, and validate the instance count + #for prefab_filename in mesh_prefabs: + spawner_entity = dynveg.create_prefab_spawner("PrefabSpawner", center_point, 16.0, 16.0, 16.0, + get_prefab_file_path("Sphere")) + + # 5) Report errors/asserts + helper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0) + for error_info in error_tracer.errors: + Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}") + for assert_info in error_tracer.asserts: + Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}") + + general.idle_wait(20.0) +if __name__ == "__main__": + + from editor_python_test_tools.utils import Report + Report.start_test(DynVegUtils_TempPrefabCreationWorks) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/TestSuite_Periodic_Optimized.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/TestSuite_Periodic_Optimized.py new file mode 100644 index 0000000000..764d2dec75 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/TestSuite_Periodic_Optimized.py @@ -0,0 +1,22 @@ +""" +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 +""" + +import os +import pytest + +import ly_test_tools.environment.file_system as file_system +from ly_test_tools.o3de.editor_test import EditorSingleTest, EditorSharedTest, EditorParallelTest, EditorTestSuite + + +@pytest.mark.SUITE_main +@pytest.mark.parametrize("launcher_platform", ['windows_editor']) +@pytest.mark.parametrize("project", ["AutomatedTesting"]) +class TestAutomation(EditorTestSuite): + global_extra_cmdline_args = [] + + class test_DynVegUtils_TempPrefabCreationWorks(EditorSharedTest): + from .EditorScripts import DynVegUtils_TempPrefabCreationWorks as test_module diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py b/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py index 957536fffb..3004038b7f 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py @@ -19,6 +19,25 @@ import azlmbr.paths sys.path.append(os.path.join(azlmbr.paths.projectroot, 'Gem', 'PythonTests')) import editor_python_test_tools.hydra_editor_utils as hydra +from editor_python_test_tools.editor_entity_utils import EditorEntity, EditorComponent +from editor_python_test_tools.prefab_utils import Prefab + + +def create_temp_mesh_prefab(mesh_asset_path, prefab_filename): + # Create initial entity + root = EditorEntity.create_editor_entity(name=prefab_filename) + assert root.exists(), "Failed to create entity" + # Add mesh component + mesh_component = root.add_component("Mesh") + assert root.has_component("Mesh") and mesh_component.is_enabled(), "Failed to add/activate Mesh component" + # Assign the specified mesh asset + mesh_asset = asset.AssetCatalogRequestBus(bus.Broadcast, "GetAssetIdByPath", mesh_asset_path, math.Uuid(), False) + mesh_component.set_component_property_value("Controller|Configuration|Mesh Asset", mesh_asset) + assert mesh_component.get_component_property_value("Controller|Configuration|Mesh Asset"), \ + "Failed to set Mesh asset" + # Create and return the temporary/in-memory prefab + temp_prefab = Prefab.create_prefab([root], prefab_filename) + return temp_prefab def create_surface_entity(name, center_point, box_size_x, box_size_y, box_size_z): @@ -52,6 +71,40 @@ def create_mesh_surface_entity_with_slopes(name, center_point, uniform_scale): return surface_entity +def create_prefab_spawner(name, center_point, box_size_x, box_size_y, box_size_z, prefab_asset_path): + # Create a vegetation area entity to use as our test vegetation spawner + spawner_entity = EditorEntity.create_editor_entity_at(center_point, name=name) + spawner_entity.add_components(["Vegetation Layer Spawner", "Box Shape", "Vegetation Asset List"]) + if spawner_entity.id.IsValid(): + print(f"'{spawner_entity.get_name()}' created") + spawner_entity.components[1].set_component_property_value("Box Shape|Box Configuration|Dimensions", + math.Vector3(box_size_x, box_size_y, box_size_z)) + + # Set the vegetation area to a Prefab spawner with a specific prefab asset selected + prefab_spawner = vegetation.PrefabInstanceSpawner() + prefab_spawner.SetPrefabAssetPath(prefab_asset_path) + descriptor = spawner_entity.components[2].get_component_property_value("Configuration|Embedded Assets|[0]") + descriptor.spawner = prefab_spawner + spawner_entity.components[2].set_component_property_value("Configuration|Embedded Assets|[0]", descriptor) + return spawner_entity + +def create_empty_spawner(name, center_point, box_size_x, box_size_y, box_size_z): + # Create a vegetation area entity to use as our test vegetation spawner + spawner_entity = EditorEntity.create_editor_entity_at(center_point, name=name) + spawner_entity.add_components(["Vegetation Layer Spawner", "Box Shape", "Vegetation Asset List"]) + if spawner_entity.id.IsValid(): + print(f"'{spawner_entity.get_name()}' created") + spawner_entity.components[1].set_component_property_value("Box Shape|Box Configuration|Dimensions", + math.Vector3(box_size_x, box_size_y, box_size_z)) + + # Set the vegetation area to an empty spawner + empty_spawner = vegetation.EmptyInstanceSpawner() + descriptor = spawner_entity.components[2].get_component_property_value("Configuration|Embedded Assets|[0]") + descriptor.spawner = empty_spawner + spawner_entity.components[2].set_component_property_value("Configuration|Embedded Assets|[0]", descriptor) + return spawner_entity + + def create_vegetation_area(name, center_point, box_size_x, box_size_y, box_size_z, dynamic_slice_asset_path): # Create a vegetation area entity to use as our test vegetation spawner spawner_entity = hydra.Entity(name) @@ -67,7 +120,7 @@ def create_vegetation_area(name, center_point, box_size_x, box_size_y, box_size_ # Set the vegetation area to a Dynamic Slice spawner with a specific slice asset selected dynamic_slice_spawner = vegetation.DynamicSliceInstanceSpawner() dynamic_slice_spawner.SetSliceAssetPath(dynamic_slice_asset_path) - descriptor = hydra.get_component_property_value(spawner_entity.components[2], 'Configuration|Embedded Assets|[0]') + descriptor = vegetation.Descriptor() descriptor.spawner = dynamic_slice_spawner spawner_entity.get_set_test(2, "Configuration|Embedded Assets|[0]", descriptor) return spawner_entity From 0d3ab12d4221596d163a37b60badc6ef41b55687 Mon Sep 17 00:00:00 2001 From: jckand-amzn Date: Fri, 12 Nov 2021 16:34:57 -0600 Subject: [PATCH 02/13] Removing unused imports and debug waits Signed-off-by: jckand-amzn --- .../DynVegUtils_TempPrefabCreationWorks.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py index d684d7eb02..6f0aace162 100644 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py @@ -33,12 +33,8 @@ def DynVegUtils_TempPrefabCreationWorks(): import os - import azlmbr.editor as editor - import azlmbr.legacy.general as general - import azlmbr.bus as bus import azlmbr.math as math - import editor_python_test_tools.hydra_editor_utils as hydra from largeworlds.large_worlds_utils import editor_dynveg_test_helper as dynveg from editor_python_test_tools.utils import Report, Tracer from editor_python_test_tools.utils import TestHelper as helper @@ -72,9 +68,9 @@ def DynVegUtils_TempPrefabCreationWorks(): Report.result(prefab_created, helper.wait_for_condition(lambda: PrefabInstance.is_valid(prefab[1]), 3.0)) # 4) Assign the temp prefab to the prefab instance spawner, and validate the instance count - #for prefab_filename in mesh_prefabs: - spawner_entity = dynveg.create_prefab_spawner("PrefabSpawner", center_point, 16.0, 16.0, 16.0, - get_prefab_file_path("Sphere")) + for prefab_filename in mesh_prefabs: + spawner_entity = dynveg.create_prefab_spawner("PrefabSpawner", center_point, 16.0, 16.0, 16.0, + get_prefab_file_path(get_prefab_file_path(prefab_filename))) # 5) Report errors/asserts helper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0) @@ -83,7 +79,7 @@ def DynVegUtils_TempPrefabCreationWorks(): for assert_info in error_tracer.asserts: Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}") - general.idle_wait(20.0) + if __name__ == "__main__": from editor_python_test_tools.utils import Report From 0a801ffd783e91b550c48f6f218e69baef6785e7 Mon Sep 17 00:00:00 2001 From: jckand-amzn Date: Mon, 15 Nov 2021 15:33:46 -0600 Subject: [PATCH 03/13] Finalizing temporary prefab helpers and test Signed-off-by: jckand-amzn --- .../DynVegUtils_TempPrefabCreationWorks.py | 49 ++++++++++--------- .../editor_dynveg_test_helper.py | 41 +++++++++------- 2 files changed, 49 insertions(+), 41 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py index 6f0aace162..3aac745149 100644 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py @@ -10,18 +10,16 @@ def DynVegUtils_TempPrefabCreationWorks(): """ Summary: An existing level is opened. Each Prefab setup to be spawned by Dynamic Vegetation tests is created in memory and - validated against existing components/mesh assignments. A spawner is then created with the temporary prefabs to ensure - proper functionality with Dynamic Vegetation components. + validated against existing test slice components/mesh assignments. Expected Behavior: - Temporary prefabs contain the expected components/assets. Instances plant as expected in the assigned area. + Temporary prefabs contain the expected components/assets. Test Steps: 1) Open an existing level - 2) Create each of the necessary temporary prefabs, and validate the component/mesh setups - 3) Create a Vegetation Layer Spawner setup using the temporary prefabs as Prefab Instance Spawner types - 4) Create a surface to plant on and validate instance counts - 5) Verify expected instance counts + 2) Create each of the necessary temporary Mesh prefabs, and validate the component/mesh setups + 3) Create the necessary temporary PhysX Collider, and validate the component setup + 4) Report errors/asserts Note: - This test file must be called from the Open 3D Engine Editor command terminal @@ -33,12 +31,15 @@ def DynVegUtils_TempPrefabCreationWorks(): import os + import azlmbr.asset as asset + import azlmbr.bus as bus + import azlmbr.legacy.general as general import azlmbr.math as math from largeworlds.large_worlds_utils import editor_dynveg_test_helper as dynveg from editor_python_test_tools.utils import Report, Tracer from editor_python_test_tools.utils import TestHelper as helper - from editor_python_test_tools.prefab_utils import Prefab, PrefabInstance, get_prefab_file_path + from editor_python_test_tools.prefab_utils import PrefabInstance with Tracer() as error_tracer: # Create dictionary for prefab filenames and paths to create using helper function @@ -54,25 +55,29 @@ def DynVegUtils_TempPrefabCreationWorks(): helper.init_idle() helper.open_level("Prefab", "Base") - # 2) Create a Dynamic Vegetation surface in preparation of prefab creation - center_point = math.Vector3(0.0, 0.0, 0.0) - dynveg.create_surface_entity("Planting Surface", center_point, 128.0, 128.0, 1.0) - - # 3) Create each of the Mesh asset prefabs and validate that the prefab created successfully + # 2) Create each of the Mesh asset prefabs and validate that the prefab created successfully for prefab_filename, asset_path in mesh_prefabs.items(): - prefab_created = ( - f"Temporary {prefab_filename} prefab created successfully", - f"Failed to create temporary {prefab_filename} prefab" + mesh_prefab_created = ( + f"Temporary mesh prefab: {prefab_filename} created successfully", + f"Failed to create temporary mesh prefab: {prefab_filename}" ) prefab = dynveg.create_temp_mesh_prefab(asset_path, prefab_filename) - Report.result(prefab_created, helper.wait_for_condition(lambda: PrefabInstance.is_valid(prefab[1]), 3.0)) + Report.result(mesh_prefab_created, helper.wait_for_condition(lambda: + PrefabInstance.is_valid(prefab[1]), 3.0)) - # 4) Assign the temp prefab to the prefab instance spawner, and validate the instance count - for prefab_filename in mesh_prefabs: - spawner_entity = dynveg.create_prefab_spawner("PrefabSpawner", center_point, 16.0, 16.0, 16.0, - get_prefab_file_path(get_prefab_file_path(prefab_filename))) + # 3) Create temp PhysX Collider prefab and validate that the prefab created successfully + physx_prefab_filename = "CedarTree_Collision" + physx_collider_prefab_created = ( + f"Temporary mesh prefab: {physx_prefab_filename} created successfully", + f"Failed to create temporary mesh prefab: {physx_prefab_filename}" + ) + test_physx_mesh_asset_id = asset.AssetCatalogRequestBus(bus.Broadcast, "GetAssetIdByPath", os.path.join( + "assets", "objects", "foliage", "cedar.pxmesh"), math.Uuid(), False) + dynveg.create_temp_physx_mesh_collider(test_physx_mesh_asset_id, "CedarTree_Collision") + Report.result(physx_collider_prefab_created, helper.wait_for_condition(lambda: + PrefabInstance.is_valid(prefab[1]), 3.0)) - # 5) Report errors/asserts + # 4) Report errors/asserts helper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0) for error_info in error_tracer.errors: Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}") diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py b/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py index 3004038b7f..9840a4c5fd 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py @@ -19,7 +19,7 @@ import azlmbr.paths sys.path.append(os.path.join(azlmbr.paths.projectroot, 'Gem', 'PythonTests')) import editor_python_test_tools.hydra_editor_utils as hydra -from editor_python_test_tools.editor_entity_utils import EditorEntity, EditorComponent +from editor_python_test_tools.editor_entity_utils import EditorEntity from editor_python_test_tools.prefab_utils import Prefab @@ -33,13 +33,33 @@ def create_temp_mesh_prefab(mesh_asset_path, prefab_filename): # Assign the specified mesh asset mesh_asset = asset.AssetCatalogRequestBus(bus.Broadcast, "GetAssetIdByPath", mesh_asset_path, math.Uuid(), False) mesh_component.set_component_property_value("Controller|Configuration|Mesh Asset", mesh_asset) - assert mesh_component.get_component_property_value("Controller|Configuration|Mesh Asset"), \ + assert mesh_component.get_component_property_value("Controller|Configuration|Mesh Asset") == mesh_asset, \ "Failed to set Mesh asset" # Create and return the temporary/in-memory prefab temp_prefab = Prefab.create_prefab([root], prefab_filename) return temp_prefab +def create_temp_physx_mesh_collider(physx_mesh_id, prefab_filename): + # Create initial entity + root = EditorEntity.create_editor_entity(name=prefab_filename) + assert root.exists(), "Failed to create entity" + # Add PhysX Collider component + collider_component = root.add_component("PhysX Collider") + assert root.has_component("PhysX Collider") and collider_component.is_enabled(), \ + "Failed to add/activate PhysX Collider component" + # Set the Collider's Shape Configuration field to PhysicsAsset, and assign the specified PhysX Mesh asset + collider_component.set_component_property_value("Shape Configuration|Shape", 7) + assert collider_component.get_component_property_value("Shape Configuration|Shape") == 7, \ + "Failed to set Collider Shape to PhysicsAsset" + collider_component.set_component_property_value("Shape Configuration|Asset|PhysX Mesh", physx_mesh_id) + assert collider_component.get_component_property_value("Shape Configuration|Asset|PhysX Mesh") == physx_mesh_id, \ + "Failed to assign PhysX Mesh asset" + # Create and return the temporary/in-memory prefab + temp_prefab = Prefab.create_prefab([root], prefab_filename) + return temp_prefab + + def create_surface_entity(name, center_point, box_size_x, box_size_y, box_size_z): # Create a "flat surface" entity to use as a plantable vegetation surface surface_entity = hydra.Entity(name) @@ -71,23 +91,6 @@ def create_mesh_surface_entity_with_slopes(name, center_point, uniform_scale): return surface_entity -def create_prefab_spawner(name, center_point, box_size_x, box_size_y, box_size_z, prefab_asset_path): - # Create a vegetation area entity to use as our test vegetation spawner - spawner_entity = EditorEntity.create_editor_entity_at(center_point, name=name) - spawner_entity.add_components(["Vegetation Layer Spawner", "Box Shape", "Vegetation Asset List"]) - if spawner_entity.id.IsValid(): - print(f"'{spawner_entity.get_name()}' created") - spawner_entity.components[1].set_component_property_value("Box Shape|Box Configuration|Dimensions", - math.Vector3(box_size_x, box_size_y, box_size_z)) - - # Set the vegetation area to a Prefab spawner with a specific prefab asset selected - prefab_spawner = vegetation.PrefabInstanceSpawner() - prefab_spawner.SetPrefabAssetPath(prefab_asset_path) - descriptor = spawner_entity.components[2].get_component_property_value("Configuration|Embedded Assets|[0]") - descriptor.spawner = prefab_spawner - spawner_entity.components[2].set_component_property_value("Configuration|Embedded Assets|[0]", descriptor) - return spawner_entity - def create_empty_spawner(name, center_point, box_size_x, box_size_y, box_size_z): # Create a vegetation area entity to use as our test vegetation spawner spawner_entity = EditorEntity.create_editor_entity_at(center_point, name=name) From 327d4192f8943b3fcdd427257177df6f8d516222 Mon Sep 17 00:00:00 2001 From: jckand-amzn Date: Mon, 15 Nov 2021 15:48:44 -0600 Subject: [PATCH 04/13] Enabling new optimized periodic test runner for DynamicVegetation tests Signed-off-by: jckand-amzn --- .../Gem/PythonTests/largeworlds/CMakeLists.txt | 15 ++++++++++++++- .../dyn_veg/TestSuite_Periodic_Optimized.py | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/CMakeLists.txt b/AutomatedTesting/Gem/PythonTests/largeworlds/CMakeLists.txt index c2123d683c..98801b49d6 100644 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/CMakeLists.txt +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/CMakeLists.txt @@ -24,7 +24,6 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS AND PAL_TRAIT_ LargeWorlds ) - ly_add_pytest( NAME AutomatedTesting::DynamicVegetationTests_Periodic TEST_SERIAL @@ -39,6 +38,20 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS AND PAL_TRAIT_ LargeWorlds ) + ly_add_pytest( + NAME AutomatedTesting::DynamicVegetationTests_Periodic_Optimized + TEST_SERIAL + TEST_SUITE periodic + PATH ${CMAKE_CURRENT_LIST_DIR}/dyn_veg/TestSuite_Periodic_Optimized.py + RUNTIME_DEPENDENCIES + AZ::AssetProcessor + Legacy::Editor + AutomatedTesting.Assets + AutomatedTesting.GameLauncher + COMPONENT + LargeWorlds + ) + ly_add_pytest( NAME AutomatedTesting::DynamicVegetationTests_Main_Optimized TEST_SERIAL diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/TestSuite_Periodic_Optimized.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/TestSuite_Periodic_Optimized.py index 764d2dec75..8d298e970b 100644 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/TestSuite_Periodic_Optimized.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/TestSuite_Periodic_Optimized.py @@ -16,7 +16,8 @@ from ly_test_tools.o3de.editor_test import EditorSingleTest, EditorSharedTest, E @pytest.mark.parametrize("launcher_platform", ['windows_editor']) @pytest.mark.parametrize("project", ["AutomatedTesting"]) class TestAutomation(EditorTestSuite): - global_extra_cmdline_args = [] + + global_extra_cmdline_args = ["-BatchMode", "-autotest_mode", "--regset=/Amazon/Preferences/EnablePrefabSystem=true"] class test_DynVegUtils_TempPrefabCreationWorks(EditorSharedTest): from .EditorScripts import DynVegUtils_TempPrefabCreationWorks as test_module From 60f7ea54aa3eaadc4a709ecf331b30e7fda05e6b Mon Sep 17 00:00:00 2001 From: jckand-amzn Date: Mon, 15 Nov 2021 17:45:52 -0600 Subject: [PATCH 05/13] Reverting unintentional change to create_vegetation_area() helper Signed-off-by: jckand-amzn --- .../EditorScripts/DynVegUtils_TempPrefabCreationWorks.py | 3 +-- .../large_worlds_utils/editor_dynveg_test_helper.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py index 3aac745149..16a6c2eda6 100644 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py @@ -33,7 +33,6 @@ def DynVegUtils_TempPrefabCreationWorks(): import azlmbr.asset as asset import azlmbr.bus as bus - import azlmbr.legacy.general as general import azlmbr.math as math from largeworlds.large_worlds_utils import editor_dynveg_test_helper as dynveg @@ -73,7 +72,7 @@ def DynVegUtils_TempPrefabCreationWorks(): ) test_physx_mesh_asset_id = asset.AssetCatalogRequestBus(bus.Broadcast, "GetAssetIdByPath", os.path.join( "assets", "objects", "foliage", "cedar.pxmesh"), math.Uuid(), False) - dynveg.create_temp_physx_mesh_collider(test_physx_mesh_asset_id, "CedarTree_Collision") + dynveg.create_temp_physx_mesh_collider(test_physx_mesh_asset_id, physx_prefab_filename) Report.result(physx_collider_prefab_created, helper.wait_for_condition(lambda: PrefabInstance.is_valid(prefab[1]), 3.0)) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py b/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py index 9840a4c5fd..d840628abc 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py @@ -123,7 +123,7 @@ def create_vegetation_area(name, center_point, box_size_x, box_size_y, box_size_ # Set the vegetation area to a Dynamic Slice spawner with a specific slice asset selected dynamic_slice_spawner = vegetation.DynamicSliceInstanceSpawner() dynamic_slice_spawner.SetSliceAssetPath(dynamic_slice_asset_path) - descriptor = vegetation.Descriptor() + descriptor = hydra.get_component_property_value(spawner_entity.components[2], 'Configuration|Embedded Assets|[0]') descriptor.spawner = dynamic_slice_spawner spawner_entity.get_set_test(2, "Configuration|Embedded Assets|[0]", descriptor) return spawner_entity From 05caf1b29da517f188704337d5ec9fa452c242b0 Mon Sep 17 00:00:00 2001 From: jckand-amzn Date: Mon, 15 Nov 2021 17:50:42 -0600 Subject: [PATCH 06/13] Removed redundant append to components list from add_component() Signed-off-by: jckand-amzn --- .../editor_python_test_tools/editor_entity_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py index aee8846afe..59e454479c 100644 --- a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py +++ b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py @@ -259,7 +259,6 @@ class EditorEntity: :return: Component object of newly added component. """ component = self.add_components([component_name])[0] - self.components.append(component) return component def add_components(self, component_names: list) -> List[EditorComponent]: From e5ebdaebcf2452d1c10806a7c4cfb31f543ecd60 Mon Sep 17 00:00:00 2001 From: jckand-amzn Date: Mon, 15 Nov 2021 18:27:52 -0600 Subject: [PATCH 07/13] Removing unused helper for now and utilizing helper function for opening base level Signed-off-by: jckand-amzn --- .../DynVegUtils_TempPrefabCreationWorks.py | 4 ++-- .../editor_dynveg_test_helper.py | 17 ----------------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py index 16a6c2eda6..8d7f02425d 100644 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py @@ -35,6 +35,7 @@ def DynVegUtils_TempPrefabCreationWorks(): import azlmbr.bus as bus import azlmbr.math as math + from Prefab.tests import PrefabTestUtils as prefab_test_utils from largeworlds.large_worlds_utils import editor_dynveg_test_helper as dynveg from editor_python_test_tools.utils import Report, Tracer from editor_python_test_tools.utils import TestHelper as helper @@ -51,8 +52,7 @@ def DynVegUtils_TempPrefabCreationWorks(): } # 1) Open an existing simple level - helper.init_idle() - helper.open_level("Prefab", "Base") + prefab_test_utils.open_base_tests_level() # 2) Create each of the Mesh asset prefabs and validate that the prefab created successfully for prefab_filename, asset_path in mesh_prefabs.items(): diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py b/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py index d840628abc..d7d5842518 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/large_worlds_utils/editor_dynveg_test_helper.py @@ -91,23 +91,6 @@ def create_mesh_surface_entity_with_slopes(name, center_point, uniform_scale): return surface_entity -def create_empty_spawner(name, center_point, box_size_x, box_size_y, box_size_z): - # Create a vegetation area entity to use as our test vegetation spawner - spawner_entity = EditorEntity.create_editor_entity_at(center_point, name=name) - spawner_entity.add_components(["Vegetation Layer Spawner", "Box Shape", "Vegetation Asset List"]) - if spawner_entity.id.IsValid(): - print(f"'{spawner_entity.get_name()}' created") - spawner_entity.components[1].set_component_property_value("Box Shape|Box Configuration|Dimensions", - math.Vector3(box_size_x, box_size_y, box_size_z)) - - # Set the vegetation area to an empty spawner - empty_spawner = vegetation.EmptyInstanceSpawner() - descriptor = spawner_entity.components[2].get_component_property_value("Configuration|Embedded Assets|[0]") - descriptor.spawner = empty_spawner - spawner_entity.components[2].set_component_property_value("Configuration|Embedded Assets|[0]", descriptor) - return spawner_entity - - def create_vegetation_area(name, center_point, box_size_x, box_size_y, box_size_z, dynamic_slice_asset_path): # Create a vegetation area entity to use as our test vegetation spawner spawner_entity = hydra.Entity(name) From d2d83079eb36d3620fcf67e383bdfb95f03e1339 Mon Sep 17 00:00:00 2001 From: jckand-amzn Date: Mon, 15 Nov 2021 18:30:06 -0600 Subject: [PATCH 08/13] Cleaning up test docstring Signed-off-by: jckand-amzn --- .../EditorScripts/DynVegUtils_TempPrefabCreationWorks.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py index 8d7f02425d..d016473d5e 100644 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynVegUtils_TempPrefabCreationWorks.py @@ -21,11 +21,6 @@ def DynVegUtils_TempPrefabCreationWorks(): 3) Create the necessary temporary PhysX Collider, and validate the component setup 4) Report errors/asserts - Note: - - This test file must be called from the Open 3D Engine Editor command terminal - - Any passed and failed tests are written to the Editor.log file. - Parsing the file or running a log_monitor are required to observe the test results. - :return: None """ From 83df48381345cf0b6aa31816cf14379ce0c74909 Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Tue, 16 Nov 2021 08:08:53 -0600 Subject: [PATCH 09/13] Updated splash screen and about dialog with Stable 21.11 name Signed-off-by: Chris Galvan --- Code/Editor/AboutDialog.ui | 2 +- Code/Editor/StartupLogoDialog.ui | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Editor/AboutDialog.ui b/Code/Editor/AboutDialog.ui index a6c5bb5d52..a36d65e35b 100644 --- a/Code/Editor/AboutDialog.ui +++ b/Code/Editor/AboutDialog.ui @@ -125,7 +125,7 @@ - General Availability + Stable 21.11 Qt::AutoText diff --git a/Code/Editor/StartupLogoDialog.ui b/Code/Editor/StartupLogoDialog.ui index c0b8115cb0..c2cbfcfd69 100644 --- a/Code/Editor/StartupLogoDialog.ui +++ b/Code/Editor/StartupLogoDialog.ui @@ -103,7 +103,7 @@ - General Availability + Stable 21.11 From 3428bcb5dad0fd628c07cd11d63c17ca36975dd4 Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Tue, 16 Nov 2021 10:07:45 -0600 Subject: [PATCH 10/13] Updated splash screen and about dialog with development name Signed-off-by: Chris Galvan --- Code/Editor/AboutDialog.ui | 2 +- Code/Editor/StartupLogoDialog.ui | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Editor/AboutDialog.ui b/Code/Editor/AboutDialog.ui index a36d65e35b..09a7c18841 100644 --- a/Code/Editor/AboutDialog.ui +++ b/Code/Editor/AboutDialog.ui @@ -125,7 +125,7 @@ - Stable 21.11 + development Qt::AutoText diff --git a/Code/Editor/StartupLogoDialog.ui b/Code/Editor/StartupLogoDialog.ui index c2cbfcfd69..cbc596f53a 100644 --- a/Code/Editor/StartupLogoDialog.ui +++ b/Code/Editor/StartupLogoDialog.ui @@ -103,7 +103,7 @@ - Stable 21.11 + development From a1c67a52033250d8cae8c4e71037266e28dc1a55 Mon Sep 17 00:00:00 2001 From: chiyenteng <82238204+chiyenteng@users.noreply.github.com> Date: Tue, 16 Nov 2021 09:56:24 -0800 Subject: [PATCH 11/13] Fix prefab enabled automated tests (#5626) Signed-off-by: chiyenteng <82238204+chiyenteng@users.noreply.github.com> --- .../Gem/PythonTests/Physics/TestSuite_Main_Optimized.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AutomatedTesting/Gem/PythonTests/Physics/TestSuite_Main_Optimized.py b/AutomatedTesting/Gem/PythonTests/Physics/TestSuite_Main_Optimized.py index 3d668a2085..0661c6742b 100644 --- a/AutomatedTesting/Gem/PythonTests/Physics/TestSuite_Main_Optimized.py +++ b/AutomatedTesting/Gem/PythonTests/Physics/TestSuite_Main_Optimized.py @@ -60,7 +60,7 @@ class EditorSingleTest_WithFileOverrides(EditorSingleTest): class TestAutomationWithPrefabSystemEnabled(EditorTestSuite): global_extra_cmdline_args = ['-BatchMode', '-autotest_mode', - 'extra_cmdline_args=["--regset=/Amazon/Preferences/EnablePrefabSystem=true"]'] + '--regset=/Amazon/Preferences/EnablePrefabSystem=true'] @staticmethod def get_number_parallel_editors(): From 59b12a6ec7e8e2bce2c6a2669fc71bca6fd673ce Mon Sep 17 00:00:00 2001 From: Vincent Liu <5900509+onecent1101@users.noreply.github.com> Date: Tue, 16 Nov 2021 12:14:05 -0800 Subject: [PATCH 12/13] Add cvar for aws log level (#5507) * Add cvar for aws log level Signed-off-by: onecent1101 * Remove old crysystem registered cmd and add safeguard to get cvar from console Signed-off-by: onecent1101 * Suppress error for client auth unit test as logging was routed to warning before Signed-off-by: onecent1101 --- Code/Legacy/CrySystem/SystemInit.cpp | 16 -- Code/Tools/AWSNativeSDKInit/CMakeLists.txt | 27 +++ .../aws_native_sdk_init_tests_files.cmake | 12 ++ .../source/AWSLogSystemInterface.cpp | 26 +-- .../source/AWSNativeSDKInit.cpp | 4 +- .../tests/AWSLogSystemInterfaceTest.cpp | 169 ++++++++++++++++++ .../tests/AWSNativeSDKInitTest.cpp | 11 ++ .../AWSCognitoAuthorizationControllerTest.cpp | 6 + .../Code/AWSGameLiftClient/CMakeLists.txt | 2 - .../Source/AWSGameLiftClientManager.cpp | 4 +- 10 files changed, 244 insertions(+), 33 deletions(-) create mode 100644 Code/Tools/AWSNativeSDKInit/aws_native_sdk_init_tests_files.cmake create mode 100644 Code/Tools/AWSNativeSDKInit/tests/AWSLogSystemInterfaceTest.cpp create mode 100644 Code/Tools/AWSNativeSDKInit/tests/AWSNativeSDKInitTest.cpp diff --git a/Code/Legacy/CrySystem/SystemInit.cpp b/Code/Legacy/CrySystem/SystemInit.cpp index 8a0586fb13..5cb60f2cdf 100644 --- a/Code/Legacy/CrySystem/SystemInit.cpp +++ b/Code/Legacy/CrySystem/SystemInit.cpp @@ -1225,20 +1225,6 @@ static AZStd::string ConcatPath(const char* szPart1, const char* szPart2) return ret; } -// Helper to maintain backwards compatibility with our CVar but not force our new code to -// pull in CryCommon by routing through an environment variable -void CmdSetAwsLogLevel(IConsoleCmdArgs* pArgs) -{ - static const char* const logLevelEnvVar = "sys_SetLogLevel"; - static AZ::EnvironmentVariable logVar = AZ::Environment::CreateVariable(logLevelEnvVar); - if (pArgs->GetArgCount() > 1) - { - int logLevel = atoi(pArgs->GetArg(1)); - *logVar = logLevel; - AZ_TracePrintf("AWSLogging", "Log level set to %d", *logVar); - } -} - ////////////////////////////////////////////////////////////////////////// void CSystem::CreateSystemVars() { @@ -1601,8 +1587,6 @@ void CSystem::CreateSystemVars() // Since the UI Canvas Editor is incomplete, we have a variable to enable it. // By default it is now enabled. Modify system.cfg or game.cfg to disable it REGISTER_INT("sys_enableCanvasEditor", 1, VF_NULL, "Enables the UI Canvas Editor"); - - REGISTER_COMMAND("sys_SetLogLevel", CmdSetAwsLogLevel, 0, "Set AWS log level [0 - 6]."); } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Tools/AWSNativeSDKInit/CMakeLists.txt b/Code/Tools/AWSNativeSDKInit/CMakeLists.txt index d571f0d9e3..57ee31d30d 100644 --- a/Code/Tools/AWSNativeSDKInit/CMakeLists.txt +++ b/Code/Tools/AWSNativeSDKInit/CMakeLists.txt @@ -24,3 +24,30 @@ ly_add_target( 3rdParty::AWSNativeSDK::Core AZ::AzCore ) + +################################################################################ +# Tests +################################################################################ +if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) + ly_add_target( + NAME AWSNativeSDKInit.Tests ${PAL_TRAIT_TEST_TARGET_TYPE} + NAMESPACE AZ + FILES_CMAKE + aws_native_sdk_init_tests_files.cmake + INCLUDE_DIRECTORIES + PRIVATE + include + tests + source + BUILD_DEPENDENCIES + PRIVATE + AZ::AzCore + AZ::AzFramework + AZ::AzTest + AZ::AWSNativeSDKInit + 3rdParty::AWSNativeSDK::Core + ) + ly_add_googletest( + NAME AZ::AWSNativeSDKInit.Tests + ) +endif() diff --git a/Code/Tools/AWSNativeSDKInit/aws_native_sdk_init_tests_files.cmake b/Code/Tools/AWSNativeSDKInit/aws_native_sdk_init_tests_files.cmake new file mode 100644 index 0000000000..9029a1198a --- /dev/null +++ b/Code/Tools/AWSNativeSDKInit/aws_native_sdk_init_tests_files.cmake @@ -0,0 +1,12 @@ +# +# 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 +# +# + +set(FILES + tests/AWSLogSystemInterfaceTest.cpp + tests/AWSNativeSDKInitTest.cpp +) diff --git a/Code/Tools/AWSNativeSDKInit/source/AWSLogSystemInterface.cpp b/Code/Tools/AWSNativeSDKInit/source/AWSLogSystemInterface.cpp index 113e513743..0ccfc43ba4 100644 --- a/Code/Tools/AWSNativeSDKInit/source/AWSLogSystemInterface.cpp +++ b/Code/Tools/AWSNativeSDKInit/source/AWSLogSystemInterface.cpp @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include @@ -24,6 +26,9 @@ AZ_POP_DISABLE_WARNING namespace AWSNativeSDKInit { + AZ_CVAR(int, bg_awsLogLevel, -1, nullptr, AZ::ConsoleFunctorFlags::Null, + "AWSLogLevel used to control verbosity of logging system. Off = 0, Fatal = 1, Error = 2, Warn = 3, Info = 4, Debug = 5, Trace = 6"); + const char* AWSLogSystemInterface::AWS_API_LOG_PREFIX = "AwsApi-"; const int AWSLogSystemInterface::MAX_MESSAGE_LENGTH = 4096; const char* AWSLogSystemInterface::MESSAGE_FORMAT = "[AWS] %s - %s"; @@ -40,15 +45,16 @@ namespace AWSNativeSDKInit Aws::Utils::Logging::LogLevel AWSLogSystemInterface::GetLogLevel() const { Aws::Utils::Logging::LogLevel newLevel = m_logLevel; - static const char* const logLevelEnvVar = "sys_SetLogLevel"; - auto logVar = AZ::Environment::FindVariable(logLevelEnvVar); - - if (logVar) + if (auto console = AZ::Interface::Get(); console != nullptr) { - newLevel = (Aws::Utils::Logging::LogLevel) *logVar; + int awsLogLevel = -1; + console->GetCvarValue("bg_awsLogLevel", awsLogLevel); + if (awsLogLevel >= 0) + { + newLevel = static_cast(awsLogLevel); + } } - - return newLevel != m_logLevel ? newLevel : m_logLevel; + return newLevel; } /** @@ -78,14 +84,12 @@ namespace AWSNativeSDKInit */ void AWSLogSystemInterface::LogStream(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const Aws::OStringStream &messageStream) { - if(!ShouldLog(logLevel)) { return; } ForwardAwsApiLogMessage(logLevel, tag, messageStream.str().c_str()); - } bool AWSLogSystemInterface::ShouldLog(Aws::Utils::Logging::LogLevel logLevel) @@ -93,7 +97,7 @@ namespace AWSNativeSDKInit #if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK) Aws::Utils::Logging::LogLevel newLevel = GetLogLevel(); - if (newLevel > Aws::Utils::Logging::LogLevel::Info && newLevel <= Aws::Utils::Logging::LogLevel::Trace && newLevel != m_logLevel) + if (newLevel != m_logLevel) { SetLogLevel(newLevel); } @@ -124,7 +128,7 @@ namespace AWSNativeSDKInit break; case Aws::Utils::Logging::LogLevel::Error: - AZ::Debug::Trace::Instance().Warning(__FILE__, __LINE__, AZ_FUNCTION_SIGNATURE, AWSLogSystemInterface::ERROR_WINDOW_NAME, MESSAGE_FORMAT, tag, message); + AZ::Debug::Trace::Instance().Error(__FILE__, __LINE__, AZ_FUNCTION_SIGNATURE, AWSLogSystemInterface::ERROR_WINDOW_NAME, MESSAGE_FORMAT, tag, message); break; case Aws::Utils::Logging::LogLevel::Warn: diff --git a/Code/Tools/AWSNativeSDKInit/source/AWSNativeSDKInit.cpp b/Code/Tools/AWSNativeSDKInit/source/AWSNativeSDKInit.cpp index 815fc1bbf0..ca63859945 100644 --- a/Code/Tools/AWSNativeSDKInit/source/AWSNativeSDKInit.cpp +++ b/Code/Tools/AWSNativeSDKInit/source/AWSNativeSDKInit.cpp @@ -64,10 +64,10 @@ namespace AWSNativeSDKInit { #if defined(PLATFORM_SUPPORTS_AWS_NATIVE_SDK) Aws::Utils::Logging::LogLevel logLevel; -#ifdef _DEBUG +#if defined(AZ_DEBUG_BUILD) || defined(AZ_PROFILE_BUILD) logLevel = Aws::Utils::Logging::LogLevel::Warn; #else - logLevel = Aws::Utils::Logging::LogLevel::Warn; + logLevel = Aws::Utils::Logging::LogLevel::Error; #endif m_awsSDKOptions.loggingOptions.logLevel = logLevel; m_awsSDKOptions.loggingOptions.logger_create_fn = [logLevel]() diff --git a/Code/Tools/AWSNativeSDKInit/tests/AWSLogSystemInterfaceTest.cpp b/Code/Tools/AWSNativeSDKInit/tests/AWSLogSystemInterfaceTest.cpp new file mode 100644 index 0000000000..02b6cbebc1 --- /dev/null +++ b/Code/Tools/AWSNativeSDKInit/tests/AWSLogSystemInterfaceTest.cpp @@ -0,0 +1,169 @@ +/* + * 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 + * + */ + +#include +#include +#include +#include +#include + +#include + +#include + +using namespace AWSNativeSDKInit; + +class AWSLogSystemInterfaceTest + : public UnitTest::ScopedAllocatorSetupFixture + , public AZ::Debug::TraceMessageBus::Handler +{ +public: + bool OnPreAssert(const char*, int, const char*, const char*) override + { + return true; + } + + bool OnPreError(const char*, const char*, int, const char*, const char*) override + { + m_error = true; + return true; + } + + bool OnPreWarning(const char*, const char*, int, const char*, const char*) override + { + m_warning = true; + return true; + } + + bool OnPrintf(const char*, const char*) override + { + m_printf = true; + return true; + } + + void SetUp() override + { + BusConnect(); + if (!AZ::Interface::Get()) + { + m_console = AZStd::make_unique(); + m_console->LinkDeferredFunctors(AZ::ConsoleFunctorBase::GetDeferredHead()); + AZ::Interface::Register(m_console.get()); + } + } + + void TearDown() override + { + if (m_console) + { + AZ::Interface::Unregister(m_console.get()); + m_console.reset(); + } + BusDisconnect(); + } + + bool m_error = false; + bool m_warning = false; + bool m_printf = false; + +private: + AZStd::unique_ptr m_console; +}; + +TEST_F(AWSLogSystemInterfaceTest, LogStream_LogFatalMessage_GetExpectedNotification) +{ + AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace); + Aws::OStringStream testString; + logSystem.LogStream(Aws::Utils::Logging::LogLevel::Fatal, "test", testString); + ASSERT_TRUE(m_error); + ASSERT_FALSE(m_warning); + ASSERT_FALSE(m_printf); +} + +TEST_F(AWSLogSystemInterfaceTest, LogStream_LogErrorMessage_GetExpectedNotification) +{ + AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace); + Aws::OStringStream testString; + logSystem.LogStream(Aws::Utils::Logging::LogLevel::Error, "test", testString); + ASSERT_TRUE(m_error); + ASSERT_FALSE(m_warning); + ASSERT_FALSE(m_printf); +} + +TEST_F(AWSLogSystemInterfaceTest, LogStream_LogWarningMessage_GetExpectedNotification) +{ + AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace); + Aws::OStringStream testString; + logSystem.LogStream(Aws::Utils::Logging::LogLevel::Warn, "test", testString); + ASSERT_FALSE(m_error); + ASSERT_TRUE(m_warning); + ASSERT_FALSE(m_printf); +} + +TEST_F(AWSLogSystemInterfaceTest, LogStream_LogInfoMessage_GetExpectedNotification) +{ + AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace); + Aws::OStringStream testString; + logSystem.LogStream(Aws::Utils::Logging::LogLevel::Info, "test", testString); + ASSERT_FALSE(m_error); + ASSERT_FALSE(m_warning); + ASSERT_TRUE(m_printf); +} + +TEST_F(AWSLogSystemInterfaceTest, LogStream_LogDebugMessage_GetExpectedNotification) +{ + AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace); + Aws::OStringStream testString; + logSystem.LogStream(Aws::Utils::Logging::LogLevel::Debug, "test", testString); + ASSERT_FALSE(m_error); + ASSERT_FALSE(m_warning); + ASSERT_TRUE(m_printf); +} + +TEST_F(AWSLogSystemInterfaceTest, LogStream_LogTraceMessage_GetExpectedNotification) +{ + AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace); + Aws::OStringStream testString; + logSystem.LogStream(Aws::Utils::Logging::LogLevel::Trace, "test", testString); + ASSERT_FALSE(m_error); + ASSERT_FALSE(m_warning); + ASSERT_TRUE(m_printf); +} + +TEST_F(AWSLogSystemInterfaceTest, LogStream_OverrideWarnAndLogInfoMessage_GetExpectedNotification) +{ + AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace); + Aws::OStringStream testString; + AZ::Interface::Get()->PerformCommand("bg_awsLogLevel 3"); + logSystem.LogStream(Aws::Utils::Logging::LogLevel::Info, "test", testString); + ASSERT_FALSE(m_error); + ASSERT_FALSE(m_warning); + ASSERT_FALSE(m_printf); +} + +TEST_F(AWSLogSystemInterfaceTest, LogStream_OverrideWarnAndLogeErrorMessage_GetExpectedNotification) +{ + AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace); + Aws::OStringStream testString; + AZ::Interface::Get()->PerformCommand("bg_awsLogLevel 3"); + logSystem.LogStream(Aws::Utils::Logging::LogLevel::Error, "test", testString); + ASSERT_TRUE(m_error); + ASSERT_FALSE(m_warning); + ASSERT_FALSE(m_printf); +} + +TEST_F(AWSLogSystemInterfaceTest, LogStream_OverrideOffAndLogInfoMessage_GetExpectedNotification) +{ + AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace); + Aws::OStringStream testString; + AZ::Interface::Get()->PerformCommand("bg_awsLogLevel 0"); + logSystem.LogStream(Aws::Utils::Logging::LogLevel::Info, "test", testString); + ASSERT_FALSE(m_error); + ASSERT_FALSE(m_warning); + ASSERT_FALSE(m_printf); +} diff --git a/Code/Tools/AWSNativeSDKInit/tests/AWSNativeSDKInitTest.cpp b/Code/Tools/AWSNativeSDKInit/tests/AWSNativeSDKInitTest.cpp new file mode 100644 index 0000000000..40217ff9bc --- /dev/null +++ b/Code/Tools/AWSNativeSDKInit/tests/AWSNativeSDKInitTest.cpp @@ -0,0 +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. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include + +AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV); diff --git a/Gems/AWSClientAuth/Code/Tests/Authorization/AWSCognitoAuthorizationControllerTest.cpp b/Gems/AWSClientAuth/Code/Tests/Authorization/AWSCognitoAuthorizationControllerTest.cpp index 9f31891512..2269a2340a 100644 --- a/Gems/AWSClientAuth/Code/Tests/Authorization/AWSCognitoAuthorizationControllerTest.cpp +++ b/Gems/AWSClientAuth/Code/Tests/Authorization/AWSCognitoAuthorizationControllerTest.cpp @@ -140,7 +140,9 @@ TEST_F(AWSCognitoAuthorizationControllerTest, RequestAWSCredentials_Fail_GetIdEr EXPECT_CALL(*m_cognitoIdentityClientMock, GetCredentialsForIdentity(testing::_)).Times(0); EXPECT_CALL(m_awsCognitoAuthorizationNotificationsBusMock, OnRequestAWSCredentialsSuccess(testing::_)).Times(0); EXPECT_CALL(m_awsCognitoAuthorizationNotificationsBusMock, OnRequestAWSCredentialsFail(testing::_)).Times(1); + AZ_TEST_START_TRACE_SUPPRESSION; m_mockController->RequestAWSCredentialsAsync(); + AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; } TEST_F(AWSCognitoAuthorizationControllerTest, RequestAWSCredentials_Fail_GetCredentialsForIdentityError) @@ -174,7 +176,9 @@ TEST_F(AWSCognitoAuthorizationControllerTest, RequestAWSCredentials_Fail_GetCred EXPECT_CALL(*m_cognitoIdentityClientMock, GetCredentialsForIdentity(testing::_)).Times(1).WillOnce(testing::Return(outcome)); EXPECT_CALL(m_awsCognitoAuthorizationNotificationsBusMock, OnRequestAWSCredentialsSuccess(testing::_)).Times(0); EXPECT_CALL(m_awsCognitoAuthorizationNotificationsBusMock, OnRequestAWSCredentialsFail(testing::_)).Times(1); + AZ_TEST_START_TRACE_SUPPRESSION; m_mockController->RequestAWSCredentialsAsync(); + AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; } TEST_F(AWSCognitoAuthorizationControllerTest, AddRemoveLogins_Succuess) @@ -331,8 +335,10 @@ TEST_F(AWSCognitoAuthorizationControllerTest, GetCredentialsProvider_NoPersisted EXPECT_CALL(*m_cognitoIdentityClientMock, GetCredentialsForIdentity(testing::_)).Times(0); std::shared_ptr actualCredentialsProvider; + AZ_TEST_START_TRACE_SUPPRESSION; AWSCore::AWSCredentialRequestBus::BroadcastResult( actualCredentialsProvider, &AWSCore::AWSCredentialRequests::GetCredentialsProvider); + AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; EXPECT_TRUE(actualCredentialsProvider == nullptr); } diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/CMakeLists.txt b/Gems/AWSGameLift/Code/AWSGameLiftClient/CMakeLists.txt index 1fab09e9f4..ab85e89f75 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/CMakeLists.txt +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/CMakeLists.txt @@ -6,8 +6,6 @@ # # -set(awsgameliftclient_compile_definition $,AWSGAMELIFT_RELEASE,AWSGAMELIFT_DEV>) - ly_add_target( NAME AWSGameLift.Client.Static STATIC NAMESPACE Gem diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/AWSGameLiftClientManager.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/AWSGameLiftClientManager.cpp index 4ee2d31ebf..a071b8f859 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/AWSGameLiftClientManager.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/AWSGameLiftClientManager.cpp @@ -33,7 +33,7 @@ namespace AWSGameLift { -#if defined(AWSGAMELIFT_DEV) +#if defined(AZ_DEBUG_BUILD) || defined(AZ_PROFILE_BUILD) AZ_CVAR(AZ::CVarFixedString, cl_gameliftLocalEndpoint, "", nullptr, AZ::ConsoleFunctorFlags::Null, "The local endpoint to test with GameLiftLocal SDK."); #endif @@ -87,7 +87,7 @@ namespace AWSGameLift // Set up client endpoint or region AZStd::string localEndpoint = ""; -#if defined(AWSGAMELIFT_DEV) +#if defined(AZ_DEBUG_BUILD) || defined(AZ_PROFILE_BUILD) localEndpoint = static_cast(cl_gameliftLocalEndpoint); #endif if (!localEndpoint.empty()) From 8ca5a79076c349faef31b26423d4c4c1c11dd769 Mon Sep 17 00:00:00 2001 From: Vincent Liu <5900509+onecent1101@users.noreply.github.com> Date: Tue, 16 Nov 2021 13:06:59 -0800 Subject: [PATCH 13/13] Move gamelift client usage into each activity scope (#5554) Signed-off-by: onecent1101 --- .../Source/AWSGameLiftClientManager.cpp | 155 +++--------------- .../Source/AWSGameLiftClientManager.h | 9 - .../AWSGameLiftAcceptMatchActivity.cpp | 14 +- .../Activity/AWSGameLiftAcceptMatchActivity.h | 2 +- .../AWSGameLiftCreateSessionActivity.cpp | 23 ++- .../AWSGameLiftCreateSessionActivity.h | 6 +- ...WSGameLiftCreateSessionOnQueueActivity.cpp | 23 ++- .../AWSGameLiftCreateSessionOnQueueActivity.h | 6 +- .../AWSGameLiftJoinSessionActivity.cpp | 15 +- .../Activity/AWSGameLiftJoinSessionActivity.h | 1 - .../AWSGameLiftLeaveSessionActivity.cpp | 5 +- .../AWSGameLiftSearchSessionsActivity.cpp | 19 ++- .../AWSGameLiftSearchSessionsActivity.h | 3 - .../AWSGameLiftStartMatchmakingActivity.cpp | 15 +- .../AWSGameLiftStartMatchmakingActivity.h | 2 +- .../AWSGameLiftStopMatchmakingActivity.cpp | 14 +- .../AWSGameLiftStopMatchmakingActivity.h | 2 +- .../AWSGameLiftCreateSessionActivityTest.cpp | 2 + ...meLiftCreateSessionOnQueueActivityTest.cpp | 2 + .../AWSGameLiftJoinSessionActivityTest.cpp | 2 + .../AWSGameLiftSearchSessionsActivityTest.cpp | 3 + 21 files changed, 139 insertions(+), 184 deletions(-) diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/AWSGameLiftClientManager.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/AWSGameLiftClientManager.cpp index a071b8f859..f900310078 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/AWSGameLiftClientManager.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/AWSGameLiftClientManager.cpp @@ -139,7 +139,7 @@ namespace AWSGameLift { const AWSGameLiftAcceptMatchRequest& gameliftStartMatchmakingRequest = static_cast(acceptMatchRequest); - AcceptMatchHelper(gameliftStartMatchmakingRequest); + AcceptMatchActivity::AcceptMatch(gameliftStartMatchmakingRequest); } } @@ -157,9 +157,9 @@ namespace AWSGameLift AZ::JobContext* jobContext = nullptr; AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext); AZ::Job* acceptMatchJob = AZ::CreateJobFunction( - [this, gameliftStartMatchmakingRequest]() + [gameliftStartMatchmakingRequest]() { - AcceptMatchHelper(gameliftStartMatchmakingRequest); + AcceptMatchActivity::AcceptMatch(gameliftStartMatchmakingRequest); AzFramework::MatchmakingAsyncRequestNotificationBus::Broadcast( &AzFramework::MatchmakingAsyncRequestNotifications::OnAcceptMatchAsyncComplete); @@ -169,21 +169,6 @@ namespace AWSGameLift acceptMatchJob->Start(); } - void AWSGameLiftClientManager::AcceptMatchHelper(const AWSGameLiftAcceptMatchRequest& acceptMatchRequest) - { - auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); - - AZStd::string response; - if (!gameliftClient) - { - AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage); - } - else - { - AcceptMatchActivity::AcceptMatch(*gameliftClient, acceptMatchRequest); - } - } - AZStd::string AWSGameLiftClientManager::CreateSession(const AzFramework::CreateSessionRequest& createSessionRequest) { AZStd::string result = ""; @@ -191,13 +176,13 @@ namespace AWSGameLift { const AWSGameLiftCreateSessionRequest& gameliftCreateSessionRequest = static_cast(createSessionRequest); - result = CreateSessionHelper(gameliftCreateSessionRequest); + result = CreateSessionActivity::CreateSession(gameliftCreateSessionRequest); } else if (CreateSessionOnQueueActivity::ValidateCreateSessionOnQueueRequest(createSessionRequest)) { const AWSGameLiftCreateSessionOnQueueRequest& gameliftCreateSessionOnQueueRequest = static_cast(createSessionRequest); - result = CreateSessionOnQueueHelper(gameliftCreateSessionOnQueueRequest); + result = CreateSessionOnQueueActivity::CreateSessionOnQueue(gameliftCreateSessionOnQueueRequest); } else { @@ -217,9 +202,9 @@ namespace AWSGameLift AZ::JobContext* jobContext = nullptr; AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext); AZ::Job* createSessionJob = AZ::CreateJobFunction( - [this, gameliftCreateSessionRequest]() + [gameliftCreateSessionRequest]() { - AZStd::string result = CreateSessionHelper(gameliftCreateSessionRequest); + AZStd::string result = CreateSessionActivity::CreateSession(gameliftCreateSessionRequest); AzFramework::SessionAsyncRequestNotificationBus::Broadcast( &AzFramework::SessionAsyncRequestNotifications::OnCreateSessionAsyncComplete, result); @@ -235,9 +220,9 @@ namespace AWSGameLift AZ::JobContext* jobContext = nullptr; AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext); AZ::Job* createSessionOnQueueJob = AZ::CreateJobFunction( - [this, gameliftCreateSessionOnQueueRequest]() + [gameliftCreateSessionOnQueueRequest]() { - AZStd::string result = CreateSessionOnQueueHelper(gameliftCreateSessionOnQueueRequest); + AZStd::string result = CreateSessionOnQueueActivity::CreateSessionOnQueue(gameliftCreateSessionOnQueueRequest); AzFramework::SessionAsyncRequestNotificationBus::Broadcast( &AzFramework::SessionAsyncRequestNotifications::OnCreateSessionAsyncComplete, result); @@ -253,38 +238,6 @@ namespace AWSGameLift } } - AZStd::string AWSGameLiftClientManager::CreateSessionHelper( - const AWSGameLiftCreateSessionRequest& createSessionRequest) - { - auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); - AZStd::string result = ""; - if (!gameliftClient) - { - AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage); - } - else - { - result = CreateSessionActivity::CreateSession(*gameliftClient, createSessionRequest); - } - return result; - } - - AZStd::string AWSGameLiftClientManager::CreateSessionOnQueueHelper( - const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest) - { - auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); - AZStd::string result; - if (!gameliftClient) - { - AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage); - } - else - { - result = CreateSessionOnQueueActivity::CreateSessionOnQueue(*gameliftClient, createSessionOnQueueRequest); - } - return result; - } - bool AWSGameLiftClientManager::JoinSession(const AzFramework::JoinSessionRequest& joinSessionRequest) { bool result = false; @@ -292,7 +245,8 @@ namespace AWSGameLift { const AWSGameLiftJoinSessionRequest& gameliftJoinSessionRequest = static_cast(joinSessionRequest); - result = JoinSessionHelper(gameliftJoinSessionRequest); + auto createPlayerSessionOutcome = JoinSessionActivity::CreatePlayerSession(gameliftJoinSessionRequest); + result = JoinSessionActivity::RequestPlayerJoinSession(createPlayerSessionOutcome); } return result; @@ -313,9 +267,10 @@ namespace AWSGameLift AZ::JobContext* jobContext = nullptr; AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext); AZ::Job* joinSessionJob = AZ::CreateJobFunction( - [this, gameliftJoinSessionRequest]() + [gameliftJoinSessionRequest]() { - bool result = JoinSessionHelper(gameliftJoinSessionRequest); + auto createPlayerSessionOutcome = JoinSessionActivity::CreatePlayerSession(gameliftJoinSessionRequest); + bool result = JoinSessionActivity::RequestPlayerJoinSession(createPlayerSessionOutcome); AzFramework::SessionAsyncRequestNotificationBus::Broadcast( &AzFramework::SessionAsyncRequestNotifications::OnJoinSessionAsyncComplete, result); @@ -325,23 +280,6 @@ namespace AWSGameLift joinSessionJob->Start(); } - bool AWSGameLiftClientManager::JoinSessionHelper(const AWSGameLiftJoinSessionRequest& joinSessionRequest) - { - auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); - bool result = false; - if (!gameliftClient) - { - AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage); - } - else - { - auto createPlayerSessionOutcome = JoinSessionActivity::CreatePlayerSession(*gameliftClient, joinSessionRequest); - - result = JoinSessionActivity::RequestPlayerJoinSession(createPlayerSessionOutcome); - } - return result; - } - void AWSGameLiftClientManager::LeaveSession() { AWSGameLift::LeaveSessionActivity::LeaveSession(); @@ -371,7 +309,7 @@ namespace AWSGameLift { const AWSGameLiftSearchSessionsRequest& gameliftSearchSessionsRequest = static_cast(searchSessionsRequest); - response = SearchSessionsHelper(gameliftSearchSessionsRequest); + response = SearchSessionsActivity::SearchSessions(gameliftSearchSessionsRequest); } return response; @@ -392,9 +330,9 @@ namespace AWSGameLift AZ::JobContext* jobContext = nullptr; AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext); AZ::Job* searchSessionsJob = AZ::CreateJobFunction( - [this, gameliftSearchSessionsRequest]() + [gameliftSearchSessionsRequest]() { - AzFramework::SearchSessionsResponse response = SearchSessionsHelper(gameliftSearchSessionsRequest); + AzFramework::SearchSessionsResponse response = SearchSessionsActivity::SearchSessions(gameliftSearchSessionsRequest); AzFramework::SessionAsyncRequestNotificationBus::Broadcast( &AzFramework::SessionAsyncRequestNotifications::OnSearchSessionsAsyncComplete, response); @@ -404,22 +342,6 @@ namespace AWSGameLift searchSessionsJob->Start(); } - AzFramework::SearchSessionsResponse AWSGameLiftClientManager::SearchSessionsHelper( - const AWSGameLiftSearchSessionsRequest& searchSessionsRequest) const - { - auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); - AzFramework::SearchSessionsResponse response; - if (!gameliftClient) - { - AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage); - } - else - { - response = SearchSessionsActivity::SearchSessions(*gameliftClient, searchSessionsRequest); - } - return response; - } - AZStd::string AWSGameLiftClientManager::StartMatchmaking(const AzFramework::StartMatchmakingRequest& startMatchmakingRequest) { AZStd::string response; @@ -427,7 +349,7 @@ namespace AWSGameLift { const AWSGameLiftStartMatchmakingRequest& gameliftStartMatchmakingRequest = static_cast(startMatchmakingRequest); - response = StartMatchmakingHelper(gameliftStartMatchmakingRequest); + response = StartMatchmakingActivity::StartMatchmaking(gameliftStartMatchmakingRequest); } return response; @@ -448,9 +370,9 @@ namespace AWSGameLift AZ::JobContext* jobContext = nullptr; AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext); AZ::Job* startMatchmakingJob = AZ::CreateJobFunction( - [this, gameliftStartMatchmakingRequest]() + [gameliftStartMatchmakingRequest]() { - AZStd::string response = StartMatchmakingHelper(gameliftStartMatchmakingRequest); + AZStd::string response = StartMatchmakingActivity::StartMatchmaking(gameliftStartMatchmakingRequest); AzFramework::MatchmakingAsyncRequestNotificationBus::Broadcast( &AzFramework::MatchmakingAsyncRequestNotifications::OnStartMatchmakingAsyncComplete, response); @@ -460,29 +382,14 @@ namespace AWSGameLift startMatchmakingJob->Start(); } - AZStd::string AWSGameLiftClientManager::StartMatchmakingHelper(const AWSGameLiftStartMatchmakingRequest& startMatchmakingRequest) - { - auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); - - AZStd::string response; - if (!gameliftClient) - { - AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage); - } - else - { - response = StartMatchmakingActivity::StartMatchmaking(*gameliftClient, startMatchmakingRequest); - } - return response; - } - void AWSGameLiftClientManager::StopMatchmaking(const AzFramework::StopMatchmakingRequest& stopMatchmakingRequest) { if (StopMatchmakingActivity::ValidateStopMatchmakingRequest(stopMatchmakingRequest)) { const AWSGameLiftStopMatchmakingRequest& gameliftStopMatchmakingRequest = static_cast(stopMatchmakingRequest); - StopMatchmakingHelper(gameliftStopMatchmakingRequest); + + StopMatchmakingActivity::StopMatchmaking(gameliftStopMatchmakingRequest); } } @@ -501,9 +408,9 @@ namespace AWSGameLift AZ::JobContext* jobContext = nullptr; AWSCore::AWSCoreRequestBus::BroadcastResult(jobContext, &AWSCore::AWSCoreRequests::GetDefaultJobContext); AZ::Job* stopMatchmakingJob = AZ::CreateJobFunction( - [this, gameliftStopMatchmakingRequest]() + [gameliftStopMatchmakingRequest]() { - StopMatchmakingHelper(gameliftStopMatchmakingRequest); + StopMatchmakingActivity::StopMatchmaking(gameliftStopMatchmakingRequest); AzFramework::MatchmakingAsyncRequestNotificationBus::Broadcast( &AzFramework::MatchmakingAsyncRequestNotifications::OnStopMatchmakingAsyncComplete); @@ -512,18 +419,4 @@ namespace AWSGameLift stopMatchmakingJob->Start(); } - - void AWSGameLiftClientManager::StopMatchmakingHelper(const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest) - { - auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); - - if (!gameliftClient) - { - AZ_Error(AWSGameLiftClientManagerName, false, AWSGameLiftClientMissingErrorMessage); - } - else - { - StopMatchmakingActivity::StopMatchmaking(*gameliftClient, stopMatchmakingRequest); - } - } } // namespace AWSGameLift diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/AWSGameLiftClientManager.h b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/AWSGameLiftClientManager.h index 8a0c91c36d..f37152bc60 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/AWSGameLiftClientManager.h +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/AWSGameLiftClientManager.h @@ -175,14 +175,5 @@ namespace AWSGameLift bool JoinSession(const AzFramework::JoinSessionRequest& joinSessionRequest) override; AzFramework::SearchSessionsResponse SearchSessions(const AzFramework::SearchSessionsRequest& searchSessionsRequest) const override; void LeaveSession() override; - - private: - void AcceptMatchHelper(const AWSGameLiftAcceptMatchRequest& createSessionRequest); - AZStd::string CreateSessionHelper(const AWSGameLiftCreateSessionRequest& createSessionRequest); - AZStd::string CreateSessionOnQueueHelper(const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest); - bool JoinSessionHelper(const AWSGameLiftJoinSessionRequest& joinSessionRequest); - AzFramework::SearchSessionsResponse SearchSessionsHelper(const AWSGameLiftSearchSessionsRequest& searchSessionsRequest) const; - AZStd::string StartMatchmakingHelper(const AWSGameLiftStartMatchmakingRequest& startMatchmakingRequest); - void StopMatchmakingHelper(const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest); }; } // namespace AWSGameLift diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftAcceptMatchActivity.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftAcceptMatchActivity.cpp index 25ba328fd0..dbeced1728 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftAcceptMatchActivity.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftAcceptMatchActivity.cpp @@ -7,9 +7,11 @@ */ #include +#include #include #include +#include #include #include @@ -42,13 +44,19 @@ namespace AWSGameLift return request; } - void AcceptMatch(const Aws::GameLift::GameLiftClient& gameliftClient, - const AWSGameLiftAcceptMatchRequest& AcceptMatchRequest) + void AcceptMatch(const AWSGameLiftAcceptMatchRequest& AcceptMatchRequest) { + auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); + if (!gameliftClient) + { + AZ_Error(AWSGameLiftAcceptMatchActivityName, false, AWSGameLiftClientMissingErrorMessage); + return; + } + AZ_TracePrintf(AWSGameLiftAcceptMatchActivityName, "Requesting AcceptMatch against Amazon GameLift service ..."); Aws::GameLift::Model::AcceptMatchRequest request = BuildAWSGameLiftAcceptMatchRequest(AcceptMatchRequest); - auto AcceptMatchOutcome = gameliftClient.AcceptMatch(request); + auto AcceptMatchOutcome = gameliftClient->AcceptMatch(request); if (AcceptMatchOutcome.IsSuccess()) { diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftAcceptMatchActivity.h b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftAcceptMatchActivity.h index d5f28f92e2..ac4012c347 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftAcceptMatchActivity.h +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftAcceptMatchActivity.h @@ -23,7 +23,7 @@ namespace AWSGameLift Aws::GameLift::Model::AcceptMatchRequest BuildAWSGameLiftAcceptMatchRequest(const AWSGameLiftAcceptMatchRequest& AcceptMatchRequest); // Create AcceptMatchRequest and make a AcceptMatch call through GameLift client - void AcceptMatch(const Aws::GameLift::GameLiftClient& gameliftClient, const AWSGameLiftAcceptMatchRequest& AcceptMatchRequest); + void AcceptMatch(const AWSGameLiftAcceptMatchRequest& AcceptMatchRequest); // Validate AcceptMatchRequest and check required request parameters bool ValidateAcceptMatchRequest(const AzFramework::AcceptMatchRequest& AcceptMatchRequest); diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionActivity.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionActivity.cpp index 0332ea7a76..ee93f022a1 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionActivity.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionActivity.cpp @@ -6,9 +6,16 @@ * */ +#include +#include + #include #include #include +#include + +#include +#include namespace AWSGameLift { @@ -63,15 +70,21 @@ namespace AWSGameLift return request; } - AZStd::string CreateSession( - const Aws::GameLift::GameLiftClient& gameliftClient, - const AWSGameLiftCreateSessionRequest& createSessionRequest) + AZStd::string CreateSession(const AWSGameLiftCreateSessionRequest& createSessionRequest) { + AZStd::string result = ""; + + auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); + if (!gameliftClient) + { + AZ_Error(AWSGameLiftCreateSessionActivityName, false, AWSGameLiftClientMissingErrorMessage); + return result; + } + AZ_TracePrintf(AWSGameLiftCreateSessionActivityName, "Requesting CreateGameSession against Amazon GameLift service ..."); - AZStd::string result = ""; Aws::GameLift::Model::CreateGameSessionRequest request = BuildAWSGameLiftCreateGameSessionRequest(createSessionRequest); - auto createSessionOutcome = gameliftClient.CreateGameSession(request); + auto createSessionOutcome = gameliftClient->CreateGameSession(request); AZ_TracePrintf(AWSGameLiftCreateSessionActivityName, "CreateGameSession request against Amazon GameLift service is complete"); if (createSessionOutcome.IsSuccess()) diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionActivity.h b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionActivity.h index 714675c652..af236dbfa4 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionActivity.h +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionActivity.h @@ -10,9 +10,7 @@ #include -#include #include -#include namespace AWSGameLift { @@ -24,9 +22,7 @@ namespace AWSGameLift Aws::GameLift::Model::CreateGameSessionRequest BuildAWSGameLiftCreateGameSessionRequest(const AWSGameLiftCreateSessionRequest& createSessionRequest); // Create CreateGameSessionRequest and make a CreateGameSession call through GameLift client - AZStd::string CreateSession( - const Aws::GameLift::GameLiftClient& gameliftClient, - const AWSGameLiftCreateSessionRequest& createSessionRequest); + AZStd::string CreateSession(const AWSGameLiftCreateSessionRequest& createSessionRequest); // Validate CreateSessionRequest and check required request parameters bool ValidateCreateSessionRequest(const AzFramework::CreateSessionRequest& createSessionRequest); diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionOnQueueActivity.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionOnQueueActivity.cpp index 52be365ea5..8e8d7e23c5 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionOnQueueActivity.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionOnQueueActivity.cpp @@ -6,9 +6,16 @@ * */ +#include +#include + #include #include #include +#include + +#include +#include namespace AWSGameLift { @@ -47,17 +54,23 @@ namespace AWSGameLift return request; } - AZStd::string CreateSessionOnQueue( - const Aws::GameLift::GameLiftClient& gameliftClient, - const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest) + AZStd::string CreateSessionOnQueue(const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest) { + AZStd::string result = ""; + + auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); + if (!gameliftClient) + { + AZ_Error(AWSGameLiftCreateSessionOnQueueActivityName, false, AWSGameLiftClientMissingErrorMessage); + return result; + } + AZ_TracePrintf(AWSGameLiftCreateSessionOnQueueActivityName, "Requesting StartGameSessionPlacement against Amazon GameLift service ..."); - AZStd::string result = ""; Aws::GameLift::Model::StartGameSessionPlacementRequest request = BuildAWSGameLiftStartGameSessionPlacementRequest(createSessionOnQueueRequest); - auto createSessionOnQueueOutcome = gameliftClient.StartGameSessionPlacement(request); + auto createSessionOnQueueOutcome = gameliftClient->StartGameSessionPlacement(request); AZ_TracePrintf(AWSGameLiftCreateSessionOnQueueActivityName, "StartGameSessionPlacement request against Amazon GameLift service is complete."); diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionOnQueueActivity.h b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionOnQueueActivity.h index 714bcd1060..5f16bf0b31 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionOnQueueActivity.h +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftCreateSessionOnQueueActivity.h @@ -10,9 +10,7 @@ #include -#include #include -#include namespace AWSGameLift { @@ -25,9 +23,7 @@ namespace AWSGameLift const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest); // Create StartGameSessionPlacementRequest and make a CreateGameSession call through GameLift client - AZStd::string CreateSessionOnQueue( - const Aws::GameLift::GameLiftClient& gameliftClient, - const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest); + AZStd::string CreateSessionOnQueue(const AWSGameLiftCreateSessionOnQueueRequest& createSessionOnQueueRequest); // Validate CreateSessionOnQueueRequest and check required request parameters bool ValidateCreateSessionOnQueueRequest(const AzFramework::CreateSessionRequest& createSessionRequest); diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftJoinSessionActivity.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftJoinSessionActivity.cpp index a47e59255f..71ef9e9737 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftJoinSessionActivity.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftJoinSessionActivity.cpp @@ -7,10 +7,11 @@ */ #include -#include +#include #include #include +#include namespace AWSGameLift { @@ -59,16 +60,24 @@ namespace AWSGameLift } Aws::GameLift::Model::CreatePlayerSessionOutcome CreatePlayerSession( - const Aws::GameLift::GameLiftClient& gameliftClient, const AWSGameLiftJoinSessionRequest& joinSessionRequest) { + Aws::GameLift::Model::CreatePlayerSessionOutcome createPlayerSessionOutcome; + + auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); + if (!gameliftClient) + { + AZ_Error(AWSGameLiftJoinSessionActivityName, false, AWSGameLiftClientMissingErrorMessage); + return createPlayerSessionOutcome; + } + AZ_TracePrintf(AWSGameLiftJoinSessionActivityName, "Requesting CreatePlayerSession for player %s against Amazon GameLift service ...", joinSessionRequest.m_playerId.c_str()); Aws::GameLift::Model::CreatePlayerSessionRequest request = BuildAWSGameLiftCreatePlayerSessionRequest(joinSessionRequest); - auto createPlayerSessionOutcome = gameliftClient.CreatePlayerSession(request); + createPlayerSessionOutcome = gameliftClient->CreatePlayerSession(request); AZ_TracePrintf(AWSGameLiftJoinSessionActivityName, "CreatePlayerSession request for player %s against Amazon GameLift service is complete", joinSessionRequest.m_playerId.c_str()); diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftJoinSessionActivity.h b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftJoinSessionActivity.h index fe34e5fe57..b011f4877b 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftJoinSessionActivity.h +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftJoinSessionActivity.h @@ -36,7 +36,6 @@ namespace AWSGameLift // Create CreatePlayerSessionRequest and make a CreatePlayerSession call through GameLift client Aws::GameLift::Model::CreatePlayerSessionOutcome CreatePlayerSession( - const Aws::GameLift::GameLiftClient& gameliftClient, const AWSGameLiftJoinSessionRequest& joinSessionRequest); // Request to setup networking connection for player diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftLeaveSessionActivity.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftLeaveSessionActivity.cpp index a99fed4edc..fd3b3d6ebc 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftLeaveSessionActivity.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftLeaveSessionActivity.cpp @@ -6,11 +6,12 @@ * */ -#include - #include +#include #include +#include + namespace AWSGameLift { namespace LeaveSessionActivity diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftSearchSessionsActivity.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftSearchSessionsActivity.cpp index 5f0b6fd012..b7917e6d59 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftSearchSessionsActivity.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftSearchSessionsActivity.cpp @@ -6,10 +6,16 @@ * */ +#include +#include #include #include #include +#include + +#include +#include namespace AWSGameLift { @@ -62,14 +68,21 @@ namespace AWSGameLift } AzFramework::SearchSessionsResponse SearchSessions( - const Aws::GameLift::GameLiftClient& gameliftClient, const AWSGameLiftSearchSessionsRequest& searchSessionsRequest) { + AzFramework::SearchSessionsResponse response; + + auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); + if (!gameliftClient) + { + AZ_Error(AWSGameLiftSearchSessionsActivityName, false, AWSGameLiftClientMissingErrorMessage); + return response; + } + AZ_TracePrintf(AWSGameLiftSearchSessionsActivityName, "Requesting SearchGameSessions against Amazon GameLift service ..."); - AzFramework::SearchSessionsResponse response; Aws::GameLift::Model::SearchGameSessionsRequest request = BuildAWSGameLiftSearchGameSessionsRequest(searchSessionsRequest); - Aws::GameLift::Model::SearchGameSessionsOutcome outcome = gameliftClient.SearchGameSessions(request); + Aws::GameLift::Model::SearchGameSessionsOutcome outcome = gameliftClient->SearchGameSessions(request); AZ_TracePrintf(AWSGameLiftSearchSessionsActivityName, "SearchGameSessions request against Amazon GameLift service is complete"); if (outcome.IsSuccess()) diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftSearchSessionsActivity.h b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftSearchSessionsActivity.h index 205e83dd96..d5bcda992c 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftSearchSessionsActivity.h +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftSearchSessionsActivity.h @@ -10,9 +10,7 @@ #include -#include #include -#include namespace AWSGameLift { @@ -28,7 +26,6 @@ namespace AWSGameLift // Create SearchGameSessionsRequest and make a SeachGameSessions call through GameLift client AzFramework::SearchSessionsResponse SearchSessions( - const Aws::GameLift::GameLiftClient& gameliftClient, const AWSGameLiftSearchSessionsRequest& searchSessionsRequest); // Convert from Aws::GameLift::Model::SearchGameSessionsResult to AzFramework::SearchSessionsResponse. diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStartMatchmakingActivity.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStartMatchmakingActivity.cpp index 00a7773491..6f6c7fccc0 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStartMatchmakingActivity.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStartMatchmakingActivity.cpp @@ -7,11 +7,13 @@ */ #include +#include #include #include #include #include +#include #include #include @@ -78,14 +80,21 @@ namespace AWSGameLift } AZStd::string StartMatchmaking( - const Aws::GameLift::GameLiftClient& gameliftClient, const AWSGameLiftStartMatchmakingRequest& startMatchmakingRequest) { + AZStd::string result = ""; + + auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); + if (!gameliftClient) + { + AZ_Error(AWSGameLiftStartMatchmakingActivityName, false, AWSGameLiftClientMissingErrorMessage); + return result; + } + AZ_TracePrintf(AWSGameLiftStartMatchmakingActivityName, "Requesting StartMatchmaking against Amazon GameLift service ..."); - AZStd::string result = ""; Aws::GameLift::Model::StartMatchmakingRequest request = BuildAWSGameLiftStartMatchmakingRequest(startMatchmakingRequest); - auto startMatchmakingOutcome = gameliftClient.StartMatchmaking(request); + auto startMatchmakingOutcome = gameliftClient->StartMatchmaking(request); if (startMatchmakingOutcome.IsSuccess()) { result = AZStd::string(startMatchmakingOutcome.GetResult().GetMatchmakingTicket().GetTicketId().c_str()); diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStartMatchmakingActivity.h b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStartMatchmakingActivity.h index db814c14b2..f736e318fb 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStartMatchmakingActivity.h +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStartMatchmakingActivity.h @@ -23,7 +23,7 @@ namespace AWSGameLift Aws::GameLift::Model::StartMatchmakingRequest BuildAWSGameLiftStartMatchmakingRequest(const AWSGameLiftStartMatchmakingRequest& startMatchmakingRequest); // Create StartMatchmakingRequest and make a StartMatchmaking call through GameLift client - AZStd::string StartMatchmaking(const Aws::GameLift::GameLiftClient& gameliftClient, const AWSGameLiftStartMatchmakingRequest& startMatchmakingRequest); + AZStd::string StartMatchmaking(const AWSGameLiftStartMatchmakingRequest& startMatchmakingRequest); // Validate StartMatchmakingRequest and check required request parameters bool ValidateStartMatchmakingRequest(const AzFramework::StartMatchmakingRequest& startMatchmakingRequest); diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStopMatchmakingActivity.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStopMatchmakingActivity.cpp index b427d0323a..022861570a 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStopMatchmakingActivity.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStopMatchmakingActivity.cpp @@ -7,9 +7,11 @@ */ #include +#include #include #include +#include #include #include @@ -32,13 +34,19 @@ namespace AWSGameLift return request; } - void StopMatchmaking(const Aws::GameLift::GameLiftClient& gameliftClient, - const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest) + void StopMatchmaking(const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest) { + auto gameliftClient = AZ::Interface::Get()->GetGameLiftClient(); + if (!gameliftClient) + { + AZ_Error(AWSGameLiftStopMatchmakingActivityName, false, AWSGameLiftClientMissingErrorMessage); + return; + } + AZ_TracePrintf(AWSGameLiftStopMatchmakingActivityName, "Requesting StopMatchmaking against Amazon GameLift service ..."); Aws::GameLift::Model::StopMatchmakingRequest request = BuildAWSGameLiftStopMatchmakingRequest(stopMatchmakingRequest); - auto stopMatchmakingOutcome = gameliftClient.StopMatchmaking(request); + auto stopMatchmakingOutcome = gameliftClient->StopMatchmaking(request); if (stopMatchmakingOutcome.IsSuccess()) { diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStopMatchmakingActivity.h b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStopMatchmakingActivity.h index 0820f2c05e..b5f19d35df 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStopMatchmakingActivity.h +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Source/Activity/AWSGameLiftStopMatchmakingActivity.h @@ -23,7 +23,7 @@ namespace AWSGameLift Aws::GameLift::Model::StopMatchmakingRequest BuildAWSGameLiftStopMatchmakingRequest(const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest); // Create StopMatchmakingRequest and make a StopMatchmaking call through GameLift client - void StopMatchmaking(const Aws::GameLift::GameLiftClient& gameliftClient, const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest); + void StopMatchmaking(const AWSGameLiftStopMatchmakingRequest& stopMatchmakingRequest); // Validate StopMatchmakingRequest and check required request parameters bool ValidateStopMatchmakingRequest(const AzFramework::StopMatchmakingRequest& stopMatchmakingRequest); diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftCreateSessionActivityTest.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftCreateSessionActivityTest.cpp index 70dcdba1af..fcf867138b 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftCreateSessionActivityTest.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftCreateSessionActivityTest.cpp @@ -9,6 +9,8 @@ #include #include +#include + using namespace AWSGameLift; using AWSGameLiftCreateSessionActivityTest = AWSGameLiftClientFixture; diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftCreateSessionOnQueueActivityTest.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftCreateSessionOnQueueActivityTest.cpp index 8a785d8007..4845586e47 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftCreateSessionOnQueueActivityTest.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftCreateSessionOnQueueActivityTest.cpp @@ -9,6 +9,8 @@ #include #include +#include + using namespace AWSGameLift; using AWSGameLiftCreateSessionOnQueueActivityTest = AWSGameLiftClientFixture; diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftJoinSessionActivityTest.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftJoinSessionActivityTest.cpp index 6a1156646a..33b03649c7 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftJoinSessionActivityTest.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftJoinSessionActivityTest.cpp @@ -6,6 +6,8 @@ * */ +#include + #include #include diff --git a/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftSearchSessionsActivityTest.cpp b/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftSearchSessionsActivityTest.cpp index 3337c2f6d2..0d3c8c137b 100644 --- a/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftSearchSessionsActivityTest.cpp +++ b/Gems/AWSGameLift/Code/AWSGameLiftClient/Tests/Activity/AWSGameLiftSearchSessionsActivityTest.cpp @@ -12,6 +12,9 @@ #include #include +#include +#include + using namespace AWSGameLift; using AWSGameLiftSearchSessionsActivityTest = AWSGameLiftClientFixture;