[Bf-blender-cvs] [77aef03d8ad] master: Cleanup: reduce variable scopes
Jacques Lucke
noreply at git.blender.org
Fri Oct 16 18:06:41 CEST 2020
Commit: 77aef03d8ade0e147a4a16354bcb33432e3d2f04
Author: Jacques Lucke
Date: Fri Oct 16 18:06:30 2020 +0200
Branches: master
https://developer.blender.org/rB77aef03d8ade0e147a4a16354bcb33432e3d2f04
Cleanup: reduce variable scopes
===================================================================
M source/blender/editors/space_node/node_relationships.c
===================================================================
diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c
index 01b4de90084..b6d9cdc729d 100644
--- a/source/blender/editors/space_node/node_relationships.c
+++ b/source/blender/editors/space_node/node_relationships.c
@@ -71,7 +71,7 @@ static bool ntree_check_nodes_connected_dfs(bNodeTree *ntree, bNode *from, bNode
return false;
}
from->flag |= NODE_TEST;
- for (bNodeLink *link = ntree->links.first; link != NULL; link = link->next) {
+ LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
if (link->fromnode == from) {
if (link->tonode == to) {
return true;
@@ -136,8 +136,7 @@ bool node_connected_to_output(Main *bmain, bNodeTree *ntree, bNode *node)
if (ntree_has_drivers(ntree)) {
return true;
}
- for (bNode *current_node = ntree->nodes.first; current_node != NULL;
- current_node = current_node->next) {
+ LISTBASE_FOREACH (bNode *, current_node, &ntree->nodes) {
/* Special case for group nodes -- if modified node connected to a group
* with active output inside we consider refresh is needed.
*
@@ -211,10 +210,8 @@ static bNodeSocket *best_socket_output(bNodeTree *ntree,
bNodeSocket *sock_target,
const bool allow_multiple)
{
- bNodeSocket *sock;
-
/* first look for selected output */
- for (sock = node->outputs.first; sock; sock = sock->next) {
+ LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
if (!socket_is_available(ntree, sock, allow_multiple)) {
continue;
}
@@ -225,7 +222,7 @@ static bNodeSocket *best_socket_output(bNodeTree *ntree,
}
/* try to find a socket with a matching name */
- for (sock = node->outputs.first; sock; sock = sock->next) {
+ LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
if (!socket_is_available(ntree, sock, allow_multiple)) {
continue;
}
@@ -239,8 +236,7 @@ static bNodeSocket *best_socket_output(bNodeTree *ntree,
}
/* otherwise settle for the first available socket of the right type */
- for (sock = node->outputs.first; sock; sock = sock->next) {
-
+ LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
if (!socket_is_available(ntree, sock, allow_multiple)) {
continue;
}
@@ -264,18 +260,15 @@ static bNodeSocket *best_socket_output(bNodeTree *ntree,
* sockets of higher types, such as image, first */
static bNodeSocket *best_socket_input(bNodeTree *ntree, bNode *node, int num, int replace)
{
- bNodeSocket *sock;
- int socktype, maxtype = 0;
- int a = 0;
-
- for (sock = node->inputs.first; sock; sock = sock->next) {
+ int maxtype = 0;
+ LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
maxtype = max_ii(sock->type, maxtype);
}
/* find sockets of higher 'types' first (i.e. image) */
- for (socktype = maxtype; socktype >= 0; socktype--) {
- for (sock = node->inputs.first; sock; sock = sock->next) {
-
+ int a = 0;
+ for (int socktype = maxtype; socktype >= 0; socktype--) {
+ LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
if (!socket_is_available(ntree, sock, replace)) {
a++;
continue;
@@ -320,13 +313,10 @@ static void snode_autoconnect(Main *bmain,
{
bNodeTree *ntree = snode->edittree;
ListBase *nodelist = MEM_callocN(sizeof(ListBase), "items_list");
- bNodeListItem *nli;
- bNode *node;
- int numlinks = 0;
- for (node = ntree->nodes.first; node; node = node->next) {
+ LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->flag & NODE_SELECT) {
- nli = MEM_mallocN(sizeof(bNodeListItem), "temporary node list item");
+ bNodeListItem *nli = MEM_mallocN(sizeof(bNodeListItem), "temporary node list item");
nli->node = node;
BLI_addtail(nodelist, nli);
}
@@ -335,24 +325,23 @@ static void snode_autoconnect(Main *bmain,
/* sort nodes left to right */
BLI_listbase_sort(nodelist, sort_nodes_locx);
- for (nli = nodelist->first; nli; nli = nli->next) {
- bNode *node_fr, *node_to;
- bNodeSocket *sock_fr, *sock_to;
+ int numlinks = 0;
+ LISTBASE_FOREACH (bNodeListItem *, nli, nodelist) {
bool has_selected_inputs = false;
if (nli->next == NULL) {
break;
}
- node_fr = nli->node;
- node_to = nli->next->node;
+ bNode *node_fr = nli->node;
+ bNode *node_to = nli->next->node;
/* corner case: input/output node aligned the wrong way around (T47729) */
if (BLI_listbase_is_empty(&node_to->inputs) || BLI_listbase_is_empty(&node_fr->outputs)) {
SWAP(bNode *, node_fr, node_to);
}
/* if there are selected sockets, connect those */
- for (sock_to = node_to->inputs.first; sock_to; sock_to = sock_to->next) {
+ LISTBASE_FOREACH (bNodeSocket *, sock_to, &node_to->inputs) {
if (sock_to->flag & SELECT) {
has_selected_inputs = 1;
@@ -361,7 +350,7 @@ static void snode_autoconnect(Main *bmain,
}
/* check for an appropriate output socket to connect from */
- sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple);
+ bNodeSocket *sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple);
if (!sock_fr) {
continue;
}
@@ -379,13 +368,13 @@ static void snode_autoconnect(Main *bmain,
for (int i = 0; i < num_inputs; i++) {
/* find the best guess input socket */
- sock_to = best_socket_input(ntree, node_to, i, replace);
+ bNodeSocket *sock_to = best_socket_input(ntree, node_to, i, replace);
if (!sock_to) {
continue;
}
/* check for an appropriate output socket to connect from */
- sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple);
+ bNodeSocket *sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple);
if (!sock_fr) {
continue;
}
@@ -411,9 +400,6 @@ static void snode_autoconnect(Main *bmain,
static int node_link_viewer(const bContext *C, bNode *tonode)
{
SpaceNode *snode = CTX_wm_space_node(C);
- bNode *node;
- bNodeLink *link;
- bNodeSocket *sock;
/* context check */
if (tonode == NULL || BLI_listbase_is_empty(&tonode->outputs)) {
@@ -424,31 +410,36 @@ static int node_link_viewer(const bContext *C, bNode *tonode)
}
/* get viewer */
- for (node = snode->edittree->nodes.first; node; node = node->next) {
+ bNode *viewer_node = NULL;
+ LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) {
if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
if (node->flag & NODE_DO_OUTPUT) {
+ viewer_node = node;
break;
}
}
}
/* no viewer, we make one active */
- if (node == NULL) {
- for (node = snode->edittree->nodes.first; node; node = node->next) {
+ if (viewer_node == NULL) {
+ LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) {
if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
node->flag |= NODE_DO_OUTPUT;
+ viewer_node = node;
break;
}
}
}
- sock = NULL;
+ bNodeSocket *sock = NULL;
+ bNodeLink *link = NULL;
/* try to find an already connected socket to cycle to the next */
- if (node) {
+ if (viewer_node) {
link = NULL;
+
for (link = snode->edittree->links.first; link; link = link->next) {
- if (link->tonode == node && link->fromnode == tonode) {
- if (link->tosock == node->inputs.first) {
+ if (link->tonode == viewer_node && link->fromnode == tonode) {
+ if (link->tosock == viewer_node->inputs.first) {
break;
}
}
@@ -488,10 +479,10 @@ static int node_link_viewer(const bContext *C, bNode *tonode)
if (sock) {
/* add a new viewer if none exists yet */
- if (!node) {
+ if (!viewer_node) {
/* XXX location is a quick hack, just place it next to the linked socket */
- node = node_add_node(C, NULL, CMP_NODE_VIEWER, sock->locx + 100, sock->locy);
- if (!node) {
+ viewer_node = node_add_node(C, NULL, CMP_NODE_VIEWER, sock->locx + 100, sock->locy);
+ if (!viewer_node) {
return OPERATOR_CANCELLED;
}
@@ -500,14 +491,14 @@ static int node_link_viewer(const bContext *C, bNode *tonode)
else {
/* get link to viewer */
for (link = snode->edittree->links.first; link; link = link->next) {
- if (link->tonode == node && link->tosock == node->inputs.first) {
+ if (link->tonode == viewer_node && link->tosock == viewer_node->inputs.first) {
break;
}
}
}
if (link == NULL) {
- nodeAddLink(snode->edittree, tonode, sock, node, node->inputs.first);
+ nodeAddLink(snode->edittree, tonode, sock, viewer_node, viewer_node->inputs.first);
}
else {
link->fromnode = tonode;
@@ -516,7 +507,7 @@ static int node_link_viewer(const bContext *C, bNode *tonode)
snode->edittree->update |= NTREE_UPDATE_LINKS;
}
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
- snode_update(snode, node);
+ snode_update(snode, viewer_node);
}
return OPERATOR_FINISHED;
@@ -525,9 +516,7 @@ static int node_link_viewer(const bContext *C, bNode *tonode)
static int node_active_link_viewer_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceNode *snode = CTX_wm_space_node(C);
- bNode *node;
-
- node = nodeGetActive(snode->edittree);
+ bNode *node = nodeGetActive(snode->edittree);
if (!node) {
return OPERATOR_CANCELLED;
@@ -571,9 +560,8 @@ static void node_link_update_header(bContext *C, bNodeLinkDrag *UNUSED(nldrag))
static int node_count_links(bNodeTree *ntree, bNodeSocket *sock)
{
- bNodeLink *link;
int count = 0;
- for (link = ntree->links.first; link; link = link->next) {
+ LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
if (link->fromsock == sock) {
count++;
}
@@ -588,14 +576,12 @@ static void node_remove_extra_links(SpaceNode *snode, bNodeLink *link)
{
bNodeTree *ntree = snode->edittree;
bNodeSocket *from = link->fromsock, *to = link->tosock;
- bNodeLink *tlink, *tlink_next;
int to_count = node_count_
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list