[Bf-blender-cvs] [3ed0843df9a] temp-derived-node-tree-refactor: remove all uses of old derived node tree

Jacques Lucke noreply at git.blender.org
Thu Mar 4 11:08:00 CET 2021


Commit: 3ed0843df9abc4c6a82b0979da3535152da22f11
Author: Jacques Lucke
Date:   Thu Mar 4 10:08:42 2021 +0100
Branches: temp-derived-node-tree-refactor
https://developer.blender.org/rB3ed0843df9abc4c6a82b0979da3535152da22f11

remove all uses of old derived node tree

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

M	source/blender/modifiers/intern/MOD_nodes.cc
M	source/blender/nodes/NOD_XXX_node_tree.hh
M	source/blender/nodes/NOD_node_tree_multi_function.hh
M	source/blender/nodes/NOD_node_tree_ref.hh
M	source/blender/nodes/function/nodes/node_fn_group_instance_id.cc
M	source/blender/nodes/function/nodes/node_fn_random_float.cc
M	source/blender/nodes/intern/node_tree_multi_function.cc
M	source/blender/nodes/intern/xxx_node_tree.cc
M	source/blender/nodes/shader/nodes/node_shader_math.cc
M	source/blender/nodes/shader/nodes/node_shader_value.cc

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

diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index cc66ea1c122..920cb37eddc 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -303,8 +303,8 @@ class GeometryNodesEvaluator {
   Vector<GMutablePointer> get_input_values(const XXXInputSocket socket_to_compute)
   {
     Vector<XXXSocket> from_sockets;
-    this->foreach_origin_socket(socket_to_compute,
-                                [&](XXXSocket socket) { from_sockets.append(socket); });
+    socket_to_compute.foreach_origin_socket(
+        [&](XXXSocket socket) { from_sockets.append(socket); });
 
     if (from_sockets.is_empty()) {
       /* The input is not connected, use the value from the socket itself. */
@@ -360,41 +360,6 @@ class GeometryNodesEvaluator {
     return {get_unlinked_input_value(from_input_socket)};
   }
 
-  void foreach_origin_socket(XXXInputSocket to_socket, FunctionRef<void(XXXSocket)> callback) const
-  {
-    for (const OutputSocketRef *linked_socket : to_socket->linked_sockets()) {
-      const NodeRef &linked_node = linked_socket->node();
-      XXXOutputSocket linked_xxx_socket{to_socket.context, linked_socket};
-      if (linked_node.is_group_input_node()) {
-        if (to_socket.context->is_root()) {
-          callback(linked_xxx_socket);
-        }
-        else {
-          XXXInputSocket socket_in_parent_group =
-              linked_xxx_socket.get_corresponding_group_node_input();
-          if (socket_in_parent_group->is_linked()) {
-            this->foreach_origin_socket(socket_in_parent_group, callback);
-          }
-          else {
-            callback(socket_in_parent_group);
-          }
-        }
-      }
-      else if (linked_node.is_group_node()) {
-        XXXInputSocket socket_in_group = linked_xxx_socket.get_corresponding_group_output_socket();
-        if (socket_in_group->is_linked()) {
-          this->foreach_origin_socket(socket_in_group, callback);
-        }
-        else {
-          callback(socket_in_group);
-        }
-      }
-      else {
-        callback(linked_xxx_socket);
-      }
-    }
-  }
-
   void compute_output_and_forward(const XXXOutputSocket socket_to_compute)
   {
     const XXXNode node{socket_to_compute.context, &socket_to_compute->node()};
@@ -451,7 +416,7 @@ class GeometryNodesEvaluator {
     }
 
     /* Use the multi-function implementation if it exists. */
-    const MultiFunction *multi_function = nullptr;  // mf_by_node_.lookup_default(&node, nullptr);
+    const MultiFunction *multi_function = mf_by_node_.lookup_default(node, nullptr);
     if (multi_function != nullptr) {
       this->execute_multi_function_node(node, params, *multi_function);
       return;
@@ -1092,7 +1057,7 @@ static GeometrySet compute_geometry(const XXXNodeTree &tree,
 {
   blender::ResourceCollector resources;
   blender::LinearAllocator<> &allocator = resources.linear_allocator();
-  blender::nodes::MultiFunctionByNode mf_by_node = {}; /* TODO */
+  blender::nodes::MultiFunctionByNode mf_by_node = get_multi_function_per_node(tree, resources);
 
   PersistentDataHandleMap handle_map;
   fill_data_handle_map(nmd->settings, tree, handle_map);
diff --git a/source/blender/nodes/NOD_XXX_node_tree.hh b/source/blender/nodes/NOD_XXX_node_tree.hh
index aecc968aae8..10a0c28a568 100644
--- a/source/blender/nodes/NOD_XXX_node_tree.hh
+++ b/source/blender/nodes/NOD_XXX_node_tree.hh
@@ -100,6 +100,8 @@ struct XXXInputSocket {
 
   XXXOutputSocket get_corresponding_group_node_output() const;
   XXXOutputSocket get_corresponding_group_input_socket() const;
+
+  void foreach_origin_socket(FunctionRef<void(XXXSocket)> callback) const;
 };
 
 struct XXXOutputSocket {
@@ -136,6 +138,7 @@ class XXXNodeTree {
   Span<const NodeTreeRef *> used_node_tree_refs() const;
 
   bool has_link_cycles() const;
+  void foreach_node(FunctionRef<void(XXXNode)> callback) const;
 
  private:
   XXXNodeTreeContext &construct_context_recursively(XXXNodeTreeContext *parent_context,
@@ -143,6 +146,9 @@ class XXXNodeTree {
                                                     bNodeTree &btree,
                                                     NodeTreeRefMap &node_tree_refs);
   void destruct_context_recursively(XXXNodeTreeContext *context);
+
+  void foreach_node_in_context_recursive(const XXXNodeTreeContext &context,
+                                         FunctionRef<void(XXXNode)> callback) const;
 };
 
 namespace xxx_node_tree_types {
diff --git a/source/blender/nodes/NOD_node_tree_multi_function.hh b/source/blender/nodes/NOD_node_tree_multi_function.hh
index 552ef5509fa..54c123d53e8 100644
--- a/source/blender/nodes/NOD_node_tree_multi_function.hh
+++ b/source/blender/nodes/NOD_node_tree_multi_function.hh
@@ -25,17 +25,19 @@
 #include "FN_multi_function_builder.hh"
 #include "FN_multi_function_network.hh"
 
+#include "NOD_XXX_node_tree.hh"
 #include "NOD_derived_node_tree.hh"
 #include "NOD_type_callbacks.hh"
 
+#include "BLI_multi_value_map.hh"
 #include "BLI_resource_collector.hh"
 
 namespace blender::nodes {
 
 /**
- * A MFNetworkTreeMap maps various components of a DerivedNodeTree to components of a
- * fn::MFNetwork. This is necessary for further processing of a multi-function network that has
- * been generated from a node tree.
+ * A MFNetworkTreeMap maps various components of a node tree to components of a fn::MFNetwork. This
+ * is necessary for further processing of a multi-function network that has been generated from a
+ * node tree.
  */
 class MFNetworkTreeMap {
  private:
@@ -45,21 +47,17 @@ class MFNetworkTreeMap {
    * Input sockets in a node tree can have multiple corresponding sockets in the generated
    * MFNetwork. This is because nodes are allowed to expand into multiple multi-function nodes.
    */
-  const DerivedNodeTree &tree_;
+  const XXXNodeTree &tree_;
   fn::MFNetwork &network_;
-  Array<Vector<fn::MFSocket *, 1>> sockets_by_dsocket_id_;
-  Array<fn::MFOutputSocket *> socket_by_group_input_id_;
+  MultiValueMap<XXXSocket, fn::MFSocket *> sockets_by_xxx_socket_;
 
  public:
-  MFNetworkTreeMap(const DerivedNodeTree &tree, fn::MFNetwork &network)
-      : tree_(tree),
-        network_(network),
-        sockets_by_dsocket_id_(tree.sockets().size()),
-        socket_by_group_input_id_(tree.group_inputs().size(), nullptr)
+  MFNetworkTreeMap(const XXXNodeTree &tree, fn::MFNetwork &network)
+      : tree_(tree), network_(network)
   {
   }
 
-  const DerivedNodeTree &tree() const
+  const XXXNodeTree &tree() const
   {
     return tree_;
   }
@@ -74,101 +72,100 @@ class MFNetworkTreeMap {
     return network_;
   }
 
-  void add(const DSocket &dsocket, fn::MFSocket &socket)
+  void add(const XXXSocket &dsocket, fn::MFSocket &socket)
   {
-    BLI_assert(dsocket.is_input() == socket.is_input());
-    BLI_assert(dsocket.is_input() || sockets_by_dsocket_id_[dsocket.id()].size() == 0);
-    sockets_by_dsocket_id_[dsocket.id()].append(&socket);
+    BLI_assert(dsocket->is_input() == socket.is_input());
+    BLI_assert(dsocket->is_input() || sockets_by_xxx_socket_.lookup(dsocket).is_empty());
+    sockets_by_xxx_socket_.add(dsocket, &socket);
   }
 
-  void add(const DInputSocket &dsocket, fn::MFInputSocket &socket)
+  void add(const XXXInputSocket &dsocket, fn::MFInputSocket &socket)
   {
-    sockets_by_dsocket_id_[dsocket.id()].append(&socket);
+    sockets_by_xxx_socket_.add(dsocket, &socket);
   }
 
-  void add(const DOutputSocket &dsocket, fn::MFOutputSocket &socket)
+  void add(const XXXOutputSocket &dsocket, fn::MFOutputSocket &socket)
   {
     /* There can be at most one matching output socket. */
-    BLI_assert(sockets_by_dsocket_id_[dsocket.id()].size() == 0);
-    sockets_by_dsocket_id_[dsocket.id()].append(&socket);
+    BLI_assert(sockets_by_xxx_socket_.lookup(dsocket).is_empty());
+    sockets_by_xxx_socket_.add(dsocket, &socket);
   }
 
-  void add(Span<const DInputSocket *> dsockets, Span<fn::MFInputSocket *> sockets)
+  void add(const XXXNodeTreeContext &context,
+           Span<const InputSocketRef *> dsockets,
+           Span<fn::MFInputSocket *> sockets)
   {
     assert_same_size(dsockets, sockets);
     for (int i : dsockets.index_range()) {
-      this->add(*dsockets[i], *sockets[i]);
+      this->add(XXXInputSocket(&context, dsockets[i]), *sockets[i]);
     }
   }
 
-  void add(Span<const DOutputSocket *> dsockets, Span<fn::MFOutputSocket *> sockets)
+  void add(const XXXNodeTreeContext &context,
+           Span<const OutputSocketRef *> dsockets,
+           Span<fn::MFOutputSocket *> sockets)
   {
     assert_same_size(dsockets, sockets);
     for (int i : dsockets.index_range()) {
-      this->add(*dsockets[i], *sockets[i]);
+      this->add(XXXOutputSocket(&context, dsockets[i]), *sockets[i]);
     }
   }
 
-  void add(const DGroupInput &group_input, fn::MFOutputSocket &socket)
+  void add_try_match(const XXXNode &dnode, fn::MFNode &node)
   {
-    BLI_assert(socket_by_group_input_id_[group_input.id()] == nullptr);
-    socket_by_group_input_id_[group_input.id()] = &socket;
-  }
-
-  void add_try_match(const DNode &dnode, fn::MFNode &node)
-  {
-    this->add_try_match(dnode.inputs().cast<const DSocket *>(),
+    this->add_try_match(*dnode.context,
+                        dnode->inputs().cast<const SocketRef *>(),
                         node.inputs().cast<fn::MFSocket *>());
-    this->add_try_match(dnode.outputs().cast<const DSocket *>(),
+    this->add_try_match(*dnode.context,
+                        dnode->outputs().cast<const SocketRef *>(),
                         node.outputs().cast<fn::MFSocket *>());
   }
 
-  void add_try_match(Span<const DInputSocket *> dsockets, Span<fn::MFInputSocket *> sockets)
+  void add_try_match(const XXXNodeTreeContext &context,
+                     Span<const InputSocketRef *> dsockets,
+                     Span<fn::MFInputSocket *> sockets)
   {
-    this->add_try_match(dsockets.cast<const DSocket *>(), sockets.cast<fn::MFSocket *>());
+    this->add_try_match(
+        context, dsockets.cast<const SocketRef *>(), sockets.cast<fn::MFSocket *>());
   }
 
-  void add_try_match(Span<const DOutputSocket *> dsockets, Span<fn::MFOutputSocket *> so

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list