You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
[FYI] rob.gay Original CL Desc ----------------------------------------------------------------- Round 2 w/registry validity check [Backout] - CL33559423 [FYI] rob.gay Original CL Desc ----------------------------------------------------------------- [Backout] - CL33551869 [FYI] Rob.Gay Original CL Desc ----------------------------------------------------------------- - Fix for rename ensure regression from AssetManager refactor - Add logging and track case when multiple assets are registered with the AssetManager with the same key for better debugging - Add ability to force unregistration when request to finish building & utilize on destruction of MetaSound assets #rb phil.popp #jira UE-212969 #rnx [FYI] sondra.moyls [CL 33563652 by rob gay in ue5-main branch]
111 lines
3.9 KiB
C++
111 lines
3.9 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "MetasoundDocumentBuilderRegistry.h"
|
|
|
|
#include "MetasoundTrace.h"
|
|
#include "MetasoundUObjectRegistry.h"
|
|
|
|
|
|
namespace Metasound::Engine
|
|
{
|
|
FDocumentBuilderRegistry::~FDocumentBuilderRegistry()
|
|
{
|
|
for(const TPair<FMetasoundFrontendClassName, TWeakObjectPtr<UMetaSoundBuilderBase>>& Pair : Builders)
|
|
{
|
|
TWeakObjectPtr<UMetaSoundBuilderBase> Builder = Pair.Value;
|
|
if (Builder.IsValid())
|
|
{
|
|
// If the builder has applied transactions to its document object that are not mirrored in the frontend registry,
|
|
// unregister version in registry. This will ensure that future requests for the builder's associated asset will
|
|
// register a fresh version from the object as the transaction history is intrinsically lost once this builder
|
|
// is destroyed.
|
|
if (Builder->GetLastTransactionRegistered() != Builder->GetConstBuilder().GetTransactionCount())
|
|
{
|
|
UObject& MetaSound = Builder->GetConstBuilder().CastDocumentObjectChecked<UObject>();
|
|
if (FMetasoundAssetBase* MetaSoundAsset = IMetasoundUObjectRegistry::Get().GetObjectAsAssetBase(&MetaSound))
|
|
{
|
|
MetaSoundAsset->UnregisterGraphWithFrontend();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Builders.Reset();
|
|
}
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
FMetaSoundFrontendDocumentBuilder& FDocumentBuilderRegistry::FindOrBeginBuilding(TScriptInterface<IMetaSoundDocumentInterface> MetaSound)
|
|
{
|
|
UObject* Object = MetaSound.GetObject();
|
|
check(Object);
|
|
|
|
return FindOrBeginBuilding(*Object).GetBuilder();
|
|
}
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
FMetaSoundFrontendDocumentBuilder* FDocumentBuilderRegistry::FindBuilder(TScriptInterface<IMetaSoundDocumentInterface> MetaSound) const
|
|
{
|
|
if (UObject* Object = MetaSound.GetObject())
|
|
{
|
|
return FindBuilder(MetaSound->GetConstDocument().RootGraph.Metadata.GetClassName());
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
FMetaSoundFrontendDocumentBuilder* FDocumentBuilderRegistry::FindBuilder(const FMetasoundFrontendClassName& InClassName) const
|
|
{
|
|
using namespace Metasound::Engine;
|
|
if (UMetaSoundBuilderBase* Builder = Builders.FindRef(InClassName).Get())
|
|
{
|
|
return &Builder->GetBuilder();
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
UMetaSoundBuilderBase* FDocumentBuilderRegistry::FindBuilderObject(TScriptInterface<const IMetaSoundDocumentInterface> MetaSound) const
|
|
{
|
|
if (const UObject* MetaSoundObject = MetaSound.GetObject())
|
|
{
|
|
const FMetasoundFrontendDocument& Document = MetaSound->GetConstDocument();
|
|
const FMetasoundFrontendClassName& ClassName = Document.RootGraph.Metadata.GetClassName();
|
|
return Builders.FindRef(ClassName).Get();
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
UMetaSoundBuilderBase* FDocumentBuilderRegistry::FindBuilderObject(const FMetasoundFrontendClassName& ClassName) const
|
|
{
|
|
return Builders.FindRef(ClassName).Get();
|
|
}
|
|
|
|
bool FDocumentBuilderRegistry::FinishBuilding(const FMetasoundFrontendClassName& InClassName) const
|
|
{
|
|
using namespace Metasound;
|
|
using namespace Metasound::Engine;
|
|
|
|
TWeakObjectPtr<UMetaSoundBuilderBase> Builder = Builders.FindRef(InClassName);
|
|
if (Builder.IsValid())
|
|
{
|
|
// If the builder has applied transactions to its document object that are not mirrored in the frontend registry,
|
|
// unregister version in registry. This will ensure that future requests for the builder's associated asset will
|
|
// register a fresh version from the object as the transaction history is intrinsically lost once this builder
|
|
// is destroyed.
|
|
if (Builder->GetLastTransactionRegistered() != Builder->GetConstBuilder().GetTransactionCount())
|
|
{
|
|
UObject& MetaSound = Builder->GetConstBuilder().CastDocumentObjectChecked<UObject>();
|
|
if (FMetasoundAssetBase* MetaSoundAsset = IMetasoundUObjectRegistry::Get().GetObjectAsAssetBase(&MetaSound))
|
|
{
|
|
MetaSoundAsset->UnregisterGraphWithFrontend();
|
|
}
|
|
}
|
|
|
|
Builder->GetBuilder().FinishBuilding();
|
|
ensureAlways(Builders.Remove(InClassName));
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} // namespace Metasound::Engine
|