Commit: 73334782202438be7aaa4b443ee356a23547fa50
Author: Jacques Lucke
Date:   Fri Mar 1 13:41:54 2019 +0100
Branches: functions
https://developer.blender.org/rB73334782202438be7aaa4b443ee356a23547fa50

refactor function generation from data flow nodes

===================================================================

M       source/blender/functions/CMakeLists.txt
M       source/blender/functions/FN_data_flow_nodes.hpp
M       source/blender/functions/FN_functions.hpp
M       source/blender/functions/c_wrapper.cpp
A       source/blender/functions/frontends/data_flow_nodes/builder.cpp
A       source/blender/functions/frontends/data_flow_nodes/builder.hpp
A       
source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
A       
source/blender/functions/frontends/data_flow_nodes/function_generation.hpp
M       source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
M       source/blender/functions/frontends/data_flow_nodes/graph_generation.hpp
A       source/blender/functions/frontends/data_flow_nodes/inserters.cpp
A       source/blender/functions/frontends/data_flow_nodes/inserters.hpp
D       source/blender/functions/frontends/data_flow_nodes/nodes.cpp
D       source/blender/functions/frontends/data_flow_nodes/nodes.hpp
A       source/blender/functions/frontends/data_flow_nodes/registry.hpp
M       source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
A       source/blender/functions/frontends/data_flow_nodes/test_sockets.cpp
A       source/blender/functions/frontends/data_flow_nodes/util_wrappers.hpp
R068    source/blender/functions/frontends/data_flow_nodes/socket_inputs.cpp    
source/blender/functions/functions/socket_input.cpp
A       source/blender/functions/functions/socket_input.hpp

===================================================================

