Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-03-06 14:20:05 +0300
committerJacques Lucke <jacques@blender.org>2020-03-06 14:33:04 +0300
commitc08151c6fa4dec57b57ca8150a87aad9615683ed (patch)
tree3072bbc6a16dbcecbb12444c7c4aab5393c6cc2b /source/blender/blenkernel
parent98d562af5265109500fbc9ec4600311e2143322e (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/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_node.h9
-rw-r--r--source/blender/blenkernel/intern/node.c16
2 files changed, 24 insertions, 1 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 9b184ef0e8c..163f48d7bbb 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -89,7 +89,7 @@ struct uiLayout;
* in RNA types automatically.
*/
typedef struct bNodeSocketTemplate {
- int type, limit;
+ int type;
char name[64]; /* MAX_NAME */
float val1, val2, val3, val4; /* default alloc value for inputs */
float min, max;
@@ -146,6 +146,11 @@ typedef struct bNodeSocketType {
/* for standard socket types in C */
int type, subtype;
+ /* When set, bNodeSocket->limit does not have any effect anymore. */
+ bool use_link_limits_of_type;
+ int input_link_limit;
+ int output_link_limit;
+
/* Callback to free the socket type. */
void (*free_self)(struct bNodeSocketType *stype);
} bNodeSocketType;
@@ -633,6 +638,8 @@ int nodeSocketIsHidden(struct bNodeSocket *sock);
void ntreeTagUsedSockets(struct bNodeTree *ntree);
void nodeSetSocketAvailability(struct bNodeSocket *sock, bool is_available);
+int nodeSocketLinkLimit(struct bNodeSocket *sock);
+
/* Node Clipboard */
void BKE_node_clipboard_init(struct bNodeTree *ntree);
void BKE_node_clipboard_clear(void);
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 4793ca93a3b..05f971ec367 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -2913,6 +2913,18 @@ void nodeSetSocketAvailability(bNodeSocket *sock, bool is_available)
}
}
+int nodeSocketLinkLimit(struct bNodeSocket *sock)
+{
+ bNodeSocketType *stype = sock->typeinfo;
+ if (stype != NULL && stype->use_link_limits_of_type) {
+ int limit = (sock->in_out == SOCK_IN) ? stype->input_link_limit : stype->output_link_limit;
+ return limit;
+ }
+ else {
+ return sock->limit;
+ }
+}
+
/* ************** Node Clipboard *********** */
#define USE_NODE_CB_VALIDATE
@@ -3847,6 +3859,10 @@ static void register_undefined_types(void)
/* extra type info for standard socket types */
NodeSocketTypeUndefined.type = SOCK_CUSTOM;
NodeSocketTypeUndefined.subtype = PROP_NONE;
+
+ NodeSocketTypeUndefined.use_link_limits_of_type = true;
+ NodeSocketTypeUndefined.input_link_limit = 0xFFF;
+ NodeSocketTypeUndefined.output_link_limit = 0xFFF;
}
static void registerCompositNodes(void)