From 626b16dbaeeb40594303fa49ad473d37684eb9b1 Mon Sep 17 00:00:00 2001 From: Gene Walters Date: Tue, 18 Jan 2022 10:27:10 -0800 Subject: [PATCH 1/3] Updating NetworkingSpawnableLibrary to only store network spawnables, instead of all spawnables Signed-off-by: Gene Walters --- .../Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp | 4 ++-- .../Code/Source/NetworkEntity/NetworkSpawnableLibrary.h | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp index f60778dbb4..7fb7bfdc39 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include namespace Multiplayer @@ -42,7 +41,8 @@ namespace Multiplayer auto enumerateCallback = [this](const AZ::Data::AssetId id, const AZ::Data::AssetInfo& info) { - if (info.m_assetType == AZ::AzTypeInfo::Uuid()) + if (info.m_assetType == AZ::AzTypeInfo::Uuid() && + info.m_relativePath.ends_with(".network.spawnable")) { ProcessSpawnableAsset(info.m_relativePath, id); } diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h index 0fc3ae07cc..469086f4cb 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h @@ -23,12 +23,15 @@ namespace Multiplayer NetworkSpawnableLibrary(); ~NetworkSpawnableLibrary(); - /// INetworkSpawnableLibrary overrides. + //! INetworkSpawnableLibrary overrides. + //! @{ + // Iterates over all assets (on-disk and in-memory) and stores any spawnables that are "network.spawnables" + // This allows us to look up network spawnable assets by name or id for later use void BuildSpawnablesList() override; void ProcessSpawnableAsset(const AZStd::string& relativePath, AZ::Data::AssetId id) override; AZ::Name GetSpawnableNameFromAssetId(AZ::Data::AssetId assetId) override; AZ::Data::AssetId GetAssetIdByName(AZ::Name name) override; - + //! @} private: AZStd::unordered_map m_spawnables; From 54de15b0ecd555a481c24f569e382d8a1e514ad0 Mon Sep 17 00:00:00 2001 From: Gene Walters Date: Tue, 18 Jan 2022 16:34:58 -0800 Subject: [PATCH 2/3] Adding '.network.spawnable' as a network constant Signed-off-by: Gene Walters --- .../Code/Include/Multiplayer/MultiplayerConstants.h | 1 + .../Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp | 3 ++- .../Code/Source/Pipeline/NetworkPrefabProcessor.cpp | 3 ++- Gems/Multiplayer/Code/Tests/PrefabProcessingTests.cpp | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerConstants.h b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerConstants.h index 4471aa0c2b..3a4a9b1f58 100644 --- a/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerConstants.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerConstants.h @@ -20,6 +20,7 @@ namespace Multiplayer constexpr AZStd::string_view MpNetworkInterfaceName("MultiplayerNetworkInterface"); constexpr AZStd::string_view MpEditorInterfaceName("MultiplayerEditorNetworkInterface"); constexpr AZStd::string_view LocalHost("127.0.0.1"); + constexpr AZStd::string_view NetworkSpawnableFileExtension(".network.spawnable"); constexpr uint16_t DefaultServerPort = 33450; constexpr uint16_t DefaultServerEditorPort = 33451; diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp index 7fb7bfdc39..e668d43267 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace Multiplayer { @@ -42,7 +43,7 @@ namespace Multiplayer auto enumerateCallback = [this](const AZ::Data::AssetId id, const AZ::Data::AssetInfo& info) { if (info.m_assetType == AZ::AzTypeInfo::Uuid() && - info.m_relativePath.ends_with(".network.spawnable")) + info.m_relativePath.ends_with(NetworkSpawnableFileExtension)) { ProcessSpawnableAsset(info.m_relativePath, id); } diff --git a/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp b/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp index a797523bc0..9d6c47bb00 100644 --- a/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp +++ b/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -95,7 +96,7 @@ namespace Multiplayer using namespace AzToolsFramework::Prefab; AZStd::string uniqueName = prefab.GetName(); - uniqueName += ".network.spawnable"; + uniqueName += NetworkSpawnableFileExtension; auto serializer = [serializationFormat](AZStd::vector& output, const ProcessedObjectStore& object) -> bool { AZ::IO::ByteContainerStream stream(&output); diff --git a/Gems/Multiplayer/Code/Tests/PrefabProcessingTests.cpp b/Gems/Multiplayer/Code/Tests/PrefabProcessingTests.cpp index aef13fbfe2..32be828686 100644 --- a/Gems/Multiplayer/Code/Tests/PrefabProcessingTests.cpp +++ b/Gems/Multiplayer/Code/Tests/PrefabProcessingTests.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace UnitTest @@ -92,7 +93,7 @@ namespace UnitTest // Verify the name and the type of the spawnable asset const AZ::Data::AssetData& spawnableAsset = processedObjects[0].GetAsset(); - EXPECT_EQ(prefabName + ".network.spawnable", processedObjects[0].GetId()); + EXPECT_EQ(prefabName + Multiplayer::NetworkSpawnableFileExtension.data(), processedObjects[0].GetId()); EXPECT_EQ(spawnableAsset.GetType(), azrtti_typeid()); // Verify we have only the networked entity in the network spawnable and not the static one From fbfea49b68dbd0fb5c139087a6acbfe4a2f0c6be Mon Sep 17 00:00:00 2001 From: Gene Walters Date: Tue, 18 Jan 2022 23:55:40 -0800 Subject: [PATCH 3/3] small comment tweak based on feedback Signed-off-by: Gene Walters --- .../Code/Source/NetworkEntity/NetworkSpawnableLibrary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h index 469086f4cb..ab6211f522 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkSpawnableLibrary.h @@ -26,7 +26,7 @@ namespace Multiplayer //! INetworkSpawnableLibrary overrides. //! @{ // Iterates over all assets (on-disk and in-memory) and stores any spawnables that are "network.spawnables" - // This allows us to look up network spawnable assets by name or id for later use + // This allows users to look up network spawnable assets by name or id if needed later void BuildSpawnablesList() override; void ProcessSpawnableAsset(const AZStd::string& relativePath, AZ::Data::AssetId id) override; AZ::Name GetSpawnableNameFromAssetId(AZ::Data::AssetId assetId) override;