[Bf-blender-cvs] [887105c4c9d] master: Cleanup: Use inline function for node socket visibility

Hans Goudey noreply at git.blender.org
Thu Dec 29 16:31:43 CET 2022


Commit: 887105c4c9df5df26f2553f71530c4cce058dddb
Author: Hans Goudey
Date:   Thu Dec 29 10:27:27 2022 -0500
Branches: master
https://developer.blender.org/rB887105c4c9df5df26f2553f71530c4cce058dddb

Cleanup: Use inline function for node socket visibility

This may very slightly improve performance too, the old function
was showing up in profiles when it shouldn't, since it's so small.

===================================================================

M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/BKE_node_runtime.hh
M	source/blender/blenkernel/intern/node.cc
M	source/blender/blenloader/intern/versioning_250.c
M	source/blender/editors/space_node/node_draw.cc
M	source/blender/editors/space_node/node_edit.cc
M	source/blender/editors/space_node/node_relationships.cc
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/nodes/intern/node_util.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index d247ee5eea0..266ee0d2988 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -843,7 +843,6 @@ struct bNode *nodeGetActivePaintCanvas(struct bNodeTree *ntree);
  */
 bool nodeSupportsActiveFlag(const struct bNode *node, int sub_active);
 
-int nodeSocketIsHidden(const struct bNodeSocket *sock);
 void nodeSetSocketAvailability(struct bNodeTree *ntree,
                                struct bNodeSocket *sock,
                                bool is_available);
diff --git a/source/blender/blenkernel/BKE_node_runtime.hh b/source/blender/blenkernel/BKE_node_runtime.hh
index 2c9f05c08a6..cedb3a6fd8c 100644
--- a/source/blender/blenkernel/BKE_node_runtime.hh
+++ b/source/blender/blenkernel/BKE_node_runtime.hh
@@ -680,6 +680,11 @@ inline bool bNodeSocket::is_available() const
   return (this->flag & SOCK_UNAVAIL) == 0;
 }
 
+inline bool bNodeSocket::is_visible() const
+{
+  return !this->is_hidden() && this->is_available();
+}
+
 inline bNode &bNodeSocket::owner_node()
 {
   BLI_assert(blender::bke::node_tree_runtime::topology_cache_is_available(*this));
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 097d14ae7b9..8bae267d1b8 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -2443,7 +2443,7 @@ void nodeRemSocketLinks(bNodeTree *ntree, bNodeSocket *sock)
 
 bool nodeLinkIsHidden(const bNodeLink *link)
 {
-  return nodeSocketIsHidden(link->fromsock) || nodeSocketIsHidden(link->tosock);
+  return !(link->fromsock->is_visible() && link->tosock->is_visible());
 }
 
 bool nodeLinkIsSelected(const bNodeLink *link)
@@ -3555,10 +3555,7 @@ void nodeSetActive(bNodeTree *ntree, bNode *node)
   node->flag |= flags_to_set;
 }
 
