Skip to content

Commit de4fe5a

Browse files
committed
Sockets can now support multiple types; Breaking Change: std::string NodeSocket::GetType() const was replaced with std::vector<std::string> NodeSocket::GetAllowedTypes() const; Introduced FindOutOfOrderConnectionPair() and a sorting loop to resolve processing dependencies for multi-type sockets during NodeArea JSON loading; Breaking Change: Refactored save/load logic to align with overall code style, unfortunately in new version old saves would not be read correctly; Breaking Change: Renamed NodeArea::SetMainContextMenuFunc to NodeArea::SetMainContextMenuFunction; Added static bool Node::bInputCountCheck and bool Node::bOutputCountCheck to allow specific nodes to disable input/output count checks if needed; Added numerous standard nodes (e.g., branch node, for-loop node, variable nodes, etc.); Standard nodes are not included by default—enable them with the CMake option VISUAL_NODE_SYSTEM_BUILD_STANDARD_NODES; If enabled, NodeArea will include extended functionality such as: bool SetExecutionEntryNode(Node* NewEntryNode) or bool ExecuteNodeNetwork(); Made many selection-related functions in NodeArea public for broader usability.
1 parent 0fe6f80 commit de4fe5a

98 files changed

Lines changed: 5919 additions & 295 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ project(VisualNodeSystem LANGUAGES CXX)
1010
option(VISUAL_NODE_SYSTEM_USE_EXTERNAL_IMGUI "Use an external ImGui library instead of compiling our own" OFF)
1111
option(VISUAL_NODE_SYSTEM_BUILD_SHARED_LIBS "Build VisualNodeSystem as a shared library" OFF)
1212
option(VISUAL_NODE_SYSTEM_USE_STATIC_RUNTIME "Use static runtime (/MT) instead of dynamic (/MD) for VisualNodeSystem" ON)
13+
option(VISUAL_NODE_SYSTEM_BUILD_STANDARD_NODES "Build the Visual Node System with standard nodes module" OFF)
1314
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1415

1516
if(MSVC)
@@ -66,10 +67,172 @@ file(GLOB jsoncpp_SRC
6667

6768
# *************** THIRD_PARTY END ***************
6869

70+
71+
set(BaseExecutionFlowNodes_SOURCE_FILES)
72+
set(LogicalOperatorNodes_SOURCE_FILES)
73+
set(ComparisonOperatorNodes_SOURCE_FILES)
74+
set(ArithmeticOperatorNodes_SOURCE_FILES)
75+
set(LiteralsNodes_SOURCE_FILES)
76+
set(VariablesNodes_SOURCE_FILES)
77+
set(ControlFlowNodes_SOURCE_FILES)
78+
79+
if(VISUAL_NODE_SYSTEM_BUILD_STANDARD_NODES)
80+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DVISUAL_NODE_SYSTEM_BUILD_STANDARD_NODES")
81+
82+
# *************** STANDARD_NODES ***************
83+
list(APPEND BaseExecutionFlowNodes_SOURCE_FILES
84+
"StandardNodes/ExecutionFlowNodes/BaseExecutionFlowNode.h"
85+
"StandardNodes/ExecutionFlowNodes/BaseExecutionFlowNode.cpp"
86+
)
87+
88+
list(APPEND LogicalOperatorNodes_SOURCE_FILES
89+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Logical/BaseLogicalOperatorNode.h"
90+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Logical/BaseLogicalOperatorNode.cpp"
91+
92+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Logical/LogicalANDOperatorNode.h"
93+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Logical/LogicalANDOperatorNode.cpp"
94+
95+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Logical/LogicalOROperatorNode.h"
96+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Logical/LogicalOROperatorNode.cpp"
97+
98+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Logical/LogicalXOROperatorNode.h"
99+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Logical/LogicalXOROperatorNode.cpp"
100+
101+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Logical/LogicalNOTOperatorNode.h"
102+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Logical/LogicalNOTOperatorNode.cpp"
103+
)
104+
105+
list(APPEND ComparisonOperatorNodes_SOURCE_FILES
106+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/BaseComparisonOperatorNode.h"
107+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/BaseComparisonOperatorNode.cpp"
108+
109+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/EqualNode.h"
110+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/EqualNode.cpp"
111+
112+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/NotEqualNode.h"
113+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/NotEqualNode.cpp"
114+
115+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/LessThanOrEqualNode.h"
116+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/LessThanOrEqualNode.cpp"
117+
118+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/GreaterThanOrEqualNode.h"
119+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/GreaterThanOrEqualNode.cpp"
120+
121+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/GreaterThanNode.h"
122+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/GreaterThanNode.cpp"
123+
124+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/LessThanNode.h"
125+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison/LessThanNode.cpp"
126+
)
127+
128+
list(APPEND ArithmeticOperatorNodes_SOURCE_FILES
129+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/BaseArithmeticOperatorNode.h"
130+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/BaseArithmeticOperatorNode.cpp"
131+
132+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/ArithmeticAddNode.h"
133+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/ArithmeticAddNode.cpp"
134+
135+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/ArithmeticSubtractNode.h"
136+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/ArithmeticSubtractNode.cpp"
137+
138+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/ArithmeticMultiplyNode.h"
139+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/ArithmeticMultiplyNode.cpp"
140+
141+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/ArithmeticDivideNode.h"
142+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/ArithmeticDivideNode.cpp"
143+
144+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/ArithmeticModulusNode.h"
145+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/ArithmeticModulusNode.cpp"
146+
147+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/ArithmeticPowerNode.h"
148+
"StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic/ArithmeticPowerNode.cpp"
149+
)
150+
151+
list(APPEND LiteralsNodes_SOURCE_FILES
152+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/BoolLiteralNode.h"
153+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/BoolLiteralNode.cpp"
154+
155+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/IntegerLiteralNode.h"
156+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/IntegerLiteralNode.cpp"
157+
158+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/FloatLiteralNode.h"
159+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/FloatLiteralNode.cpp"
160+
161+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/Vec2LiteralNode.h"
162+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/Vec2LiteralNode.cpp"
163+
164+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/BoolVec2LiteralNode.h"
165+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/BoolVec2LiteralNode.cpp"
166+
167+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/Vec3LiteralNode.h"
168+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/Vec3LiteralNode.cpp"
169+
170+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/BoolVec3LiteralNode.h"
171+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/BoolVec3LiteralNode.cpp"
172+
173+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/Vec4LiteralNode.h"
174+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/Vec4LiteralNode.cpp"
175+
176+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/BoolVec4LiteralNode.h"
177+
"StandardNodes/ExecutionFlowNodes/LiteralsNodes/BoolVec4LiteralNode.cpp"
178+
)
179+
180+
list(APPEND VariablesNodes_SOURCE_FILES
181+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/BoolVariableNode.h"
182+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/BoolVariableNode.cpp"
183+
184+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/IntegerVariableNode.h"
185+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/IntegerVariableNode.cpp"
186+
187+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/FloatVariableNode.h"
188+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/FloatVariableNode.cpp"
189+
190+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/Vec2VariableNode.h"
191+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/Vec2VariableNode.cpp"
192+
193+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/BoolVec2VariableNode.h"
194+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/BoolVec2VariableNode.cpp"
195+
196+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/Vec3VariableNode.h"
197+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/Vec3VariableNode.cpp"
198+
199+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/BoolVec3VariableNode.h"
200+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/BoolVec3VariableNode.cpp"
201+
202+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/Vec4VariableNode.h"
203+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/Vec4VariableNode.cpp"
204+
205+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/BoolVec4VariableNode.h"
206+
"StandardNodes/ExecutionFlowNodes/VariablesNodes/BoolVec4VariableNode.cpp"
207+
)
208+
209+
list(APPEND ControlFlowNodes_SOURCE_FILES
210+
"StandardNodes/ExecutionFlowNodes/ControlFlowNodes/BranchNode.h"
211+
"StandardNodes/ExecutionFlowNodes/ControlFlowNodes/BranchNode.cpp"
212+
213+
"StandardNodes/ExecutionFlowNodes/ControlFlowNodes/SequenceNode.h"
214+
"StandardNodes/ExecutionFlowNodes/ControlFlowNodes/SequenceNode.cpp"
215+
216+
"StandardNodes/ExecutionFlowNodes/ControlFlowNodes/LoopNode.h"
217+
"StandardNodes/ExecutionFlowNodes/ControlFlowNodes/LoopNode.cpp"
218+
219+
"StandardNodes/ExecutionFlowNodes/ControlFlowNodes/WhileLoopNode.h"
220+
"StandardNodes/ExecutionFlowNodes/ControlFlowNodes/WhileLoopNode.cpp"
221+
)
222+
# *************** STANDARD_NODES END ***************
223+
endif()
224+
69225
set(ALL_SOURCE_FILES "")
70226
list(APPEND ALL_SOURCE_FILES
71227
${VisualNodeSystem_SRC}
72228
${VisualNodeArea_SRC}
229+
${BaseExecutionFlowNodes_SOURCE_FILES}
230+
${LiteralsNodes_SOURCE_FILES}
231+
${VariablesNodes_SOURCE_FILES}
232+
${LogicalOperatorNodes_SOURCE_FILES}
233+
${ComparisonOperatorNodes_SOURCE_FILES}
234+
${ArithmeticOperatorNodes_SOURCE_FILES}
235+
${ControlFlowNodes_SOURCE_FILES}
73236
# *************** THIRD_PARTY ***************
74237
${jsoncpp_SRC}
75238
)
@@ -91,6 +254,15 @@ endif()
91254

92255
source_group("Source Files" FILES ${VisualNodeSystem_SRC})
93256
source_group("Source Files/SubSystems/VisualNodeArea/" FILES ${VisualNodeArea_SRC})
257+
if(VISUAL_NODE_SYSTEM_BUILD_STANDARD_NODES)
258+
source_group("Source Files/StandardNodes/ExecutionFlowNodes" FILES ${BaseExecutionFlowNodes_SOURCE_FILES})
259+
source_group("Source Files/StandardNodes/ExecutionFlowNodes/LiteralsNodes" FILES ${LiteralsNodes_SOURCE_FILES})
260+
source_group("Source Files/StandardNodes/ExecutionFlowNodes/VariablesNodes" FILES ${VariablesNodes_SOURCE_FILES})
261+
source_group("Source Files/StandardNodes/ExecutionFlowNodes/OperatorNodes/Logical" FILES ${LogicalOperatorNodes_SOURCE_FILES})
262+
source_group("Source Files/StandardNodes/ExecutionFlowNodes/OperatorNodes/Comparison" FILES ${ComparisonOperatorNodes_SOURCE_FILES})
263+
source_group("Source Files/StandardNodes/ExecutionFlowNodes/OperatorNodes/Arithmetic" FILES ${ArithmeticOperatorNodes_SOURCE_FILES})
264+
source_group("Source Files/StandardNodes/ExecutionFlowNodes/ControlFlowNodes" FILES ${ControlFlowNodes_SOURCE_FILES})
265+
endif()
94266
# *************** THIRD_PARTY ***************
95267
source_group("Source Files/ThirdParty/jsoncpp" FILES ${jsoncpp_SRC})
96268

GroupComment.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,33 @@ Json::Value GroupComment::ToJson()
6464
Json::Value Result;
6565

6666
Result["ID"] = ID;
67-
Result["position"]["x"] = Position.x;
68-
Result["position"]["y"] = Position.y;
69-
Result["size"]["x"] = Size.x;
70-
Result["size"]["y"] = Size.y;
71-
Result["caption"] = Caption;
67+
Result["Position"]["X"] = Position.x;
68+
Result["Position"]["Y"] = Position.y;
69+
Result["Size"]["X"] = Size.x;
70+
Result["Size"]["Y"] = Size.y;
71+
Result["Caption"] = Caption;
7272
Result["bMoveElementsWithComment"] = bMoveElementsWithComment;
73-
Result["BackgroundColor"]["x"] = BackgroundColor.x;
74-
Result["BackgroundColor"]["y"] = BackgroundColor.y;
75-
Result["BackgroundColor"]["z"] = BackgroundColor.z;
76-
Result["BackgroundColor"]["w"] = BackgroundColor.w;
73+
Result["BackgroundColor"]["X"] = BackgroundColor.x;
74+
Result["BackgroundColor"]["Y"] = BackgroundColor.y;
75+
Result["BackgroundColor"]["Z"] = BackgroundColor.z;
76+
Result["BackgroundColor"]["W"] = BackgroundColor.w;
7777

7878
return Result;
7979
}
8080

