2022-02-10 07:13:27 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "RigVMModel/RigVMBuildData.h"
|
|
|
|
|
|
2022-11-16 03:33:17 -05:00
|
|
|
#include "RigVMModel/RigVMFunctionLibrary.h"
|
|
|
|
|
|
2022-09-24 13:31:25 -04:00
|
|
|
#include UE_INLINE_GENERATED_CPP_BY_NAME(RigVMBuildData)
|
|
|
|
|
|
2022-02-10 07:13:27 -05:00
|
|
|
FRigVMReferenceNodeData::FRigVMReferenceNodeData(URigVMFunctionReferenceNode* InReferenceNode)
|
|
|
|
|
{
|
|
|
|
|
check(InReferenceNode);
|
|
|
|
|
ReferenceNodePtr = TSoftObjectPtr<URigVMFunctionReferenceNode>(InReferenceNode);
|
|
|
|
|
ReferenceNodePath = ReferenceNodePtr.ToString();
|
2022-11-16 03:33:17 -05:00
|
|
|
ReferencedHeader = InReferenceNode->GetReferencedFunctionHeader();
|
2022-02-10 07:13:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSoftObjectPtr<URigVMFunctionReferenceNode> FRigVMReferenceNodeData::GetReferenceNodeObjectPath()
|
|
|
|
|
{
|
|
|
|
|
if(ReferenceNodePtr.IsNull())
|
|
|
|
|
{
|
|
|
|
|
ReferenceNodePtr = TSoftObjectPtr<URigVMFunctionReferenceNode>(ReferenceNodePath);
|
|
|
|
|
}
|
|
|
|
|
return ReferenceNodePtr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
URigVMFunctionReferenceNode* FRigVMReferenceNodeData::GetReferenceNode()
|
|
|
|
|
{
|
|
|
|
|
if(ReferenceNodePtr.IsNull())
|
|
|
|
|
{
|
|
|
|
|
ReferenceNodePtr = TSoftObjectPtr<URigVMFunctionReferenceNode>(ReferenceNodePath);
|
|
|
|
|
}
|
|
|
|
|
if(!ReferenceNodePtr.IsValid())
|
|
|
|
|
{
|
|
|
|
|
ReferenceNodePtr.LoadSynchronous();
|
|
|
|
|
}
|
|
|
|
|
if(ReferenceNodePtr.IsValid())
|
|
|
|
|
{
|
|
|
|
|
return ReferenceNodePtr.Get();
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
URigVMBuildData::URigVMBuildData()
|
|
|
|
|
: UObject()
|
2022-02-15 12:05:01 -05:00
|
|
|
, bIsRunningUnitTest(false)
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 03:33:17 -05:00
|
|
|
const FRigVMFunctionReferenceArray* URigVMBuildData::FindFunctionReferences(const FRigVMGraphFunctionIdentifier& InFunction) const
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
2022-11-16 03:33:17 -05:00
|
|
|
return GraphFunctionReferences.Find(InFunction);
|
2022-02-10 07:13:27 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-16 03:33:17 -05:00
|
|
|
void URigVMBuildData::ForEachFunctionReference(const FRigVMGraphFunctionIdentifier& InFunction,
|
|
|
|
|
TFunction<void(URigVMFunctionReferenceNode*)> PerReferenceFunction) const
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
|
|
|
|
if (const FRigVMFunctionReferenceArray* ReferencesEntry = FindFunctionReferences(InFunction))
|
|
|
|
|
{
|
|
|
|
|
for (int32 ReferenceIndex = 0; ReferenceIndex < ReferencesEntry->Num(); ReferenceIndex++)
|
|
|
|
|
{
|
|
|
|
|
const TSoftObjectPtr<URigVMFunctionReferenceNode>& Reference = ReferencesEntry->operator [](ReferenceIndex);
|
|
|
|
|
if (!Reference.IsValid())
|
|
|
|
|
{
|
|
|
|
|
Reference.LoadSynchronous();
|
|
|
|
|
}
|
|
|
|
|
if (Reference.IsValid())
|
|
|
|
|
{
|
|
|
|
|
PerReferenceFunction(Reference.Get());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 03:33:17 -05:00
|
|
|
void URigVMBuildData::ForEachFunctionReferenceSoftPtr(const FRigVMGraphFunctionIdentifier& InFunction,
|
|
|
|
|
TFunction<void(TSoftObjectPtr<URigVMFunctionReferenceNode>)> PerReferenceFunction) const
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
|
|
|
|
if (const FRigVMFunctionReferenceArray* ReferencesEntry = FindFunctionReferences(InFunction))
|
|
|
|
|
{
|
|
|
|
|
for (int32 ReferenceIndex = 0; ReferenceIndex < ReferencesEntry->Num(); ReferenceIndex++)
|
|
|
|
|
{
|
|
|
|
|
const TSoftObjectPtr<URigVMFunctionReferenceNode>& Reference = ReferencesEntry->operator [](ReferenceIndex);
|
|
|
|
|
PerReferenceFunction(Reference);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void URigVMBuildData::UpdateReferencesForFunctionReferenceNode(URigVMFunctionReferenceNode* InReferenceNode)
|
|
|
|
|
{
|
|
|
|
|
check(InReferenceNode);
|
|
|
|
|
|
|
|
|
|
if(InReferenceNode->GetOutermost() == GetTransientPackage())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-16 03:33:17 -05:00
|
|
|
|
|
|
|
|
const FRigVMGraphFunctionHeader& Header = InReferenceNode->GetReferencedFunctionHeader();
|
|
|
|
|
FRigVMFunctionReferenceArray* ReferencesEntry = GraphFunctionReferences.Find(Header.LibraryPointer);
|
|
|
|
|
if (ReferencesEntry == nullptr)
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
|
|
|
|
Modify();
|
2022-11-16 03:33:17 -05:00
|
|
|
GraphFunctionReferences.Add(Header.LibraryPointer);
|
|
|
|
|
ReferencesEntry = GraphFunctionReferences.Find(Header.LibraryPointer);
|
2022-02-10 07:13:27 -05:00
|
|
|
}
|
2022-11-16 03:33:17 -05:00
|
|
|
|
|
|
|
|
const FString ReferenceNodePathName = InReferenceNode->GetPathName();
|
|
|
|
|
for (int32 ReferenceIndex = 0; ReferenceIndex < ReferencesEntry->Num(); ReferenceIndex++)
|
|
|
|
|
{
|
|
|
|
|
const TSoftObjectPtr<URigVMFunctionReferenceNode>& Reference = ReferencesEntry->operator [](ReferenceIndex);
|
|
|
|
|
if(Reference.ToString() == ReferenceNodePathName)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Modify();
|
|
|
|
|
ReferencesEntry->FunctionReferences.Add(InReferenceNode);
|
|
|
|
|
MarkPackageDirty();
|
|
|
|
|
|
2022-02-10 07:13:27 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-16 03:33:17 -05:00
|
|
|
void URigVMBuildData::RegisterFunctionReference(const FRigVMGraphFunctionIdentifier& InFunction, URigVMFunctionReferenceNode* InReference)
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
2022-11-16 03:33:17 -05:00
|
|
|
if(InReference == nullptr)
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TSoftObjectPtr<URigVMFunctionReferenceNode> ReferenceKey(InReference);
|
|
|
|
|
|
2022-11-16 03:33:17 -05:00
|
|
|
RegisterFunctionReference(InFunction, ReferenceKey);
|
2022-02-10 07:13:27 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-16 03:33:17 -05:00
|
|
|
void URigVMBuildData::RegisterFunctionReference(const FRigVMGraphFunctionIdentifier& InFunction,
|
|
|
|
|
TSoftObjectPtr<URigVMFunctionReferenceNode> InReference)
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
2022-11-16 03:33:17 -05:00
|
|
|
if(InReference.IsNull())
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 03:33:17 -05:00
|
|
|
if(FRigVMFunctionReferenceArray* ReferenceEntry = GraphFunctionReferences.Find(InFunction))
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
|
|
|
|
if(ReferenceEntry->FunctionReferences.Contains(InReference))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Modify();
|
|
|
|
|
ReferenceEntry->FunctionReferences.Add(InReference);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Modify();
|
|
|
|
|
FRigVMFunctionReferenceArray NewReferenceEntry;
|
|
|
|
|
NewReferenceEntry.FunctionReferences.Add(InReference);
|
2022-11-16 03:33:17 -05:00
|
|
|
GraphFunctionReferences.Add(InFunction, NewReferenceEntry);
|
2022-02-10 07:13:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MarkPackageDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void URigVMBuildData::RegisterFunctionReference(FRigVMReferenceNodeData InReferenceNodeData)
|
|
|
|
|
{
|
2022-11-16 03:33:17 -05:00
|
|
|
if (InReferenceNodeData.ReferencedHeader.IsValid())
|
|
|
|
|
{
|
|
|
|
|
return RegisterFunctionReference(InReferenceNodeData.ReferencedHeader.LibraryPointer, InReferenceNodeData.GetReferenceNodeObjectPath());
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-18 04:44:06 -05:00
|
|
|
if (!InReferenceNodeData.ReferencedHeader.LibraryPointer.LibraryNode.IsValid())
|
|
|
|
|
{
|
|
|
|
|
InReferenceNodeData.ReferencedHeader.LibraryPointer.LibraryNode = InReferenceNodeData.ReferencedFunctionPath_DEPRECATED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check(InReferenceNodeData.ReferencedHeader.LibraryPointer.LibraryNode.IsValid());
|
|
|
|
|
|
|
|
|
|
FSoftObjectPath LibraryNodePath = InReferenceNodeData.ReferencedHeader.LibraryPointer.LibraryNode;
|
|
|
|
|
TSoftObjectPtr<URigVMLibraryNode> LibraryNodePtr = TSoftObjectPtr<URigVMLibraryNode>(LibraryNodePath);
|
|
|
|
|
|
|
|
|
|
// Try to find a FunctionIdentifier with the same LibraryNodePath
|
2022-11-16 03:33:17 -05:00
|
|
|
bool bFound = false;
|
|
|
|
|
for (TPair< FRigVMGraphFunctionIdentifier, FRigVMFunctionReferenceArray >& Pair : GraphFunctionReferences)
|
|
|
|
|
{
|
2022-11-18 04:44:06 -05:00
|
|
|
if (Pair.Key.LibraryNode == LibraryNodePath)
|
2022-11-16 03:33:17 -05:00
|
|
|
{
|
|
|
|
|
Pair.Value.FunctionReferences.Add(InReferenceNodeData.GetReferenceNodeObjectPath());
|
|
|
|
|
bFound = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-18 04:44:06 -05:00
|
|
|
// Otherwise, lets add a new identifier, even if it has no function host
|
2022-11-16 03:33:17 -05:00
|
|
|
if (!bFound)
|
|
|
|
|
{
|
2022-11-18 04:44:06 -05:00
|
|
|
FRigVMGraphFunctionIdentifier Pointer(nullptr, LibraryNodePath);
|
2022-11-16 03:33:17 -05:00
|
|
|
if (LibraryNodePtr.IsValid())
|
|
|
|
|
{
|
|
|
|
|
Pointer.HostObject = Cast<UObject>(LibraryNodePtr.Get()->GetFunctionHeader().GetFunctionHost());
|
|
|
|
|
}
|
|
|
|
|
FRigVMFunctionReferenceArray RefArray;
|
|
|
|
|
RefArray.FunctionReferences.Add(InReferenceNodeData.GetReferenceNodeObjectPath());
|
|
|
|
|
GraphFunctionReferences.Add(Pointer, RefArray);
|
|
|
|
|
}
|
2022-02-10 07:13:27 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-16 03:33:17 -05:00
|
|
|
void URigVMBuildData::UnregisterFunctionReference(const FRigVMGraphFunctionIdentifier& InFunction,
|
2022-02-10 07:13:27 -05:00
|
|
|
URigVMFunctionReferenceNode* InReference)
|
|
|
|
|
{
|
2022-11-16 03:33:17 -05:00
|
|
|
if(InReference == nullptr)
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TSoftObjectPtr<URigVMFunctionReferenceNode> ReferenceKey(InReference);
|
|
|
|
|
|
2022-11-16 03:33:17 -05:00
|
|
|
return UnregisterFunctionReference(InFunction, ReferenceKey);
|
2022-02-10 07:13:27 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-16 03:33:17 -05:00
|
|
|
void URigVMBuildData::UnregisterFunctionReference(const FRigVMGraphFunctionIdentifier& InFunction,
|
|
|
|
|
TSoftObjectPtr<URigVMFunctionReferenceNode> InReference)
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
2022-11-16 03:33:17 -05:00
|
|
|
if(InReference.IsNull())
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 03:33:17 -05:00
|
|
|
if(FRigVMFunctionReferenceArray* ReferenceEntry = GraphFunctionReferences.Find(InFunction))
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
|
|
|
|
if(!ReferenceEntry->FunctionReferences.Contains(InReference))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Modify();
|
|
|
|
|
ReferenceEntry->FunctionReferences.Remove(InReference);
|
|
|
|
|
MarkPackageDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void URigVMBuildData::ClearInvalidReferences()
|
|
|
|
|
{
|
2022-02-15 12:05:01 -05:00
|
|
|
if (bIsRunningUnitTest)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 07:13:27 -05:00
|
|
|
Modify();
|
|
|
|
|
|
|
|
|
|
// check each function's each reference
|
|
|
|
|
int32 NumRemoved = 0;
|
2022-11-16 03:33:17 -05:00
|
|
|
for (TTuple<FRigVMGraphFunctionIdentifier, FRigVMFunctionReferenceArray>& FunctionReferenceInfo : GraphFunctionReferences)
|
2022-02-10 07:13:27 -05:00
|
|
|
{
|
|
|
|
|
FRigVMFunctionReferenceArray* ReferencesEntry = &FunctionReferenceInfo.Value;
|
|
|
|
|
|
|
|
|
|
static FString sTransientPackagePrefix;
|
|
|
|
|
if(sTransientPackagePrefix.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
sTransientPackagePrefix = GetTransientPackage()->GetPathName();
|
|
|
|
|
}
|
|
|
|
|
static const FString sTempPrefix = TEXT("/Temp/");
|
|
|
|
|
|
|
|
|
|
NumRemoved += ReferencesEntry->FunctionReferences.RemoveAll([](TSoftObjectPtr<URigVMFunctionReferenceNode> Referencer)
|
|
|
|
|
{
|
|
|
|
|
// ignore keys / references within the transient package
|
|
|
|
|
const FString ReferencerString = Referencer.ToString();
|
|
|
|
|
return ReferencerString.StartsWith(sTransientPackagePrefix) || ReferencerString.StartsWith(sTempPrefix);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NumRemoved > 0)
|
|
|
|
|
{
|
|
|
|
|
MarkPackageDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-09-24 13:31:25 -04:00
|
|
|
|