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:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/nodes/intern/node_util.c
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/nodes/intern/node_util.c')
-rw-r--r--source/blender/nodes/intern/node_util.c530
1 files changed, 284 insertions, 246 deletions
diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c
index 069a5bb599e..a4a39caf8df 100644
--- a/source/blender/nodes/intern/node_util.c
+++ b/source/blender/nodes/intern/node_util.c
@@ -47,164 +47,163 @@
void node_free_curves(bNode *node)
{
- curvemapping_free(node->storage);
+ curvemapping_free(node->storage);
}
void node_free_standard_storage(bNode *node)
{
- if (node->storage) {
- MEM_freeN(node->storage);
- }
+ if (node->storage) {
+ MEM_freeN(node->storage);
+ }
}
void node_copy_curves(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node)
{
- dest_node->storage = curvemapping_copy(src_node->storage);
+ dest_node->storage = curvemapping_copy(src_node->storage);
}
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node)
{
- dest_node->storage = MEM_dupallocN(src_node->storage);
+ dest_node->storage = MEM_dupallocN(src_node->storage);
}
-void *node_initexec_curves(bNodeExecContext *UNUSED(context), bNode *node, bNodeInstanceKey UNUSED(key))
+void *node_initexec_curves(bNodeExecContext *UNUSED(context),
+ bNode *node,
+ bNodeInstanceKey UNUSED(key))
{
- curvemapping_initialize(node->storage);
- return NULL; /* unused return */
+ curvemapping_initialize(node->storage);
+ return NULL; /* unused return */
}
-
/**** Labels ****/
void node_blend_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
{
- const char *name;
- RNA_enum_name(rna_enum_ramp_blend_items, node->custom1, &name);
- BLI_strncpy(label, IFACE_(name), maxlen);
+ const char *name;
+ RNA_enum_name(rna_enum_ramp_blend_items, node->custom1, &name);
+ BLI_strncpy(label, IFACE_(name), maxlen);
}
void node_image_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
{
- /* if there is no loaded image, return an empty string, and let nodeLabel() fill in the proper type translation. */
- BLI_strncpy(label, (node->id) ? node->id->name + 2 : "", maxlen);
+ /* if there is no loaded image, return an empty string, and let nodeLabel() fill in the proper type translation. */
+ BLI_strncpy(label, (node->id) ? node->id->name + 2 : "", maxlen);
}
void node_math_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
{
- const char *name;
- RNA_enum_name(rna_enum_node_math_items, node->custom1, &name);
- BLI_strncpy(label, IFACE_(name), maxlen);
+ const char *name;
+ RNA_enum_name(rna_enum_node_math_items, node->custom1, &name);
+ BLI_strncpy(label, IFACE_(name), maxlen);
}
void node_vect_math_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
{
- const char *name;
- RNA_enum_name(rna_enum_node_vec_math_items, node->custom1, &name);
- BLI_strncpy(label, IFACE_(name), maxlen);
+ const char *name;
+ RNA_enum_name(rna_enum_node_vec_math_items, node->custom1, &name);
+ BLI_strncpy(label, IFACE_(name), maxlen);
}
void node_filter_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
{
- const char *name;
- RNA_enum_name(rna_enum_node_filter_items, node->custom1, &name);
- BLI_strncpy(label, IFACE_(name), maxlen);
+ const char *name;
+ RNA_enum_name(rna_enum_node_filter_items, node->custom1, &name);
+ BLI_strncpy(label, IFACE_(name), maxlen);
}
-
/*** Link Insertion ***/
/* test if two sockets are interchangeable */
static bool node_link_socket_match(bNodeSocket *a, bNodeSocket *b)
{
- /* check if sockets are of the same type */
- if (a->typeinfo != b->typeinfo) {
- return false;
- }
-
- /* tests if alphabetic prefix matches
- * this allows for imperfect matches, such as numeric suffixes,
- * like Color1/Color2
- */
- int prefix_len = 0;
- char *ca = a->name, *cb = b->name;
- for (; *ca != '\0' && *cb != '\0'; ++ca, ++cb) {
- /* end of common prefix? */
- if (*ca != *cb) {
- /* prefix delimited by non-alphabetic char */
- if (isalpha(*ca) || isalpha(*cb))
- return false;
- break;
- }
- ++prefix_len;
- }
- return prefix_len > 0;
+ /* check if sockets are of the same type */
+ if (a->typeinfo != b->typeinfo) {
+ return false;
+ }
+
+ /* tests if alphabetic prefix matches
+ * this allows for imperfect matches, such as numeric suffixes,
+ * like Color1/Color2
+ */
+ int prefix_len = 0;
+ char *ca = a->name, *cb = b->name;
+ for (; *ca != '\0' && *cb != '\0'; ++ca, ++cb) {
+ /* end of common prefix? */
+ if (*ca != *cb) {
+ /* prefix delimited by non-alphabetic char */
+ if (isalpha(*ca) || isalpha(*cb))
+ return false;
+ break;
+ }
+ ++prefix_len;
+ }
+ return prefix_len > 0;
}
static int node_count_links(bNodeTree *ntree, bNodeSocket *sock)
{
- bNodeLink *link;
- int count = 0;
- for (link = ntree->links.first; link; link = link->next) {
- if (link->fromsock == sock)
- ++count;
- if (link->tosock == sock)
- ++count;
- }
- return count;
+ bNodeLink *link;
+ int count = 0;
+ for (link = ntree->links.first; link; link = link->next) {
+ if (link->fromsock == sock)
+ ++count;
+ if (link->tosock == sock)
+ ++count;
+ }
+ return count;
}
/* find an eligible socket for linking */
static bNodeSocket *node_find_linkable_socket(bNodeTree *ntree, bNode *node, bNodeSocket *cur)
{
- /* link swapping: try to find a free slot with a matching name */
-
- bNodeSocket *first = cur->in_out == SOCK_IN ? node->inputs.first : node->outputs.first;
- bNodeSocket *sock;
-
- sock = cur->next ? cur->next : first; /* wrap around the list end */
- while (sock != cur) {
- 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)
- return sock; /* found a valid free socket we can swap to */
- }
-
- sock = sock->next ? sock->next : first; /* wrap around the list end */
- }
- return NULL;
+ /* link swapping: try to find a free slot with a matching name */
+
+ bNodeSocket *first = cur->in_out == SOCK_IN ? node->inputs.first : node->outputs.first;
+ bNodeSocket *sock;
+
+ sock = cur->next ? cur->next : first; /* wrap around the list end */
+ while (sock != cur) {
+ 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)
+ return sock; /* found a valid free socket we can swap to */
+ }
+
+ sock = sock->next ? sock->next : first; /* wrap around the list end */
+ }
+ return NULL;
}
void node_insert_link_default(bNodeTree *ntree, bNode *node, bNodeLink *link)
{
- bNodeSocket *sock = link->tosock;
- bNodeLink *tlink, *tlink_next;
-
- /* inputs can have one link only, outputs can have unlimited links */
- if (node != link->tonode)
- return;
-
- for (tlink = ntree->links.first; tlink; tlink = tlink_next) {
- bNodeSocket *new_sock;
- tlink_next = tlink->next;
-
- if (sock != tlink->tosock)
- continue;
-
- new_sock = node_find_linkable_socket(ntree, node, sock);
- if (new_sock && new_sock != sock) {
- /* redirect existing link */
- tlink->tosock = new_sock;
- }
- else if (!new_sock) {
- /* no possible replacement, remove tlink */
- nodeRemLink(ntree, tlink);
- tlink = NULL;
- }
- }
+ bNodeSocket *sock = link->tosock;
+ bNodeLink *tlink, *tlink_next;
+
+ /* inputs can have one link only, outputs can have unlimited links */
+ if (node != link->tonode)
+ return;
+
+ for (tlink = ntree->links.first; tlink; tlink = tlink_next) {
+ bNodeSocket *new_sock;
+ tlink_next = tlink->next;
+
+ if (sock != tlink->tosock)
+ continue;
+
+ new_sock = node_find_linkable_socket(ntree, node, sock);
+ if (new_sock && new_sock != sock) {
+ /* redirect existing link */
+ tlink->tosock = new_sock;
+ }
+ else if (!new_sock) {
+ /* no possible replacement, remove tlink */
+ nodeRemLink(ntree, tlink);
+ tlink = NULL;
+ }
+ }
}
-
/**** Internal Links (mute and disconnect) ****/
/* common datatype priorities, works for compositor, shader and texture nodes alike
@@ -214,184 +213,223 @@ void node_insert_link_default(bNodeTree *ntree, bNode *node, bNodeLink *link)
*/
static int node_datatype_priority(eNodeSocketDatatype from, eNodeSocketDatatype to)
{
- switch (to) {
- case SOCK_RGBA:
- switch (from) {
- case SOCK_RGBA: return 4;
- case SOCK_FLOAT: return 3;
- case SOCK_INT: return 2;
- case SOCK_BOOLEAN: return 1;
- default: return -1;
- }
- case SOCK_VECTOR:
- switch (from) {
- case SOCK_VECTOR: return 4;
- case SOCK_FLOAT: return 3;
- case SOCK_INT: return 2;
- case SOCK_BOOLEAN: return 1;
- default: return -1;
- }
- case SOCK_FLOAT:
- switch (from) {
- case SOCK_FLOAT: return 5;
- case SOCK_INT: return 4;
- case SOCK_BOOLEAN: return 3;
- case SOCK_RGBA: return 2;
- case SOCK_VECTOR: return 1;
- default: return -1;
- }
- case SOCK_INT:
- switch (from) {
- case SOCK_INT: return 5;
- case SOCK_FLOAT: return 4;
- case SOCK_BOOLEAN: return 3;
- case SOCK_RGBA: return 2;
- case SOCK_VECTOR: return 1;
- default: return -1;
- }
- case SOCK_BOOLEAN:
- switch (from) {
- case SOCK_BOOLEAN: return 5;
- case SOCK_INT: return 4;
- case SOCK_FLOAT: return 3;
- case SOCK_RGBA: return 2;
- case SOCK_VECTOR: return 1;
- default: return -1;
- }
- case SOCK_SHADER:
- switch (from) {
- case SOCK_SHADER: return 1;
- default: return -1;
- }
- case SOCK_STRING:
- switch (from) {
- case SOCK_STRING: return 1;
- default: return -1;
- }
- default: return -1;
- }
+ switch (to) {
+ case SOCK_RGBA:
+ switch (from) {
+ case SOCK_RGBA:
+ return 4;
+ case SOCK_FLOAT:
+ return 3;
+ case SOCK_INT:
+ return 2;
+ case SOCK_BOOLEAN:
+ return 1;
+ default:
+ return -1;
+ }
+ case SOCK_VECTOR:
+ switch (from) {
+ case SOCK_VECTOR:
+ return 4;
+ case SOCK_FLOAT:
+ return 3;
+ case SOCK_INT:
+ return 2;
+ case SOCK_BOOLEAN:
+ return 1;
+ default:
+ return -1;
+ }
+ case SOCK_FLOAT:
+ switch (from) {
+ case SOCK_FLOAT:
+ return 5;
+ case SOCK_INT:
+ return 4;
+ case SOCK_BOOLEAN:
+ return 3;
+ case SOCK_RGBA:
+ return 2;
+ case SOCK_VECTOR:
+ return 1;
+ default:
+ return -1;
+ }
+ case SOCK_INT:
+ switch (from) {
+ case SOCK_INT:
+ return 5;
+ case SOCK_FLOAT:
+ return 4;
+ case SOCK_BOOLEAN:
+ return 3;
+ case SOCK_RGBA:
+ return 2;
+ case SOCK_VECTOR:
+ return 1;
+ default:
+ return -1;
+ }
+ case SOCK_BOOLEAN:
+ switch (from) {
+ case SOCK_BOOLEAN:
+ return 5;
+ case SOCK_INT:
+ return 4;
+ case SOCK_FLOAT:
+ return 3;
+ case SOCK_RGBA:
+ return 2;
+ case SOCK_VECTOR:
+ return 1;
+ default:
+ return -1;
+ }
+ case SOCK_SHADER:
+ switch (from) {
+ case SOCK_SHADER:
+ return 1;
+ default:
+ return -1;
+ }
+ case SOCK_STRING:
+ switch (from) {
+ case SOCK_STRING:
+ return 1;
+ default:
+ return -1;
+ }
+ default:
+ return -1;
+ }
}
/* select a suitable input socket for an output */
static bNodeSocket *select_internal_link_input(bNode *node, bNodeSocket *output)
{
- bNodeSocket *selected = NULL, *input;
- int i;
- int sel_priority = -1;
- bool sel_is_linked = false;
-
- for (input = node->inputs.first, i = 0; input; input = input->next, ++i) {
- int priority = node_datatype_priority(input->type, output->type);
- bool is_linked = (input->link != NULL);
- bool preferred;
-
- if (nodeSocketIsHidden(input) || /* ignore hidden sockets */
- input->flag & SOCK_NO_INTERNAL_LINK || /* ignore if input is not allowed for internal connections */
- priority < 0 || /* ignore incompatible types */
- priority < sel_priority) /* ignore if we already found a higher priority input */
- {
- continue;
- }
-
- /* determine if this input is preferred over the currently selected */
- preferred = (priority > sel_priority) || /* prefer higher datatype priority */
- (is_linked && !sel_is_linked); /* prefer linked over unlinked */
-
- if (preferred) {
- selected = input;
- sel_is_linked = is_linked;
- sel_priority = priority;
- }
- }
-
- return selected;
+ bNodeSocket *selected = NULL, *input;
+ int i;
+ int sel_priority = -1;
+ bool sel_is_linked = false;
+
+ for (input = node->inputs.first, i = 0; input; input = input->next, ++i) {
+ int priority = node_datatype_priority(input->type, output->type);
+ bool is_linked = (input->link != NULL);
+ bool preferred;
+
+ if (nodeSocketIsHidden(input) || /* ignore hidden sockets */
+ input->flag &
+ SOCK_NO_INTERNAL_LINK || /* ignore if input is not allowed for internal connections */
+ priority < 0 || /* ignore incompatible types */
+ priority < sel_priority) /* ignore if we already found a higher priority input */
+ {
+ continue;
+ }
+
+ /* determine if this input is preferred over the currently selected */
+ preferred = (priority > sel_priority) || /* prefer higher datatype priority */
+ (is_linked && !sel_is_linked); /* prefer linked over unlinked */
+
+ if (preferred) {
+ selected = input;
+ sel_is_linked = is_linked;
+ sel_priority = priority;
+ }
+ }
+
+ return selected;
}
void node_update_internal_links_default(bNodeTree *ntree, bNode *node)
{
- bNodeLink *link;
- bNodeSocket *output, *input;
-
- /* sanity check */
- if (!ntree)
- return;
-
- /* use link pointer as a tag for handled sockets (for outputs is unused anyway) */
- for (output = node->outputs.first; output; output = output->next)
- output->link = NULL;
-
- for (link = ntree->links.first; link; link = link->next) {
- if (nodeLinkIsHidden(link))
- continue;
-
- output = link->fromsock;
- if (link->fromnode != node || output->link)
- continue;
- if (nodeSocketIsHidden(output) || output->flag & SOCK_NO_INTERNAL_LINK)
- continue;
- output->link = link; /* not really used, just for tagging handled sockets */
-
- /* look for suitable input */
- input = select_internal_link_input(node, output);
-
- if (input) {
- bNodeLink *ilink = MEM_callocN(sizeof(bNodeLink), "internal node link");
- ilink->fromnode = node;
- ilink->fromsock = input;
- ilink->tonode = node;
- ilink->tosock = output;
- /* internal link is always valid */
- ilink->flag |= NODE_LINK_VALID;
- BLI_addtail(&node->internal_links, ilink);
- }
- }
-
- /* clean up */
- for (output = node->outputs.first; output; output = output->next)
- output->link = NULL;
+ bNodeLink *link;
+ bNodeSocket *output, *input;
+
+ /* sanity check */
+ if (!ntree)
+ return;
+
+ /* use link pointer as a tag for handled sockets (for outputs is unused anyway) */
+ for (output = node->outputs.first; output; output = output->next)
+ output->link = NULL;
+
+ for (link = ntree->links.first; link; link = link->next) {
+ if (nodeLinkIsHidden(link))
+ continue;
+
+ output = link->fromsock;
+ if (link->fromnode != node || output->link)
+ continue;
+ if (nodeSocketIsHidden(output) || output->flag & SOCK_NO_INTERNAL_LINK)
+ continue;
+ output->link = link; /* not really used, just for tagging handled sockets */
+
+ /* look for suitable input */
+ input = select_internal_link_input(node, output);
+
+ if (input) {
+ bNodeLink *ilink = MEM_callocN(sizeof(bNodeLink), "internal node link");
+ ilink->fromnode = node;
+ ilink->fromsock = input;
+ ilink->tonode = node;
+ ilink->tosock = output;
+ /* internal link is always valid */
+ ilink->flag |= NODE_LINK_VALID;
+ BLI_addtail(&node->internal_links, ilink);
+ }
+ }
+
+ /* clean up */
+ for (output = node->outputs.first; output; output = output->next)
+ output->link = NULL;
}
-
/**** Default value RNA access ****/
float node_socket_get_float(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock)
{
- PointerRNA ptr;
- RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
- return RNA_float_get(&ptr, "default_value");
+ PointerRNA ptr;
+ RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
+ return RNA_float_get(&ptr, "default_value");
}
void node_socket_set_float(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, float value)
{
- PointerRNA ptr;
- RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
- RNA_float_set(&ptr, "default_value", value);
+ PointerRNA ptr;
+ RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
+ RNA_float_set(&ptr, "default_value", value);
}
void node_socket_get_color(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, float *value)
{
- PointerRNA ptr;
- RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
- RNA_float_get_array(&ptr, "default_value", value);
+ PointerRNA ptr;
+ RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
+ RNA_float_get_array(&ptr, "default_value", value);
}
-void node_socket_set_color(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, const float *value)
+void node_socket_set_color(bNodeTree *ntree,
+ bNode *UNUSED(node),
+ bNodeSocket *sock,
+ const float *value)
{
- PointerRNA ptr;
- RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
- RNA_float_set_array(&ptr, "default_value", value);
+ PointerRNA ptr;
+ RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
+ RNA_float_set_array(&ptr, "default_value", value);
}
void node_socket_get_vector(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, float *value)
{
- PointerRNA ptr;
- RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
- RNA_float_get_array(&ptr, "default_value", value);
+ PointerRNA ptr;
+ RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
+ RNA_float_get_array(&ptr, "default_value", value);
}
-void node_socket_set_vector(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, const float *value)
+void node_socket_set_vector(bNodeTree *ntree,
+ bNode *UNUSED(node),
+ bNodeSocket *sock,
+ const float *value)
{
- PointerRNA ptr;
- RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
- RNA_float_set_array(&ptr, "default_value", value);
+ PointerRNA ptr;
+ RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
+ RNA_float_set_array(&ptr, "default_value", value);
}