8181
void GroupComment::FromJson(Json::Value Json)
8282
{
8383
ID = Json["ID"].asCString();
84-
Position.x = Json["position"]["x"].asFloat();
85-
Position.y = Json["position"]["y"].asFloat();
86-
Size.x = Json["size"]["x"].asFloat();
87-
Size.y = Json["size"]["y"].asFloat();
88-
Caption = Json["caption"].asCString();
84+
Position.x = Json["Position"]["X"].asFloat();
85+
Position.y = Json["Position"]["Y"].asFloat();
86+
Size.x = Json["Size"]["X"].asFloat();
87+
Size.y = Json["Size"]["Y"].asFloat();
88+
Caption = Json["Caption"].asCString();
8989
bMoveElementsWithComment = Json["bMoveElementsWithComment"].asBool();
90-
BackgroundColor.x = Json["BackgroundColor"]["x"].asFloat();
91-
BackgroundColor.y = Json["BackgroundColor"]["y"].asFloat();
92-
BackgroundColor.z = Json["BackgroundColor"]["z"].asFloat();
93-
BackgroundColor.w = Json["BackgroundColor"]["w"].asFloat();
90+
BackgroundColor.x = Json["BackgroundColor"]["X"].asFloat();
91+
BackgroundColor.y = Json["BackgroundColor"]["Y"].asFloat();
92+
BackgroundColor.z = Json["BackgroundColor"]["Z"].asFloat();
93+
BackgroundColor.w = Json["BackgroundColor"]["W"].asFloat();
9494
}
9595

