diff options
author | Jacques Lucke <jacques@blender.org> | 2020-03-06 14:20:05 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-03-06 14:33:04 +0300 |
commit | c08151c6fa4dec57b57ca8150a87aad9615683ed (patch) | |
tree | 3072bbc6a16dbcecbb12444c7c4aab5393c6cc2b /source/blender/nodes/intern | |
parent | 98d562af5265109500fbc9ec4600311e2143322e (diff) |
Nodes: Support storing socket link limits in bNodeSocketType
Currently the link limit of sockets is stored in bNodeSocket->limit.
This allows for a lot of flexibility, but is also very redundant.
In every case I've had to deal with so far, it would have "more correct"
to set the link limit per socket type and not per socket. I did not enforce
this constraint yet, because the link limit is exposed in the Python API,
which I did not want to break here.
In the future it might even make sense to only support only three kinds of link limits:
a) no links, b) at most one link, c) an arbitrary number links links. The other link
limits usually don't work well with tools (e.g. which link should be removed when a new
one is connected?) and is not used in practice. However, that is for another day.
Eventually, I would like to get rid of bNodeSocket->limit completely and replace it
either with fixed link limits or a callback in bNodeSocketType.
This patch consists of three parts:
**1. Support defining link limit in socket type**
This introduces a new `nodeSocketLinkLimit` function that serves as an indirection to
hide where the link limit of a socket is defined.
**2. Define link limits for builtin sockets on socket type**
Data sockets: one input, many outputs
Virtual sockets: one input, one output
Undefined sockets: many inputs, many outputs (to avoid that links are removed when the type of the socket is not known)
**3. Remove `bNodeSocketTemplate->limit`**
This wasn't used anymore after the second commit. Removing it simplifies socket definitions
in hundreds of places and removes a lot of redundancy.
Differential Revision: https://developer.blender.org/D7038
Reviewers: brecht
Diffstat (limited to 'source/blender/nodes/intern')
-rw-r--r-- | source/blender/nodes/intern/node_common.c | 4 | ||||
-rw-r--r-- | source/blender/nodes/intern/node_socket.c | 9 | ||||
-rw-r--r-- | source/blender/nodes/intern/node_util.c | 2 |
3 files changed, 11 insertions, 4 deletions
diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index ba00190b1da..7886fcf4f4d 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -301,11 +301,11 @@ static void node_reroute_inherit_type_recursive(bNodeTree *ntree, bNode *node, i } /* determine socket type from unambiguous input/output connection if possible */ - if (input->limit == 1 && input->link) { + if (nodeSocketLinkLimit(input) == 1 && input->link) { type = input->link->fromsock->type; type_idname = nodeStaticSocketType(type, PROP_NONE); } - else if (output->limit == 1 && output->link) { + else if (nodeSocketLinkLimit(output) == 1 && output->link) { type = output->link->tosock->type; type_idname = nodeStaticSocketType(type, PROP_NONE); } diff --git a/source/blender/nodes/intern/node_socket.c b/source/blender/nodes/intern/node_socket.c index 740e45bc5e1..15e41d03583 100644 --- a/source/blender/nodes/intern/node_socket.c +++ b/source/blender/nodes/intern/node_socket.c @@ -106,7 +106,6 @@ static bNodeSocket *verify_socket_template( if (sock->type != stemp->type) { nodeModifySocketType(ntree, node, sock, stemp->type, stemp->subtype); } - sock->limit = (stemp->limit == 0 ? (in_out == SOCK_IN ? 1 : 0xFFF) : stemp->limit); sock->flag |= stemp->flag; } else { @@ -430,6 +429,10 @@ static bNodeSocketType *make_standard_socket_type(int type, int subtype) stype->interface_from_socket = standard_node_socket_interface_from_socket; stype->interface_verify_socket = standard_node_socket_interface_verify_socket; + stype->use_link_limits_of_type = true; + stype->input_link_limit = 1; + stype->output_link_limit = 0xFFF; + return stype; } @@ -457,6 +460,10 @@ static bNodeSocketType *make_socket_type_virtual(void) ED_init_node_socket_type_virtual(stype); + stype->use_link_limits_of_type = true; + stype->input_link_limit = 1; + stype->output_link_limit = 1; + return stype; } diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c index 7d029e7a400..9efbdc079e6 100644 --- a/source/blender/nodes/intern/node_util.c +++ b/source/blender/nodes/intern/node_util.c @@ -280,7 +280,7 @@ static bNodeSocket *node_find_linkable_socket(bNodeTree *ntree, bNode *node, bNo if (!nodeSocketIsHidden(sock) && node_link_socket_match(sock, cur)) { int link_count = node_count_links(ntree, sock); /* take +1 into account since we would add a new link */ - if (link_count + 1 <= sock->limit) { + if (link_count + 1 <= nodeSocketLinkLimit(sock)) { return sock; /* found a valid free socket we can swap to */ } } |