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/editors | |
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/editors')
-rw-r--r-- | source/blender/editors/space_node/node_relationships.c | 12 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_templates.c | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c index df7d5ca6ac1..75937d8da4e 100644 --- a/source/blender/editors/space_node/node_relationships.c +++ b/source/blender/editors/space_node/node_relationships.c @@ -588,6 +588,8 @@ static void node_remove_extra_links(SpaceNode *snode, bNodeLink *link) bNodeLink *tlink, *tlink_next; int to_count = node_count_links(ntree, to); int from_count = node_count_links(ntree, from); + int to_link_limit = nodeSocketLinkLimit(to); + int from_link_limit = nodeSocketLinkLimit(from); for (tlink = ntree->links.first; tlink; tlink = tlink_next) { tlink_next = tlink->next; @@ -596,7 +598,7 @@ static void node_remove_extra_links(SpaceNode *snode, bNodeLink *link) } if (tlink && tlink->fromsock == from) { - if (from_count > from->limit) { + if (from_count > from_link_limit) { nodeRemLink(ntree, tlink); tlink = NULL; from_count--; @@ -604,7 +606,7 @@ static void node_remove_extra_links(SpaceNode *snode, bNodeLink *link) } if (tlink && tlink->tosock == to) { - if (to_count > to->limit) { + if (to_count > to_link_limit) { nodeRemLink(ntree, tlink); tlink = NULL; to_count--; @@ -793,7 +795,8 @@ static bNodeLinkDrag *node_link_init(Main *bmain, SpaceNode *snode, float cursor nldrag = MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata"); num_links = nodeCountSocketLinks(snode->edittree, sock); - if (num_links > 0 && (num_links >= sock->limit || detach)) { + int link_limit = nodeSocketLinkLimit(sock); + if (num_links > 0 && (num_links >= link_limit || detach)) { /* dragged links are fixed on input side */ nldrag->in_out = SOCK_IN; /* detach current links and store them in the operator data */ @@ -844,7 +847,8 @@ static bNodeLinkDrag *node_link_init(Main *bmain, SpaceNode *snode, float cursor nldrag = MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata"); num_links = nodeCountSocketLinks(snode->edittree, sock); - if (num_links > 0 && (num_links >= sock->limit || detach)) { + int link_limit = nodeSocketLinkLimit(sock); + if (num_links > 0 && (num_links >= link_limit || detach)) { /* dragged links are fixed on output side */ nldrag->in_out = SOCK_OUT; /* detach current links and store them in the operator data */ diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c index 23bc6b32344..ccbd09d8b68 100644 --- a/source/blender/editors/space_node/node_templates.c +++ b/source/blender/editors/space_node/node_templates.c @@ -263,7 +263,7 @@ static void node_socket_add_replace(const bContext *C, for (sock_prev = node_prev->inputs.first; sock_prev; sock_prev = sock_prev->next) { for (sock_from = node_from->inputs.first; sock_from; sock_from = sock_from->next) { - if (nodeCountSocketLinks(ntree, sock_from) >= sock_from->limit) { + if (nodeCountSocketLinks(ntree, sock_from) >= nodeSocketLinkLimit(sock_from)) { continue; } |