From 4ec5a8cbc23311776ad3f5745c52331b4937ddb0 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Sat, 5 Nov 2022 16:10:27 +0100 Subject: Cleanup: Remove unnecessary node type registraction functions These functions provided little benefit compared to simply setting the function pointers directly. --- source/blender/nodes/intern/node_common.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source/blender/nodes/intern/node_common.cc') diff --git a/source/blender/nodes/intern/node_common.cc b/source/blender/nodes/intern/node_common.cc index d7cc0b6065a..d01faeac401 100644 --- a/source/blender/nodes/intern/node_common.cc +++ b/source/blender/nodes/intern/node_common.cc @@ -255,7 +255,7 @@ void register_node_type_frame() ntype->free_self = (void (*)(bNodeType *))MEM_freeN; node_type_base(ntype, NODE_FRAME, "Frame", NODE_CLASS_LAYOUT); - node_type_init(ntype, node_frame_init); + ntype->initfunc = node_frame_init; node_type_storage(ntype, "NodeFrame", node_free_standard_storage, node_copy_standard_storage); node_type_size(ntype, 150, 100, 0); ntype->flag |= NODE_BACKGROUND; @@ -285,7 +285,7 @@ void register_node_type_reroute() ntype->free_self = (void (*)(bNodeType *))MEM_freeN; node_type_base(ntype, NODE_REROUTE, "Reroute", NODE_CLASS_LAYOUT); - node_type_init(ntype, node_reroute_init); + ntype->initfunc = node_reroute_init; nodeRegisterType(ntype); } @@ -527,8 +527,8 @@ void register_node_type_group_input() node_type_base(ntype, NODE_GROUP_INPUT, "Group Input", NODE_CLASS_INTERFACE); node_type_size(ntype, 140, 80, 400); - node_type_init(ntype, node_group_input_init); - node_type_update(ntype, node_group_input_update); + ntype->initfunc = node_group_input_init; + ntype->updatefunc = node_group_input_update; nodeRegisterType(ntype); } @@ -617,8 +617,8 @@ void register_node_type_group_output() node_type_base(ntype, NODE_GROUP_OUTPUT, "Group Output", NODE_CLASS_INTERFACE); node_type_size(ntype, 140, 80, 400); - node_type_init(ntype, node_group_output_init); - node_type_update(ntype, node_group_output_update); + ntype->initfunc = node_group_output_init; + ntype->updatefunc = node_group_output_update; ntype->no_muting = true; -- cgit v1.2.3 From c6725dc5079d9a69e4a2e4d8d655d9497b56b18e Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Sat, 5 Nov 2022 18:59:36 +0100 Subject: Cleanup: Use Vector in group input/output node update functions Also reduce the scope of variables and use ListBase macros --- source/blender/nodes/intern/node_common.cc | 79 +++++++++++------------------- 1 file changed, 29 insertions(+), 50 deletions(-) (limited to 'source/blender/nodes/intern/node_common.cc') diff --git a/source/blender/nodes/intern/node_common.cc b/source/blender/nodes/intern/node_common.cc index d01faeac401..37a52daa73c 100644 --- a/source/blender/nodes/intern/node_common.cc +++ b/source/blender/nodes/intern/node_common.cc @@ -86,8 +86,6 @@ bool nodeGroupPoll(const bNodeTree *nodetree, const bNodeTree *grouptree, const char **r_disabled_hint) { - bool valid = true; - /* unspecified node group, generally allowed * (if anything, should be avoided on operator level) */ @@ -106,11 +104,10 @@ bool nodeGroupPoll(const bNodeTree *nodetree, if (node->typeinfo->poll_instance && !node->typeinfo->poll_instance( const_cast(node), const_cast(nodetree), r_disabled_hint)) { - valid = false; - break; + return false; } } - return valid; + return true; } static void add_new_socket_from_interface(bNodeTree &node_tree, @@ -460,62 +457,53 @@ bNodeSocket *node_group_input_find_socket(bNode *node, const char *identifier) void node_group_input_update(bNodeTree *ntree, bNode *node) { bNodeSocket *extsock = (bNodeSocket *)node->outputs.last; - bNodeLink *link, *linknext, *exposelink; /* Adding a tree socket and verifying will remove the extension socket! * This list caches the existing links from the extension socket - * so they can be recreated after verification. - */ - ListBase tmplinks; + * so they can be recreated after verification. */ + Vector temp_links; /* find links from the extension socket and store them */ - BLI_listbase_clear(&tmplinks); - for (link = (bNodeLink *)ntree->links.first; link; link = linknext) { - linknext = link->next; + LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) { if (nodeLinkIsHidden(link)) { continue; } if (link->fromsock == extsock) { - bNodeLink *tlink = MEM_cnew("temporary link"); - *tlink = *link; - BLI_addtail(&tmplinks, tlink); - + temp_links.append(*link); nodeRemLink(ntree, link); } } /* find valid link to expose */ - exposelink = nullptr; - for (link = (bNodeLink *)tmplinks.first; link; link = link->next) { + bNodeLink *exposelink = nullptr; + for (bNodeLink &link : temp_links) { /* XXX Multiple sockets can be connected to the extension socket at once, * in that case the arbitrary first link determines name and type. * This could be improved by choosing the "best" type among all links, * whatever that means. */ - if (!is_group_extension_socket(link->tonode, link->tosock)) { - exposelink = link; + if (!is_group_extension_socket(link.tonode, link.tosock)) { + exposelink = &link; break; } } if (exposelink) { - bNodeSocket *gsock, *newsock; - - gsock = ntreeAddSocketInterfaceFromSocket(ntree, exposelink->tonode, exposelink->tosock); + bNodeSocket *gsock = ntreeAddSocketInterfaceFromSocket( + ntree, exposelink->tonode, exposelink->tosock); node_group_input_update(ntree, node); - newsock = node_group_input_find_socket(node, gsock->identifier); + bNodeSocket *newsock = node_group_input_find_socket(node, gsock->identifier); /* redirect links from the extension socket */ - for (link = (bNodeLink *)tmplinks.first; link; link = link->next) { - bNodeLink *newlink = nodeAddLink(ntree, node, newsock, link->tonode, link->tosock); + for (bNodeLink &link : temp_links) { + bNodeLink *newlink = nodeAddLink(ntree, node, newsock, link.tonode, link.tosock); if (newlink->tosock->flag & SOCK_MULTI_INPUT) { - newlink->multi_input_socket_index = link->multi_input_socket_index; + newlink->multi_input_socket_index = link.multi_input_socket_index; } } } - BLI_freelistN(&tmplinks); group_verify_socket_list(*ntree, *node, ntree->inputs, node->outputs, SOCK_OUT, true); } @@ -552,60 +540,51 @@ bNodeSocket *node_group_output_find_socket(bNode *node, const char *identifier) void node_group_output_update(bNodeTree *ntree, bNode *node) { bNodeSocket *extsock = (bNodeSocket *)node->inputs.last; - bNodeLink *link, *linknext, *exposelink; /* Adding a tree socket and verifying will remove the extension socket! * This list caches the existing links to the extension socket - * so they can be recreated after verification. - */ - ListBase tmplinks; + * so they can be recreated after verification. */ + Vector temp_links; /* find links to the extension socket and store them */ - BLI_listbase_clear(&tmplinks); - for (link = (bNodeLink *)ntree->links.first; link; link = linknext) { - linknext = link->next; + LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) { if (nodeLinkIsHidden(link)) { continue; } if (link->tosock == extsock) { - bNodeLink *tlink = MEM_cnew("temporary link"); - *tlink = *link; - BLI_addtail(&tmplinks, tlink); - + temp_links.append(*link); nodeRemLink(ntree, link); } } /* find valid link to expose */ - exposelink = nullptr; - for (link = (bNodeLink *)tmplinks.first; link; link = link->next) { + bNodeLink *exposelink = nullptr; + for (bNodeLink &link : temp_links) { /* XXX Multiple sockets can be connected to the extension socket at once, * in that case the arbitrary first link determines name and type. * This could be improved by choosing the "best" type among all links, * whatever that means. */ - if (!is_group_extension_socket(link->fromnode, link->fromsock)) { - exposelink = link; + if (!is_group_extension_socket(link.fromnode, link.fromsock)) { + exposelink = &link; break; } } if (exposelink) { - bNodeSocket *gsock, *newsock; - /* XXX what if connecting virtual to virtual socket?? */ - gsock = ntreeAddSocketInterfaceFromSocket(ntree, exposelink->fromnode, exposelink->fromsock); + bNodeSocket *gsock = ntreeAddSocketInterfaceFromSocket( + ntree, exposelink->fromnode, exposelink->fromsock); node_group_output_update(ntree, node); - newsock = node_group_output_find_socket(node, gsock->identifier); + bNodeSocket *newsock = node_group_output_find_socket(node, gsock->identifier); /* redirect links to the extension socket */ - for (link = (bNodeLink *)tmplinks.first; link; link = link->next) { - nodeAddLink(ntree, link->fromnode, link->fromsock, node, newsock); + for (bNodeLink &link : temp_links) { + nodeAddLink(ntree, link.fromnode, link.fromsock, node, newsock); } } - BLI_freelistN(&tmplinks); group_verify_socket_list(*ntree, *node, ntree->outputs, node->inputs, SOCK_IN, true); } -- cgit v1.2.3 From 8b29d6cd75c92c3931476e9b8c5b9449cd6f4cab Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Sat, 5 Nov 2022 19:00:50 +0100 Subject: Cleanup: Remove unused node function --- source/blender/nodes/intern/node_common.cc | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'source/blender/nodes/intern/node_common.cc') diff --git a/source/blender/nodes/intern/node_common.cc b/source/blender/nodes/intern/node_common.cc index 37a52daa73c..69631fa5213 100644 --- a/source/blender/nodes/intern/node_common.cc +++ b/source/blender/nodes/intern/node_common.cc @@ -416,17 +416,6 @@ bool BKE_node_is_connected_to_output(bNodeTree *ntree, bNode *node) return node_is_connected_to_output_recursive(ntree, node); } -void BKE_node_tree_unlink_id(ID *id, struct bNodeTree *ntree) -{ - bNode *node; - - for (node = (bNode *)ntree->nodes.first; node; node = node->next) { - if (node->id == id) { - node->id = nullptr; - } - } -} - /** \} */ /* -------------------------------------------------------------------- */ -- cgit v1.2.3 From 3852094b35ea659094ab30ffca9e2fe086b1a368 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Sat, 5 Nov 2022 22:40:17 +0100 Subject: Cleanup: Nodes: Use const arguments, avoid recursive iteration Use the node topology cache and avoid modifying the node tree in a non-threadsafe way to improve the predictability of using the helper function. Replaces the implementation from e0d40471364aafca967b6ebd52. --- source/blender/nodes/intern/node_common.cc | 48 +++++++++++------------------- 1 file changed, 18 insertions(+), 30 deletions(-) (limited to 'source/blender/nodes/intern/node_common.cc') diff --git a/source/blender/nodes/intern/node_common.cc b/source/blender/nodes/intern/node_common.cc index 69631fa5213..975bf0c01ca 100644 --- a/source/blender/nodes/intern/node_common.cc +++ b/source/blender/nodes/intern/node_common.cc @@ -22,6 +22,7 @@ #include "BLT_translation.h" #include "BKE_node.h" +#include "BKE_node_runtime.hh" #include "BKE_node_tree_update.h" #include "RNA_types.h" @@ -378,42 +379,29 @@ void ntree_update_reroute_nodes(bNodeTree *ntree) } } -static bool node_is_connected_to_output_recursive(bNodeTree *ntree, bNode *node) +bool BKE_node_is_connected_to_output(const bNodeTree *ntree, const bNode *node) { - bNodeLink *link; - - /* avoid redundant checks, and infinite loops in case of cyclic node links */ - if (node->done) { - return false; - } - node->done = 1; - - /* main test, done before child loop so it catches output nodes themselves as well */ - if (node->typeinfo->nclass == NODE_CLASS_OUTPUT && node->flag & NODE_DO_OUTPUT) { - return true; + ntree->ensure_topology_cache(); + Stack nodes_to_check; + for (const bNodeSocket *socket : node->output_sockets()) { + for (const bNodeLink *link : socket->directly_linked_links()) { + nodes_to_check.push(link->tonode); + } } - - /* test all connected nodes, first positive find is sufficient to return true */ - for (link = (bNodeLink *)ntree->links.first; link; link = link->next) { - if (link->fromnode == node) { - if (node_is_connected_to_output_recursive(ntree, link->tonode)) { - return true; + while (!nodes_to_check.is_empty()) { + const bNode *next_node = nodes_to_check.pop(); + for (const bNodeSocket *socket : next_node->output_sockets()) { + for (const bNodeLink *link : socket->directly_linked_links()) { + if (link->tonode->typeinfo->nclass == NODE_CLASS_OUTPUT && + link->tonode->flag & NODE_DO_OUTPUT) { + return true; + } + nodes_to_check.push(link->tonode); } } } - return false; -} - -bool BKE_node_is_connected_to_output(bNodeTree *ntree, bNode *node) -{ - bNode *tnode; - - /* clear flags */ - for (tnode = (bNode *)ntree->nodes.first; tnode; tnode = tnode->next) { - tnode->done = 0; - } - return node_is_connected_to_output_recursive(ntree, node); + return false; } /** \} */ -- cgit v1.2.3