3#include "Engine/Network/Network.h"
4#include "Engine/Network/Node.h"
5#include "Engine/Network/Scope.h"
6#include "Engine/Network/UpdateLock.h"
7#include "Engine/NetworkGraph/NetworkGraph.h"
8#include "Engine/UndoRedo/UndoStack.h"
68 const std::string& name =
"",
69 Vector2 position = {0.f, 0.f}
172 floatT
getTime()
const {
return (frame_ - 1) / fps_; }
201 void moveNode(
NodeId nodeId, Vector2 newPos,
bool skipUndo =
false);
278 unsigned int inputIndex,
280 unsigned int outputIndex
292 return network_.
findNode(path, fromNode);
297 std::weak_ptr<prm::NodeParameter>
307 boost::signals2::signal<void(std::optional<nt::NodeId>)> displayNodeChanged;
312 boost::signals2::signal<void(std::shared_ptr<const enzo::NodePacket>)> displayGeoChanged;
315 boost::signals2::signal<void(std::shared_ptr<const enzo::NodePacket>)> selectedGeoChanged;
318 boost::signals2::signal<void(std::optional<nt::NodeId>)> primaryNodeChanged;
321 boost::signals2::signal<void(std::shared_ptr<const enzo::NodePacket>)> primaryGeoChanged;
324 boost::signals2::signal<void(std::vector<nt::NodeId> selectedNodeIds)> selectedNodesChanged;
327 boost::signals2::signal<void(
nt::NodeId)> nodeCreated;
330 boost::signals2::signal<void(
nt::NodeId)> nodeRemoved;
339 boost::signals2::signal<void()> networkCleared;
342 boost::signals2::signal<void(
nt::NodeId, Vector2)> nodePositionChanged;
345 boost::signals2::signal<void(floatT frame)> frameChanged;
348 boost::signals2::signal<void(intT startFrame, intT endFrame)> frameRangeChanged;
351 boost::signals2::signal<void(floatT fps)> fpsChanged;
354 UndoStack& undoStack() {
return undoStack_; }
366 void disconnectNode(NodeId nodeId);
369 void openInputGap(NodeId nodeId,
unsigned int fromIndex);
372 void closeInputGap(NodeId nodeId,
unsigned int fromIndex);
375 void moveInput(
const nt::Connection& connection,
unsigned int inputIndex);
380 void onNodeDirtied(nt::NodeId nodeId,
bool dirtyDependents);
384 void dirtyUnits_(
const std::vector<nt::Unit>& units);
387 void dirtyTimeDependents_();
394 nt::Network network_;
395 std::vector<enzo::nt::NodeId> selectedNodes_;
397 std::optional<NodeId> displayNode_ = std::nullopt;
399 std::optional<NodeId> primaryNode_ = std::nullopt;
403 intT startFrame_ = 1;
404 intT endFrame_ = 240;
407 UndoStack undoStack_;
Basic attribute, parameter, and node types for Enzo.
uint64_t NodeId
The unique ID assigned to each node in the network.
Definition Types.h:306
A path that references a network entity, either a node or a parameter on a node.
Definition NetworkPath.h:20
Definition NodePacket.h:9
A default path class for creation and manipulation of tree-based paths.
Definition Path.h:14
The single owner of the network's wiring and dependencies.
Definition NetworkGraph.h:24
The central coordinator of the engine's node system.
Definition NetworkManager.h:31
void setEndFrame(intT frame)
Sets the frame the playback range ends on.
Definition NetworkManager.cpp:193
std::optional< NodeId > getPrimaryNode()
Returns the node ID of the primary node, or nullopt when none.
Definition NetworkManager.cpp:152
void setDisplayNode(NodeId nodeId)
Sets given NodeId to be displayed, releasing previous display Node.
Definition NetworkManager.cpp:134
bool isValidNode(nt::NodeId nodeId)
Returns whether the node exists in the network and is valid.
Definition NetworkManager.cpp:132
intT getStartFrame() const
Returns the first frame of the playback range.
Definition NetworkManager.h:150
Node * findNode(const NetworkPath &path, NodeId fromNode=nullNode)
Resolves a node reference such as "grid1" or "../grid1" to its node.
Definition NetworkManager.h:290
auto nodes()
Returns an iterable range over all nodes in the network.
Definition NetworkManager.h:37
void clearPrimaryNode()
Clears the primary node so none is primary.
Definition NetworkManager.cpp:165
Node & getNode(nt::NodeId nodeId)
Returns a reference to the Node with the given NodeId.
Definition NetworkManager.cpp:130
void cook(enzo::nt::NodeId nodeId)
Cooks the given node.
Definition NetworkManager.cpp:319
Node * getNodeAtPath(const Path &path)
Returns the node at an exact path, or null when no node is there.
Definition NetworkManager.h:74
floatT getTime() const
Returns the current frame as seconds, where the start of frame 1 is zero.
Definition NetworkManager.h:172
void setStartFrame(intT frame)
Sets the frame the playback range starts on.
Definition NetworkManager.cpp:183
enzo::nt::UpdateLock lockUpdates()
Creates a lock object that prevents cooking until destroyed.
Definition NetworkManager.cpp:257
const std::vector< enzo::nt::NodeId > & getSelectedNodes()
Returns the NodeIds for all selected nodes.
Definition NetworkManager.cpp:291
void setSelectedNode(NodeId nodeId, bool selected, bool add=false)
Set the selection state for the given node.
Definition NetworkManager.cpp:222
enzo::NodePacket cookOutput(enzo::nt::NodeId nodeId, unsigned int outputIndex)
Returns a copy of one of a node's outputs.
Definition NetworkManager.cpp:337
NetworkManager(const NetworkManager &obj)=delete
Deleted the copy constructor for singleton.
void moveNode(NodeId nodeId, Vector2 newPos, bool skipUndo=false)
Moves a node to a new position, pushing an undo command.
Definition NetworkManager.cpp:38
void clearDisplayFlag()
Clears the display flag so no node is displayed.
Definition NetworkManager.cpp:145
floatT getFrame() const
Returns the frame the scene sits on.
Definition NetworkManager.h:144
unsigned int getInputCount(NodeId nodeId)
Returns how many inputs a node currently takes.
Definition NetworkManager.cpp:343
void setSelectedNodes(std::vector< enzo::nt::NodeId > nodeIds)
Replaces the entire selection with the given set of nodes.
Definition NetworkManager.cpp:293
void deleteNode(NodeId nodeId)
Deletes a node, pushing an undo command.
Definition NetworkManager.cpp:52
intT getEndFrame() const
Returns the last frame of the playback range.
Definition NetworkManager.h:153
void _reset()
For use in unit tests, resets the state of the node.
Definition NetworkManager.cpp:493
NodeId createNode(const nt::NodeType &nodeType, const Path &parent=Path("/"), const std::string &name="", Vector2 position={0.f, 0.f})
Creates a new node inside a scope.
Definition NetworkManager.cpp:20
void disconnectNodes(const nt::Connection &connection)
Removes a wired connection between two nodes.
Definition NetworkManager.cpp:397
void createNodeWithId(NodeId nodeId, const nt::NodeType &nodeType, const Path &path, Vector2 position)
Creates a node with an identity the caller dictates rather than one picked here.
Definition NetworkManager.cpp:83
Scope * getScope(const Path &path)
Returns the scope at a path, or null when no scope sits there.
Definition NetworkManager.h:78
void setFrame(floatT frame)
Moves the scene to a frame, clamped to the playback range.
Definition NetworkManager.cpp:172
void setFps(floatT fps)
Sets how many frames make up a second of playback.
Definition NetworkManager.cpp:202
nt::Network & network()
Returns the network holding every node, its wiring, and its scopes.
Definition NetworkManager.h:34
void clear()
Clears all nodes and resets the network to its initial state.
Definition NetworkManager.cpp:307
nt::NetworkGraph & graph()
Returns the graph that owns the network's wiring and dependencies.
Definition NetworkManager.h:260
floatT getFps() const
Returns how many frames make up a second of playback.
Definition NetworkManager.h:164
void update()
Cooks dirtied nodes, is called automatically.
Definition NetworkManager.cpp:259
std::weak_ptr< prm::NodeParameter > findParameter(const NetworkPath &path, NodeId fromNode=nullNode)
Resolves a parameter reference such as "grid1.tx" to its parameter.
Definition NetworkManager.h:298
std::vector< NodeId > getChildNodeIds(const Path &scope)
Returns the ids of the nodes living directly inside a scope, in no particular order.
Definition NetworkManager.h:82
std::optional< NodeId > getDisplayNode()
Returns the node ID for the node with its display flag set. There can only be only be one node displa...
Definition NetworkManager.cpp:461
nt::Connection connectNodes(NodeId inputNodeId, unsigned int inputIndex, NodeId outputNodeId, unsigned int outputIndex)
Wires one node's output into another node's input.
Definition NetworkManager.cpp:356
void setPrimaryNode(NodeId nodeId)
Sets the given NodeId as the primary node, releasing the previous one.
Definition NetworkManager.cpp:154
static NetworkManager & getInstance()
Returns a reference to the singleton instance.
Definition NetworkManager.cpp:124
Every node in a scene, their wiring, and the scopes they live in.
Definition Network.h:30
Node * getNodeAtPath(const Path &path)
Returns the node at an exact path, or null when no node is there.
Definition Network.cpp:26
std::vector< NodeId > getChildNodeIds(const Path &scope)
Returns the ids of the nodes living directly inside a scope, in no particular order.
Definition Network.cpp:35
NetworkGraph & graph()
Returns the wiring and dependencies between the nodes.
Definition Network.h:103
std::weak_ptr< prm::NodeParameter > findParameter(const NetworkPath &path, NodeId fromNode=nullNode)
Resolves a parameter reference to its parameter.
Definition Network.cpp:102
Node * findNode(const NetworkPath &path, NodeId fromNode=nullNode)
Resolves a node reference to its node.
Definition Network.cpp:88
Scope * getScope(const Path &path)
Returns the scope at a path, or null when no scope sits there.
Definition Network.cpp:64
auto nodes()
Returns an iterable range over every node, yielding {NodeId, Node&} pairs.
Definition Network.h:43
The unique runtime representation of a node.
Definition Node.h:18
One place nodes live, either the root or the inside of a node that holds one.
Definition Scope.h:26
Definition UndoStack.h:11
Prevents updates on the network manager while in scope.
Definition UpdateLock.h:15
One wired link between two nodes, the ground truth of the network's wiring.
Definition Connection.h:20
Everything every node of one kind shares.
Definition NodeType.h:39