You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
Blueprint real number support. This change deprecates the use the of "float" and "double" types in Blueprints in favor of a new "real". By default, "real" is back by a double precision floating point number. However, it can be single precision if the number is a native float property or function parameter. This distinction won't be visible to the Blueprint user: in both instances, they'll be represented by "real" pin types. During deserialization, we'll automatically convert Blueprint pin types to use real/doubles, unless they're used to represent native code (including delegate signatures). One consequence of this change is that we need to perform implicit casts between single and double precision real numbers. During Blueprint compilation, the compiler will detect points in the graph for when either a widening or narrowing conversion needs to occur. Subsequently, the script bytecode will contain a new cast instruction that performs the conversion. This also works on container types, but each entry in the container will have to be converted. This can introduce unwanted overhead for large containers that are frequently passed between Blueprint and native code. The scope of this change affects Blueprints used by Gameplay, Animation, Control Rig, and UMG. #rb marc.audy (serialization changes) #jira UE-116484 #preflight 61f8bdd5a2514ba12ff7bdfc #ROBOMERGE-AUTHOR: dave.jones2 #ROBOMERGE-SOURCE: CL 18809077 in //UE5/Release-5.0/... via CL 18809455 via CL 18822548 #ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v908-18788545) [CL 18823569 by dave jones2 in ue5-main branch]
257 lines
8.0 KiB
C++
257 lines
8.0 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
#include "K2Node_AssignmentStatement.h"
|
|
#include "EdGraphSchema_K2.h"
|
|
#include "EdGraphUtilities.h"
|
|
#include "KismetCastingUtils.h"
|
|
#include "KismetCompiler.h"
|
|
#include "VariableSetHandler.h"
|
|
#include "BlueprintNodeSpawner.h"
|
|
#include "EditorCategoryUtils.h"
|
|
#include "BlueprintActionDatabaseRegistrar.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "K2Node_AssignmentStatement"
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// FKCHandler_AssignmentStatement
|
|
|
|
class FKCHandler_AssignmentStatement : public FKCHandler_VariableSet
|
|
{
|
|
public:
|
|
FKCHandler_AssignmentStatement(FKismetCompilerContext& InCompilerContext)
|
|
: FKCHandler_VariableSet(InCompilerContext)
|
|
{
|
|
}
|
|
|
|
virtual void RegisterNets(FKismetFunctionContext& Context, UEdGraphNode* Node) override
|
|
{
|
|
UEdGraphPin* VariablePin = Node->FindPin(TEXT("Variable"));
|
|
UEdGraphPin* ValuePin = Node->FindPin(TEXT("Value"));
|
|
|
|
if ((VariablePin == NULL) || (ValuePin == NULL))
|
|
{
|
|
CompilerContext.MessageLog.Error(*LOCTEXT("MissingPins_Error", "Missing pin(s) on @@; expected a pin named Variable and a pin named Value").ToString(), Node);
|
|
return;
|
|
}
|
|
|
|
if (VariablePin->LinkedTo.Num() == 0)
|
|
{
|
|
CompilerContext.MessageLog.Error(*LOCTEXT("NoVariableConnected_Error", "A variable needs to be connected to @@").ToString(), VariablePin);
|
|
return;
|
|
}
|
|
|
|
ValidateAndRegisterNetIfLiteral(Context, ValuePin);
|
|
|
|
#if ENABLE_BLUEPRINT_REAL_NUMBERS
|
|
{
|
|
using namespace UE::KismetCompiler;
|
|
|
|
UEdGraphPin* VariablePinNet = FEdGraphUtilities::GetNetFromPin(VariablePin);
|
|
UEdGraphPin* ValuePinNet = FEdGraphUtilities::GetNetFromPin(ValuePin);
|
|
|
|
if (VariablePinNet && ValuePinNet)
|
|
{
|
|
TOptional<CastingUtils::StatementNamePair> ConversionType =
|
|
CastingUtils::GetFloatingPointConversionType(*ValuePinNet, *VariablePinNet);
|
|
|
|
if (ConversionType)
|
|
{
|
|
|
|
FString DescriptiveName = Node->GetName();
|
|
|
|
FString TerminalName = FString::Printf(TEXT("%s_%s_%s"),
|
|
*DescriptiveName,
|
|
*VariablePinNet->PinName.ToString(),
|
|
ConversionType->Get<1>());
|
|
|
|
FBPTerminal* NewTerm = Context.CreateLocalTerminal();
|
|
NewTerm->Name = TerminalName;
|
|
NewTerm->Type = VariablePinNet->PinType;
|
|
NewTerm->Source = Node;
|
|
|
|
EKismetCompiledStatementType CastType = ConversionType->Get<0>();
|
|
|
|
Context.ImplicitCastMap.Add(VariablePin, FImplicitCastParams{CastType, NewTerm, Node});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CompilerContext.MessageLog.Error(*LOCTEXT("NoVariableOrValueNets_Error", "Expected Variable and Value pins to have valid connections in @@").ToString(), Node);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
virtual void Compile(FKismetFunctionContext& Context, UEdGraphNode* Node) override
|
|
{
|
|
UEdGraphPin* VariablePin = Node->FindPin(TEXT("Variable"));
|
|
UEdGraphPin* ValuePin = Node->FindPin(TEXT("Value"));
|
|
|
|
check(VariablePin);
|
|
check(VariablePin->LinkedTo.Num() == 1);
|
|
check(ValuePin);
|
|
|
|
InnerAssignment(Context, Node, VariablePin, ValuePin);
|
|
|
|
// Generate the output impulse from this node
|
|
GenerateSimpleThenGoto(Context, *Node);
|
|
}
|
|
|
|
protected:
|
|
virtual bool UsesVariablePinAsKey() const override { return true; }
|
|
};
|
|
|
|
|
|
FName UK2Node_AssignmentStatement::VariablePinName(TEXT("Variable"));
|
|
FName UK2Node_AssignmentStatement::ValuePinName(TEXT("Value"));
|
|
|
|
|
|
UK2Node_AssignmentStatement::UK2Node_AssignmentStatement(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
}
|
|
|
|
void UK2Node_AssignmentStatement::AllocateDefaultPins()
|
|
{
|
|
CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Exec, UEdGraphSchema_K2::PN_Execute);
|
|
CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Exec, UEdGraphSchema_K2::PN_Then);
|
|
|
|
UEdGraphPin* VariablePin = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Wildcard, VariablePinName);
|
|
UEdGraphPin* ValuePin = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Wildcard, ValuePinName);
|
|
|
|
Super::AllocateDefaultPins();
|
|
}
|
|
|
|
FText UK2Node_AssignmentStatement::GetTooltipText() const
|
|
{
|
|
return LOCTEXT("AssignmentStatementTooltip", "Assigns Value to Variable");
|
|
}
|
|
|
|
FText UK2Node_AssignmentStatement::GetNodeTitle(ENodeTitleType::Type TitleType) const
|
|
{
|
|
return LOCTEXT("Assign", "Assign");
|
|
}
|
|
|
|
bool UK2Node_AssignmentStatement::IsCompatibleWithGraph(const UEdGraph* TargetGraph) const
|
|
{
|
|
bool bIsCompatible = Super::IsCompatibleWithGraph(TargetGraph);
|
|
if (bIsCompatible)
|
|
{
|
|
const EGraphType GraphType = TargetGraph->GetSchema()->GetGraphType(TargetGraph);
|
|
bIsCompatible = (GraphType == GT_Macro);
|
|
}
|
|
|
|
return bIsCompatible;
|
|
}
|
|
|
|
bool UK2Node_AssignmentStatement::CanPasteHere(const UEdGraph* TargetGraph) const
|
|
{
|
|
// These nodes can be pasted anywhere that UK2Node's are compatible with the graph
|
|
// Avoiding the call to IsCompatibleWithGraph because these nodes should normally only
|
|
// be placed in Macros, but it's nice to be able to paste Macro functionality anywhere.
|
|
return Super::IsCompatibleWithGraph(TargetGraph);
|
|
}
|
|
|
|
void UK2Node_AssignmentStatement::NotifyPinConnectionListChanged(UEdGraphPin* Pin)
|
|
{
|
|
Super::NotifyPinConnectionListChanged(Pin);
|
|
|
|
UEdGraphPin* VariablePin = FindPin(TEXT("Variable"));
|
|
UEdGraphPin* ValuePin = FindPin(TEXT("Value"));
|
|
|
|
if ((VariablePin->LinkedTo.Num() == 0) && (ValuePin->LinkedTo.Num() == 0))
|
|
{
|
|
// Restore the wildcard status
|
|
VariablePin->PinType.PinCategory = UEdGraphSchema_K2::PC_Wildcard;
|
|
VariablePin->PinType.PinSubCategory = TEXT("");
|
|
VariablePin->PinType.PinSubCategoryObject = NULL;
|
|
ValuePin->PinType.PinCategory = UEdGraphSchema_K2::PC_Wildcard;
|
|
ValuePin->PinType.PinSubCategory = TEXT("");
|
|
ValuePin->PinType.PinSubCategoryObject = NULL;
|
|
}
|
|
else if (Pin->LinkedTo.Num() > 0 &&
|
|
( Pin->LinkedTo[0]->PinType.PinCategory != UEdGraphSchema_K2::PC_Wildcard ||
|
|
Pin->LinkedTo[0]->PinType.PinCategory == Pin->PinType.PinCategory) )
|
|
{
|
|
Pin->PinType = Pin->LinkedTo[0]->PinType;
|
|
|
|
// Enforce the type on the other pin
|
|
if (VariablePin == Pin)
|
|
{
|
|
ValuePin->PinType = VariablePin->PinType;
|
|
UEdGraphSchema_K2::ValidateExistingConnections(ValuePin);
|
|
}
|
|
else
|
|
{
|
|
VariablePin->PinType = ValuePin->PinType;
|
|
UEdGraphSchema_K2::ValidateExistingConnections(VariablePin);
|
|
}
|
|
}
|
|
}
|
|
|
|
void UK2Node_AssignmentStatement::PostReconstructNode()
|
|
{
|
|
UEdGraphPin* VariablePin = FindPin(TEXT("Variable"));
|
|
UEdGraphPin* ValuePin = FindPin(TEXT("Value"));
|
|
|
|
PinConnectionListChanged(VariablePin);
|
|
PinConnectionListChanged(ValuePin);
|
|
|
|
Super::PostReconstructNode();
|
|
}
|
|
|
|
UEdGraphPin* UK2Node_AssignmentStatement::GetThenPin() const
|
|
{
|
|
UEdGraphPin* Pin = FindPin(UEdGraphSchema_K2::PN_Then);
|
|
check(Pin != NULL);
|
|
return Pin;
|
|
}
|
|
|
|
UEdGraphPin* UK2Node_AssignmentStatement::GetVariablePin() const
|
|
{
|
|
UEdGraphPin* Pin = FindPin(VariablePinName);
|
|
check(Pin != NULL);
|
|
return Pin;
|
|
}
|
|
|
|
UEdGraphPin* UK2Node_AssignmentStatement::GetValuePin() const
|
|
{
|
|
UEdGraphPin* Pin = FindPin(ValuePinName);
|
|
check(Pin != NULL);
|
|
return Pin;
|
|
}
|
|
|
|
FNodeHandlingFunctor* UK2Node_AssignmentStatement::CreateNodeHandler(FKismetCompilerContext& CompilerContext) const
|
|
{
|
|
return new FKCHandler_AssignmentStatement(CompilerContext);
|
|
}
|
|
|
|
void UK2Node_AssignmentStatement::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const
|
|
{
|
|
// actions get registered under specific object-keys; the idea is that
|
|
// actions might have to be updated (or deleted) if their object-key is
|
|
// mutated (or removed)... here we use the node's class (so if the node
|
|
// type disappears, then the action should go with it)
|
|
UClass* ActionKey = GetClass();
|
|
// to keep from needlessly instantiating a UBlueprintNodeSpawner, first
|
|
// check to make sure that the registrar is looking for actions of this type
|
|
// (could be regenerating actions for a specific asset, and therefore the
|
|
// registrar would only accept actions corresponding to that asset)
|
|
if (ActionRegistrar.IsOpenForRegistration(ActionKey))
|
|
{
|
|
UBlueprintNodeSpawner* NodeSpawner = UBlueprintNodeSpawner::Create(GetClass());
|
|
check(NodeSpawner != nullptr);
|
|
|
|
ActionRegistrar.AddBlueprintAction(ActionKey, NodeSpawner);
|
|
}
|
|
}
|
|
|
|
FText UK2Node_AssignmentStatement::GetMenuCategory() const
|
|
{
|
|
return FEditorCategoryUtils::GetCommonCategory(FCommonEditorCategory::Macro);
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE
|