2022-03-01 04:23:55 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
# include "RigVMModel/Nodes/RigVMTemplateNode.h"
2022-05-09 07:34:28 -04:00
# include "RigVMCore/RigVMTemplate.h"
2022-03-14 10:19:31 -04:00
# include "RigVMModel/RigVMController.h"
2022-06-28 13:41:23 -04:00
# include "UObject/ObjectSaveContext.h"
2022-09-24 13:31:25 -04:00
# include UE_INLINE_GENERATED_CPP_BY_NAME(RigVMTemplateNode)
2022-06-28 13:41:23 -04:00
////////////////////////////////////////////////////////////////////////////////////////////////
void FRigVMTemplatePreferredType : : UpdateStringFromIndex ( )
{
static constexpr TCHAR Format [ ] = TEXT ( " %s,%s " ) ;
const FRigVMTemplateArgumentType Type = FRigVMRegistry : : Get ( ) . GetType ( TypeIndex ) ;
TypeString = FString : : Printf ( Format , * Type . CPPType . ToString ( ) , * Type . GetCPPTypeObjectPath ( ) . ToString ( ) ) ;
}
void FRigVMTemplatePreferredType : : UpdateIndexFromString ( )
{
// during duplicate we may not have type strings here
if ( TypeString . IsEmpty ( ) )
{
return ;
}
FString Left , Right ;
verify ( TypeString . Split ( TEXT ( " , " ) , & Left , & Right ) ) ;
UObject * CPPTypeObject = nullptr ;
static const FString NoneString = FName ( NAME_None ) . ToString ( ) ;
if ( Right ! = NoneString )
{
CPPTypeObject = URigVMPin : : FindObjectFromCPPTypeObjectPath ( Right ) ;
}
const FRigVMTemplateArgumentType Type ( * Left , CPPTypeObject ) ;
TypeIndex = FRigVMRegistry : : Get ( ) . FindOrAddType ( Type ) ;
}
////////////////////////////////////////////////////////////////////////////////////////////////
2022-03-14 10:19:31 -04:00
2022-03-01 04:23:55 -05:00
URigVMTemplateNode : : URigVMTemplateNode ( )
: Super ( )
, TemplateNotation ( NAME_None )
, ResolvedFunctionName ( )
, CachedTemplate ( nullptr )
, CachedFunction ( nullptr )
2022-07-18 04:44:55 -04:00
, ResolvedPermutation ( INDEX_NONE )
2022-03-01 04:23:55 -05:00
{
}
2022-06-28 13:41:23 -04:00
void URigVMTemplateNode : : PreSave ( FObjectPreSaveContext SaveContext )
{
Super : : PreSave ( SaveContext ) ;
ConvertPreferredTypesToString ( ) ;
}
2022-04-20 10:28:28 -04:00
void URigVMTemplateNode : : PostLoad ( )
{
Super : : PostLoad ( ) ;
2022-09-01 23:33:24 -04:00
for ( URigVMPin * Pin : GetPins ( ) )
{
// GetTypeIndex ensures that the pin type is registered
// Only need to register for visible pins
if ( Pin - > GetDirection ( ) = = ERigVMPinDirection : : IO | |
Pin - > GetDirection ( ) = = ERigVMPinDirection : : Input | |
Pin - > GetDirection ( ) = = ERigVMPinDirection : : Output )
{
Pin - > GetTypeIndex ( ) ;
}
}
2022-04-20 10:28:28 -04:00
// if there are brackets in the notation remove them
const FString OriginalNotation = TemplateNotation . ToString ( ) ;
const FString SanitizedNotation = OriginalNotation . Replace ( TEXT ( " [] " ) , TEXT ( " " ) ) ;
if ( OriginalNotation ! = SanitizedNotation )
{
TemplateNotation = * SanitizedNotation ;
}
2022-06-28 13:41:23 -04:00
// upgrade from a previous version where we stored the preferred types as strings
if ( ! PreferredPermutationTypes_DEPRECATED . IsEmpty ( ) )
{
const FRigVMRegistry & Registry = FRigVMRegistry : : Get ( ) ;
PreferredPermutationPairs . Reserve ( PreferredPermutationTypes_DEPRECATED . Num ( ) ) ;
for ( const FString & PreferredPermutation : PreferredPermutationTypes_DEPRECATED )
{
FString ArgName , CPPType ;
PreferredPermutation . Split ( TEXT ( " : " ) , & ArgName , & CPPType ) ;
const FRigVMTemplateArgumentType Type = Registry . FindTypeFromCPPType ( CPPType ) ;
PreferredPermutationPairs . Emplace ( * ArgName , Registry . GetTypeIndex ( Type ) ) ;
}
PreferredPermutationTypes_DEPRECATED . Reset ( ) ;
}
ConvertPreferredTypesToTypeIndex ( ) ;
2022-04-20 10:28:28 -04:00
InvalidateCache ( ) ;
}
2022-06-28 13:41:23 -04:00
void URigVMTemplateNode : : ConvertPreferredTypesToString ( )
{
// we rely on the strings being serialized
for ( FRigVMTemplatePreferredType & PreferredType : PreferredPermutationPairs )
{
PreferredType . UpdateStringFromIndex ( ) ;
}
}
void URigVMTemplateNode : : ConvertPreferredTypesToTypeIndex ( )
{
2022-07-05 11:39:15 -04:00
const FRigVMTemplate * Template = GetTemplate ( ) ;
2022-06-28 13:41:23 -04:00
// we rely on the strings being serialized - so on load we need to update the type index again
for ( FRigVMTemplatePreferredType & PreferredType : PreferredPermutationPairs )
{
PreferredType . UpdateIndexFromString ( ) ;
2022-07-05 11:39:15 -04:00
if ( Template )
{
if ( const FRigVMTemplateArgument * Argument = Template - > FindArgument ( PreferredType . GetArgument ( ) ) )
{
TRigVMTypeIndex ResolvedTypeIndex = INDEX_NONE ;
if ( Argument - > SupportsTypeIndex ( PreferredType . GetTypeIndex ( ) , & ResolvedTypeIndex ) )
{
if ( ResolvedTypeIndex ! = PreferredType . GetTypeIndex ( ) )
{
PreferredType . TypeIndex = ResolvedTypeIndex ;
PreferredType . UpdateStringFromIndex ( ) ;
}
}
}
}
2022-06-28 13:41:23 -04:00
}
}
2022-07-14 06:53:37 -04:00
TRigVMTypeIndex URigVMTemplateNode : : GetPreferredType ( const FName & ArgumentName ) const
{
for ( const FRigVMTemplatePreferredType & PreferredType : PreferredPermutationPairs )
{
if ( PreferredType . Argument = = ArgumentName )
{
2022-07-18 04:44:55 -04:00
return PreferredType . GetTypeIndex ( ) ;
2022-07-14 06:53:37 -04:00
}
}
return INDEX_NONE ;
}
2022-03-01 04:23:55 -05:00
UScriptStruct * URigVMTemplateNode : : GetScriptStruct ( ) const
{
if ( const FRigVMFunction * Function = GetResolvedFunction ( ) )
{
return Function - > Struct ;
}
return nullptr ;
}
FString URigVMTemplateNode : : GetNodeTitle ( ) const
{
if ( ! IsResolved ( ) )
{
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
{
return Template - > GetName ( ) . ToString ( ) ;
}
}
FString ResolvedNodeTitle = Super : : GetNodeTitle ( ) ;
const int32 BracePos = ResolvedNodeTitle . Find ( TEXT ( " ( " ) ) ;
if ( BracePos ! = INDEX_NONE )
{
ResolvedNodeTitle = ResolvedNodeTitle . Left ( BracePos ) ;
}
return ResolvedNodeTitle ;
}
FName URigVMTemplateNode : : GetMethodName ( ) const
{
if ( const FRigVMFunction * Function = GetResolvedFunction ( ) )
{
return Function - > GetMethodName ( ) ;
}
return NAME_None ;
}
FText URigVMTemplateNode : : GetToolTipText ( ) const
{
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
{
2022-05-09 07:34:28 -04:00
const TArray < int32 > PermutationIndices = GetFilteredPermutationsIndices ( ) ;
2022-03-01 04:23:55 -05:00
return Template - > GetTooltipText ( PermutationIndices ) ;
}
return Super : : GetToolTipText ( ) ;
}
FText URigVMTemplateNode : : GetToolTipTextForPin ( const URigVMPin * InPin ) const
{
const FText SuperToolTip = Super : : GetToolTipTextForPin ( InPin ) ;
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
{
const URigVMPin * RootPin = InPin - > GetRootPin ( ) ;
if ( RootPin - > IsWildCard ( ) )
{
if ( const FRigVMTemplateArgument * Arg = Template - > FindArgument ( RootPin - > GetFName ( ) ) )
{
2022-04-20 05:02:39 -04:00
FString Tooltip ;
2022-07-14 06:53:37 -04:00
if ( FilteredPermutations . Num ( ) = = GetTemplate ( ) - > NumPermutations ( ) )
2022-04-20 05:02:39 -04:00
{
2022-06-28 13:41:23 -04:00
if ( Arg - > GetTypeIndices ( ) . Num ( ) > 100 )
2022-04-20 05:02:39 -04:00
{
Tooltip = TEXT ( " Supports any type. " ) ;
}
}
if ( Tooltip . IsEmpty ( ) )
{
2022-05-09 07:34:28 -04:00
FString SupportedTypesJoined ;
2022-07-14 06:53:37 -04:00
TArray < TRigVMTypeIndex > TypesPrinted ;
for ( int32 Index = 0 ; Index < Template - > NumPermutations ( ) ; + + Index )
2022-05-09 07:34:28 -04:00
{
2022-07-05 11:39:15 -04:00
const TRigVMTypeIndex TypeIndex = Arg - > GetTypeIndices ( ) [ Index ] ;
2022-07-14 06:53:37 -04:00
if ( TypesPrinted . Contains ( TypeIndex ) )
{
continue ;
}
TypesPrinted . Add ( TypeIndex ) ;
2022-06-28 13:41:23 -04:00
FString Type = FRigVMRegistry : : Get ( ) . GetType ( TypeIndex ) . CPPType . ToString ( ) ;
2022-05-09 07:34:28 -04:00
if ( ! FilteredPermutations . Contains ( Index ) )
{
Type + = TEXT ( " : Breaks Connections " ) ;
}
SupportedTypesJoined + = Type + TEXT ( " \n " ) ;
}
2022-04-20 05:02:39 -04:00
Tooltip = TEXT ( " Supported Types: \n \n " ) + SupportedTypesJoined ;
}
2022-03-01 04:23:55 -05:00
if ( ! SuperToolTip . IsEmpty ( ) )
{
Tooltip + = TEXT ( " \n \n " ) + SuperToolTip . ToString ( ) ;
}
return FText : : FromString ( Tooltip ) ;
}
}
}
return SuperToolTip ;
}
2022-07-14 06:53:37 -04:00
TArray < URigVMPin * > URigVMTemplateNode : : GetAggregateInputs ( ) const
{
return GetAggregatePins ( ERigVMPinDirection : : Input ) ;
}
TArray < URigVMPin * > URigVMTemplateNode : : GetAggregateOutputs ( ) const
{
return GetAggregatePins ( ERigVMPinDirection : : Output ) ;
}
TArray < URigVMPin * > URigVMTemplateNode : : GetAggregatePins ( const ERigVMPinDirection & InDirection ) const
{
TArray < URigVMPin * > AggregatePins ;
# if UE_RIGVM_AGGREGATE_NODES_ENABLED
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
{
2022-07-18 04:44:55 -04:00
TArray < int32 > Permutations = FilteredPermutations ;
if ( Permutations . IsEmpty ( ) )
{
Permutations . Reserve ( Template - > NumPermutations ( ) ) ;
for ( int32 i = 0 ; i < Template - > NumPermutations ( ) ; + + i )
{
Permutations . Add ( i ) ;
}
}
if ( Permutations . IsEmpty ( ) )
2022-07-14 06:53:37 -04:00
{
return AggregatePins ;
}
auto FindAggregatePins = [ & ] ( const int32 & PermutationIndex )
{
TArray < URigVMPin * > Inputs ;
if ( const FRigVMFunction * Permutation = Template - > GetPermutation ( PermutationIndex ) )
{
const TSharedPtr < FStructOnScope > StructOnScope = MakeShareable ( new FStructOnScope ( Permutation - > Struct ) ) ;
if ( const UScriptStruct * ScriptStruct = Cast < UScriptStruct > ( StructOnScope - > GetStruct ( ) ) )
{
for ( URigVMPin * Pin : GetPins ( ) )
{
if ( Pin - > GetDirection ( ) = = InDirection )
{
if ( const FProperty * Property = ScriptStruct - > FindPropertyByName ( Pin - > GetFName ( ) ) )
{
if ( Property - > HasMetaData ( FRigVMStruct : : AggregateMetaName ) )
{
Inputs . Add ( Pin ) ;
}
}
}
}
}
}
return Inputs ;
} ;
2022-07-18 04:44:55 -04:00
AggregatePins = FindAggregatePins ( Permutations [ 0 ] ) ;
for ( int32 i = 1 ; i < Permutations . Num ( ) ; + + i )
2022-07-14 06:53:37 -04:00
{
2022-07-18 04:44:55 -04:00
TArray < URigVMPin * > OtherAggregateInputs = FindAggregatePins ( Permutations [ i ] ) ;
2022-07-14 06:53:37 -04:00
if ( OtherAggregateInputs . Num ( ) ! = AggregatePins . Num ( ) | |
OtherAggregateInputs . FilterByPredicate ( [ & ] ( const URigVMPin * OtherPin )
{
return ! AggregatePins . Contains ( OtherPin ) ;
} ) . Num ( ) > 0 )
{
return { } ;
}
}
}
# endif
return AggregatePins ;
}
FName URigVMTemplateNode : : GetNextAggregateName ( const FName & InLastAggregatePinName ) const
{
FName NextName ;
# if UE_RIGVM_AGGREGATE_NODES_ENABLED
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
{
if ( FilteredPermutations . IsEmpty ( ) )
{
return NextName ;
}
if ( const FRigVMFunction * Permutation = Template - > GetPermutation ( FilteredPermutations [ 0 ] ) )
{
const TSharedPtr < FStructOnScope > StructOnScope = MakeShareable ( new FStructOnScope ( Permutation - > Struct ) ) ;
if ( const UScriptStruct * ScriptStruct = Cast < UScriptStruct > ( StructOnScope - > GetStruct ( ) ) )
{
check ( ScriptStruct - > IsChildOf ( FRigVMStruct : : StaticStruct ( ) ) ) ;
const FRigVMStruct * StructMemory = ( const FRigVMStruct * ) StructOnScope - > GetStructMemory ( ) ;
return StructMemory - > GetNextAggregateName ( InLastAggregatePinName ) ;
}
}
}
# endif
return FName ( ) ;
}
2022-03-01 04:23:55 -05:00
FName URigVMTemplateNode : : GetNotation ( ) const
{
return TemplateNotation ;
}
2022-05-09 07:34:28 -04:00
bool URigVMTemplateNode : : IsSingleton ( ) const
{
return GetTemplate ( ) = = nullptr ;
}
2022-07-05 11:39:15 -04:00
bool URigVMTemplateNode : : SupportsType ( const URigVMPin * InPin , TRigVMTypeIndex InTypeIndex , TRigVMTypeIndex * OutTypeIndex )
2022-03-01 04:23:55 -05:00
{
2022-06-28 13:41:23 -04:00
const FRigVMRegistry & Registry = FRigVMRegistry : : Get ( ) ;
2022-03-01 04:23:55 -05:00
static const FString WildCardCPPType = RigVMTypeUtils : : GetWildCardCPPType ( ) ;
static const FString WildCardArrayCPPType = RigVMTypeUtils : : ArrayTypeFromBaseType ( WildCardCPPType ) ;
2022-03-14 10:19:31 -04:00
const URigVMPin * RootPin = InPin - > GetRootPin ( ) ;
2022-07-05 11:39:15 -04:00
TRigVMTypeIndex TypeIndex = InTypeIndex ;
2022-04-20 10:28:28 -04:00
if ( InPin - > GetParentPin ( ) = = RootPin & & RootPin - > IsArray ( ) )
{
2022-06-28 13:41:23 -04:00
TypeIndex = Registry . GetArrayTypeFromBaseTypeIndex ( TypeIndex ) ;
2022-04-20 10:28:28 -04:00
}
2022-03-01 04:23:55 -05:00
// we always support the unknown type
2022-06-28 13:41:23 -04:00
if ( Registry . IsWildCardType ( TypeIndex ) )
2022-03-01 04:23:55 -05:00
{
2022-03-14 10:19:31 -04:00
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
2022-03-01 04:23:55 -05:00
{
2022-03-14 10:19:31 -04:00
if ( const FRigVMTemplateArgument * Argument = Template - > FindArgument ( RootPin - > GetFName ( ) ) )
{
// support this only on non-singleton arguments
if ( Argument - > IsSingleton ( ) )
{
return false ;
}
2022-04-20 10:28:28 -04:00
2022-06-28 13:41:23 -04:00
if ( Registry . IsArrayType ( TypeIndex ) )
2022-04-20 10:28:28 -04:00
{
if ( Argument - > GetArrayType ( ) = = FRigVMTemplateArgument : : EArrayType_SingleValue )
{
return false ;
}
}
else
{
if ( Argument - > GetArrayType ( ) = = FRigVMTemplateArgument : : EArrayType_ArrayValue )
{
return false ;
}
}
2022-03-14 10:19:31 -04:00
2022-06-28 13:41:23 -04:00
if ( OutTypeIndex )
2022-03-14 10:19:31 -04:00
{
2022-06-28 13:41:23 -04:00
* OutTypeIndex = InTypeIndex ;
2022-03-14 10:19:31 -04:00
}
return true ;
}
2022-07-14 06:53:37 -04:00
else if ( IsA < URigVMFunctionEntryNode > ( ) | | IsA < URigVMFunctionReturnNode > ( ) )
{
if ( OutTypeIndex )
{
* OutTypeIndex = InTypeIndex ;
}
return true ;
}
2022-03-01 04:23:55 -05:00
}
2022-03-14 10:19:31 -04:00
return false ;
2022-03-01 04:23:55 -05:00
}
2022-03-14 10:19:31 -04:00
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
2022-03-01 04:23:55 -05:00
{
2022-07-05 11:39:15 -04:00
const TPair < FName , TRigVMTypeIndex > CacheKey ( RootPin - > GetFName ( ) , TypeIndex ) ;
TRigVMTypeIndex SupportedTypeIndex = INDEX_NONE ;
2022-06-28 13:41:23 -04:00
if ( Template - > ArgumentSupportsTypeIndex ( RootPin - > GetFName ( ) , TypeIndex , & SupportedTypeIndex ) )
2022-03-01 04:23:55 -05:00
{
2022-06-28 13:41:23 -04:00
if ( OutTypeIndex )
2022-03-01 04:23:55 -05:00
{
2022-06-28 13:41:23 -04:00
( * OutTypeIndex ) = SupportedTypeIndex ;
2022-03-01 04:23:55 -05:00
}
2022-05-18 06:43:26 -04:00
return true ;
2022-03-01 04:23:55 -05:00
}
2022-07-14 06:53:37 -04:00
// an entry/return node that does not contain an argument for the pin will always support the connections
if ( IsA < URigVMFunctionEntryNode > ( ) | | IsA < URigVMFunctionReturnNode > ( ) )
{
if ( Template - > FindArgument ( RootPin - > GetFName ( ) ) = = nullptr )
{
return true ;
}
}
2022-05-18 06:43:26 -04:00
return false ;
2022-03-14 10:19:31 -04:00
}
2022-06-28 13:41:23 -04:00
if ( RootPin - > GetTypeIndex ( ) = = TypeIndex )
2022-03-01 04:23:55 -05:00
{
2022-06-28 13:41:23 -04:00
if ( OutTypeIndex )
2022-03-01 04:23:55 -05:00
{
2022-06-28 13:41:23 -04:00
* OutTypeIndex = TypeIndex ;
2022-03-01 04:23:55 -05:00
}
return true ;
}
return false ;
}
2022-07-05 11:39:15 -04:00
bool URigVMTemplateNode : : FilteredSupportsType ( const URigVMPin * InPin , TRigVMTypeIndex InTypeIndex , TRigVMTypeIndex * OutTypeIndex , bool bAllowFloatingPointCasts )
2022-03-14 10:19:31 -04:00
{
2022-06-28 13:41:23 -04:00
if ( OutTypeIndex )
2022-03-14 10:19:31 -04:00
{
2022-06-28 13:41:23 -04:00
* OutTypeIndex = INDEX_NONE ;
2022-05-09 07:34:28 -04:00
}
const URigVMPin * RootPin = InPin ;
bool bIsArrayElement = false ;
2022-05-09 14:13:48 -04:00
bool bIsStructElement = false ;
2022-05-09 07:34:28 -04:00
if ( URigVMPin * ParentPin = InPin - > GetParentPin ( ) )
{
RootPin = ParentPin ;
2022-05-09 14:13:48 -04:00
if ( ParentPin - > IsArray ( ) )
{
bIsArrayElement = true ;
}
else if ( ParentPin - > IsStruct ( ) )
{
bIsStructElement = true ;
}
2022-05-09 07:34:28 -04:00
}
2022-05-09 14:13:48 -04:00
if ( bIsStructElement )
{
2022-06-28 13:41:23 -04:00
const bool bResult = InPin - > GetTypeIndex ( ) = = InTypeIndex ;
if ( bResult )
{
if ( OutTypeIndex )
{
* OutTypeIndex = InTypeIndex ;
}
}
return bResult ;
2022-05-09 14:13:48 -04:00
}
2022-05-09 07:34:28 -04:00
const FRigVMTemplateArgument * Argument = GetTemplate ( ) - > FindArgument ( RootPin - > GetFName ( ) ) ;
if ( Argument = = nullptr )
{
return false ;
}
2022-06-28 13:41:23 -04:00
const FRigVMRegistry & Registry = FRigVMRegistry : : Get ( ) ;
2022-07-05 11:39:15 -04:00
TRigVMTypeIndex RootTypeIndex = InTypeIndex ;
2022-05-18 06:43:26 -04:00
if ( bIsArrayElement )
{
2022-06-28 13:41:23 -04:00
RootTypeIndex = Registry . GetArrayTypeFromBaseTypeIndex ( RootTypeIndex ) ;
2022-05-18 06:43:26 -04:00
}
if ( FilteredPermutations . Num ( ) = = GetTemplate ( ) - > NumPermutations ( ) )
{
2022-06-28 13:41:23 -04:00
return GetTemplate ( ) - > ArgumentSupportsTypeIndex ( RootPin - > GetFName ( ) , InTypeIndex , OutTypeIndex ) ;
2022-05-18 06:43:26 -04:00
}
2022-07-05 11:39:15 -04:00
const TArray < TRigVMTypeIndex > & TypeIndices = Argument - > GetTypeIndices ( ) ;
2022-06-28 13:41:23 -04:00
for ( const int32 & PermutationIndex : FilteredPermutations )
2022-05-09 07:34:28 -04:00
{
2022-07-05 11:39:15 -04:00
const TRigVMTypeIndex & FilteredTypeIndex = TypeIndices [ PermutationIndex ] ;
2022-06-28 13:41:23 -04:00
if ( Registry . CanMatchTypes ( FilteredTypeIndex , RootTypeIndex , bAllowFloatingPointCasts ) )
2022-05-09 07:34:28 -04:00
{
return true ;
}
2022-03-14 10:19:31 -04:00
}
return false ;
}
2022-05-09 07:34:28 -04:00
TArray < const FRigVMFunction * > URigVMTemplateNode : : GetResolvedPermutations ( ) const
2022-03-01 04:23:55 -05:00
{
2022-05-09 07:34:28 -04:00
TArray < int32 > Indices = GetFilteredPermutationsIndices ( ) ;
2022-03-01 04:23:55 -05:00
TArray < const FRigVMFunction * > Functions ;
for ( const int32 Index : Indices )
{
Functions . Add ( GetTemplate ( ) - > GetPermutation ( Index ) ) ;
}
return Functions ;
}
const FRigVMTemplate * URigVMTemplateNode : : GetTemplate ( ) const
{
if ( CachedTemplate = = nullptr )
{
2022-04-20 10:28:28 -04:00
CachedTemplate = FRigVMRegistry : : Get ( ) . FindTemplate ( GetNotation ( ) ) ;
2022-03-01 04:23:55 -05:00
}
return CachedTemplate ;
}
const FRigVMFunction * URigVMTemplateNode : : GetResolvedFunction ( ) const
{
if ( CachedFunction = = nullptr )
{
if ( ! ResolvedFunctionName . IsEmpty ( ) )
{
CachedFunction = FRigVMRegistry : : Get ( ) . FindFunction ( * ResolvedFunctionName ) ;
}
if ( CachedFunction = = nullptr )
{
2022-07-18 04:44:55 -04:00
if ( ResolvedPermutation ! = INDEX_NONE )
2022-03-01 04:23:55 -05:00
{
2022-07-18 04:44:55 -04:00
CachedFunction = GetTemplate ( ) - > GetPermutation ( ResolvedPermutation ) ;
2022-03-01 04:23:55 -05:00
}
}
}
return CachedFunction ;
}
bool URigVMTemplateNode : : IsResolved ( ) const
{
return GetScriptStruct ( ) ! = nullptr ;
}
2022-03-14 10:19:31 -04:00
bool URigVMTemplateNode : : IsFullyUnresolved ( ) const
{
check ( GetTemplate ( ) ) ;
// all permutations are available means we haven't resolved any wildcard pin
2022-05-09 07:34:28 -04:00
return GetFilteredPermutationsIndices ( ) . Num ( ) = = GetTemplate ( ) - > NumPermutations ( ) ;
2022-03-14 10:19:31 -04:00
}
FString URigVMTemplateNode : : GetInitialDefaultValueForPin ( const FName & InRootPinName , const TArray < int32 > & InPermutationIndices ) const
{
if ( GetTemplate ( ) = = nullptr )
{
return FString ( ) ;
}
2022-07-14 06:53:37 -04:00
URigVMPin * Pin = FindPin ( InRootPinName . ToString ( ) ) ;
if ( ! Pin )
{
return FString ( ) ;
}
2022-03-14 10:19:31 -04:00
TArray < int32 > PermutationIndices = InPermutationIndices ;
if ( PermutationIndices . IsEmpty ( ) )
{
2022-05-09 07:34:28 -04:00
PermutationIndices = GetFilteredPermutationsIndices ( ) ;
2022-03-14 10:19:31 -04:00
}
FString DefaultValue ;
2022-07-05 11:39:15 -04:00
const FRigVMTemplate * Template = GetTemplate ( ) ;
const FRigVMDispatchFactory * Factory = Template - > GetDispatchFactory ( ) ;
2022-07-14 06:53:37 -04:00
const FRigVMTemplateArgument * Argument = Template - > FindArgument ( InRootPinName ) ;
2022-03-14 10:19:31 -04:00
2022-07-14 06:53:37 -04:00
if ( Argument )
2022-03-14 10:19:31 -04:00
{
2022-07-14 06:53:37 -04:00
for ( const int32 PermutationIndex : PermutationIndices )
2022-07-05 11:39:15 -04:00
{
2022-07-14 06:53:37 -04:00
FString NewDefaultValue ;
2022-03-14 10:19:31 -04:00
2022-07-14 06:53:37 -04:00
const TRigVMTypeIndex TypeIndex = Argument - > GetTypeIndices ( ) [ PermutationIndex ] ;
2022-09-01 23:33:24 -04:00
// INDEX_NONE indicates deleted permutation
if ( TypeIndex = = INDEX_NONE )
{
continue ;
}
2022-07-14 06:53:37 -04:00
if ( Factory )
2022-04-21 09:10:19 -04:00
{
2022-07-14 06:53:37 -04:00
NewDefaultValue = Factory - > GetArgumentDefaultValue ( Argument - > GetName ( ) , TypeIndex ) ;
}
else if ( const FRigVMFunction * Permutation = Template - > GetPermutation ( PermutationIndex ) )
{
const TSharedPtr < FStructOnScope > StructOnScope = MakeShareable ( new FStructOnScope ( Permutation - > Struct ) ) ;
const FRigVMStruct * DefaultStruct = ( const FRigVMStruct * ) StructOnScope - > GetStructMemory ( ) ;
const bool bUseQuotes = TypeIndex ! = RigVMTypeUtils : : TypeIndex : : FString & & TypeIndex ! = RigVMTypeUtils : : TypeIndex : : FName ;
NewDefaultValue = DefaultStruct - > ExportToFullyQualifiedText (
Cast < UScriptStruct > ( StructOnScope - > GetStruct ( ) ) , InRootPinName , nullptr , bUseQuotes ) ;
2022-04-21 09:10:19 -04:00
}
else
{
2022-07-14 06:53:37 -04:00
if ( FRigVMRegistry : : Get ( ) . IsArrayType ( TypeIndex ) )
2022-04-21 09:10:19 -04:00
{
2022-07-14 06:53:37 -04:00
NewDefaultValue = TEXT ( " () " ) ;
}
else
{
const FRigVMTemplateArgumentType & Type = FRigVMRegistry : : Get ( ) . GetType ( TypeIndex ) ;
if ( UScriptStruct * ScriptStruct = Cast < UScriptStruct > ( Type . CPPTypeObject ) )
{
TArray < uint8 , TAlignedHeapAllocator < 16 > > TempBuffer ;
TempBuffer . AddUninitialized ( ScriptStruct - > GetStructureSize ( ) ) ;
2022-04-21 09:10:19 -04:00
2022-07-14 06:53:37 -04:00
// call the struct constructor to initialize the struct
ScriptStruct - > InitializeDefaultValue ( TempBuffer . GetData ( ) ) ;
2022-04-21 09:10:19 -04:00
2022-07-14 06:53:37 -04:00
ScriptStruct - > ExportText ( NewDefaultValue , TempBuffer . GetData ( ) , nullptr , nullptr , PPF_None , nullptr ) ;
ScriptStruct - > DestroyStruct ( TempBuffer . GetData ( ) ) ;
}
else if ( const UEnum * Enum = Cast < UEnum > ( Type . CPPTypeObject ) )
{
NewDefaultValue = Enum - > GetNameStringByValue ( 0 ) ;
}
else if ( const UClass * Class = Cast < UClass > ( Type . CPPTypeObject ) )
{
// not supporting objects yet
ensure ( false ) ;
}
else if ( Type . CPPType = = RigVMTypeUtils : : FloatTypeName )
{
NewDefaultValue = TEXT ( " 0.000000 " ) ;
}
else if ( Type . CPPType = = RigVMTypeUtils : : DoubleTypeName )
{
NewDefaultValue = TEXT ( " 0.000000 " ) ;
}
else if ( Type . CPPType = = RigVMTypeUtils : : Int32TypeName )
{
NewDefaultValue = TEXT ( " 0 " ) ;
}
else if ( Type . CPPType = = RigVMTypeUtils : : BoolTypeName )
{
NewDefaultValue = TEXT ( " False " ) ;
}
else if ( Type . CPPType = = RigVMTypeUtils : : FStringTypeName )
{
NewDefaultValue = TEXT ( " " ) ;
}
else if ( Type . CPPType = = RigVMTypeUtils : : FNameTypeName )
{
NewDefaultValue = TEXT ( " " ) ;
}
}
2022-03-14 10:19:31 -04:00
}
2022-07-14 06:53:37 -04:00
if ( ! NewDefaultValue . IsEmpty ( ) )
2022-03-14 10:19:31 -04:00
{
2022-07-14 06:53:37 -04:00
if ( DefaultValue . IsEmpty ( ) )
{
DefaultValue = NewDefaultValue ;
}
else if ( ! NewDefaultValue . Equals ( DefaultValue ) )
{
return FString ( ) ;
}
2022-03-14 10:19:31 -04:00
}
}
}
return DefaultValue ;
}
2022-03-17 07:20:36 -04:00
FName URigVMTemplateNode : : GetDisplayNameForPin ( const FName & InRootPinName ,
const TArray < int32 > & InPermutationIndices ) const
{
# if WITH_EDITOR
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
{
const TArray < int32 > * PermutationIndicesPtr = & InPermutationIndices ;
if ( PermutationIndicesPtr - > IsEmpty ( ) )
{
2022-05-09 07:34:28 -04:00
PermutationIndicesPtr = & GetFilteredPermutationsIndices ( ) ;
2022-03-17 07:20:36 -04:00
}
const FText DisplayNameText = Template - > GetDisplayNameForArgument ( InRootPinName , * PermutationIndicesPtr ) ;
if ( DisplayNameText . IsEmpty ( ) )
{
return InRootPinName ;
}
const FName DisplayName = * DisplayNameText . ToString ( ) ;
if ( DisplayName . IsEqual ( InRootPinName ) )
{
return NAME_None ;
}
return DisplayName ;
}
# endif
return NAME_None ;
}
2022-05-09 07:34:28 -04:00
const TArray < int32 > & URigVMTemplateNode : : GetFilteredPermutationsIndices ( ) const
{
return FilteredPermutations ;
}
2022-07-05 11:39:15 -04:00
TArray < TRigVMTypeIndex > URigVMTemplateNode : : GetFilteredTypesForPin ( URigVMPin * InPin ) const
2022-05-09 07:34:28 -04:00
{
ensureMsgf ( InPin - > GetNode ( ) = = this , TEXT ( " GetFilteredTypesForPin of %s with pin from another node %s " ) , * GetNodePath ( ) , * InPin - > GetPinPath ( true ) ) ;
2022-07-05 11:39:15 -04:00
TArray < TRigVMTypeIndex > FilteredTypes ;
2022-05-09 07:34:28 -04:00
2022-08-26 11:02:53 -04:00
if ( IsSingleton ( ) )
{
return { InPin - > GetTypeIndex ( ) } ;
}
2022-05-09 07:34:28 -04:00
if ( FilteredPermutations . IsEmpty ( ) )
{
return FilteredTypes ;
}
2022-05-18 06:43:26 -04:00
2022-07-14 06:53:37 -04:00
if ( InPin - > IsStructMember ( ) )
{
return { InPin - > GetTypeIndex ( ) } ;
}
2022-06-28 13:41:23 -04:00
if ( ! PreferredPermutationPairs . IsEmpty ( ) )
2022-05-18 06:43:26 -04:00
{
2022-06-28 13:41:23 -04:00
for ( const FRigVMTemplatePreferredType & PreferredType : PreferredPermutationPairs )
2022-05-18 06:43:26 -04:00
{
2022-07-05 11:39:15 -04:00
if ( InPin - > GetFName ( ) = = PreferredType . GetArgument ( ) )
2022-05-18 06:43:26 -04:00
{
2022-07-05 11:39:15 -04:00
const FRigVMTemplateArgument * Argument = GetTemplate ( ) - > FindArgument ( PreferredType . GetArgument ( ) ) ;
for ( const TRigVMTypeIndex & TypeIndex : Argument - > GetTypeIndices ( ) )
2022-05-18 06:43:26 -04:00
{
2022-07-05 11:39:15 -04:00
if ( TypeIndex = = PreferredType . GetTypeIndex ( ) )
2022-05-18 06:43:26 -04:00
{
2022-07-14 06:53:37 -04:00
if ( InPin - > IsArrayElement ( ) )
{
return { FRigVMRegistry : : Get ( ) . GetArrayTypeFromBaseTypeIndex ( TypeIndex ) } ;
}
else
{
return { TypeIndex } ;
}
2022-05-18 06:43:26 -04:00
}
2022-07-14 06:53:37 -04:00
}
2022-05-18 06:43:26 -04:00
}
}
}
2022-05-09 07:34:28 -04:00
2022-06-28 13:41:23 -04:00
const URigVMPin * RootPin = InPin ;
2022-05-09 07:34:28 -04:00
bool bIsArrayElement = false ;
if ( URigVMPin * ParentPin = InPin - > GetParentPin ( ) )
{
RootPin = ParentPin ;
bIsArrayElement = true ;
}
if ( const FRigVMTemplateArgument * Argument = GetTemplate ( ) - > FindArgument ( RootPin - > GetFName ( ) ) )
{
2022-06-28 13:41:23 -04:00
FilteredTypes = Argument - > GetSupportedTypeIndices ( FilteredPermutations ) ;
2022-05-09 07:34:28 -04:00
if ( bIsArrayElement )
{
2022-07-05 11:39:15 -04:00
for ( TRigVMTypeIndex & ArrayType : FilteredTypes )
2022-05-09 07:34:28 -04:00
{
2022-06-28 13:41:23 -04:00
ArrayType = FRigVMRegistry : : Get ( ) . GetBaseTypeFromArrayTypeIndex ( ArrayType ) ;
2022-05-09 07:34:28 -04:00
}
}
}
return FilteredTypes ;
}
2022-09-06 11:24:29 -04:00
TRigVMTypeIndex URigVMTemplateNode : : TryReduceTypesToSingle ( const TArray < TRigVMTypeIndex > & InTypes , const TRigVMTypeIndex PreferredType ) const
2022-07-14 06:53:37 -04:00
{
2022-09-06 11:24:29 -04:00
if ( InTypes . IsEmpty ( ) )
2022-07-14 06:53:37 -04:00
{
2022-09-06 11:24:29 -04:00
return INDEX_NONE ;
2022-07-14 06:53:37 -04:00
}
2022-09-06 11:24:29 -04:00
if ( InTypes . Num ( ) = = 1 )
2022-07-14 06:53:37 -04:00
{
2022-09-06 11:24:29 -04:00
return InTypes [ 0 ] ;
2022-07-14 06:53:37 -04:00
}
2022-09-06 11:24:29 -04:00
for ( int32 i = 1 ; i < InTypes . Num ( ) ; + + i )
2022-07-14 06:53:37 -04:00
{
2022-09-06 11:24:29 -04:00
if ( ! FRigVMRegistry : : Get ( ) . CanMatchTypes ( InTypes [ 0 ] , InTypes [ i ] , true ) )
2022-07-14 06:53:37 -04:00
{
2022-09-06 11:24:29 -04:00
return INDEX_NONE ;
2022-07-14 06:53:37 -04:00
}
}
2022-09-06 11:24:29 -04:00
if ( InTypes . Contains ( PreferredType ) )
2022-07-14 06:53:37 -04:00
{
2022-09-06 11:24:29 -04:00
return PreferredType ;
2022-07-14 06:53:37 -04:00
}
2022-09-06 11:24:29 -04:00
return InTypes [ 0 ] ;
2022-07-14 06:53:37 -04:00
}
2022-05-09 07:34:28 -04:00
TArray < int32 > URigVMTemplateNode : : GetNewFilteredPermutations ( URigVMPin * InPin , URigVMPin * LinkedPin )
{
TArray < int32 > NewFilteredPermutations ;
if ( InPin - > GetNode ( ) ! = this )
{
return NewFilteredPermutations ;
}
NewFilteredPermutations . Reserve ( FilteredPermutations . Num ( ) ) ;
bool bIsArrayElement = false ;
2022-05-09 14:13:48 -04:00
bool bIsStructElement = false ;
2022-05-09 07:34:28 -04:00
URigVMPin * RootPin = InPin ;
if ( URigVMPin * ParentPin = InPin - > GetParentPin ( ) )
{
RootPin = ParentPin ;
2022-05-09 14:13:48 -04:00
bIsArrayElement = RootPin - > IsArray ( ) ;
bIsStructElement = RootPin - > IsStruct ( ) ;
}
if ( bIsStructElement )
{
2022-06-28 13:41:23 -04:00
if ( FRigVMRegistry : : Get ( ) . CanMatchTypes ( InPin - > GetTypeIndex ( ) , LinkedPin - > GetTypeIndex ( ) , true ) )
2022-05-09 14:13:48 -04:00
{
return FilteredPermutations ;
}
2022-05-09 07:34:28 -04:00
}
2022-06-07 04:43:09 -04:00
TArray < int32 > PermutationsToTry = FilteredPermutations ;
// Reduce permutations to the ones respecting the preferred types
2022-06-28 13:41:23 -04:00
const TArray < int32 > PreferredPermutations = FindPermutationsForTypes ( PreferredPermutationPairs , true ) ;
2022-06-07 04:43:09 -04:00
PermutationsToTry = PermutationsToTry . FilterByPredicate ( [ & ] ( const int32 & OtherPermutation ) { return PreferredPermutations . Contains ( OtherPermutation ) ; } ) ;
2022-05-09 07:34:28 -04:00
bool bLinkedIsTemplate = false ;
if ( URigVMTemplateNode * LinkedTemplate = Cast < URigVMTemplateNode > ( LinkedPin - > GetNode ( ) ) )
{
2022-05-10 09:29:27 -04:00
if ( ! LinkedTemplate - > IsSingleton ( ) & & ! LinkedPin - > IsStructMember ( ) )
2022-05-09 07:34:28 -04:00
{
bLinkedIsTemplate = true ;
if ( const FRigVMTemplateArgument * Argument = GetTemplate ( ) - > FindArgument ( RootPin - > GetFName ( ) ) )
{
for ( int32 PermutationIndex : PermutationsToTry )
{
2022-07-05 11:39:15 -04:00
TRigVMTypeIndex TypeIndex = Argument - > GetTypeIndices ( ) [ PermutationIndex ] ;
2022-05-09 07:34:28 -04:00
if ( bIsArrayElement )
{
2022-06-28 13:41:23 -04:00
TypeIndex = FRigVMRegistry : : Get ( ) . GetBaseTypeFromArrayTypeIndex ( TypeIndex ) ;
2022-05-09 07:34:28 -04:00
}
2022-06-28 13:41:23 -04:00
if ( LinkedTemplate - > FilteredSupportsType ( LinkedPin , TypeIndex ) )
2022-05-09 07:34:28 -04:00
{
NewFilteredPermutations . Add ( PermutationIndex ) ;
}
}
}
}
}
if ( ! bLinkedIsTemplate )
{
if ( const FRigVMTemplateArgument * Argument = GetTemplate ( ) - > FindArgument ( RootPin - > GetFName ( ) ) )
{
2022-07-05 11:39:15 -04:00
const TRigVMTypeIndex LinkedTypeIndex = LinkedPin - > GetTypeIndex ( ) ;
2022-06-28 13:41:23 -04:00
for ( int32 PermutationIndex : PermutationsToTry )
2022-05-09 07:34:28 -04:00
{
2022-07-05 11:39:15 -04:00
TRigVMTypeIndex TypeIndex = Argument - > GetTypeIndices ( ) [ PermutationIndex ] ;
2022-05-09 07:34:28 -04:00
if ( bIsArrayElement )
{
2022-06-28 13:41:23 -04:00
TypeIndex = FRigVMRegistry : : Get ( ) . GetBaseTypeFromArrayTypeIndex ( TypeIndex ) ;
2022-05-09 07:34:28 -04:00
}
2022-06-28 13:41:23 -04:00
if ( FRigVMRegistry : : Get ( ) . CanMatchTypes ( TypeIndex , LinkedTypeIndex , true ) )
2022-05-09 07:34:28 -04:00
{
2022-06-28 13:41:23 -04:00
NewFilteredPermutations . Add ( PermutationIndex ) ;
2022-05-09 07:34:28 -04:00
}
}
}
}
return NewFilteredPermutations ;
}
2022-07-05 11:39:15 -04:00
TArray < int32 > URigVMTemplateNode : : GetNewFilteredPermutations ( URigVMPin * InPin , const TArray < TRigVMTypeIndex > & InTypeIndices )
2022-05-09 07:34:28 -04:00
{
TArray < int32 > NewFilteredPermutations ;
NewFilteredPermutations . Reserve ( FilteredPermutations . Num ( ) ) ;
URigVMPin * RootPin = InPin ;
2022-07-05 11:39:15 -04:00
TArray < TRigVMTypeIndex > RootTypes = InTypeIndices ;
2022-05-09 07:34:28 -04:00
if ( URigVMPin * ParentPin = InPin - > GetParentPin ( ) )
{
RootPin = ParentPin ;
2022-07-05 11:39:15 -04:00
for ( TRigVMTypeIndex & TypeIndex : RootTypes )
2022-05-09 07:34:28 -04:00
{
2022-06-28 13:41:23 -04:00
TypeIndex = FRigVMRegistry : : Get ( ) . GetArrayTypeFromBaseTypeIndex ( TypeIndex ) ;
2022-05-09 07:34:28 -04:00
}
}
2022-06-07 04:43:09 -04:00
TArray < int32 > PermutationsToTry = FilteredPermutations ;
// Reduce permutations to the ones respecting the preferred types
2022-06-28 13:41:23 -04:00
const TArray < int32 > PreferredPermutations = FindPermutationsForTypes ( PreferredPermutationPairs , true ) ;
2022-06-07 04:43:09 -04:00
PermutationsToTry = PermutationsToTry . FilterByPredicate ( [ & ] ( const int32 & OtherPermutation ) { return PreferredPermutations . Contains ( OtherPermutation ) ; } ) ;
2022-05-09 07:34:28 -04:00
if ( const FRigVMTemplateArgument * Argument = GetTemplate ( ) - > FindArgument ( RootPin - > GetFName ( ) ) )
{
2022-07-05 11:39:15 -04:00
const TArray < TRigVMTypeIndex > & TypeIndices = Argument - > GetTypeIndices ( ) ;
2022-06-28 13:41:23 -04:00
for ( int32 PermutationIndex : PermutationsToTry )
2022-05-09 07:34:28 -04:00
{
2022-07-05 11:39:15 -04:00
for ( const TRigVMTypeIndex & RootTypeIndex : RootTypes )
2022-05-09 07:34:28 -04:00
{
2022-06-28 13:41:23 -04:00
if ( FRigVMRegistry : : Get ( ) . CanMatchTypes ( TypeIndices [ PermutationIndex ] , RootTypeIndex , true ) )
2022-05-09 07:34:28 -04:00
{
2022-06-28 13:41:23 -04:00
NewFilteredPermutations . Add ( PermutationIndex ) ;
2022-05-09 07:34:28 -04:00
break ;
}
}
}
}
return NewFilteredPermutations ;
}
2022-06-28 13:41:23 -04:00
TArray < int32 > URigVMTemplateNode : : FindPermutationsForTypes ( const TArray < FRigVMTemplatePreferredType > & ArgumentTypes , bool bAllowCasting ) const
2022-05-09 07:34:28 -04:00
{
2022-05-11 05:46:12 -04:00
TArray < int32 > Permutations ;
2022-05-09 07:34:28 -04:00
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
{
2022-06-28 13:41:23 -04:00
const FRigVMRegistry & Registry = FRigVMRegistry : : Get ( ) ;
2022-05-18 06:43:26 -04:00
TArray < const FRigVMTemplateArgument * > Args ;
2022-07-05 11:39:15 -04:00
TArray < TRigVMTypeIndex > TypeIndices ;
2022-06-28 13:41:23 -04:00
for ( const FRigVMTemplatePreferredType & ArgumentType : ArgumentTypes )
2022-05-18 06:43:26 -04:00
{
2022-07-05 11:39:15 -04:00
if ( const FRigVMTemplateArgument * Argument = Template - > FindArgument ( ArgumentType . GetArgument ( ) ) )
2022-05-18 06:43:26 -04:00
{
Args . Add ( Argument ) ;
2022-07-05 11:39:15 -04:00
TypeIndices . Add ( ArgumentType . GetTypeIndex ( ) ) ;
2022-05-18 06:43:26 -04:00
}
else
{
return { } ;
}
}
2022-05-09 07:34:28 -04:00
for ( int32 i = 0 ; i < Template - > NumPermutations ( ) ; + + i )
{
bool bAllArgsMatched = true ;
2022-05-18 06:43:26 -04:00
for ( int32 ArgIndex = 0 ; ArgIndex < Args . Num ( ) ; + + ArgIndex )
2022-05-09 07:34:28 -04:00
{
2022-05-18 06:43:26 -04:00
const FRigVMTemplateArgument * Argument = Args [ ArgIndex ] ;
2022-07-14 06:53:37 -04:00
if ( Argument )
2022-05-09 07:34:28 -04:00
{
2022-06-28 13:41:23 -04:00
if ( ( bAllowCasting & & ! Registry . CanMatchTypes ( Argument - > GetTypeIndices ( ) [ i ] , TypeIndices [ ArgIndex ] , true ) ) | |
( ! bAllowCasting & & Argument - > GetTypeIndices ( ) [ i ] ! = TypeIndices [ ArgIndex ] ) )
2022-05-09 07:34:28 -04:00
{
bAllArgsMatched = false ;
break ;
}
}
2022-07-14 06:53:37 -04:00
else
{
// The preferred type doesn't own an argument yet. Supports all types.
}
2022-05-09 07:34:28 -04:00
}
if ( bAllArgsMatched )
{
2022-05-11 05:46:12 -04:00
Permutations . Add ( i ) ;
2022-05-09 07:34:28 -04:00
}
}
}
2022-05-11 05:46:12 -04:00
return Permutations ;
2022-05-09 07:34:28 -04:00
}
2022-07-05 11:39:15 -04:00
TArray < FRigVMTemplatePreferredType > URigVMTemplateNode : : GetPreferredTypesForPermutation ( const int32 InPermutationIndex ) const
2022-05-09 07:34:28 -04:00
{
2022-06-28 13:41:23 -04:00
TArray < FRigVMTemplatePreferredType > ArgTypes ;
2022-05-09 07:34:28 -04:00
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
{
for ( int32 ArgIndex = 0 ; ArgIndex < Template - > NumArguments ( ) ; + + ArgIndex )
{
const FRigVMTemplateArgument * Argument = Template - > GetArgument ( ArgIndex ) ;
2022-06-28 13:41:23 -04:00
if ( Argument - > GetTypeIndices ( ) . Num ( ) > InPermutationIndex )
2022-05-09 07:34:28 -04:00
{
2022-06-28 13:41:23 -04:00
ArgTypes . Emplace ( Argument - > GetName ( ) , Argument - > GetTypeIndices ( ) [ InPermutationIndex ] ) ;
2022-05-09 07:34:28 -04:00
}
else
{
2022-07-14 06:53:37 -04:00
return { } ;
2022-05-09 07:34:28 -04:00
}
}
}
return ArgTypes ;
}
2022-07-05 11:39:15 -04:00
FRigVMTemplateTypeMap URigVMTemplateNode : : GetTypesForPermutation ( const int32 InPermutationIndex ) const
{
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
{
return Template - > GetTypesForPermutation ( InPermutationIndex ) ;
}
return FRigVMTemplateTypeMap ( ) ;
}
bool URigVMTemplateNode : : PinNeedsFilteredTypesUpdate ( URigVMPin * InPin , const TArray < TRigVMTypeIndex > & InTypeIndices )
2022-05-09 07:34:28 -04:00
{
2022-06-28 13:41:23 -04:00
const TArray < int32 > NewFilteredPermutations = GetNewFilteredPermutations ( InPin , InTypeIndices ) ;
2022-05-09 07:34:28 -04:00
if ( NewFilteredPermutations . Num ( ) = = FilteredPermutations . Num ( ) )
{
return false ;
}
return true ;
}
bool URigVMTemplateNode : : PinNeedsFilteredTypesUpdate ( URigVMPin * InPin , URigVMPin * LinkedPin )
{
2022-06-28 13:41:23 -04:00
const TArray < int32 > NewFilteredPermutations = GetNewFilteredPermutations ( InPin , LinkedPin ) ;
2022-05-09 07:34:28 -04:00
if ( NewFilteredPermutations . Num ( ) = = FilteredPermutations . Num ( ) )
{
return false ;
}
return true ;
}
bool URigVMTemplateNode : : UpdateFilteredPermutations ( URigVMPin * InPin , URigVMPin * LinkedPin )
{
ensureMsgf ( InPin - > GetNode ( ) = = this , TEXT ( " Updating filtered permutations of %s with pin from another node %s " ) , * GetNodePath ( ) , * InPin - > GetPinPath ( true ) ) ;
ensureMsgf ( LinkedPin - > GetNode ( ) ! = this , TEXT ( " Updating filtered permutations of %s with linked pin from same node %s " ) , * GetNodePath ( ) , * LinkedPin - > GetPinPath ( true ) ) ;
2022-06-28 13:41:23 -04:00
const TArray < int32 > NewFilteredPermutations = GetNewFilteredPermutations ( InPin , LinkedPin ) ;
2022-05-09 07:34:28 -04:00
if ( NewFilteredPermutations . Num ( ) = = FilteredPermutations . Num ( ) )
{
return false ;
}
if ( NewFilteredPermutations . IsEmpty ( ) )
{
return false ;
}
FilteredPermutations = NewFilteredPermutations ;
return true ;
}
2022-07-05 11:39:15 -04:00
bool URigVMTemplateNode : : UpdateFilteredPermutations ( URigVMPin * InPin , const TArray < TRigVMTypeIndex > & InTypeIndices )
2022-05-09 07:34:28 -04:00
{
2022-06-28 13:41:23 -04:00
const TArray < int32 > NewFilteredPermutations = GetNewFilteredPermutations ( InPin , InTypeIndices ) ;
2022-05-09 07:34:28 -04:00
if ( NewFilteredPermutations . Num ( ) = = FilteredPermutations . Num ( ) )
{
return false ;
}
if ( NewFilteredPermutations . IsEmpty ( ) )
{
return false ;
}
FilteredPermutations = NewFilteredPermutations ;
return true ;
}
2022-03-01 04:23:55 -05:00
void URigVMTemplateNode : : InvalidateCache ( )
{
2022-06-22 08:37:48 -04:00
Super : : InvalidateCache ( ) ;
2022-03-01 04:23:55 -05:00
CachedFunction = nullptr ;
2022-05-09 14:13:48 -04:00
CachedTemplate = nullptr ;
2022-03-01 04:23:55 -05:00
2022-08-23 13:08:34 -04:00
if ( HasWildCardPin ( ) )
2022-03-01 04:23:55 -05:00
{
2022-08-23 13:08:34 -04:00
ResolvedFunctionName . Reset ( ) ;
2022-03-01 04:23:55 -05:00
}
}
2022-05-09 07:34:28 -04:00
void URigVMTemplateNode : : InitializeFilteredPermutations ( )
{
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
{
2022-06-28 13:41:23 -04:00
if ( ! PreferredPermutationPairs . IsEmpty ( ) )
2022-05-09 07:34:28 -04:00
{
2022-07-14 06:53:37 -04:00
FilteredPermutations = FindPermutationsForTypes ( PreferredPermutationPairs , true ) ;
2022-05-09 07:34:28 -04:00
}
else
{
FilteredPermutations . SetNumUninitialized ( Template - > NumPermutations ( ) ) ;
for ( int32 i = 0 ; i < FilteredPermutations . Num ( ) ; + + i )
{
FilteredPermutations [ i ] = i ;
}
}
}
}
2022-05-09 14:13:48 -04:00
2022-07-14 06:53:37 -04:00
void URigVMTemplateNode : : InitializeFilteredPermutationsFromTypes ( bool bAllowCasting )
2022-05-09 14:13:48 -04:00
{
if ( IsSingleton ( ) )
{
return ;
}
2022-07-14 06:53:37 -04:00
if ( IsA < URigVMFunctionEntryNode > ( ) | | IsA < URigVMFunctionReturnNode > ( ) )
2022-05-09 14:13:48 -04:00
{
2022-06-28 13:41:23 -04:00
TArray < FRigVMTemplatePreferredType > ArgTypes ;
2022-07-14 06:53:37 -04:00
for ( URigVMPin * Pin : GetPins ( ) )
2022-05-09 14:13:48 -04:00
{
2022-07-14 06:53:37 -04:00
if ( ! Pin - > IsWildCard ( ) )
2022-05-09 14:13:48 -04:00
{
2022-07-14 06:53:37 -04:00
ArgTypes . Emplace ( Pin - > GetFName ( ) , Pin - > GetTypeIndex ( ) ) ;
2022-05-09 14:13:48 -04:00
}
}
2022-07-14 06:53:37 -04:00
PreferredPermutationPairs = ArgTypes ;
}
else
{
if ( const FRigVMTemplate * Template = GetTemplate ( ) )
{
TArray < FRigVMTemplatePreferredType > ArgTypes ;
for ( int32 ArgIndex = 0 ; ArgIndex < Template - > NumArguments ( ) ; + + ArgIndex )
{
const FRigVMTemplateArgument * Argument = Template - > GetArgument ( ArgIndex ) ;
if ( URigVMPin * Pin = FindPin ( Argument - > GetName ( ) . ToString ( ) ) )
{
if ( ! Pin - > IsWildCard ( ) )
{
ArgTypes . Emplace ( Argument - > GetName ( ) , Pin - > GetTypeIndex ( ) ) ;
}
}
}
2022-05-09 14:13:48 -04:00
2022-07-14 06:53:37 -04:00
const TArray < int32 > Permutations = FindPermutationsForTypes ( ArgTypes , bAllowCasting ) ;
if ( ! Permutations . IsEmpty ( ) )
{
FilteredPermutations = Permutations ;
PreferredPermutationPairs = ArgTypes ;
}
else
{
InitializeFilteredPermutations ( ) ;
}
2022-05-09 14:13:48 -04:00
}
}
}
2022-09-24 13:31:25 -04:00