diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-01-27 13:17:56 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-01-27 13:19:27 +0400 |
commit | bee6c1779e9337fbc0b34d9747b4aeb647b44cfa (patch) | |
tree | be330663109d8224fb9e5af68dfa013b1451b1ef /source/blender | |
parent | 2d3bd587fd26972495d939927513583be108aa4d (diff) |
Code Cleanup: de-duplicate nested node tree checking
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 17 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_draw.c | 17 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_edit.c | 21 |
4 files changed, 22 insertions, 36 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index e3af696c8a9..fc0359d8ff0 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -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! diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 34b016a08ba..79f77416639 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -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; diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 78116ee0968..08375faf680 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -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 diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index d6e85457ae0..0f70c5a5972 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -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; } |