From 36911723c2b9054468db629a23fa5cc9b1dfbc8d Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 18:17:39 -0700 Subject: [PATCH] Addressed PR feedback --- .../AzCore/Asset/AssetJsonSerializer.cpp | 24 ++++++++++--- .../AzCore/AzCore/Asset/AssetJsonSerializer.h | 14 ++++++++ .../AzCore/Asset/SerializedAssetTracker.cpp | 34 ------------------- .../AzCore/Asset/SerializedAssetTracker.h | 34 ------------------- .../AzCore/AzCore/azcore_files.cmake | 2 -- .../Prefab/PrefabDomUtils.cpp | 9 +++-- .../AzToolsFramework/Prefab/PrefabDomUtils.h | 14 ++++---- 7 files changed, 44 insertions(+), 87 deletions(-) delete mode 100644 Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp delete mode 100644 Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp index 6968b51025..0078abf2d1 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp +++ b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -112,8 +111,8 @@ namespace AZ AssetId id; JSR::ResultCode result(JSR::Tasks::ReadField); - SerializedAssetTracker** assetIdTracker = - context.GetMetadata().Find(); + SerializedAssetTracker* assetTracker = + context.GetMetadata().Find(); { Data::AssetLoadBehavior loadBehavior = instance->GetAutoLoadBehavior(); @@ -168,9 +167,9 @@ namespace AZ "The asset hint is missing for Asset, so it will be left empty.")); } - if (assetIdTracker && *assetIdTracker) + if (assetTracker) { - (*assetIdTracker)->AddAsset(*instance); + assetTracker->AddAsset(*instance); } bool success = result.GetOutcome() <= JSR::Outcomes::PartialSkip; @@ -181,5 +180,20 @@ namespace AZ "Not enough information was available to create an instance of Asset or data was corrupted."; return context.Report(result, message); } + + void SerializedAssetTracker::AddAsset(Asset& asset) + { + m_serializedAssets.emplace_back(asset); + } + + const AZStd::vector>& SerializedAssetTracker::GetTrackedAssets() const + { + return m_serializedAssets; + } + + AZStd::vector>& SerializedAssetTracker::GetTrackedAssets() + { + return m_serializedAssets; + } } // namespace Data } // namespace AZ diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h index 3d5271035c..dca12df21b 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h +++ b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h @@ -13,6 +13,7 @@ #pragma once #include +#include #include namespace AZ @@ -37,5 +38,18 @@ namespace AZ private: JsonSerializationResult::Result LoadAsset(void* outputValue, const rapidjson::Value& inputValue, JsonDeserializerContext& context); }; + + class SerializedAssetTracker + { + public: + AZ_RTTI(SerializedAssetTracker, "{1E067091-8C0A-44B1-A455-6E97663F6963}"); + + void AddAsset(Asset& asset); + AZStd::vector>& GetTrackedAssets(); + const AZStd::vector>& GetTrackedAssets() const; + + private: + AZStd::vector> m_serializedAssets; + }; } // namespace Data } // namespace AZ diff --git a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp b/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp deleted file mode 100644 index bdd89683f6..0000000000 --- a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include - -namespace AZ -{ - namespace Data - { - void SerializedAssetTracker::AddAsset(Asset& asset) - { - m_serializedAssets.emplace_back(asset); - } - - const AZStd::vector>& SerializedAssetTracker::GetTrackedAssets() const - { - return m_serializedAssets; - } - - AZStd::vector>& SerializedAssetTracker::GetTrackedAssets() - { - return m_serializedAssets; - } - } -} diff --git a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h b/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h deleted file mode 100644 index ad80a077fe..0000000000 --- a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -namespace AZ -{ - namespace Data - { - class SerializedAssetTracker - { - public: - AZ_RTTI(SerializedAssetTracker, "{1E067091-8C0A-44B1-A455-6E97663F6963}"); - - void AddAsset(Asset& asset); - AZStd::vector>& GetTrackedAssets(); - const AZStd::vector>& GetTrackedAssets() const; - - private: - AZStd::vector> m_serializedAssets; - }; - } -} diff --git a/Code/Framework/AzCore/AzCore/azcore_files.cmake b/Code/Framework/AzCore/AzCore/azcore_files.cmake index c6ad90200b..5357ed66a6 100644 --- a/Code/Framework/AzCore/AzCore/azcore_files.cmake +++ b/Code/Framework/AzCore/AzCore/azcore_files.cmake @@ -35,8 +35,6 @@ set(FILES Asset/AssetSerializer.h Asset/AssetTypeInfoBus.h Asset/AssetInternal/WeakAsset.h - Asset/SerializedAssetTracker.cpp - Asset/SerializedAssetTracker.h Casting/lossy_cast.h Casting/numeric_cast.h Component/Component.cpp diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp index 9163b681de..0bffd26be0 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp @@ -11,7 +11,7 @@ */ #include -#include +#include #include #include @@ -132,15 +132,13 @@ namespace AzToolsFramework entityIdMapper.SetEntityIdGenerationApproach(InstanceEntityIdMapper::EntityIdGenerationApproach::Random); } - AZ::Data::SerializedAssetTracker assetTracker; - AZ::JsonDeserializerSettings settings; // The InstanceEntityIdMapper is registered twice because it's used in several places during deserialization where one is // specific for the InstanceEntityIdMapper and once for the generic JsonEntityIdMapper. Because the Json Serializer's meta // data has strict typing and doesn't look for inheritance both have to be explicitly added so they're found both locations. settings.m_metadata.Add(static_cast(&entityIdMapper)); settings.m_metadata.Add(&entityIdMapper); - settings.m_metadata.Add(&assetTracker); + settings.m_metadata.Create(); AZ::JsonSerializationResult::ResultCode result = AZ::JsonSerialization::Load(instance, prefabDom, settings); @@ -155,8 +153,9 @@ namespace AzToolsFramework return false; } + AZ::Data::SerializedAssetTracker* assetTracker = settings.m_metadata.Find(); - referencedAssets = AZStd::move(assetTracker.GetTrackedAssets()); + referencedAssets = AZStd::move(assetTracker->GetTrackedAssets()); return true; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h index 6778c236ee..c7c2827770 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h @@ -43,7 +43,7 @@ namespace AzToolsFramework /** * Stores a valid Prefab Instance within a Prefab Dom. Useful for generating Templates * @param instance The instance to store - * @param prefabDom the prefabDom that will be used to store the Instance data + * @param prefabDom The prefabDom that will be used to store the Instance data * @return bool on whether the operation succeeded */ bool StoreInstanceInPrefabDom(const Instance& instance, PrefabDom& prefabDom); @@ -61,8 +61,8 @@ namespace AzToolsFramework /** * Loads a valid Prefab Instance from a Prefab Dom. Useful for generating Instances. * @param instance The Instance to load. - * @param prefabDom the prefabDom that will be used to load the Instance data. - * @param shouldClearContainers whether to clear containers in Instance while loading. + * @param prefabDom The prefabDom that will be used to load the Instance data. + * @param shouldClearContainers Whether to clear containers in Instance while loading. * @return bool on whether the operation succeeded. */ bool LoadInstanceFromPrefabDom( @@ -72,8 +72,8 @@ namespace AzToolsFramework * Loads a valid Prefab Instance from a Prefab Dom. Useful for generating Instances. * @param instance The Instance to load. * @param referencedAssets AZ::Assets discovered during json load are added to this list - * @param prefabDom the prefabDom that will be used to load the Instance data. - * @param shouldClearContainers whether to clear containers in Instance while loading. + * @param prefabDom The prefabDom that will be used to load the Instance data. + * @param shouldClearContainers Whether to clear containers in Instance while loading. * @return bool on whether the operation succeeded. */ bool LoadInstanceFromPrefabDom( @@ -85,8 +85,8 @@ namespace AzToolsFramework * @param instance The Instance to load. * @param newlyAddedEntities The new instances added during deserializing the instance. These are the entities found * in the prefabDom. - * @param prefabDom the prefabDom that will be used to load the Instance data. - * @param shouldClearContainers whether to clear containers in Instance while loading. + * @param prefabDom The prefabDom that will be used to load the Instance data. + * @param shouldClearContainers Whether to clear containers in Instance while loading. * @return bool on whether the operation succeeded. */ bool LoadInstanceFromPrefabDom(