1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
4 #include "Deprecated/DocGraphNodes/DocGraphBranchNode.h"
6 #include <CrySchematyc2/ICompiler.h>
7 #include <CrySchematyc2/LibUtils.h>
8 #include <CrySchematyc2/Deprecated/DocUtils.h>
9 #include <CrySchematyc2/Deprecated/IGlobalFunction.h>
11 #include "Deprecated/DocGraphNodes/DocGraphNodeBase.h"
12 #include "Script/ScriptVariableDeclaration.h"
16 //////////////////////////////////////////////////////////////////////////
17 CDocGraphBranchNode::CDocGraphBranchNode(IScriptFile
& file
, IDocGraph
& graph
, const SGUID
& guid
, const SGUID
& contextGUID
, const SGUID
& refGUID
, Vec2 pos
)
18 : CDocGraphNodeBase(file
, graph
, guid
, "Branch", EScriptGraphNodeType::Branch
, contextGUID
, refGUID
, pos
)
21 Refresh(SScriptRefreshParams(EScriptRefreshReason::Other
));
24 //////////////////////////////////////////////////////////////////////////
25 IAnyConstPtr
CDocGraphBranchNode::GetCustomOutputDefault() const
27 return IAnyConstPtr();
30 //////////////////////////////////////////////////////////////////////////
31 size_t CDocGraphBranchNode::AddCustomOutput(const IAny
& value
)
36 //////////////////////////////////////////////////////////////////////////
37 void CDocGraphBranchNode::EnumerateOptionalOutputs(const ScriptGraphNodeOptionalOutputEnumerator
& enumerator
) {}
39 //////////////////////////////////////////////////////////////////////////
40 size_t CDocGraphBranchNode::AddOptionalOutput(const char* szName
, EScriptGraphPortFlags flags
, const CAggregateTypeId
& typeId
)
45 //////////////////////////////////////////////////////////////////////////
46 void CDocGraphBranchNode::RemoveOutput(size_t outputIdx
) {}
48 //////////////////////////////////////////////////////////////////////////
49 void CDocGraphBranchNode::Refresh(const SScriptRefreshParams
& params
)
51 CRY_PROFILE_FUNCTION(PROFILE_LOADING_ONLY
);
52 CDocGraphNodeBase::Refresh(params
);
53 CDocGraphNodeBase::AddInput("In", EScriptGraphPortFlags::MultiLink
| EScriptGraphPortFlags::Execute
);
54 CDocGraphNodeBase::AddInput("Value", EScriptGraphPortFlags::None
, GetAggregateTypeId
<bool>());
55 CDocGraphNodeBase::AddOutput("True", EScriptGraphPortFlags::Execute
);
56 CDocGraphNodeBase::AddOutput("False", EScriptGraphPortFlags::Execute
);
59 //////////////////////////////////////////////////////////////////////////
60 void CDocGraphBranchNode::Serialize(Serialization::IArchive
& archive
)
62 CRY_PROFILE_FUNCTION(PROFILE_LOADING_ONLY
);
63 CDocGraphNodeBase::Serialize(archive
);
64 archive(m_bValue
, "value", "Value");
67 //////////////////////////////////////////////////////////////////////////
68 void CDocGraphBranchNode::PreCompileSequence(IDocGraphSequencePreCompiler
& preCompiler
, size_t outputIdx
) const {}
70 //////////////////////////////////////////////////////////////////////////
71 void CDocGraphBranchNode::LinkSequence(IDocGraphSequenceLinker
& linker
, size_t outputIdx
, const LibFunctionId
& functionId
) const {}
73 //////////////////////////////////////////////////////////////////////////
74 void CDocGraphBranchNode::Compile(IDocGraphNodeCompiler
& compiler
, EDocGraphSequenceStep sequenceStep
, size_t portIdx
) const
78 case EDocGraphSequenceStep::BeginInput
:
80 CompileInputs(compiler
);
83 case EDocGraphSequenceStep::BeginOutput
:
89 CompileTrue(compiler
);
94 CompileFalse(compiler
);
100 case EDocGraphSequenceStep::EndInput
:
102 CompileEnd(compiler
);
108 //////////////////////////////////////////////////////////////////////////
109 void CDocGraphBranchNode::CompileInputs(IDocGraphNodeCompiler
& compiler
) const
111 compiler
.CreateStackFrame(*this, EStackFrame::Value
);
112 const size_t stackPos
= compiler
.FindInputOnStack(*this, EInput::Value
);
113 if(stackPos
!= INVALID_INDEX
)
115 if(stackPos
!= (compiler
.GetStackSize() - 1))
117 compiler
.Copy(stackPos
, INVALID_INDEX
, MakeAny(m_bValue
), CDocGraphNodeBase::GetGUID(), GetInputName(EInput::Value
));
121 compiler
.SetDebugInput(CDocGraphNodeBase::GetGUID(), GetInputName(EInput::Value
));
126 compiler
.Push(MakeAny(m_bValue
), CDocGraphNodeBase::GetGUID(), GetInputName(EInput::Value
));
130 //////////////////////////////////////////////////////////////////////////
131 void CDocGraphBranchNode::CompileTrue(IDocGraphNodeCompiler
& compiler
) const
133 compiler
.BranchIfZero(*this, EMarker::BranchFalse
);
134 compiler
.CollapseStackFrame(*this, EStackFrame::Value
);
135 compiler
.CreateStackFrame(*this, EStackFrame::Value
);
138 //////////////////////////////////////////////////////////////////////////
139 void CDocGraphBranchNode::CompileFalse(IDocGraphNodeCompiler
& compiler
) const
141 compiler
.Branch(*this, EMarker::BranchEnd
);
142 compiler
.CreateMarker(*this, EMarker::BranchFalse
);
143 compiler
.CollapseStackFrame(*this, EStackFrame::Value
);
144 compiler
.CreateStackFrame(*this, EStackFrame::Value
);
147 //////////////////////////////////////////////////////////////////////////
148 void CDocGraphBranchNode::CompileEnd(IDocGraphNodeCompiler
& compiler
) const
150 compiler
.CreateMarker(*this, EMarker::BranchEnd
);
151 compiler
.CollapseStackFrame(*this, EStackFrame::Value
);