9696
bool GroupComment::IsHovered() const
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "BaseExecutionFlowNode.h"
2+
using namespace VisNodeSys;
3+
4+
BaseExecutionFlowNode::BaseExecutionFlowNode(bool bIsInputExecuteSocketNeeded) : Node()
5+
{
6+
Type = "BaseExecutionFlowNode";
7+
8+
if (bIsInputExecuteSocketNeeded)
9+
AddSocket(new NodeSocket(this, "EXECUTE", "", false));
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include "../../VisualNode.h"
4+
5+
#define NODE_WITH_PER_SOCKET 40
6+
7+
class BaseExecutionFlowNode : public VisNodeSys::Node
8+
{
9+
public:
10+
BaseExecutionFlowNode(bool bIsInputExecuteSocketNeeded = true);
11+
virtual ~BaseExecutionFlowNode() = default;
12+
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include "BranchNode.h"
2+
#include "../../../SubSystems/VisualNodeArea/VisualNodeArea.h"
3+
using namespace VisNodeSys;
4+
5+
BranchNode::BranchNode() : BaseExecutionFlowNode()
6+
{
7+
Type = "BranchNode";
8+
9+
SetStyle(DEFAULT);
10+
SetName("Branch");
11+
12+
TitleBackgroundColor = ImColor(31, 117, 208);
13+
TitleBackgroundColorHovered = ImColor(35, 145, 255);
14+
15+
AddSocket(new NodeSocket(this, "BOOL", "Condition", false));
16+
17+
AddSocket(new NodeSocket(this, "EXECUTE", "True", true));
18+
AddSocket(new NodeSocket(this, "EXECUTE", "False", true));
19+
20+
SetSize(ImVec2(190.0f, static_cast<float>(NODE_WITH_PER_SOCKET * std::max(Input.size(), Output.size()))));
21+
}
22+
23+
BranchNode::BranchNode(const BranchNode& Other) : BaseExecutionFlowNode(Other)
24+
{
25+
SetStyle(DEFAULT);
26+
}
27+
28+
void BranchNode::Draw()
29+
{
30+
Node::Draw();
31+
}
32+
33+
void BranchNode::SocketEvent(NodeSocket* OwnSocket, NodeSocket* ConnectedSocket, NODE_SOCKET_EVENT EventType)
34+
{
35+
Node::SocketEvent(OwnSocket, ConnectedSocket, EventType);
36+
37+
if (EventType == EXECUTE)
38+
{
39+
bool bConditionState = false;
40+
41+
if (Input[1]->GetConnectedSockets().size() > 0)
42+
{
43+
void* TempData = Input[1]->GetConnectedSockets()[0]->GetData();
44+
if (TempData != nullptr)
45+
bConditionState = *reinterpret_cast<bool*>(TempData);
46+
}
47+
48+
if (bConditionState)
49+
{
50+
if (Output[0]->GetConnectedSockets().size() > 0)
51+
ParentArea->TriggerSocketEvent(Output[0], Output[0]->GetConnectedSockets()[0], EXECUTE);
52+
}
53+
else
54+
{
55+
if (Output[1]->GetConnectedSockets().size() > 0)
56+
ParentArea->TriggerSocketEvent(Output[1], Output[1]->GetConnectedSockets()[0], EXECUTE);
57+
}
58+
}
59+
}
60+
61+
bool BranchNode::CanConnect(NodeSocket* OwnSocket, NodeSocket* CandidateSocket, char** MsgToUser)
62+
{
63+
if (!Node::CanConnect(OwnSocket, CandidateSocket, nullptr))
64+
return false;
65+
66+
return true;
67+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
#include "../BaseExecutionFlowNode.h"
3+
4+
class BranchNode : public BaseExecutionFlowNode
5+
{
6+
bool CanConnect(VisNodeSys::NodeSocket* OwnSocket, VisNodeSys::NodeSocket* CandidateSocket, char** MsgToUser);
7+
void SocketEvent(VisNodeSys::NodeSocket* OwnSocket, VisNodeSys::NodeSocket* ConnectedSocket, VisNodeSys::NODE_SOCKET_EVENT EventType);
8+
public:
9+
BranchNode();
10+
BranchNode(const BranchNode& Other);
11+
12+
void Draw();
13+
};

0 commit comments

Comments
 (0)