1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
4 #include "Script/GraphNodes/ScriptGraphBranchNode.h"
6 #include <CrySchematyc2/IDomainContext.h>
7 #include <CrySchematyc2/Script/IScriptGraphNodeCompiler.h>
8 #include <CrySchematyc2/Script/IScriptGraphNodeCreationMenu.h>
10 #include "Script/GraphNodes/ScriptGraphNodeFactory.h"
14 const SGUID
CScriptGraphBranchNode::s_typeGUID
= "4F2A4D42-ED2A-40A3-9555-DBB1210A36D8";
16 CScriptGraphBranchNode::CScriptGraphBranchNode()
21 CScriptGraphBranchNode::CScriptGraphBranchNode(const SGUID
& guid
)
22 : CScriptGraphNodeBase(guid
)
26 CScriptGraphBranchNode::CScriptGraphBranchNode(const SGUID
& guid
, const Vec2
& pos
)
27 : CScriptGraphNodeBase(guid
, pos
)
31 SGUID
CScriptGraphBranchNode::GetTypeGUID() const
36 EScriptGraphColor
CScriptGraphBranchNode::GetColor() const
38 return EScriptGraphColor::Green
;
41 void CScriptGraphBranchNode::Refresh(const SScriptRefreshParams
& params
)
43 CRY_PROFILE_FUNCTION(PROFILE_LOADING_ONLY
);
45 CScriptGraphNodeBase::Refresh(params
);
47 CScriptGraphNodeBase::SetName("Branch");
48 CScriptGraphNodeBase::AddInput(EScriptGraphPortFlags::MultiLink
| EScriptGraphPortFlags::Execute
, "In");
49 CScriptGraphNodeBase::AddInput(EScriptGraphPortFlags::Data
, "Value", GetAggregateTypeId
<bool>());
51 CScriptGraphNodeBase::AddOutput(EScriptGraphPortFlags::Execute
, "True");
52 CScriptGraphNodeBase::AddOutput(EScriptGraphPortFlags::Execute
, "False");
55 void CScriptGraphBranchNode::Serialize(Serialization::IArchive
& archive
)
57 CRY_PROFILE_FUNCTION(PROFILE_LOADING_ONLY
);
59 CScriptGraphNodeBase::Serialize(archive
);
61 archive(m_bValue
, "value", "Value");
64 void CScriptGraphBranchNode::RemapGUIDs(IGUIDRemapper
& guidRemapper
)
66 CScriptGraphNodeBase::RemapGUIDs(guidRemapper
);
69 void CScriptGraphBranchNode::Compile_New(IScriptGraphNodeCompiler
& compiler
) const
71 compiler
.BindCallback(&Execute
);
73 compiler
.BindInput(EInputIdx::Value
, m_bValue
);
76 void CScriptGraphBranchNode::RegisterCreator(CScriptGraphNodeFactory
& factory
)
78 class CCreator
: public IScriptGraphNodeCreator
80 class CNodeCreationMenuCommand
: public IScriptGraphNodeCreationMenuCommand
84 // IScriptGraphNodeCreationMenuCommand
85 IScriptGraphNodePtr
Execute(const Vec2
& pos
)
87 return std::make_shared
<CScriptGraphBranchNode
>(gEnv
->pSchematyc2
->CreateGUID(), pos
);
89 // ~IScriptGraphNodeCreationMenuCommand
94 // IScriptGraphNodeCreator
95 virtual SGUID
GetTypeGUID() const override
97 return CScriptGraphBranchNode::s_typeGUID
;
100 virtual IScriptGraphNodePtr
CreateNode() override
102 return std::make_shared
<CScriptGraphBranchNode
>(gEnv
->pSchematyc2
->CreateGUID());
105 virtual void PopulateNodeCreationMenu(IScriptGraphNodeCreationMenu
& nodeCreationMenu
, const IDomainContext
& domainContext
, const IScriptGraphExtension
& graph
) override
107 nodeCreationMenu
.AddOption("Branch", "Branch on input Bool value", "", std::make_shared
<CNodeCreationMenuCommand
>());
109 // ~IScriptGraphNodeCreator
112 factory
.RegisterCreator(std::make_shared
<CCreator
>());
115 SRuntimeResult
CScriptGraphBranchNode::Execute(IObject
* pObject
, const SRuntimeActivationParams
& activationParams
, CRuntimeNodeData
& data
)
117 const bool* pValue
= data
.GetInput
<bool>(EInputIdx::Value
);
118 SCHEMATYC2_SYSTEM_ASSERT_FATAL(pValue
!= nullptr);
120 const uint32 output
= *pValue
? EOutputIdx::True
: EOutputIdx::False
;
121 return SRuntimeResult(ERuntimeStatus::Continue
, output
);