/** Evaluates the graph connected to a pin. */
static int32 EvaluateGraph(FNiagaraCompilerContext& Context, UEdGraphPin* Pin)
{
	int32 ExpressionIndex = INDEX_NONE;
	if (Pin)
	{
		if (Pin->LinkedTo.Num() == 1)
		{
			check(Pin->Direction == EGPD_Input);
			Pin = Pin->LinkedTo[0];
			check(Pin->Direction == EGPD_Output);

			int32* CachedExpressionIndex = Context.PinToExpression.Find(Pin);
			if (CachedExpressionIndex)
			{
				ExpressionIndex = *CachedExpressionIndex;
			}
			else
			{
				UEdGraphNode* Node = Pin->GetOwningNode();
				if (Node->IsA(UNiagaraNodeOp::StaticClass()))
				{
					UNiagaraNodeOp* OpNode = (UNiagaraNodeOp*)Node;
					VectorVM::FVectorVMOpInfo const& OpInfo = VectorVM::GetOpCodeInfo(OpNode->OpIndex);

					FNiagaraExpr NewOp;
					NewOp.OpIndex = OpNode->OpIndex;
					NewOp.SrcOperandTypeVector = 0;

					for (int32 SrcIndex = 0; SrcIndex < 3; ++SrcIndex)
					{
						if (OpInfo.SrcTypes[SrcIndex] != VectorVM::EOpSrc::Invalid)
						{
							UEdGraphPin* SrcPin = OpNode->FindPinChecked(UNiagaraNodeOp::InPinNames[SrcIndex]);
							NewOp.Src[SrcIndex] = EvaluateGraph(Context,SrcPin);
							if (NewOp.Src[SrcIndex] & 0x40000000)
							{
								NewOp.SrcOperandTypeVector |= (1 << SrcIndex);
							}
						}
					}

					ExpressionIndex = Context.Expressions.Add(NewOp);
				}
				else if (Node->IsA(UNiagaraNodeGetAttr::StaticClass()))
				{
					UNiagaraNodeGetAttr* AttrNode = (UNiagaraNodeGetAttr*)Node;
					int32 AttrIndex = INDEX_NONE;
					if (Context.Attributes.Find(AttrNode->AttrName, AttrIndex))
					{
						ExpressionIndex = AttrIndex | 0x80000000;
					}
					else if (Context.ConstantNames.Find(AttrNode->AttrName, AttrIndex))
					{
						ExpressionIndex = AttrIndex | 0x40000000;
					}
				}
				Context.PinToExpression.Add(Pin, ExpressionIndex);
			}
		}
		else if (!Pin->bDefaultValueIsIgnored)
		{
			FString ConstString = Pin->GetDefaultAsString();
			FName ConstName(*ConstString);
			int32 ConstIndex = Context.ConstantNames.Find(ConstName);
			if (ConstIndex == INDEX_NONE)
			{
				TArray<FString> ResultString;
				ConstString.Trim();
				ConstString.TrimTrailing();
				ConstString.ParseIntoArray(&ResultString, TEXT(","), true);
				ConstIndex = 0;
				if (ResultString.Num() == 4)
				{
					ConstIndex = Context.Constants.Add(FVector4(FCString::Atof(*ResultString[0]), FCString::Atof(*ResultString[1]), FCString::Atof(*ResultString[2]), FCString::Atof(*ResultString[3])));
					check(Context.ConstantNames.Num() == ConstIndex);
					Context.ConstantNames.Add(ConstName);
				}
			}
			check(Context.Constants.IsValidIndex(ConstIndex));
			ExpressionIndex = ConstIndex | 0x40000000;			
		}
	}
	return ExpressionIndex;
}
TNiagaraExprPtr FNiagaraCompiler::CompilePin(UEdGraphPin* Pin)
{
	check(Pin);
	TNiagaraExprPtr Ret;
	if (Pin->Direction == EGPD_Input)
	{
		if (Pin->LinkedTo.Num() > 0)
		{
			// > 1 ???
			Ret = CompileOutputPin(Pin->LinkedTo[0]);
		}
		else if (!Pin->bDefaultValueIsIgnored)
		{
			//No connections to this input so add the default as a const expression.
			const UEdGraphSchema_Niagara* Schema = Cast<const UEdGraphSchema_Niagara>(Pin->GetSchema());
			ENiagaraDataType PinType = Schema->GetPinType(Pin);

			FString ConstString = Pin->GetDefaultAsString();
			FName ConstName(*ConstString);

			FNiagaraVariableInfo Var(ConstName, PinType);

			switch (PinType)
			{
			case ENiagaraDataType::Scalar:
			{
				float Default;
				Schema->GetPinDefaultValue(Pin, Default);
				ConstantData.SetOrAddInternal(Var, Default);
			}
				break;
			case ENiagaraDataType::Vector:
			{
				FVector4 Default;
				Schema->GetPinDefaultValue(Pin, Default);
				ConstantData.SetOrAddInternal(Var, Default);
			}
				break;
			case ENiagaraDataType::Matrix:
			{
				FMatrix Default;
				Schema->GetPinDefaultValue(Pin, Default);
				ConstantData.SetOrAddInternal(Var, Default);
			}
				break;
			case ENiagaraDataType::Curve:
			{
				FNiagaraDataObject *Default = nullptr;
				ConstantData.SetOrAddInternal(Var, Default);
			}
				break;
			}
			Ret = Expression_GetInternalConstant(Var);
		}
	}
	else
	{
		Ret = CompileOutputPin(Pin);
	}

	return Ret;
}
Exemple #3
0
 const unsigned char *PkcsAttribute ( unsigned int Val ) {
   return ConstName ( PkcsAttributeInfo, PkcsAttributeSize, Val);
 }
Exemple #4
0
const unsigned char *ResponseSeverity( unsigned int Val ) {
  return ConstName ( PkcsResponseSeverityInfo, PkcsResponseSeveritySize, Val);
}
Exemple #5
0
 const unsigned char *PkcsObject ( unsigned int Val ) {
   return ConstName ( PkcsObjectInfo, PkcsObjectSize, Val );
 }
Exemple #6
0
 const unsigned char *PkcsKey ( unsigned int Val ) {
   return ConstName( PkcsKeyInfo, PkcsKeySize, Val);
 }
Exemple #7
0
 const unsigned char *PkcsFlags ( unsigned int Val ) {
   return ConstName( PkcsFlagsInfo, PkcsFlagsSize, Val );
 }
Exemple #8
0
 const unsigned char *PkcsMechanism ( unsigned int Val) {
   return ConstName(PkcsMechanismInfo, PkcsMechanismSize, Val);
 }
Exemple #9
0
 const unsigned char *PkcsReturn ( unsigned int Val ) {
   return ConstName( PkcsReturnInfo,  PkcsReturnSize, Val );
 }
Exemple #10
0
 const unsigned char *SysConst ( unsigned int Val ) {
   return ConstName ( SysErrorInfo, SysErrorSize, Val );
 }
Exemple #11
0
 const unsigned char *ODMConst( unsigned int Val ) {
   return ConstName( ODMError, ODMErrorSize, Val);
 }
Exemple #12
0
 const unsigned char *SignalConst ( unsigned int Val ) {
   return ConstName ( SignalInfo, SignalInfoSize, Val );
 }
Exemple #13
0
 const unsigned char *DAEConst( unsigned int Val ) {
   return ConstName( DAEError, DAEErrorSize, Val);
 }