Updated PrefabBuilder to include product dependencies defined in AddProductDependency

This commit is contained in:
sconel
2021-04-29 14:15:48 -07:00
parent c3c90cc821
commit 845b748061
4 changed files with 55 additions and 14 deletions
@@ -49,30 +49,42 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils
return !m_prefabs.empty();
}
void PrefabProcessorContext::RegisterProductDependency(AZStd::string& prefabName, AZStd::string& dependentPrefabName)
bool PrefabProcessorContext::RegisterProductDependency(const AZStd::string& prefabName, const AZStd::string& dependentPrefabName)
{
using ConversionUtils = PrefabConversionUtils::ProcessedObjectStore;
uint32_t prefabSubId = ConversionUtils::BuildSubId(prefabName +
uint32_t spawnableSubId = ConversionUtils::BuildSubId(prefabName +
AzFramework::Spawnable::DotFileExtension);
uint32_t dependentPrefabSubId = ConversionUtils::BuildSubId(dependentPrefabName +
uint32_t spawnablePrefabSubId = ConversionUtils::BuildSubId(dependentPrefabName +
AzFramework::Spawnable::DotFileExtension);
RegisterProductDependency(prefabSubId, dependentPrefabSubId);
return RegisterProductDependency(spawnableSubId, spawnablePrefabSubId);
}
void PrefabProcessorContext::RegisterProductDependency(uint32_t spawnableAssetSubId, uint32_t dependentSpawnableAssetSubId)
bool PrefabProcessorContext::RegisterProductDependency(const AZStd::string& prefabName, const AZ::Data::AssetId& dependentAssetId)
{
using ConversionUtils = PrefabConversionUtils::ProcessedObjectStore;
uint32_t spawnableSubId = ConversionUtils::BuildSubId(prefabName +
AzFramework::Spawnable::DotFileExtension);
AZ::Data::AssetId spawnableAssetId(GetSourceUuid(), spawnableSubId);
return RegisterProductDependency(spawnableAssetId, dependentAssetId);
}
bool PrefabProcessorContext::RegisterProductDependency(uint32_t spawnableAssetSubId, uint32_t dependentSpawnableAssetSubId)
{
AZ::Data::AssetId spawnableAssetId(GetSourceUuid(), spawnableAssetSubId);
AZ::Data::AssetId dependentSpawnableAssetId(GetSourceUuid(), dependentSpawnableAssetSubId);
RegisterProductDependency(spawnableAssetId, dependentSpawnableAssetId);
return RegisterProductDependency(spawnableAssetId, dependentSpawnableAssetId);
}
void PrefabProcessorContext::RegisterProductDependency(AZ::Data::AssetId& assetId, AZ::Data::AssetId& dependentAssetId)
bool PrefabProcessorContext::RegisterProductDependency(const AZ::Data::AssetId& assetId, const AZ::Data::AssetId& dependentAssetId)
{
m_registeredProductDependencies[assetId].emplace(dependentAssetId);
return m_registeredProductDependencies[assetId].emplace(dependentAssetId).second;
}
PrefabProcessorContext::ProcessedObjectStoreContainer& PrefabProcessorContext::GetProcessedObjects()
@@ -85,6 +97,16 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils
return m_products;
}
PrefabProcessorContext::ProductDependencyContainer& PrefabProcessorContext::GetRegisteredProductDependencies()
{
return m_registeredProductDependencies;
}
const PrefabProcessorContext::ProductDependencyContainer& PrefabProcessorContext::GetRegisteredProductDependencies() const
{
return m_registeredProductDependencies;
}
void PrefabProcessorContext::SetPlatformTags(AZ::PlatformTagSet tags)
{
m_platformTags = AZStd::move(tags);
@@ -29,6 +29,8 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils
{
public:
using ProcessedObjectStoreContainer = AZStd::vector<ProcessedObjectStore>;
using ProductDependencyContainer =
AZStd::unordered_map<AZ::Data::AssetId, AZStd::unordered_set<AZ::Data::AssetId>>;
AZ_CLASS_ALLOCATOR(PrefabProcessorContext, AZ::SystemAllocator, 0);
AZ_RTTI(PrefabProcessorContext, "{C7D77E3A-C544-486B-B774-7C82C38FE22F}");
@@ -41,13 +43,17 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils
virtual void ListPrefabs(const AZStd::function<void(AZStd::string_view, const PrefabDom&)>& callback) const;
virtual bool HasPrefabs() const;
virtual void RegisterProductDependency(AZStd::string& prefabName, AZStd::string& dependentPrefabName);
virtual void RegisterProductDependency(uint32_t spawnableAssetSubId, uint32_t dependentSpawnableAssetSubId);
virtual void RegisterProductDependency(AZ::Data::AssetId& assetId, AZ::Data::AssetId& dependentAssetId);
virtual bool RegisterProductDependency(const AZStd::string& prefabName, const AZStd::string& dependentPrefabName);
virtual bool RegisterProductDependency(const AZStd::string& prefabName, const AZ::Data::AssetId& dependentAssetId);
virtual bool RegisterProductDependency(uint32_t spawnableAssetSubId, uint32_t dependentSpawnableAssetSubId);
virtual bool RegisterProductDependency(const AZ::Data::AssetId& assetId, const AZ::Data::AssetId& dependentAssetId);
virtual ProcessedObjectStoreContainer& GetProcessedObjects();
virtual const ProcessedObjectStoreContainer& GetProcessedObjects() const;
virtual ProductDependencyContainer& GetRegisteredProductDependencies();
virtual const ProductDependencyContainer& GetRegisteredProductDependencies() const;
virtual void SetPlatformTags(AZ::PlatformTagSet tags);
virtual const AZ::PlatformTagSet& GetPlatformTags() const;
virtual const AZ::Uuid& GetSourceUuid() const;
@@ -57,8 +63,6 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils
protected:
using NamedPrefabContainer = AZStd::unordered_map<AZStd::string, PrefabDom>;
using ProductDependencyContainer =
AZStd::unordered_map<AZ::Data::AssetId, AZStd::unordered_set<AZ::Data::AssetId>>;
NamedPrefabContainer m_prefabs;
ProcessedObjectStoreContainer m_products;
@@ -176,6 +176,7 @@ namespace AZ::Prefab
bool PrefabBuilderComponent::StoreProducts(
AZ::IO::PathView tempDirPath,
const AzToolsFramework::Prefab::PrefabConversionUtils::PrefabProcessorContext::ProcessedObjectStoreContainer& store,
const AzToolsFramework::Prefab::PrefabConversionUtils::PrefabProcessorContext::ProductDependencyContainer& registeredDependencies,
AZStd::vector<AssetBuilderSDK::JobProduct>& outputProducts) const
{
outputProducts.reserve(store.size());
@@ -214,6 +215,18 @@ namespace AZ::Prefab
if (AssetBuilderSDK::OutputObject(&object.GetAsset(), object.GetAssetType(), productPath.String(), object.GetAssetType(),
object.GetAsset().GetId().m_subId, product))
{
auto findRegisteredDependencies = registeredDependencies.find(object.GetAsset().GetId());
if (findRegisteredDependencies != registeredDependencies.end())
{
AZStd::transform(findRegisteredDependencies->second.begin(), findRegisteredDependencies->second.end(),
AZStd::back_inserter(product.m_dependencies),
[](const AZ::Data::AssetId& productId) -> AssetBuilderSDK::ProductDependency
{
return AssetBuilderSDK::ProductDependency(productId,
AZ::Data::ProductDependencyInfo::CreateFlags(AZ::Data::AssetLoadBehavior::NoLoad));
});
}
outputProducts.push_back(AZStd::move(product));
}
@@ -250,7 +263,8 @@ namespace AZ::Prefab
AZ_TracePrintf("Prefab Builder", "Finalizing products.\n");
if (!context.HasPrefabs())
{
if (StoreProducts(tempDirPath, context.GetProcessedObjects(), jobProducts))
if (StoreProducts(tempDirPath, context.GetProcessedObjects(),
context.GetRegisteredProductDependencies(), jobProducts))
{
return true;
}
@@ -69,6 +69,7 @@ namespace AZ::Prefab
bool StoreProducts(
AZ::IO::PathView tempDirPath,
const AzToolsFramework::Prefab::PrefabConversionUtils::PrefabProcessorContext::ProcessedObjectStoreContainer& store,
const AzToolsFramework::Prefab::PrefabConversionUtils::PrefabProcessorContext::ProductDependencyContainer& registeredDependencies,
AZStd::vector<AssetBuilderSDK::JobProduct>& outputProducts) const;
void ProcessJob(const AssetBuilderSDK::ProcessJobRequest& request, AssetBuilderSDK::ProcessJobResponse& response);