-int nodeSocketIsHidden(const bNodeSocket *sock)
-{
-  return ((sock->flag & (SOCK_HIDDEN | SOCK_UNAVAIL)) != 0);
-}
+
 
 void nodeSetSocketAvailability(bNodeTree *ntree, bNodeSocket *sock, bool is_available)
 {
diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c
index 5dd64051881..b01d1917f6d 100644
--- a/source/blender/blenloader/intern/versioning_250.c
+++ b/source/blender/blenloader/intern/versioning_250.c
@@ -1987,7 +1987,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain)
       /* add ntree->inputs/ntree->outputs sockets for all unlinked sockets in the group tree. */
       for (node = ntree->nodes.first; node; node = node->next) {
         for (sock = node->inputs.first; sock; sock = sock->next) {
-          if (!sock->link && !nodeSocketIsHidden(sock)) {
+          if (!sock->link && !((sock->flag & (SOCK_HIDDEN | SOCK_UNAVAIL)) != 0)) {
 
             gsock = do_versions_node_group_add_socket_2_56_2(
                 ntree, sock->name, sock->type, SOCK_IN);
@@ -2012,7 +2012,8 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain)
           }
         }
         for (sock = node->outputs.first; sock; sock = sock->next) {
-          if (nodeCountSocketLinks(ntree, sock) == 0 && !nodeSocketIsHidden(sock)) {
+          if (nodeCountSocketLinks(ntree, sock) == 0 &&
+              !((sock->flag & (SOCK_HIDDEN | SOCK_UNAVAIL)) != 0)) {
             gsock = do_versions_node_group_add_socket_2_56_2(
                 ntree, sock->name, sock->type, SOCK_OUT);
 
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 4d551557bac..a77b6dd2787 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -351,7 +351,7 @@ static void node_update_basis(const bContext &C,
 
   int buty;
   LISTBASE_FOREACH (bNodeSocket *, socket, &node.outputs) {
-    if (nodeSocketIsHidden(socket)) {
+    if (!socket->is_visible()) {
       continue;
     }
 
@@ -474,7 +474,7 @@ static void node_update_basis(const bContext &C,
 
   /* Input sockets. */
   LISTBASE_FOREACH (bNodeSocket *, socket, &node.inputs) {
-    if (nodeSocketIsHidden(socket)) {
+    if (!socket->is_visible()) {
       continue;
     }
 
@@ -567,12 +567,12 @@ static void node_update_hidden(bNode &node, uiBlock &block)
 
   /* Calculate minimal radius. */
   LISTBASE_FOREACH (bNodeSocket *, socket, &node.inputs) {
-    if (!nodeSocketIsHidden(socket)) {
+    if (socket->is_visible()) {
       totin++;
     }
   }
   LISTBASE_FOREACH (bNodeSocket *, socket, &node.outputs) {
-    if (!nodeSocketIsHidden(socket)) {
+    if (socket->is_visible()) {
       totout++;
     }
   }
@@ -593,7 +593,7 @@ static void node_update_hidden(bNode &node, uiBlock &block)
   float drad = rad;
 
   LISTBASE_FOREACH (bNodeSocket *, socket, &node.outputs) {
-    if (!nodeSocketIsHidden(socket)) {
+    if (socket->is_visible()) {
       /* Round the socket location to stop it from jiggling. */
       socket->runtime->locx = round(node.runtime->totr.xmax - hiddenrad + sinf(rad) * hiddenrad);
       socket->runtime->locy = round(node.runtime->totr.ymin + hiddenrad + cosf(rad) * hiddenrad);
@@ -605,7 +605,7 @@ static void node_update_hidden(bNode &node, uiBlock &block)
   rad = drad = -float(M_PI) / (1.0f + float(totin));
 
   LISTBASE_FOREACH (bNodeSocket *, socket, &node.inputs) {
-    if (!nodeSocketIsHidden(socket)) {
+    if (socket->is_visible()) {
       /* Round the socket location to stop it from jiggling. */
       socket->runtime->locx = round(node.runtime->totr.xmin + hiddenrad + sinf(rad) * hiddenrad);
       socket->runtime->locy = round(node.runtime->totr.ymin + hiddenrad + cosf(rad) * hiddenrad);
@@ -1429,7 +1429,7 @@ static void node_draw_sockets(const View2D &v2d,
   /* Socket inputs. */
   short selected_input_len = 0;
   LISTBASE_FOREACH (bNodeSocket *, sock, &node.inputs) {
-    if (nodeSocketIsHidden(sock)) {
+    if (!sock->is_visible()) {
       continue;
     }
     if (select_all || (sock->flag & SELECT)) {
@@ -1462,7 +1462,7 @@ static void node_draw_sockets(const View2D &v2d,
   short selected_output_len = 0;
   if (draw_outputs) {
     LISTBASE_FOREACH (bNodeSocket *, sock, &node.outputs) {
-      if (nodeSocketIsHidden(sock)) {
+      if (!sock->is_visible()) {
         continue;
       }
       if (select_all || (sock->flag & SELECT)) {
@@ -1500,7 +1500,7 @@ static void node_draw_sockets(const View2D &v2d,
     if (selected_input_len) {
       /* Socket inputs. */
       LISTBASE_FOREACH (bNodeSocket *, sock, &node.inputs) {
-        if (nodeSocketIsHidden(sock)) {
+        if (!sock->is_visible()) {
           continue;
         }
         /* Don't draw multi-input sockets here since they are drawn in a different batch. */
@@ -1530,7 +1530,7 @@ static void node_draw_sockets(const View2D &v2d,
     if (selected_output_len) {
       /* Socket outputs. */
       LISTBASE_FOREACH (bNodeSocket *, sock, &node.outputs) {
-        if (nodeSocketIsHidden(sock)) {
+        if (!sock->is_visible()) {
           continue;
         }
         if (select_all || (sock->flag & SELECT)) {
@@ -1564,7 +1564,7 @@ static void node_draw_sockets(const View2D &v2d,
   /* Draw multi-input sockets after the others because they are drawn with `UI_draw_roundbox`
    * rather than with `GL_POINT`. */
   LISTBASE_FOREACH (bNodeSocket *, socket, &node.inputs) {
-    if (nodeSocketIsHidden(socket)) {
+    if (!socket->is_visible()) {
       continue;
     }
     if (!(socket->flag & SOCK_MULTI_INPUT)) {
diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc
index 9bab9eaa2bf..9849a5385ba 100644
--- a/source/blender/editors/space_node/node_edit.cc
+++ b/source/blender/editors/space_node/node_edit.cc
@@ -1236,7 +1236,7 @@ bool node_find_indicated_socket(SpaceNode &snode,
 
     if (in_out & SOCK_IN) {
       LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
-        if (!nodeSocketIsHidden(sock)) {
+        if (sock->is_visible()) {
           const float2 location(sock->runtime->locx, sock->runtime->locy);
           if (sock->flag & SOCK_MULTI_INPUT && !(node->flag & NODE_HIDDEN)) {
             if (cursor_isect_multi_input_socket(cursor, *sock)) {
@@ -1259,7 +1259,7 @@ bool node_find_indicated_socket(SpaceNode &snode,
     }
     if (in_out & SOCK_OUT) {
       LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
-        if (!nodeSocketIsHidden(sock)) {
+        if (sock->is_visible()) {
           const float2 location(sock->runtime->locx, sock->runtime->locy);
           if (BLI_rctf_isect_pt(&rect, location.x, location.y)) {
             if (!socket_is_occluded(location, *node, snode)) {
diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc
index 08b054f3d7d..2d136c58edc 100644
--- a/source/blender/editors/space_node/node_relationships.cc
+++ b/source/blender/editors/space_node/node_relationships.cc
@@ -172,7 +172,7 @@ static void pick_input_link_by_link_intersect(const bContext &C,
 
 static bool socket_is_available(bNodeTree * /*ntree*/, bNodeSocket *sock, const bool allow_used)
 {
-  if (nodeSocketIsHidden(sock)) {
+  if (!sock->is_visible()) {
     return false;
   }
 
@@ -424,7 +424,7 @@ namespace viewer_linking {
 /* Depending on the node tree type, different socket types are supported by viewer nodes. */
 static bool socket_can_be_viewed(const bNodeSocket &socket)
 {
-  if (nodeSocketIsHidden(&socket)) {
+  if (!socket.is_visible()) {
     return false;
   }
   if (STREQ(socket.idname, "NodeSocketVirtual")) {
@@ -2076,7 +2076,7 @@ bNodeSocket *get_main_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_
     int index;
     LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, sockets, index) {
       const nodes::SocketDeclaration &socket_decl = *socket_decls[index];
-      if (nodeSocketIsHidden(socket)) {
+      if (!socket->is_visible()) {
         continue;
       }
       if (socket_decl.is_default_link_socket()) {
@@ -2097,7 +2097,7 @@ bNodeSocket *get_main_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_
   /* try all priorities, starting from 'highest' */
   for (int priority = maxpriority; priority >= 0; prior

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list