From f5dde382af8078a2e5265e7d6710df7cb1b320a0 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 17 Nov 2021 11:52:44 +0100 Subject: Cleanup: use same function for updating internal links for all nodes Previously, node types had a callback that creates internal links. Pretty much all nodes used the same callback though. The exceptions are the reroute node (which probably shouldn't be mutable anyway) and some input/output nodes that are not mutable. Removing the callback helps with D13246, because it makes it easier to reason about which internal links are created and when they change. In the future, the internal links should be part of the node declaration. --- source/blender/nodes/intern/node_common.cc | 21 --------------------- source/blender/nodes/intern/node_util.c | 8 +++++++- source/blender/nodes/intern/node_util.h | 1 - 3 files changed, 7 insertions(+), 23 deletions(-) (limited to 'source/blender/nodes/intern') diff --git a/source/blender/nodes/intern/node_common.cc b/source/blender/nodes/intern/node_common.cc index e5ec50858d9..b80cedc9352 100644 --- a/source/blender/nodes/intern/node_common.cc +++ b/source/blender/nodes/intern/node_common.cc @@ -251,26 +251,6 @@ void register_node_type_frame(void) /** \name Node Re-Route * \{ */ -/* simple, only a single input and output here */ -static void node_reroute_update_internal_links(bNodeTree *ntree, bNode *node) -{ - bNodeLink *link; - - /* Security check! */ - if (!ntree) { - return; - } - - link = (bNodeLink *)MEM_callocN(sizeof(bNodeLink), "internal node link"); - link->fromnode = node; - link->fromsock = (bNodeSocket *)node->inputs.first; - link->tonode = node; - link->tosock = (bNodeSocket *)node->outputs.first; - /* internal link is always valid */ - link->flag |= NODE_LINK_VALID; - BLI_addtail(&node->internal_links, link); -} - static void node_reroute_init(bNodeTree *ntree, bNode *node) { /* NOTE: Cannot use socket templates for this, since it would reset the socket type @@ -288,7 +268,6 @@ void register_node_type_reroute(void) node_type_base(ntype, NODE_REROUTE, "Reroute", NODE_CLASS_LAYOUT, 0); node_type_init(ntype, node_reroute_init); - node_type_internal_links(ntype, node_reroute_update_internal_links); nodeRegisterType(ntype); } diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c index 4c08a6cb49c..231030030eb 100644 --- a/source/blender/nodes/intern/node_util.c +++ b/source/blender/nodes/intern/node_util.c @@ -41,6 +41,8 @@ #include "MEM_guardedalloc.h" +#include "NOD_common.h" + #include "node_util.h" /* -------------------------------------------------------------------- */ @@ -493,6 +495,10 @@ static int node_datatype_priority(eNodeSocketDatatype from, eNodeSocketDatatype /* select a suitable input socket for an output */ static bNodeSocket *select_internal_link_input(bNode *node, bNodeSocket *output) { + if (node->type == NODE_REROUTE) { + return node->inputs.first; + } + bNodeSocket *selected = NULL, *input; int i; int sel_priority = -1; @@ -526,7 +532,7 @@ static bNodeSocket *select_internal_link_input(bNode *node, bNodeSocket *output) return selected; } -void node_update_internal_links_default(bNodeTree *ntree, bNode *node) +void node_internal_links_create(bNodeTree *ntree, bNode *node) { bNodeLink *link; bNodeSocket *output, *input; diff --git a/source/blender/nodes/intern/node_util.h b/source/blender/nodes/intern/node_util.h index 9cbb21e02f7..c064ef4ab36 100644 --- a/source/blender/nodes/intern/node_util.h +++ b/source/blender/nodes/intern/node_util.h @@ -83,7 +83,6 @@ void node_filter_label(struct bNodeTree *ntree, struct bNode *node, char *label, /*** Link Handling */ void node_insert_link_default(struct bNodeTree *ntree, struct bNode *node, struct bNodeLink *link); -void node_update_internal_links_default(struct bNodeTree *ntree, struct bNode *node); float node_socket_get_float(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock); void node_socket_set_float(struct bNodeTree *ntree, -- cgit v1.2.3