From b7d5b514e7bffd3149a99bc7f1424f8251876d85 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Mon, 26 Apr 2021 14:07:28 -0700 Subject: Serialization for workflow stuff --- core/src/Model/Workflow/Workflow.hpp | 40 +++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'core/src/Model/Workflow/Workflow.hpp') diff --git a/core/src/Model/Workflow/Workflow.hpp b/core/src/Model/Workflow/Workflow.hpp index 9c02168..db341af 100644 --- a/core/src/Model/Workflow/Workflow.hpp +++ b/core/src/Model/Workflow/Workflow.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,10 @@ public: std::span GetSourcePoints() const; std::span GetDestinationPoints(); std::span GetDestinationPoints() const; + + void DrawDebugInfo() const; + void ReadFrom(std::istream& stream); + void WriteTo(std::ostream& stream); }; class WorkflowNode { @@ -71,7 +76,7 @@ public: protected: struct InputPin { size_t Connection = WorkflowConnection::kInvalidId; - BaseValue::Kind MatchingType = BaseValue::KindInvalid; + BaseValue::Kind MatchingType = BaseValue::InvalidKind; bool ConnectionToConst = false; bool AllowsMultipleConnections = false; @@ -84,7 +89,7 @@ protected: struct OutputPin { size_t Connection = WorkflowConnection::kInvalidId; - BaseValue::Kind MatchingType = BaseValue::KindInvalid; + BaseValue::Kind MatchingType = BaseValue::InvalidKind; bool AllowsMultipleConnections = false; bool IsConnected() const; @@ -100,11 +105,14 @@ protected: std::vector mInputs; std::vector mOutputs; Vec2i mPosition; - Type mType; Kind mKind; int mDepth; public: + static const char* FormatKind(Kind kind); + static const char* FormatType(Type type); + static std::unique_ptr CreateByKind(Kind kind); + WorkflowNode(Type type, Kind kind); virtual ~WorkflowNode() = default; @@ -113,14 +121,17 @@ public: WorkflowNode(WorkflowNode&&) = default; WorkflowNode& operator=(WorkflowNode&&) = default; - Vec2i GetPosition() const; void SetPosition(const Vec2i& position); + Vec2i GetPosition() const; size_t GetId() const; - Type GetType() const; Kind GetKind() const; int GetDepth() const; + Type GetType() const; + bool IsInputNode() const; + bool IsOutputNode() const; + void ConnectInput(int nodeId, WorkflowNode& output, int outputNodeId); void DisconnectInput(int nodeId); bool IsInputConnected(int nodeId) const; @@ -131,6 +142,15 @@ public: virtual void Evaluate(WorkflowEvaluationContext& ctx) = 0; + void Draw(); + virtual void DrawExtra() {} + + void DrawDebugInfo() const; + virtual void DrawExtraDebugInfo() const {} + + virtual void ReadFrom(std::istream& istream); + virtual void WriteTo(std::ostream& ostream); + protected: InputPin& InsertInputPin(int atIdx); void RemoveInputPin(int pin); @@ -153,6 +173,9 @@ private: std::vector> mNodes; std::vector> mConstants; std::vector> mDepthGroups; + int mConnectionCount; + int mNodeCount; + int mConstantCount; bool mDepthsDirty = true; public: @@ -190,6 +213,13 @@ public: /// When `getInfo == false, the corresponding error code is returned but without/with empty payloads. GraphUpdateResult UpdateGraph(bool getInfo = true); + enum ReadResult { + ReadSuccess, + ReadInvalidVersion, + }; + ReadResult ReadFrom(std::istream& stream); + void WriteTo(std::ostream& stream); + private: std::pair AllocWorkflowConnection(); std::pair&, size_t> AllocWorkflowStep(); -- cgit v1.2.3-70-g09d2