2020-12-14 15:48:27 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
#include "MetasoundUObjectRegistry.h"
|
|
|
|
|
|
|
|
|
|
#include "Algo/Copy.h"
|
2022-05-02 18:59:38 -04:00
|
|
|
#include "AssetRegistry/AssetData.h"
|
2020-12-14 15:48:27 -04:00
|
|
|
#include "AssetRegistry/AssetRegistryModule.h"
|
2020-12-26 19:37:43 -04:00
|
|
|
#include "Async/Async.h"
|
2021-01-13 10:48:59 -04:00
|
|
|
#include "Async/TaskGraphInterfaces.h"
|
2020-12-14 15:48:27 -04:00
|
|
|
#include "CoreMinimal.h"
|
2021-06-16 11:21:13 -04:00
|
|
|
#include "Engine/AssetManager.h"
|
|
|
|
|
#include "Metasound.h"
|
|
|
|
|
#include "MetasoundAssetBase.h"
|
|
|
|
|
#include "MetasoundFrontendRegistries.h"
|
|
|
|
|
#include "MetasoundFrontendTransform.h"
|
2021-08-09 15:13:40 -04:00
|
|
|
#include "MetasoundSettings.h"
|
2021-06-16 11:21:13 -04:00
|
|
|
#include "MetasoundSource.h"
|
2021-08-11 15:22:01 -04:00
|
|
|
#include "MetasoundTrace.h"
|
2020-12-14 15:48:27 -04:00
|
|
|
#include "UObject/Object.h"
|
|
|
|
|
|
2023-03-13 17:23:05 -04:00
|
|
|
|
2021-06-16 11:21:13 -04:00
|
|
|
namespace Metasound
|
|
|
|
|
{
|
2020-12-14 15:48:27 -04:00
|
|
|
class FMetasoundUObjectRegistry : public IMetasoundUObjectRegistry
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-12-10 20:37:31 -05:00
|
|
|
FMetasoundUObjectRegistry() = default;
|
2021-11-22 15:55:50 -05:00
|
|
|
|
2023-03-07 17:01:52 -05:00
|
|
|
void RegisterUClass(TUniquePtr<IMetasoundUObjectRegistryEntry>&& InEntry) override
|
2020-12-14 15:48:27 -04:00
|
|
|
{
|
2022-03-23 15:56:20 -04:00
|
|
|
METASOUND_LLM_SCOPE;
|
2023-03-07 17:01:52 -05:00
|
|
|
Entries.Add(InEntry.Get());
|
|
|
|
|
Storage.Add(MoveTemp(InEntry));
|
2020-12-14 15:48:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IsRegisteredClass(UObject* InObject) const override
|
|
|
|
|
{
|
|
|
|
|
return (nullptr != GetEntryByUObject(InObject));
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-04 19:14:26 -04:00
|
|
|
bool IsRegisteredClass(const UClass& InClass) const override
|
|
|
|
|
{
|
|
|
|
|
auto IsChildClassOfRegisteredClass = [&](const IMetasoundUObjectRegistryEntry* Entry)
|
|
|
|
|
{
|
|
|
|
|
if (Entry)
|
|
|
|
|
{
|
|
|
|
|
return Entry->IsChildClass(&InClass);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return FindEntryByPredicate(IsChildClassOfRegisteredClass) != nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 15:48:27 -04:00
|
|
|
FMetasoundAssetBase* GetObjectAsAssetBase(UObject* InObject) const override
|
|
|
|
|
{
|
|
|
|
|
if (const IMetasoundUObjectRegistryEntry* Entry = GetEntryByUObject(InObject))
|
|
|
|
|
{
|
|
|
|
|
return Entry->Cast(InObject);
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FMetasoundAssetBase* GetObjectAsAssetBase(const UObject* InObject) const override
|
|
|
|
|
{
|
|
|
|
|
if (const IMetasoundUObjectRegistryEntry* Entry = GetEntryByUObject(InObject))
|
|
|
|
|
{
|
|
|
|
|
return Entry->Cast(InObject);
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-04 19:14:26 -04:00
|
|
|
void IterateRegisteredUClasses(TFunctionRef<void(UClass&)> InFunc, bool bAssetTypesOnly) const override
|
2021-12-10 20:37:31 -05:00
|
|
|
{
|
|
|
|
|
for (const IMetasoundUObjectRegistryEntry* Entry : Entries)
|
|
|
|
|
{
|
|
|
|
|
if (Entry)
|
|
|
|
|
{
|
2023-04-04 19:14:26 -04:00
|
|
|
if (!bAssetTypesOnly || Entry->IsAssetType())
|
2021-12-10 20:37:31 -05:00
|
|
|
{
|
2023-04-04 19:14:26 -04:00
|
|
|
if (UClass* Class = Entry->GetUClass())
|
|
|
|
|
{
|
|
|
|
|
InFunc(*Class);
|
|
|
|
|
}
|
2021-12-10 20:37:31 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 15:48:27 -04:00
|
|
|
private:
|
2023-04-04 19:14:26 -04:00
|
|
|
const IMetasoundUObjectRegistryEntry* FindEntryByPredicate(TFunctionRef<bool (const IMetasoundUObjectRegistryEntry*)> InPredicate) const
|
2020-12-14 15:48:27 -04:00
|
|
|
{
|
|
|
|
|
const IMetasoundUObjectRegistryEntry* const* Entry = Entries.FindByPredicate(InPredicate);
|
|
|
|
|
|
|
|
|
|
if (nullptr == Entry)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return *Entry;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-04 19:14:26 -04:00
|
|
|
TArray<const IMetasoundUObjectRegistryEntry*> FindEntriesByPredicate(TFunctionRef<bool (const IMetasoundUObjectRegistryEntry*)> InPredicate) const
|
2020-12-14 15:48:27 -04:00
|
|
|
{
|
|
|
|
|
TArray<const IMetasoundUObjectRegistryEntry*> FoundEntries;
|
|
|
|
|
|
|
|
|
|
Algo::CopyIf(Entries, FoundEntries, InPredicate);
|
|
|
|
|
|
|
|
|
|
return FoundEntries;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const IMetasoundUObjectRegistryEntry* GetEntryByUObject(const UObject* InObject) const
|
|
|
|
|
{
|
|
|
|
|
auto IsChildClassOfRegisteredClass = [&](const IMetasoundUObjectRegistryEntry* Entry)
|
|
|
|
|
{
|
|
|
|
|
if (nullptr == Entry)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Entry->IsChildClass(InObject);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return FindEntryByPredicate(IsChildClassOfRegisteredClass);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TArray<TUniquePtr<IMetasoundUObjectRegistryEntry>> Storage;
|
|
|
|
|
TArray<const IMetasoundUObjectRegistryEntry*> Entries;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
IMetasoundUObjectRegistry& IMetasoundUObjectRegistry::Get()
|
|
|
|
|
{
|
|
|
|
|
static FMetasoundUObjectRegistry Registry;
|
|
|
|
|
return Registry;
|
|
|
|
|
}
|
2023-03-13 17:23:05 -04:00
|
|
|
} // namespace Metasound
|