[Bf-blender-cvs] [7470c10601d] master: Cleanup: Use LISTBASE_FOREACH macro, reduce variable scope

Hans Goudey noreply at git.blender.org
Tue Dec 15 00:19:49 CET 2020


Commit: 7470c10601d0fa871cdf1917da3b58af36af3225
Author: Hans Goudey
Date:   Mon Dec 14 17:19:43 2020 -0600
Branches: master
https://developer.blender.org/rB7470c10601d0fa871cdf1917da3b58af36af3225

Cleanup: Use LISTBASE_FOREACH macro, reduce variable scope

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

M	source/blender/editors/space_node/node_edit.c

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

diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index 039ddad71ef..fdce5e3f30b 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -100,9 +100,7 @@ typedef struct CompoJob {
 
 static void compo_tag_output_nodes(bNodeTree *nodetree, int recalc_flags)
 {
-  bNode *node;
-
-  for (node = nodetree->nodes.first; node; node = node->next) {
+  LISTBASE_FOREACH (bNode *, node, &nodetree->nodes) {
     if (node->type == CMP_NODE_COMPOSITE) {
       if (recalc_flags & COM_RECALC_COMPOSITE) {
         node->flag |= NODE_DO_OUTPUT_RECALC;
@@ -124,14 +122,12 @@ static void compo_tag_output_nodes(bNodeTree *nodetree, int recalc_flags)
 static int compo_get_recalc_flags(const bContext *C)
 {
   wmWindowManager *wm = CTX_wm_manager(C);
-  wmWindow *win;
   int recalc_flags = 0;
 
-  for (win = wm->windows.first; win; win = win->next) {
+  LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
     const bScreen *screen = WM_window_get_active_screen(win);
-    ScrArea *area;
 
-    for (area = screen->areabase.first; area; area = area->next) {
+    LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
       if (area->spacetype == SPACE_IMAGE) {
         SpaceImage *sima = area->spacedata.first;
         if (sima->image) {
@@ -247,7 +243,6 @@ static void compo_startjob(void *cjv,
   CompoJob *cj = cjv;
   bNodeTree *ntree = cj->localtree;
   Scene *scene = cj->scene;
-  SceneRenderView *srv;
 
   if (scene->use_nodes == false) {
     return;
@@ -280,7 +275,7 @@ static void compo_startjob(void *cjv,
                           "");
   }
   else {
-    for (srv = scene->r.views.first; srv; srv = srv->next) {
+    LISTBASE_FOREACH (SceneRenderView *, srv, &scene->r.views) {
       if (BKE_scene_multiview_is_render_view_active(&scene->r, srv) == false) {
         continue;
       }
@@ -309,8 +304,6 @@ static void compo_startjob(void *cjv,
  */
 void ED_node_composite_job(const bContext *C, struct bNodeTree *nodetree, Scene *scene_owner)
 {
-  wmJob *wm_job;
-  CompoJob *cj;
   Main *bmain = CTX_data_main(C);
   Scene *scene = CTX_data_scene(C);
   ViewLayer *view_layer = CTX_data_view_layer(C);
@@ -327,13 +320,13 @@ void ED_node_composite_job(const bContext *C, struct bNodeTree *nodetree, Scene
   BKE_image_backup_render(
       scene, BKE_image_ensure_viewer(bmain, IMA_TYPE_R_RESULT, "Render Result"), false);
 
-  wm_job = WM_jobs_get(CTX_wm_manager(C),
-                       CTX_wm_window(C),
-                       scene_owner,
-                       "Compositing",
-                       WM_JOB_EXCL_RENDER | WM_JOB_PROGRESS,
-                       WM_JOB_TYPE_COMPOSITE);
-  cj = MEM_callocN(sizeof(CompoJob), "compo job");
+  wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
+                              CTX_wm_window(C),
+                              scene_owner,
+                              "Compositing",
+                              WM_JOB_EXCL_RENDER | WM_JOB_PROGRESS,
+                              WM_JOB_TYPE_COMPOSITE);
+  CompoJob *cj = MEM_callocN(sizeof(CompoJob), "compo job");
 
   /* customdata for preview thread */
   cj->bmain = bmain;
@@ -524,9 +517,6 @@ void ED_node_shader_default(const bContext *C, ID *id)
 /* called from shading buttons or header */
 void ED_node_composit_default(const bContext *C, struct Scene *sce)
 {
-  bNode *in, *out;
-  bNodeSocket *fromsock, *tosock;
-
   /* but lets check it anyway */
   if (sce->nodetree) {
     if (G.debug & G_DEBUG) {
@@ -541,18 +531,18 @@ void ED_node_composit_default(const bContext *C, struct Scene *sce)
   sce->nodetree->edit_quality = NTREE_QUALITY_HIGH;
   sce->nodetree->render_quality = NTREE_QUALITY_HIGH;
 
-  out = nodeAddStaticNode(C, sce->nodetree, CMP_NODE_COMPOSITE);
+  bNode *out = nodeAddStaticNode(C, sce->nodetree, CMP_NODE_COMPOSITE);
   out->locx = 300.0f;
   out->locy = 400.0f;
 
-  in = nodeAddStaticNode(C, sce->nodetree, CMP_NODE_R_LAYERS);
+  bNode *in = nodeAddStaticNode(C, sce->nodetree, CMP_NODE_R_LAYERS);
   in->locx = 10.0f;
   in->locy = 400.0f;
   nodeSetActive(sce->nodetree, in);
 
   /* links from color to color */
-  fromsock = in->outputs.first;
-  tosock = out->inputs.first;
+  bNodeSocket *fromsock = in->outputs.first;
+  bNodeSocket *tosock = out->inputs.first;
   nodeAddLink(sce->nodetree, in, fromsock, out, tosock);
 
   ntreeUpdateTree(CTX_data_main(C), sce->nodetree);
@@ -562,9 +552,6 @@ void ED_node_composit_default(const bContext *C, struct Scene *sce)
 /* called from shading buttons or header */
 void ED_node_texture_default(const bContext *C, Tex *tex)
 {
-  bNode *in, *out;
-  bNodeSocket *fromsock, *tosock;
-
   /* but lets check it anyway */
   if (tex->nodetree) {
     if (G.debug & G_DEBUG) {
@@ -575,17 +562,17 @@ void ED_node_texture_default(const bContext *C, Tex *tex)
 
   tex->nodetree = ntreeAddTree(NULL, "Texture Nodetree", ntreeType_Texture->idname);
 
-  out = nodeAddStaticNode(C, tex->nodetree, TEX_NODE_OUTPUT);
+  bNode *out = nodeAddStaticNode(C, tex->nodetree, TEX_NODE_OUTPUT);
   out->locx = 300.0f;
   out->locy = 300.0f;
 
-  in = nodeAddStaticNode(C, tex->nodetree, TEX_NODE_CHECKER);
+  bNode *in = nodeAddStaticNode(C, tex->nodetree, TEX_NODE_CHECKER);
   in->locx = 10.0f;
   in->locy = 300.0f;
   nodeSetActive(tex->nodetree, in);
 
-  fromsock = in->outputs.first;
-  tosock = out->inputs.first;
+  bNodeSocket *fromsock = in->outputs.first;
+  bNodeSocket *tosock = out->inputs.first;
   nodeAddLink(tex->nodetree, in, fromsock, out, tosock);
 
   ntreeUpdateTree(CTX_data_main(C), tex->nodetree);
@@ -634,15 +621,13 @@ void snode_set_context(const bContext *C)
 
 void snode_update(SpaceNode *snode, bNode *node)
 {
-  bNodeTreePath *path;
-
   /* XXX this only updates nodes in the current node space tree path.
    * The function supposedly should update any potential group node linking to changed tree,
    * this really requires a working depsgraph ...
    */
 
   /* update all edited group nodes */
-  path = snode->treepath.last;
+  bNodeTreePath *path = snode->treepath.last;
   if (path) {
     bNodeTree *ngroup = path->nodetree;
     for (path = path->prev; path; path = path->prev) {
@@ -671,10 +656,9 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node, bool *r_acti
 
     /* generic node group output: set node as active output */
     if (node->type == NODE_GROUP_OUTPUT) {
-      bNode *tnode;
-      for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) {
-        if (tnode->type == NODE_GROUP_OUTPUT) {
-          tnode->flag &= ~NODE_DO_OUTPUT;
+      LISTBASE_FOREACH (bNode *, node_iter, &ntree->nodes) {
+        if (node_iter->type == NODE_GROUP_OUTPUT) {
+          node_iter->flag &= ~NODE_DO_OUTPUT;
         }
       }
 
@@ -696,11 +680,9 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node, bool *r_acti
                SH_NODE_OUTPUT_WORLD,
                SH_NODE_OUTPUT_LIGHT,
                SH_NODE_OUTPUT_LINESTYLE)) {
-        bNode *tnode;
-
-        for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) {
-          if (tnode->type == node->type) {
-            tnode->flag &= ~NODE_DO_OUTPUT;
+        LISTBASE_FOREACH (bNode *, node_iter, &ntree->nodes) {
+          if (node_iter->type == node->type) {
+            node_iter->flag &= ~NODE_DO_OUTPUT;
           }
         }
 
@@ -715,16 +697,13 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node, bool *r_acti
 
       /* if active texture changed, free glsl materials */
       if ((node->flag & NODE_ACTIVE_TEXTURE) && !was_active_texture) {
-        Material *ma;
-        World *wo;
-
-        for (ma = bmain->materials.first; ma; ma = ma->id.next) {
+        LISTBASE_FOREACH (Material *, ma, &bmain->materials) {
           if (ma->nodetree && ma->use_nodes && ntreeHasTree(ma->nodetree, ntree)) {
             GPU_material_free(&ma->gpumaterial);
           }
         }
 
-        for (wo = bmain->worlds.first; wo; wo = wo->id.next) {
+        LISTBASE_FOREACH (World *, wo, &bmain->materials) {
           if (wo->nodetree && wo->use_nodes && ntreeHasTree(wo->nodetree, ntree)) {
             GPU_material_free(&wo->gpumaterial);
           }
@@ -742,11 +721,9 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node, bool *r_acti
     else if (ntree->type == NTREE_COMPOSIT) {
       /* make active viewer, currently only 1 supported... */
       if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
-        bNode *tnode;
-
-        for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) {
-          if (ELEM(tnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
-            tnode->flag &= ~NODE_DO_OUTPUT;
+        LISTBASE_FOREACH (bNode *, node_iter, &ntree->nodes) {
+          if (ELEM(node_iter->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
+            node_iter->flag &= ~NODE_DO_OUTPUT;
           }
         }
 
@@ -760,11 +737,9 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node, bool *r_acti
       }
       else if (node->type == CMP_NODE_COMPOSITE) {
         if (was_output == 0) {
-          bNode *tnode;
-
-          for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) {
-            if (tnode->type == CMP_NODE_COMPOSITE) {
-              tnode->flag &= ~NODE_DO_OUTPUT;
+          LISTBASE_FOREACH (bNode *, node_iter, &ntree->nodes) {
+            if (node_iter->type == CMP_NODE_COMPOSITE) {
+              node_iter->flag &= ~NODE_DO_OUTPUT;
             }
           }
 
@@ -879,14 +854,12 @@ static void edit_node_properties_get(
 /* is rct in visible part of node? */
 static bNode *visible_node(SpaceNode *snode, const rctf *rct)
 {
-  bNode *node;
-
-  for (node = snode->edittree->nodes.last; node; node = node->prev) {
+  LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) {
     if (BLI_rctf_isect(&node->totr, rct, NULL)) {
-      break;
+      return node;
     }
   }
-  return node;
+  return NULL;
 }
 
 /* ********************** size widget operator ******************** */
@@ -952,23 +925,19 @@ static int node_resize_modal(bContext *C, wmOperator *op, const wmEvent *event)
   ARegion *region = CTX_wm_region(C);
   bNo

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list