Code Cleanup: de-duplicate nested node tree checking
authorCampbell Barton <ideasman42@gmail.com>
Mon, 27 Jan 2014 09:17:56 +0000 (20:17 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 27 Jan 2014 09:19:27 +0000 (20:19 +1100)
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/editors/space_node/node_draw.c
source/blender/editors/space_node/node_edit.c

index e3af696c8a9dccf5a7670635793b4f83b38a0625..fc0359d8ff09f19801e3b65da5c417b22c680f0c 100644 (file)
@@ -353,7 +353,8 @@ void              ntreeUserDecrefID(struct bNodeTree *ntree);
 struct bNodeTree *ntreeFromID(struct ID *id);
 
 void              ntreeMakeLocal(struct bNodeTree *ntree);
-int               ntreeHasType(struct bNodeTree *ntree, int type);
+bool              ntreeHasType(const struct bNodeTree *ntree, int type);
+bool              ntreeHasTree(const struct bNodeTree *ntree, const struct bNodeTree *lookup);
 void              ntreeUpdateTree(struct Main *main, struct bNodeTree *ntree);
 /* XXX Currently each tree update call does call to ntreeVerifyNodes too.
  * Some day this should be replaced by a decent depsgraph automatism!
index 34b016a08baf172f36f536da1e9ea32a13a44653..79f77416639704d2d9cd9008391562452ffd8d31 100644 (file)
@@ -2289,7 +2289,7 @@ void ntreeInterfaceTypeUpdate(bNodeTree *ntree)
 
 /* ************ find stuff *************** */
 
-int ntreeHasType(bNodeTree *ntree, int type)
+bool ntreeHasType(const bNodeTree *ntree, int type)
 {
        bNode *node;
        
@@ -2300,6 +2300,21 @@ int ntreeHasType(bNodeTree *ntree, int type)
        return 0;
 }
 
+bool ntreeHasTree(const bNodeTree *ntree, const bNodeTree *lookup)
+{
+       bNode *node;
+
+       if (ntree == lookup)
+               return true;
+
+       for (node = ntree->nodes.first; node; node = node->next)
+               if (node->type == NODE_GROUP && node->id)
+                       if (ntreeHasTree((bNodeTree *)node->id, lookup))
+                               return true;
+
+       return false;
+}
+
 bNodeLink *nodeFindLink(bNodeTree *ntree, bNodeSocket *from, bNodeSocket *to)
 {
        bNodeLink *link;
index 78116ee0968110bfe500f44d3ea11c5d5052f87e..08375faf68010c98f99e42c0c83cf2890d898319 100644 (file)
@@ -139,21 +139,6 @@ void ED_node_tag_update_id(ID *id)
        }
 }
 
-static int has_nodetree(bNodeTree *ntree, bNodeTree *lookup)
-{
-       bNode *node;
-       
-       if (ntree == lookup)
-               return 1;
-       
-       for (node = ntree->nodes.first; node; node = node->next)
-               if (node->type == NODE_GROUP && node->id)
-                       if (has_nodetree((bNodeTree *)node->id, lookup))
-                               return 1;
-       
-       return 0;
-}
-
 void ED_node_tag_update_nodetree(Main *bmain, bNodeTree *ntree)
 {
        if (!ntree)
@@ -162,7 +147,7 @@ void ED_node_tag_update_nodetree(Main *bmain, bNodeTree *ntree)
        /* look through all datablocks, to support groups */
        FOREACH_NODETREE(bmain, tntree, id) {
                /* check if nodetree uses the group */
-               if (has_nodetree(tntree, ntree))
+               if (ntreeHasTree(tntree, ntree))
                        ED_node_tag_update_id(id);
        } FOREACH_NODETREE_END
        
index d6e85457ae0ec64f6bffde209717c167d2e3fb05..0f70c5a59723160f3c59f17eac19635cf488cb9a 100644 (file)
@@ -329,21 +329,6 @@ int composite_node_editable(bContext *C)
        return 0;
 }
 
-static int has_nodetree(bNodeTree *ntree, bNodeTree *lookup)
-{
-       bNode *node;
-       
-       if (ntree == lookup)
-               return 1;
-       
-       for (node = ntree->nodes.first; node; node = node->next)
-               if (node->type == NODE_GROUP && node->id)
-                       if (has_nodetree((bNodeTree *)node->id, lookup))
-                               return 1;
-       
-       return 0;
-}
-
 void snode_dag_update(bContext *C, SpaceNode *snode)
 {
        Main *bmain = CTX_data_main(C);
@@ -351,7 +336,7 @@ void snode_dag_update(bContext *C, SpaceNode *snode)
        /* for groups, update all ID's using this */
        if (snode->edittree != snode->nodetree) {
                FOREACH_NODETREE(bmain, tntree, id) {
-                       if (has_nodetree(tntree, snode->edittree))
+                       if (ntreeHasTree(tntree, snode->edittree))
                                DAG_id_tag_update(id, 0);
                } FOREACH_NODETREE_END
        }
@@ -675,7 +660,7 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node)
                                Material *ma;
 
                                for (ma = bmain->mat.first; ma; ma = ma->id.next)
-                                       if (ma->nodetree && ma->use_nodes && has_nodetree(ma->nodetree, ntree))
+                                       if (ma->nodetree && ma->use_nodes && ntreeHasTree(ma->nodetree, ntree))
                                                GPU_material_free(ma);
 
                                WM_main_add_notifier(NC_IMAGE, NULL);
@@ -704,7 +689,7 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node)
                                Scene *scene;
 
                                for (scene = bmain->scene.first; scene; scene = scene->id.next) {
-                                       if (scene->nodetree && scene->use_nodes && has_nodetree(scene->nodetree, ntree)) {
+                                       if (scene->nodetree && scene->use_nodes && ntreeHasTree(scene->nodetree, ntree)) {
                                                if (node->id == NULL || node->id == (ID *)scene) {
                                                        scene->r.actlay = node->custom1;
                                                }