Skip to content

Commit 746edae

Browse files
committed
Replaced raw function pointers with std::function in NodeArea class; Breaking Change: NodeArea::RunOnEachConnectedNode was erroneously running the function on the node itself, this has been fixed.
1 parent 765f0b8 commit 746edae

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

SubSystems/VisualNodeArea/VisualNodeArea.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void NodeArea::Update()
5858
Render();
5959
}
6060

61-
void NodeArea::SetMainContextMenuFunction(void(*Function)())
61+
void NodeArea::SetMainContextMenuFunction(const std::function<void()>& Function)
6262
{
6363
MainContextMenuFunction = Function;
6464
}

SubSystems/VisualNodeArea/VisualNodeArea.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ namespace VisNodeSys
190190
void DeleteNode(const Node* Node);
191191
size_t GetNodeCount() const;
192192
void AddNodeEventCallback(std::function<void(Node*, NODE_EVENT)> Func);
193-
void RunOnEachNode(void(*Func)(Node*));
194-
void RunOnEachConnectedNode(Node* StartNode, void(*Func)(Node*));
193+
void RunOnEachNode(const std::function<void(Node*)>& Function);
194+
void RunOnEachConnectedNode(Node* StartNode, const std::function<void(Node*)>& Function);
195195
void PropagateUpdateToConnectedNodes(const Node* CallerNode) const;
196196

197197
bool TriggerSocketEvent(NodeSocket* CallerNodeSocket, NodeSocket* TriggeredNodeSocket, NODE_SOCKET_EVENT EventType);
@@ -209,7 +209,7 @@ namespace VisNodeSys
209209
std::vector<RerouteNode*> GetRerouteNodesInGroupComment(GroupComment* GroupCommentToCheck) const;
210210
std::vector<GroupComment*> GetGroupCommentsInGroupComment(GroupComment* GroupCommentToCheck) const;
211211

212-
void SetMainContextMenuFunction(void(*Function)());
212+
void SetMainContextMenuFunction(const std::function<void()>& Function);
213213

214214
void GetAllElementsAABB(ImVec2& Min, ImVec2& Max) const;
215215
ImVec2 GetAllElementsAABBCenter() const;
@@ -312,7 +312,7 @@ namespace VisNodeSys
312312
ImVec2 Position;
313313
ImVec2 Size;
314314
ImVec2 RenderOffset = ImVec2(0.0, 0.0);
315-
void(*MainContextMenuFunction)() = nullptr;
315+
std::function<void()> MainContextMenuFunction = nullptr;
316316
void RenderDefaultMainContextMenu(ImVec2 LocalMousePosition);
317317
std::vector<std::function<void(Node*, NODE_EVENT)>> NodeEventsCallbacks;
318318
std::queue<SocketEvent> SocketEventQueue;

SubSystems/VisualNodeArea/VisualNodeAreaLogic.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,15 @@ bool NodeArea::IsConnected(const Node* OutNode, std::string OutSocketID, const N
391391
return IsConnected(OutNode, OutSocketIndex, InNode, InSocketIndex);
392392
}
393393

394-
void NodeArea::RunOnEachNode(void(*Func)(Node*))
394+
void NodeArea::RunOnEachNode(const std::function<void(Node*)>& Function)
395395
{
396-
if (Func != nullptr)
397-
std::for_each(Nodes.begin(), Nodes.end(), Func);
396+
if (Function != nullptr)
397+
std::for_each(Nodes.begin(), Nodes.end(), Function);
398398
}
399399

400-
void NodeArea::RunOnEachConnectedNode(Node* StartNode, void(*Func)(Node*))
400+
void NodeArea::RunOnEachConnectedNode(Node* StartNode, const std::function<void(Node*)>& Function)
401401
{
402-
if (Func == nullptr)
402+
if (Function == nullptr)
403403
return;
404404

405405
static std::unordered_map<Node*, bool> SeenNodes;
@@ -415,9 +415,13 @@ void NodeArea::RunOnEachConnectedNode(Node* StartNode, void(*Func)(Node*))
415415
};
416416

417417
std::vector<Node*> CurrentNodes;
418-
CurrentNodes.push_back(StartNode);
419-
if (bWasNodeSeen(StartNode))
420-
return;
418+
std::vector<Node*> NewNodes = StartNode->GetNodesConnectedToOutput();
419+
for (size_t j = 0; j < NewNodes.size(); j++)
420+
{
421+
CurrentNodes.push_back(NewNodes[j]);
422+
if (bWasNodeSeen(NewNodes[j]))
423+
return;
424+
}
421425

422426
while (!IsEmptyOrFilledByNulls(CurrentNodes))
423427
{
@@ -430,7 +434,7 @@ void NodeArea::RunOnEachConnectedNode(Node* StartNode, void(*Func)(Node*))
430434
continue;
431435
}
432436

433-
Func(CurrentNodes[i]);
437+
Function(CurrentNodes[i]);
434438

435439
std::vector<Node*> NewNodes = CurrentNodes[i]->GetNodesConnectedToOutput();
436440
for (size_t j = 0; j < NewNodes.size(); j++)

0 commit comments

Comments
 (0)