Commit: 5b8e2ebd97bd795c6aea1b5270c8e49b70b3069e
Author: Hans Goudey
Date:   Fri Dec 2 11:12:51 2022 -0600
Branches: master
https://developer.blender.org/rB5b8e2ebd97bd795c6aea1b5270c8e49b70b3069e

Cleanup: Use Span to iterate over nodes instead of ListBase

Since 90ea1b76434fe175e, there is always a span of nodes
available at runtime. This is easier to read and write.

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

M       source/blender/blenkernel/intern/image.cc
M       source/blender/blenkernel/intern/material.cc
M       source/blender/blenkernel/intern/node.cc
M       source/blender/blenkernel/intern/node_tree_update.cc
M       source/blender/blenkernel/intern/scene.cc
M       source/blender/blenkernel/intern/texture.cc
M       source/blender/blenloader/intern/versioning_common.cc
M       source/blender/blenloader/intern/versioning_defaults.cc
M       source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
M       source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M       source/blender/editors/space_buttons/buttons_texture.cc
M       source/blender/editors/space_node/link_drag_search.cc
M       source/blender/editors/space_node/node_draw.cc
M       source/blender/editors/space_node/node_edit.cc
M       source/blender/editors/space_node/node_group.cc
M       source/blender/editors/space_node/node_relationships.cc
M       source/blender/editors/space_node/node_select.cc
M       source/blender/editors/space_node/space_node.cc
M       source/blender/editors/transform/transform_convert_node.cc
M       source/blender/editors/util/ed_viewer_path.cc
M       source/blender/io/usd/intern/usd_writer_material.cc
M       source/blender/nodes/composite/node_composite_tree.cc
M       source/blender/nodes/shader/node_shader_util.cc
M       source/blender/nodes/shader/nodes/node_shader_common.cc
M       source/blender/render/intern/pipeline.cc

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

diff --git a/source/blender/blenkernel/intern/image.cc 
b/source/blender/blenkernel/intern/image.cc
index ae05096826b..5e8a2cad99e 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -71,6 +71,7 @@
 #include "BKE_lib_id.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
+#include "BKE_node_runtime.hh"
 #include "BKE_node_tree_update.h"
 #include "BKE_packedFile.h"
 #include "BKE_report.h"
@@ -2743,7 +2744,7 @@ static void image_walk_ntree_all_users(
 {
   switch (ntree->type) {
     case NTREE_SHADER:
-      LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+      for (bNode *node : ntree->all_nodes()) {
         if (node->id) {
           if (node->type == SH_NODE_TEX_IMAGE) {
             NodeTexImage *tex = static_cast<NodeTexImage *>(node->storage);
@@ -2759,7 +2760,7 @@ static void image_walk_ntree_all_users(
       }
       break;
     case NTREE_TEXTURE:
-      LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+      for (bNode *node : ntree->all_nodes()) {
         if (node->id && node->type == TEX_NODE_IMAGE) {
           Image *ima = (Image *)node->id;
           ImageUser *iuser = static_cast<ImageUser *>(node->storage);
@@ -2768,7 +2769,7 @@ static void image_walk_ntree_all_users(
       }
       break;
     case NTREE_COMPOSIT:
-      LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+      for (bNode *node : ntree->all_nodes()) {
         if (node->id && node->type == CMP_NODE_IMAGE) {
           Image *ima = (Image *)node->id;
           ImageUser *iuser = static_cast<ImageUser *>(node->storage);
diff --git a/source/blender/blenkernel/intern/material.cc 
b/source/blender/blenkernel/intern/material.cc
index 597375f4f81..bcce1e61eb5 100644
--- a/source/blender/blenkernel/intern/material.cc
+++ b/source/blender/blenkernel/intern/material.cc
@@ -58,6 +58,7 @@
 #include "BKE_material.h"
 #include "BKE_mesh.h"
 #include "BKE_node.h"
+#include "BKE_node_runtime.hh"
 #include "BKE_object.h"
 #include "BKE_scene.h"
 #include "BKE_vfont.h"
@@ -1387,7 +1388,7 @@ static bool ntree_foreach_texnode_recursive(bNodeTree 
*nodetree,
 {
   const bool do_image_nodes = (slot_filter & PAINT_SLOT_IMAGE) != 0;
   const bool do_color_attributes = (slot_filter & PAINT_SLOT_COLOR_ATTRIBUTE) 
!= 0;
-  LISTBASE_FOREACH (bNode *, node, &nodetree->nodes) {
+  for (bNode *node : nodetree->all_nodes()) {
     if (do_image_nodes && node->typeinfo->nclass == NODE_CLASS_TEXTURE &&
         node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) {
       if (!callback(node, userdata)) {
diff --git a/source/blender/blenkernel/intern/node.cc 
b/source/blender/blenkernel/intern/node.cc
index c712d7ff668..c502381fc62 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -166,9 +166,9 @@ static void ntree_copy_data(Main * /*bmain*/, ID *id_dst, 
const ID *id_src, cons
   }
 
   /* update node->parent pointers */
-  LISTBASE_FOREACH (bNode *, new_node, &ntree_dst->nodes) {
-    if (new_node->parent) {
-      new_node->parent = 
dst_runtime.nodes_by_id.lookup_key_as(new_node->parent->identifier);
+  for (bNode *node : ntree_dst->all_nodes()) {
+    if (node->parent) {
+      node->parent = 
dst_runtime.nodes_by_id.lookup_key_as(node->parent->identifier);
     }
   }
 
@@ -323,7 +323,7 @@ static void node_foreach_id(ID *id, LibraryForeachIDData 
*data)
 
   BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, ntree->gpd, IDWALK_CB_USER);
 
-  LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+  for (bNode *node : ntree->all_nodes()) {
     BKE_LIB_FOREACHID_PROCESS_ID(data, node->id, IDWALK_CB_USER);
 
     BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(
@@ -363,7 +363,7 @@ static void node_foreach_cache(ID *id,
 #endif
 
   if (nodetree->type == NTREE_COMPOSIT) {
-    LISTBASE_FOREACH (bNode *, node, &nodetree->nodes) {
+    for (bNode *node : nodetree->all_nodes()) {
       if (node->type == CMP_NODE_MOVIEDISTORTION) {
         key.offset_in_ID = size_t(BLI_ghashutil_strhash_p(node->name));
         function_callback(id, &key, (void **)&node->storage, 0, user_data);
@@ -378,7 +378,7 @@ static void node_foreach_path(ID *id, BPathForeachPathData 
*bpath_data)
 
   switch (ntree->type) {
     case NTREE_SHADER: {
-      LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+      for (bNode *node : ntree->all_nodes()) {
         if (node->type == SH_NODE_SCRIPT) {
           NodeShaderScript *nss = reinterpret_cast<NodeShaderScript 
*>(node->storage);
           BKE_bpath_foreach_path_fixed_process(bpath_data, nss->filepath);
@@ -495,7 +495,7 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree)
     BKE_animdata_blend_write(writer, ntree->adt);
   }
 
-  LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+  for (bNode *node : ntree->all_nodes()) {
     BLO_write_struct(writer, bNode, node);
 
     if (node->prop) {
@@ -1229,7 +1229,7 @@ static void update_typeinfo(Main *bmain,
     }
 
     /* initialize nodes */
-    LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+    for (bNode *node : ntree->all_nodes()) {
       if (nodetype && STREQ(node->idname, nodetype->idname)) {
         node_set_typeinfo(C, ntree, node, unregister ? nullptr : nodetype);
       }
@@ -1266,7 +1266,7 @@ void ntreeSetTypes(const bContext *C, bNodeTree *ntree)
 {
   ntree_set_typeinfo(ntree, ntreeTypeFind(ntree->idname));
 
-  LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+  for (bNode *node : ntree->all_nodes()) {
     node_set_typeinfo(C, ntree, node, nodeTypeFind(node->idname));
 
     LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
@@ -2023,7 +2023,7 @@ void nodeFindNode(bNodeTree *ntree, bNodeSocket *sock, 
bNode **r_node, int *r_so
 
 bool nodeFindNodeTry(bNodeTree *ntree, bNodeSocket *sock, bNode **r_node, int 
*r_sockindex)
 {
-  LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+  for (bNode *node : ntree->all_nodes()) {
     ListBase *sockets = (sock->in_out == SOCK_IN) ? &node->inputs : 
&node->outputs;
     int i;
     LISTBASE_FOREACH_INDEX (bNodeSocket *, tsock, sockets, i) {
@@ -2778,7 +2778,7 @@ static void 
node_preview_init_tree_recursive(bNodeInstanceHash *previews,
                                              const int xsize,
                                              const int ysize)
 {
-  LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+  for (bNode *node : ntree->all_nodes()) {
     bNodeInstanceKey key = BKE_node_instance_key(parent_key, ntree, node);
 
     if (BKE_node_preview_used(node)) {
@@ -2811,7 +2811,7 @@ static void 
node_preview_tag_used_recursive(bNodeInstanceHash *previews,
                                             bNodeTree *ntree,
                                             bNodeInstanceKey parent_key)
 {
-  LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+  for (bNode *node : ntree->all_nodes()) {
     bNodeInstanceKey key = BKE_node_instance_key(parent_key, ntree, node);
 
     if (BKE_node_preview_used(node)) {
@@ -2926,7 +2926,7 @@ void nodeUnlinkNode(bNodeTree *ntree, bNode *node)
 
 static void node_unlink_attached(bNodeTree *ntree, bNode *parent)
 {
-  LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+  for (bNode *node : ntree->all_nodes()) {
     if (node->parent == parent) {
       nodeDetachNode(ntree, node);
     }
@@ -3454,7 +3454,7 @@ bool ntreeHasTree(const bNodeTree *ntree, const bNodeTree 
*lookup)
   if (ntree == lookup) {
     return true;
   }
-  LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+  for (const bNode *node : ntree->all_nodes()) {
     if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP) && node->id) {
       if (ntreeHasTree((bNodeTree *)node->id, lookup)) {
         return true;
@@ -3494,7 +3494,7 @@ bNode *nodeGetActive(bNodeTree *ntree)
     return nullptr;
   }
 
-  LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+  for (bNode *node : ntree->all_nodes()) {
     if (node->flag & NODE_ACTIVE) {
       return node;
     }
@@ -3526,7 +3526,7 @@ void nodeClearActive(bNodeTree *ntree)
     return;
   }
 
-  LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+  for (bNode *node : ntree->all_nodes()) {
     node->flag &= ~NODE_ACTIVE;
   }
 }
@@ -3540,7 +3540,7 @@ void nodeSetActive(bNodeTree *ntree, bNode *node)
   SET_FLAG_FROM_TEST(flags_to_set, is_texture_class, NODE_ACTIVE_TEXTURE);
 
   /* Make sure only one node is active per node tree. */
-  LISTBASE_FOREACH (bNode *, tnode, &ntree->nodes) {
+  for (bNode *tnode : ntree->all_nodes()) {
     tnode->flag &= ~flags_to_set;
   }
   node->flag |= flags_to_set;
@@ -3974,7 +3974,7 @@ void ntreeUpdateAllUsers(Main *main, ID *id)
 
   /* Update all users of ngroup, to add/remove sockets as needed. */
   FOREACH_NODETREE_BEGIN (main, ntree, owner_id) {
-    LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+    for (bNode *node : ntree->all_nodes()) {
       if (node->id == id) {
         BKE_ntree_update_tag_node_property(ntree, node);
         need_update = true;
@@ -4315,7 +4315,7 @@ bool BKE_node_tree_iter_step(NodeTreeIterStore 
*ntreeiter, bNodeTree **r_nodetre
 void BKE_nodetree_remove_layer_n(bNodeTree *ntree, Scene *scene, const int 
layer_index)
 {
   BLI_assert(layer_index != -1);
-  LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+  for (bNode *node : ntree->all_nodes()) {
     if (node->type == CMP_NODE_R_LAYERS && (Scene *)node->id == scene) {
       if (node->custom1 == layer_index) {
         node->custom1 = 0;
diff --git a/source/blender/blenkernel/intern/node_tree_update.cc 
b/source/blender/blenkernel/intern/node_tree_update.cc
index 57d85c10677..bb063dadb06 100644
--- a/source/blender/blenkernel/intern/node_tree_update.cc
+++ b/source/blender/blenkernel/intern/node_tree_update.cc
@@ -733,7 +733,7 @@ struct NodeTreeRelations {
     this->ensure_all_trees();
 
     for (bNodeTree *ntree : *all_trees_) {
-      LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+      for (bNode *node : ntree->all_nodes()) {
         if (node->id == nullptr) {
           continue;
         }
@@ -1012,7 +1012,7 @@ class NodeTreeMainUpdater {
 #ifdef DEBUG
     /* Check the uniqueness of node identifiers. */
     Set<int32_t> node_identifiers;
-    LISTBASE_FOREACH (bNode *, node, &ntree.nodes) {
+    for (bNode *node : ntree.all_nodes()) {
       BLI_assert(node->identifier > 0);
       node_

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to