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.
This commit is contained in:
parent
83a4d51997
commit
f5dde382af
|
@ -318,8 +318,6 @@ typedef struct bNodeType {
|
|||
|
||||
/* optional handling of link insertion */
|
||||
void (*insert_link)(struct bNodeTree *ntree, struct bNode *node, struct bNodeLink *link);
|
||||
/* Update the internal links list, for muting and disconnect operators. */
|
||||
void (*update_internal_links)(struct bNodeTree *, struct bNode *node);
|
||||
|
||||
void (*free_self)(struct bNodeType *ntype);
|
||||
|
||||
|
@ -344,6 +342,9 @@ typedef struct bNodeType {
|
|||
/* Declaration to be used when it is not dynamic. */
|
||||
NodeDeclarationHandle *fixed_declaration;
|
||||
|
||||
/** True when the node cannot be muted. */
|
||||
bool no_muting;
|
||||
|
||||
/* RNA integration */
|
||||
ExtensionRNA rna_ext;
|
||||
} bNodeType;
|
||||
|
@ -891,8 +892,6 @@ void node_type_exec(struct bNodeType *ntype,
|
|||
NodeFreeExecFunction free_exec_fn,
|
||||
NodeExecFunction exec_fn);
|
||||
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn);
|
||||
void node_type_internal_links(struct bNodeType *ntype,
|
||||
void (*update_internal_links)(struct bNodeTree *, struct bNode *));
|
||||
|
||||
/** \} */
|
||||
|
||||
|
|
|
@ -5237,9 +5237,8 @@ bool nodeUpdateID(bNodeTree *ntree, ID *id)
|
|||
void nodeUpdateInternalLinks(bNodeTree *ntree, bNode *node)
|
||||
{
|
||||
BLI_freelistN(&node->internal_links);
|
||||
|
||||
if (node->typeinfo && node->typeinfo->update_internal_links) {
|
||||
node->typeinfo->update_internal_links(ntree, node);
|
||||
if (!node->typeinfo->no_muting) {
|
||||
node_internal_links_create(ntree, node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5504,12 +5503,6 @@ void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
|
|||
ntype->gpu_fn = gpu_fn;
|
||||
}
|
||||
|
||||
void node_type_internal_links(bNodeType *ntype,
|
||||
void (*update_internal_links)(bNodeTree *, bNode *))
|
||||
{
|
||||
ntype->update_internal_links = update_internal_links;
|
||||
}
|
||||
|
||||
/* callbacks for undefined types */
|
||||
|
||||
static bool node_undefined_poll(bNodeType *UNUSED(ntype),
|
||||
|
|
|
@ -1775,8 +1775,7 @@ static int node_mute_exec(bContext *C, wmOperator *UNUSED(op))
|
|||
ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
|
||||
|
||||
LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) {
|
||||
/* Only allow muting of nodes having a mute func! */
|
||||
if ((node->flag & SELECT) && node->typeinfo->update_internal_links) {
|
||||
if ((node->flag & SELECT) && !node->typeinfo->no_muting) {
|
||||
node->flag ^= NODE_MUTED;
|
||||
snode_update(snode, node);
|
||||
do_tag_update |= (do_tag_update || node_connected_to_output(bmain, snode->edittree, node));
|
||||
|
|
|
@ -45,6 +45,8 @@ struct bNodeSocket *node_group_output_find_socket(struct bNode *node, const char
|
|||
void node_group_input_update(struct bNodeTree *ntree, struct bNode *node);
|
||||
void node_group_output_update(struct bNodeTree *ntree, struct bNode *node);
|
||||
|
||||
void node_internal_links_create(struct bNodeTree *ntree, struct bNode *node);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -52,5 +52,4 @@ void cmp_node_type_base(bNodeType *ntype, int type, const char *name, short ncla
|
|||
ntype->poll = cmp_node_poll_default;
|
||||
ntype->updatefunc = cmp_node_update_default;
|
||||
ntype->insert_link = node_insert_link_default;
|
||||
ntype->update_internal_links = node_update_internal_links_default;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ void register_node_type_cmp_group(void)
|
|||
ntype.poll = cmp_node_poll_default;
|
||||
ntype.poll_instance = node_group_poll_instance;
|
||||
ntype.insert_link = node_insert_link_default;
|
||||
ntype.update_internal_links = node_update_internal_links_default;
|
||||
ntype.rna_ext.srna = RNA_struct_find("CompositorNodeGroup");
|
||||
BLI_assert(ntype.rna_ext.srna != nullptr);
|
||||
RNA_struct_blender_type_set(ntype.rna_ext.srna, &ntype);
|
||||
|
@ -66,7 +65,4 @@ void register_node_type_cmp_custom_group(bNodeType *ntype)
|
|||
if (ntype->insert_link == nullptr) {
|
||||
ntype->insert_link = node_insert_link_default;
|
||||
}
|
||||
if (ntype->update_internal_links == nullptr) {
|
||||
ntype->update_internal_links = node_update_internal_links_default;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,7 @@ void register_node_type_cmp_composite(void)
|
|||
cmp_node_type_base(&ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT, NODE_PREVIEW);
|
||||
ntype.declare = blender::nodes::cmp_node_composite_declare;
|
||||
|
||||
/* Do not allow muting for this node. */
|
||||
node_type_internal_links(&ntype, nullptr);
|
||||
ntype.no_muting = true;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
|
|
@ -53,8 +53,7 @@ void register_node_type_cmp_splitviewer(void)
|
|||
node_type_init(&ntype, node_composit_init_splitviewer);
|
||||
node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
|
||||
|
||||
/* Do not allow muting for this node. */
|
||||
node_type_internal_links(&ntype, nullptr);
|
||||
ntype.no_muting = true;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ void register_node_type_cmp_viewer(void)
|
|||
node_type_init(&ntype, node_composit_init_viewer);
|
||||
node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
|
||||
|
||||
node_type_internal_links(&ntype, nullptr);
|
||||
ntype.no_muting = true;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,5 @@ void fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclas
|
|||
{
|
||||
node_type_base(ntype, type, name, nclass, flag);
|
||||
ntype->poll = fn_node_poll_default;
|
||||
ntype->update_internal_links = node_update_internal_links_default;
|
||||
ntype->insert_link = node_insert_link_default;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,5 @@ void geo_node_type_base(bNodeType *ntype, int type, const char *name, short ncla
|
|||
{
|
||||
node_type_base(ntype, type, name, nclass, flag);
|
||||
ntype->poll = geo_node_poll_default;
|
||||
ntype->update_internal_links = node_update_internal_links_default;
|
||||
ntype->insert_link = node_insert_link_default;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ void register_node_type_geo_group(void)
|
|||
ntype.poll = geo_node_poll_default;
|
||||
ntype.poll_instance = node_group_poll_instance;
|
||||
ntype.insert_link = node_insert_link_default;
|
||||
ntype.update_internal_links = node_update_internal_links_default;
|
||||
ntype.rna_ext.srna = RNA_struct_find("GeometryNodeGroup");
|
||||
BLI_assert(ntype.rna_ext.srna != nullptr);
|
||||
RNA_struct_blender_type_set(ntype.rna_ext.srna, &ntype);
|
||||
|
@ -53,7 +52,4 @@ void register_node_type_geo_custom_group(bNodeType *ntype)
|
|||
if (ntype->insert_link == nullptr) {
|
||||
ntype->insert_link = node_insert_link_default;
|
||||
}
|
||||
if (ntype->update_internal_links == nullptr) {
|
||||
ntype->update_internal_links = node_update_internal_links_default;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -54,7 +54,6 @@ void sh_node_type_base(
|
|||
|
||||
ntype->poll = sh_node_poll_default;
|
||||
ntype->insert_link = node_insert_link_default;
|
||||
ntype->update_internal_links = node_update_internal_links_default;
|
||||
}
|
||||
|
||||
void sh_fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
|
||||
|
|
|
@ -237,7 +237,6 @@ void register_node_type_sh_group(void)
|
|||
ntype.poll = sh_node_poll_default;
|
||||
ntype.poll_instance = node_group_poll_instance;
|
||||
ntype.insert_link = node_insert_link_default;
|
||||
ntype.update_internal_links = node_update_internal_links_default;
|
||||
ntype.rna_ext.srna = RNA_struct_find("ShaderNodeGroup");
|
||||
BLI_assert(ntype.rna_ext.srna != NULL);
|
||||
RNA_struct_blender_type_set(ntype.rna_ext.srna, &ntype);
|
||||
|
@ -261,9 +260,6 @@ void register_node_type_sh_custom_group(bNodeType *ntype)
|
|||
if (ntype->insert_link == NULL) {
|
||||
ntype->insert_link = node_insert_link_default;
|
||||
}
|
||||
if (ntype->update_internal_links == NULL) {
|
||||
ntype->update_internal_links = node_update_internal_links_default;
|
||||
}
|
||||
|
||||
node_type_exec(ntype, group_initexec, group_freeexec, group_execute);
|
||||
node_type_gpu(ntype, gpu_group_execute);
|
||||
|
|
|
@ -64,8 +64,7 @@ void register_node_type_sh_output_aov(void)
|
|||
&ntype, "NodeShaderOutputAOV", node_free_standard_storage, node_copy_standard_storage);
|
||||
node_type_gpu(&ntype, node_shader_gpu_output_aov);
|
||||
|
||||
/* Do not allow muting output node. */
|
||||
node_type_internal_links(&ntype, NULL);
|
||||
ntype.no_muting = true;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
|
|
@ -36,8 +36,7 @@ void register_node_type_sh_output_light(void)
|
|||
node_type_init(&ntype, NULL);
|
||||
node_type_storage(&ntype, "", NULL, NULL);
|
||||
|
||||
/* Do not allow muting output node. */
|
||||
node_type_internal_links(&ntype, NULL);
|
||||
ntype.no_muting = true;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
|
|
@ -38,8 +38,7 @@ void register_node_type_sh_output_linestyle(void)
|
|||
node_type_socket_templates(&ntype, sh_node_output_linestyle_in, NULL);
|
||||
node_type_init(&ntype, NULL);
|
||||
|
||||
/* Do not allow muting output node. */
|
||||
node_type_internal_links(&ntype, NULL);
|
||||
ntype.no_muting = true;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
|
|
@ -84,8 +84,7 @@ void register_node_type_sh_output_material(void)
|
|||
node_type_storage(&ntype, "", NULL, NULL);
|
||||
node_type_gpu(&ntype, node_shader_gpu_output_material);
|
||||
|
||||
/* Do not allow muting output node. */
|
||||
node_type_internal_links(&ntype, NULL);
|
||||
ntype.no_muting = true;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
|
|
@ -52,8 +52,7 @@ void register_node_type_sh_output_world(void)
|
|||
node_type_storage(&ntype, "", NULL, NULL);
|
||||
node_type_gpu(&ntype, node_shader_gpu_output_world);
|
||||
|
||||
/* Do not allow muting output node. */
|
||||
node_type_internal_links(&ntype, NULL);
|
||||
ntype.no_muting = true;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,6 @@ void tex_node_type_base(
|
|||
|
||||
ntype->poll = tex_node_poll_default;
|
||||
ntype->insert_link = node_insert_link_default;
|
||||
ntype->update_internal_links = node_update_internal_links_default;
|
||||
}
|
||||
|
||||
static void tex_call_delegate(TexDelegate *dg, float *out, TexParams *params, short thread)
|
||||
|
|
|
@ -166,7 +166,6 @@ void register_node_type_tex_group(void)
|
|||
ntype.poll = tex_node_poll_default;
|
||||
ntype.poll_instance = node_group_poll_instance;
|
||||
ntype.insert_link = node_insert_link_default;
|
||||
ntype.update_internal_links = node_update_internal_links_default;
|
||||
ntype.rna_ext.srna = RNA_struct_find("TextureNodeGroup");
|
||||
BLI_assert(ntype.rna_ext.srna != NULL);
|
||||
RNA_struct_blender_type_set(ntype.rna_ext.srna, &ntype);
|
||||
|
|
|
@ -172,8 +172,7 @@ void register_node_type_tex_output(void)
|
|||
node_type_storage(&ntype, "TexNodeOutput", node_free_standard_storage, copy);
|
||||
node_type_exec(&ntype, NULL, NULL, exec);
|
||||
|
||||
/* Do not allow muting output. */
|
||||
node_type_internal_links(&ntype, NULL);
|
||||
ntype.no_muting = true;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
|
|
@ -60,8 +60,7 @@ void register_node_type_tex_viewer(void)
|
|||
node_type_socket_templates(&ntype, inputs, outputs);
|
||||
node_type_exec(&ntype, NULL, NULL, exec);
|
||||
|
||||
/* Do not allow muting viewer node. */
|
||||
node_type_internal_links(&ntype, NULL);
|
||||
ntype.no_muting = true;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue