aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/Workflow/Workflow.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/Model/Workflow/Workflow.hpp')
-rw-r--r--core/src/Model/Workflow/Workflow.hpp100
1 files changed, 56 insertions, 44 deletions
diff --git a/core/src/Model/Workflow/Workflow.hpp b/core/src/Model/Workflow/Workflow.hpp
index 7bcd349..79c2b2f 100644
--- a/core/src/Model/Workflow/Workflow.hpp
+++ b/core/src/Model/Workflow/Workflow.hpp
@@ -17,20 +17,22 @@
class WorkflowConnection
{
public:
- static constexpr auto kInvalidId = std::numeric_limits<size_t>::max();
+ static constexpr auto kInvalidId = std::numeric_limits<uint32_t>::max();
- /// Used for `LinkId` when interfacing with imgui node editor. Runtime only (not saved to disk and generated when loading).
- size_t UniqueId;
- size_t SourceNode;
- size_t DestinationNode;
- int SourcePin;
- int DestinationPin;
+ uint32_t Id;
+ uint32_t SourceNode;
+ uint32_t SourcePin;
+ uint32_t DestinationNode;
+ uint32_t DestinationPin;
public:
WorkflowConnection();
bool IsValid() const;
+ /// Used for `LinkId` when interfacing with imgui node editor. Runtime only (not saved to disk and generated when loading).
+ size_t GetLinkId() const;
+
void DrawDebugInfo() const;
void ReadFrom(std::istream& stream);
void WriteTo(std::ostream& stream);
@@ -39,7 +41,8 @@ public:
class WorkflowNode
{
public:
- static constexpr auto kInvalidId = std::numeric_limits<size_t>::max();
+ static constexpr auto kInvalidId = std::numeric_limits<uint32_t>::max();
+ static constexpr auto kInvalidPinId = std::numeric_limits<uint32_t>::max();
enum Type
{
@@ -64,16 +67,13 @@ public:
KindCount = InvalidKind,
};
-protected:
struct InputPin
{
- /// Equivalent of `PinId` when interfacing with imgui node editor. Runtime only (not saved to disk and generated when loading).
- size_t UniqueId;
- size_t Connection = WorkflowConnection::kInvalidId;
+ uint32_t Connection = WorkflowConnection::kInvalidId;
BaseValue::Kind MatchingType = BaseValue::InvalidKind;
bool ConnectionToConst = false;
- /// A constant connection connects from a user-specified constant value, feeding to a valid \c Destination and \c DestinationPin (i.e. input pins).
+ /// A constant connection connects from a user-specified constant value, feeding to a valid \c DestinationNode and \c DestinationPin (i.e. input pins).
bool IsConstantConnection() const;
bool IsConnected() const;
BaseValue::Kind GetMatchingType() const;
@@ -81,26 +81,22 @@ protected:
struct OutputPin
{
- /// Equivalent of `PinId` when interfacing with imgui node editor. Runtime only (not saved to disk and generated when loading).
- size_t UniqueId;
- size_t Connection = WorkflowConnection::kInvalidId;
+ uint32_t Connection = WorkflowConnection::kInvalidId;
BaseValue::Kind MatchingType = BaseValue::InvalidKind;
- bool AllowsMultipleConnections = false;
bool IsConnected() const;
BaseValue::Kind GetMatchingType() const;
};
+protected:
friend class Workflow;
friend class WorkflowEvaluationContext;
Workflow* mWorkflow;
- /// Equivalent of `NodeId` when interfacing with imgui node editor. Runtime only (not saved to disk and generated when loading).
- size_t mUniqueId;
- size_t mId;
std::vector<InputPin> mInputs;
std::vector<OutputPin> mOutputs;
Vec2i mPosition;
+ uint32_t mId;
Kind mKind;
int mDepth;
@@ -120,7 +116,9 @@ public:
void SetPosition(const Vec2i& position);
Vec2i GetPosition() const;
- size_t GetId() const;
+ uint32_t GetId() const;
+ /// Used for `NodeId` when interfacing with imgui node editor. Runtime only (not saved to disk and generated when loading).
+ size_t GetNodeId() const;
Kind GetKind() const;
int GetDepth() const;
@@ -128,13 +126,15 @@ public:
bool IsInputNode() const;
bool IsOutputNode() const;
- void ConnectInput(int nodeId, WorkflowNode& output, int outputNodeId);
- void DisconnectInput(int nodeId);
- bool IsInputConnected(int nodeId) const;
+ void ConnectInput(uint32_t pinId, WorkflowNode& output, uint32_t outputNodeId);
+ void DisconnectInput(uint32_t pinId);
+ const InputPin& GetInputPin(uint32_t pinId)const ;
+ size_t GetInputPinUniqueId(uint32_t pinId) const;
- void ConnectOutput(int nodeId, WorkflowNode& input, int inputNodeId);
- void DisconnectOutput(int nodeId);
- bool IsOutputConnected(int nodeId) const;
+ void ConnectOutput(uint32_t pinId, WorkflowNode& input, uint32_t inputNodeId);
+ void DisconnectOutput(uint32_t pinId);
+ const OutputPin& GetOutputPin(uint32_t pinId)const ;
+ size_t GetOutputPinUniqueId(uint32_t pinId) const;
virtual void Evaluate(WorkflowEvaluationContext& ctx) = 0;
@@ -157,20 +157,20 @@ protected:
/* For \c Workflow to invoke, override by implementations */
- void OnAttach(Workflow& workflow, size_t newId) {}
- void OnDetach() {}
+ void OnAttach(Workflow& workflow, uint32_t newId);
+ void OnDetach();
};
class Workflow
{
private:
+ friend class WorkflowNode;
friend class WorkflowEvaluationContext;
- size_t mUniqueId = 0;
std::vector<WorkflowConnection> mConnections;
std::vector<std::unique_ptr<WorkflowNode>> mNodes;
std::vector<std::unique_ptr<BaseValue>> mConstants;
- std::vector<std::vector<size_t>> mDepthGroups;
+ std::vector<std::vector<uint32_t>> mDepthGroups;
int mConnectionCount;
int mNodeCount;
int mConstantCount;
@@ -186,23 +186,36 @@ public:
const std::vector<std::unique_ptr<BaseValue>>& GetConstants() const;
std::vector<std::unique_ptr<BaseValue>>& GetConstants();
- WorkflowConnection* GetConnectionById(size_t id);
- WorkflowNode* GetStepById(size_t id);
- BaseValue* GetConstantById(size_t id);
+ WorkflowConnection* GetConnectionById(uint32_t id);
+ WorkflowNode* GetNodeById(uint32_t id);
+ BaseValue* GetConstantById(uint32_t id);
+
+ struct GlobalPinId
+ {
+ WorkflowNode* Node;
+ uint32_t PinId;
+ /// true => input pin
+ /// false => output pin
+ bool IsOutput;
+ };
+
+ /// `pinId` should be the `UniqueId` of a pin from a node that's within this workflow.
+ GlobalPinId DisassembleGlobalPinId(size_t id);
+ size_t FabricateGlobalPinId(const WorkflowNode& node, uint32_t pinId, bool isOutput) const;
- const std::vector<std::vector<size_t>>& GetDepthGroups() const;
+ const std::vector<std::vector<uint32_t>>& GetDepthGroups() const;
bool DoesDepthNeedsUpdate() const;
/* Graph mutation */
- void AddStep(std::unique_ptr<WorkflowNode> step);
- void RemoveStep(size_t id);
+ void AddNode(std::unique_ptr<WorkflowNode> step);
+ void RemoveNode(uint32_t id);
- void RemoveConnection(size_t id);
+ void RemoveConnection(uint32_t id);
- bool Connect(WorkflowNode& sourceNode, int sourcePin, WorkflowNode& destinationNode, int destinationPin);
- bool DisconnectBySource(WorkflowNode& sourceNode, int sourcePin);
- bool DisconnectByDestination(WorkflowNode& destinationNode, int destinationPin);
+ bool Connect(WorkflowNode& sourceNode, uint32_t sourcePin, WorkflowNode& destinationNode, uint32_t destinationPin);
+ bool DisconnectBySource(WorkflowNode& sourceNode, uint32_t sourcePin);
+ bool DisconnectByDestination(WorkflowNode& destinationNode, uint32_t destinationPin);
/* Graph rebuild */
@@ -218,12 +231,12 @@ public:
struct UnsatisfiedDependencies
{
- std::vector<size_t> UnsatisfiedNodes;
+ std::vector<uint32_t> UnsatisfiedNodes;
};
struct UnreachableNodes
{
- std::vector<size_t> UnreachableNodes;
+ std::vector<uint32_t> UnreachableNodes;
};
using T = std::variant<
@@ -246,7 +259,6 @@ public:
void WriteTo(std::ostream& stream);
private:
- size_t AllocUniqueId();
std::pair<WorkflowConnection&, size_t> AllocWorkflowConnection();
std::pair<std::unique_ptr<WorkflowNode>&, size_t> AllocWorkflowStep();
};