diff --git a/source/blender/functions/CMakeLists.txt 
b/source/blender/functions/CMakeLists.txt
index cf467a9eada..15c49a3854f 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -47,13 +47,21 @@ set(SRC
        functions/scalar_math.cpp
        functions/vectors.hpp
        functions/vectors.cpp
+       functions/socket_input.hpp
+       functions/socket_input.cpp
 
-       frontends/data_flow_nodes/nodes.hpp
-       frontends/data_flow_nodes/nodes.cpp
+       frontends/data_flow_nodes/builder.hpp
+       frontends/data_flow_nodes/builder.cpp
+       frontends/data_flow_nodes/function_generation.hpp
+       frontends/data_flow_nodes/function_generation.cpp
        frontends/data_flow_nodes/graph_generation.hpp
        frontends/data_flow_nodes/graph_generation.cpp
-       frontends/data_flow_nodes/socket_inputs.cpp
+       frontends/data_flow_nodes/inserters.hpp
+       frontends/data_flow_nodes/inserters.cpp
+       frontends/data_flow_nodes/registry.hpp
        frontends/data_flow_nodes/test_nodes.cpp
+       frontends/data_flow_nodes/test_sockets.cpp
+       frontends/data_flow_nodes/util_wrappers.hpp
 )
 
 blender_add_lib(bf_functions "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/functions/FN_data_flow_nodes.hpp 
b/source/blender/functions/FN_data_flow_nodes.hpp
index 43629104aff..599b518ed1d 100644
--- a/source/blender/functions/FN_data_flow_nodes.hpp
+++ b/source/blender/functions/FN_data_flow_nodes.hpp
@@ -1,4 +1,3 @@
 #pragma once
 
-#include "frontends/data_flow_nodes/graph_generation.hpp"
-#include "frontends/data_flow_nodes/nodes.hpp"
\ No newline at end of file
+#include "frontends/data_flow_nodes/function_generation.hpp"
\ No newline at end of file
diff --git a/source/blender/functions/FN_functions.hpp 
b/source/blender/functions/FN_functions.hpp
index e70482398a8..59903af56ce 100644
--- a/source/blender/functions/FN_functions.hpp
+++ b/source/blender/functions/FN_functions.hpp
@@ -3,4 +3,5 @@
 #include "./functions/object_input.hpp"
 #include "./functions/random.hpp"
 #include "./functions/scalar_math.hpp"
-#include "./functions/vectors.hpp"
\ No newline at end of file
+#include "./functions/vectors.hpp"
+#include "./functions/socket_input.hpp"
\ No newline at end of file
diff --git a/source/blender/functions/c_wrapper.cpp 
b/source/blender/functions/c_wrapper.cpp
index 8c82a28d671..476300a6af8 100644
--- a/source/blender/functions/c_wrapper.cpp
+++ b/source/blender/functions/c_wrapper.cpp
@@ -18,7 +18,6 @@ WRAPPERS(const FN::TupleCallBody *, FnTupleCallBody);
 
 void FN_initialize()
 {
-       FN::DataFlowNodes::initialize();
 }
 
 void FN_function_call(FnTupleCallBody fn_call, FnTuple fn_in, FnTuple fn_out)
@@ -167,13 +166,12 @@ FnFunction FN_tree_to_function(bNodeTree *btree)
 {
        TIMEIT("Tree to function");
        BLI_assert(btree);
-       auto fgraph = FN::DataFlowNodes::btree_to_graph(btree);
-       //std::cout << fgraph.graph()->to_dot() << std::endl;
-
-       auto fn = FN::SharedFunction::New("Function from Node Tree", 
fgraph.signature());
-       fn->add_body(FN::function_graph_to_callable(fgraph));
+       auto fn_ = FN::DataFlowNodes::generate_function(btree);
+       if (!fn_.has_value()) {
+               return nullptr;
+       }
 
-       BLI::RefCounted<FN::Function> *fn_ref = fn.refcounter();
+       BLI::RefCounted<FN::Function> *fn_ref = fn_.value().refcounter();
        fn_ref->incref();
        return wrap(fn_ref);
 }
diff --git a/source/blender/functions/frontends/data_flow_nodes/builder.cpp 
b/source/blender/functions/frontends/data_flow_nodes/builder.cpp
new file mode 100644
index 00000000000..561f3f1963d
--- /dev/null
+++ b/source/blender/functions/frontends/data_flow_nodes/builder.cpp
@@ -0,0 +1,63 @@
+#include "builder.hpp"
+
+#include "DNA_node_types.h"
+#include "util_wrappers.hpp"
+
+namespace FN { namespace DataFlowNodes {
+
+       const Node *Builder::insert_function(SharedFunction &function)
+       {
+               return m_graph->insert(function);
+       }
+
+       void Builder::insert_link(Socket a, Socket b)
+       {
+               m_graph->link(a, b);
+       }
+
+       void Builder::map_socket(Socket socket, bNodeSocket *bsocket)
+       {
+               m_socket_map.add(bsocket, socket);
+       }
+
+       void Builder::map_sockets(const Node *node, struct bNode *bnode)
+       {
+               uint input_index = 0;
+               for (bNodeSocket *bsocket : bSocketList(&bnode->inputs)) {
+                       this->map_socket(node->input(input_index), bsocket);
+                       input_index++;
+               }
+
+               uint output_index = 0;
+               for (bNodeSocket *bsocket : bSocketList(&bnode->outputs)) {
+                       this->map_socket(node->output(output_index), bsocket);
+                       output_index++;
+               }
+       }
+
+       void Builder::map_input(Socket socket, struct bNode *bnode, uint index)
+       {
+               BLI_assert(socket.is_input());
+               auto bsocket = (bNodeSocket *)BLI_findlink(&bnode->inputs, 
index);
+               this->map_socket(socket, bsocket);
+       }
+
+       void Builder::map_output(Socket socket, struct bNode *bnode, uint index)
+       {
+               BLI_assert(socket.is_output());
+               auto bsocket = (bNodeSocket *)BLI_findlink(&bnode->outputs, 
index);
+               this->map_socket(socket, bsocket);
+       }
+
+
+       struct bNodeTree *BuilderContext::btree() const
+       {
+               return m_btree;
+       }
+
+       struct ID *BuilderContext::btree_id() const
+       {
+               return &m_btree->id;
+       }
+
+} } /* namespace FN::DataFlowNodes */
\ No newline at end of file
diff --git a/source/blender/functions/frontends/data_flow_nodes/builder.hpp 
b/source/blender/functions/frontends/data_flow_nodes/builder.hpp
new file mode 100644
index 00000000000..00468d29895
--- /dev/null
+++ b/source/blender/functions/frontends/data_flow_nodes/builder.hpp
@@ -0,0 +1,47 @@
+#pragma once
+
+#include "FN_core.hpp"
+
+struct bNode;
+struct bNodeLink;
+struct bNodeTree;
+struct bNodeSocket;
+struct ID;
+
+namespace FN { namespace DataFlowNodes {
+
+       using SocketMap = SmallMap<struct bNodeSocket *, Socket>;
+
+       class Builder {
+       private:
+               SharedDataFlowGraph &m_graph;
+               SocketMap &m_socket_map;
+
+       public:
+               Builder(
+                       SharedDataFlowGraph &graph,
+                       SocketMap &socket_map)
+                       : m_graph(graph), m_socket_map(socket_map) {}
+
+               const Node *insert_function(SharedFunction &function);
+               void insert_link(Socket a, Socket b);
+
+               void map_socket(Socket socket, struct bNodeSocket *bsocket);
+               void map_sockets(const Node *node, struct bNode *bnode);
+               void map_input(Socket socket, struct bNode *bnode, uint index);
+               void map_output(Socket socket, struct bNode *bnode, uint index);
+       };
+
+       class BuilderContext {
+       private:
+               struct bNodeTree *m_btree;
+
+       public:
+               BuilderContext(struct bNodeTree *btree)
+                       : m_btree(btree) {}
+
+               bNodeTree *btree() const;
+               ID *btree_id() const;
+       };
+
+} }
\ No newline at end of file
diff --git 
a/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp 
b/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
new file mode 100644
index 00000000000..af0ea9097f0
--- /dev/null
+++ b/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
@@ -0,0 +1,22 @@
+#include "function_generation.hpp"
+#include "graph_generation.hpp"
+
+#include "DNA_node_types.h"
+
+namespace FN { namespace DataFlowNodes {
+
+       Optional<SharedFunction> generate_function(bNodeTree *btree)
+       {
+               Optional<FunctionGraph> fgraph_ = 
generate_function_graph(btree);
+               if (!fgraph_.has_value()) {
+                       return {};
+               }
+
+               FunctionGraph fgraph = fgraph_.value();
+
+               auto fn = SharedFunction::New(btree->id.name, 
fgraph.signature());
+               fn->add_body(function_graph_to_callable(fgraph));
+               return fn;
+       }
+
+} } /* namespace FN::DataFlowNodes */
\ No newline at end of file
diff --git 
a/source/blender/functions/frontends/data_flow_nodes/function_generation.hpp 
b/source/blender/functions/frontends/data_flow_nodes/function_generation.hpp
new file mode 100644
index 00000000000..42edd1fcc41
--- /dev/null
+++ b/source/blender/functions/frontends/data_flow_nodes/function_generation.hpp
@@ -0,0 +1,12 @@
+#pragma once
+
+#include "FN_core.hpp"
+#include "BLI_optional.hpp"
+
+struct bNodeTree;
+
+namespace FN { namespace DataFlowNodes {
+
+       Optional<SharedFunction> generate_function(struct bNodeTree *btree);
+
+} } /* namespace FN::DataFlowNodes */
\ No newline at end of file
diff --git 
a/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp 
b/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
index 54248b8f4b7..520ab245517 100644
--- a/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
@@ -1,10 +1,16 @@
 #include "graph_generation.hpp"
 
+#include "inserters.hpp"
+#include "util_wrappers.hpp"
+
+#include "DNA_node_types.h"
+#include "FN_types.hpp"
+
 namespace FN { namespace DataFlowNodes {
 
        using namespace Types;
 
-       static SharedType &get_type_of_socket(bNodeTree *UNUSED(btree), 
bNodeSocket *bsocket)
+       static SharedType &get_type_of_socket(bNodeSocket *bsocket)
        {
                if (STREQ(bsocket->idname, "fn_FloatSocket")) {
                        return get_float_type();
@@ -21,51 +27,6 @@ namespace FN { namespace DataFlowNodes {
                }
        }
 
-
-       static void insert_input_node(
-               bNodeTree *btree,
-               bNode *bnode,
-               SharedDataFlowGraph &graph,
-               SocketMap &socket_map)
-       {
-               OutputParameters outputs;
-               for (bNodeSocket *bsocket : bSocketList(&bnode->outputs)) {
-                       SharedType &type = get_type_of_socket(btree, bsocket);
-                       outputs.append(OutputParameter(bsocket->name, type));
-               }
-
-               auto fn = SharedFunction::New("Function Input", Signature({}, 
outputs));
-               const Node *node = graph->insert(fn);
-
-               uint i = 0;
-               for (bNodeSocket *bsocket : bSocketList(&bnode->outputs)) {
-                       socket_map.add(bsocket, node->output(i));
-                       i++;
-               }
-       }
-
-       static void insert_output_node(
-               bNodeTree *btree,
-               bNode *bnode,
-               SharedDataFlowGraph &graph,
-               SocketMap &socket_map)
-       {
-               InputParameters inputs;
-               for (bNodeSocket *bsocket : bSocketList(&bnode->inputs)) {
-                       SharedType &type = get_type_of_socket(btree, bsocket);
-                       inputs.append(InputParameter(bsocket->name, type));
-               }
-
-               auto fn = SharedFunction::New("Function Output", 
Signature(inputs, {}));
-               const Node *node = graph->insert(fn);
-
-               uint i = 0;
-               for (bNodeSocket *bsocket : bSocketList(&bnode->inputs)) {
-                       socket_map.add(bsocket, node->input(i));
-                       i++;
-               }
-       }
-
        static bool is_input_node(const bNode *bnode)
        {
                return STREQ(bnode->idname, "fn_FunctionInputNode");
@@ -93,10 +54,42 @@ namespace 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to