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.
This commit is contained in:
parent
2bd8c67d10
commit
887105c4c9
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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; priority--) {
|
||||
LISTBASE_FOREACH (bNodeSocket *, sock, sockets) {
|
||||
if (!nodeSocketIsHidden(sock) && priority == get_main_socket_priority(sock)) {
|
||||
if (!!sock->is_visible() && priority == get_main_socket_priority(sock)) {
|
||||
return sock;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,6 +172,7 @@ typedef struct bNodeSocket {
|
|||
#ifdef __cplusplus
|
||||
bool is_hidden() const;
|
||||
bool is_available() const;
|
||||
bool is_visible() const;
|
||||
bool is_multi_input() const;
|
||||
bool is_input() const;
|
||||
bool is_output() const;
|
||||
|
|
|
@ -311,7 +311,7 @@ static bNodeSocket *node_find_linkable_socket(bNodeTree *ntree,
|
|||
/* Wrap around the list end. */
|
||||
bNodeSocket *socket_iter = to_socket->next ? to_socket->next : first;
|
||||
while (socket_iter != to_socket) {
|
||||
if (!nodeSocketIsHidden(socket_iter) && node_link_socket_match(socket_iter, to_socket)) {
|
||||
if (socket_iter->is_visible() && node_link_socket_match(socket_iter, to_socket)) {
|
||||
const int link_count = node_count_links(ntree, socket_iter);
|
||||
/* Add one to account for the new link being added. */
|
||||
if (link_count + 1 <= nodeSocketLinkLimit(socket_iter)) {
|
||||
|
|
Loading…
Reference in New Issue