Enzo
Loading...
Searching...
No Matches
NetworkGraph.h
1#pragma once
2#include "Engine/Core/Types.h"
3#include "Engine/NetworkGraph/Connection.h"
4#include "Engine/NetworkGraph/Unit.h"
5#include <optional>
6#include <unordered_map>
7#include <unordered_set>
8#include <vector>
9
10namespace enzo::nt {
11
24{
25 public:
27 void connect(const Connection& connection);
28
30 void disconnect(const Connection& connection);
31
33 std::vector<Connection> getInputs(OpId target) const;
34
37 std::optional<Connection> getInputConnection(OpId target, unsigned int inputSlot) const;
38
40 std::vector<Connection> getOutputs(OpId source) const;
41
45 void setCapturedDependencies(const Unit& dependent, const std::vector<Unit>& dependencies);
46
48 void removeNode(OpId opId);
49
51 void clear();
52
55 std::vector<OpId> getCookOrder(OpId target) const;
56
60 std::vector<Unit> getDependents(const Unit& changed) const;
61
62 private:
63 using ConnectionMap = std::unordered_map<OpId, std::vector<Connection>>;
64 using CapturedMap = std::unordered_map<Unit, std::vector<Unit>>;
65
67 static void eraseConnection_(ConnectionMap& side, OpId key, const Connection& connection);
68
70 static void eraseConnectionsTouching_(ConnectionMap& side, OpId opId);
71
73 static void eraseCapturedTouching_(CapturedMap& map, OpId opId);
74
76 static void eraseUnit_(CapturedMap& map, const Unit& key, const Unit& value);
77
79 static void addDependent_(
80 const Unit& unit,
81 std::vector<Unit>& dependents,
82 std::unordered_set<Unit>& seen,
83 std::vector<Unit>& pending
84 );
85
87 void addToCookOrder_(
88 OpId opId,
89 std::vector<OpId>& opOrder,
90 std::unordered_set<OpId>& addedOps,
91 std::unordered_set<OpId>& opsBeingAdded
92 ) const;
93
94 // Input connections keyed by the downstream node.
95 ConnectionMap byTarget_;
96 // Output connections keyed by the upstream node.
97 ConnectionMap bySource_;
98 // Captured edges are mixed granularity. The source is stored at node level
99 // since dirtying is node wide, while the reader is stored per parameter
100 // component so re-evaluating one component leaves the others intact.
101 // getDependents collapses the reader back to its node to bridge the two.
102
103 // Captured readers keyed by the node they read.
104 CapturedMap capturedDependents_;
105 // Captured reads keyed by the reading parameter component.
106 CapturedMap capturedDependencies_;
107};
108
109} // namespace enzo::nt
Basic attribute, parameter, and node types for Enzo.
uint64_t OpId
The unique ID assigned to each node in the network.
Definition Types.h:137
The single owner of the network's wiring and dependencies.
Definition NetworkGraph.h:24
void removeNode(OpId opId)
Removes every connection and captured edge touching the node.
Definition NetworkGraph.cpp:114
std::vector< OpId > getCookOrder(OpId target) const
Returns the nodes to cook before target, in cook order.
Definition NetworkGraph.cpp:187
void disconnect(const Connection &connection)
Removes a wired connection between two nodes.
Definition NetworkGraph.cpp:14
std::vector< Unit > getDependents(const Unit &changed) const
Returns everything that depends on changed, directly or through a chain.
Definition NetworkGraph.cpp:224
std::vector< Connection > getInputs(OpId target) const
Returns the connections feeding target, ordered by input slot.
Definition NetworkGraph.cpp:45
std::vector< Connection > getOutputs(OpId source) const
Returns the connections leaving source.
Definition NetworkGraph.cpp:67
void setCapturedDependencies(const Unit &dependent, const std::vector< Unit > &dependencies)
Replaces every captured dependency of one parameter at once.
Definition NetworkGraph.cpp:74
void connect(const Connection &connection)
Records a wired connection between two nodes.
Definition NetworkGraph.cpp:8
std::optional< Connection > getInputConnection(OpId target, unsigned int inputSlot) const
Returns the connection on one input slot of target, if any.
Definition NetworkGraph.cpp:56
void clear()
Empties the graph.
Definition NetworkGraph.cpp:179
One wired link between two nodes, the ground truth of the network's wiring.
Definition Connection.h:20
A point in the network graph, either an operator output or a parameter.
Definition Unit.h:20