[Bf-blender-cvs] [356373ff7af] master: Cleanup: move some data from bNodeSocket to run-time data
Jacques Lucke
noreply at git.blender.org
Wed Nov 23 10:43:06 CET 2022
Commit: 356373ff7af9dcc976a0258e18e71fc13de545b9
Author: Jacques Lucke
Date: Wed Nov 23 10:42:03 2022 +0100
Branches: master
https://developer.blender.org/rB356373ff7af9dcc976a0258e18e71fc13de545b9
Cleanup: move some data from bNodeSocket to run-time data
No functional changes are expected.
===================================================================
M source/blender/blenkernel/BKE_node_runtime.hh
M source/blender/blenkernel/intern/node.cc
M source/blender/editors/space_node/drawnode.cc
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/composite/node_composite_tree.cc
M source/blender/nodes/composite/node_composite_util.cc
M source/blender/nodes/intern/node_util.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_node_runtime.hh b/source/blender/blenkernel/BKE_node_runtime.hh
index ea523da0c55..3e712ea6523 100644
--- a/source/blender/blenkernel/BKE_node_runtime.hh
+++ b/source/blender/blenkernel/BKE_node_runtime.hh
@@ -104,6 +104,19 @@ class bNodeSocketRuntime : NonCopyable, NonMovable {
/** #eNodeTreeChangedFlag. */
uint32_t changed_flag = 0;
+ /**
+ * The location of the sockets, in the view-space of the node editor.
+ * \note Only calculated when drawing.
+ */
+ float locx = 0;
+ float locy = 0;
+
+ /* Runtime-only cache of the number of input links, for multi-input sockets. */
+ short total_inputs = 0;
+
+ /** Cached data from execution. */
+ void *cache = nullptr;
+
/** Only valid when #topology_cache_is_dirty is false. */
Vector<bNodeLink *> directly_linked_links;
Vector<bNodeSocket *> directly_linked_sockets;
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index d8451cab0f5..e17c5e31a46 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -641,8 +641,6 @@ static void direct_link_node_socket(BlendDataReader *reader, bNodeSocket *sock)
BLO_read_data_address(reader, &sock->storage);
BLO_read_data_address(reader, &sock->default_value);
BLO_read_data_address(reader, &sock->default_attribute_name);
- sock->total_inputs = 0; /* Clear runtime data set before drawing. */
- sock->cache = nullptr;
sock->runtime = MEM_new<bNodeSocketRuntime>(__func__);
}
@@ -2262,7 +2260,7 @@ static void node_socket_copy(bNodeSocket *sock_dst, const bNodeSocket *sock_src,
sock_dst->stack_index = 0;
/* XXX some compositor nodes (e.g. image, render layers) still store
* some persistent buffer data here, need to clear this to avoid dangling pointers. */
- sock_dst->cache = nullptr;
+ sock_dst->runtime->cache = nullptr;
}
namespace blender::bke {
diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index 8fc4461cd9d..708efc0c7a6 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -1585,10 +1585,10 @@ static float2 socket_link_connection_location(const bNode &node,
const bNodeSocket &socket,
const bNodeLink &link)
{
- const float2 socket_location(socket.locx, socket.locy);
+ const float2 socket_location(socket.runtime->locx, socket.runtime->locy);
if (socket.is_multi_input() && socket.is_input() && !(node.flag & NODE_HIDDEN)) {
return node_link_calculate_multi_input_position(
- socket_location, link.multi_input_socket_index, socket.total_inputs);
+ socket_location, link.multi_input_socket_index, socket.runtime->total_inputs);
}
return socket_location;
}
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 3d553ff3b0b..71ff840bd1d 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -417,8 +417,8 @@ static void node_update_basis(const bContext &C,
buty = min_ii(buty, dy - NODE_DY);
/* Round the socket location to stop it from jiggling. */
- socket->locx = round(loc.x + NODE_WIDTH(node));
- socket->locy = round(dy - NODE_DYS);
+ socket->runtime->locx = round(loc.x + NODE_WIDTH(node));
+ socket->runtime->locy = round(dy - NODE_DYS);
dy = buty;
if (socket->next) {
@@ -511,8 +511,9 @@ static void node_update_basis(const bContext &C,
* to account for the increased height of the taller sockets. */
float multi_input_socket_offset = 0.0f;
if (socket->flag & SOCK_MULTI_INPUT) {
- if (socket->total_inputs > 2) {
- multi_input_socket_offset = (socket->total_inputs - 2) * NODE_MULTI_INPUT_LINK_GAP;
+ if (socket->runtime->total_inputs > 2) {
+ multi_input_socket_offset = (socket->runtime->total_inputs - 2) *
+ NODE_MULTI_INPUT_LINK_GAP;
}
}
dy -= multi_input_socket_offset * 0.5f;
@@ -548,9 +549,9 @@ static void node_update_basis(const bContext &C,
/* Ensure minimum socket height in case layout is empty. */
buty = min_ii(buty, dy - NODE_DY);
- socket->locx = loc.x;
+ socket->runtime->locx = loc.x;
/* Round the socket vertical position to stop it from jiggling. */
- socket->locy = round(dy - NODE_DYS);
+ socket->runtime->locy = round(dy - NODE_DYS);
dy = buty - multi_input_socket_offset * 0.5;
if (socket->next) {
@@ -620,8 +621,8 @@ static void node_update_hidden(bNode &node, uiBlock &block)
LISTBASE_FOREACH (bNodeSocket *, socket, &node.outputs) {
if (!nodeSocketIsHidden(socket)) {
/* Round the socket location to stop it from jiggling. */
- socket->locx = round(node.runtime->totr.xmax - hiddenrad + sinf(rad) * hiddenrad);
- socket->locy = round(node.runtime->totr.ymin + hiddenrad + cosf(rad) * hiddenrad);
+ socket->runtime->locx = round(node.runtime->totr.xmax - hiddenrad + sinf(rad) * hiddenrad);
+ socket->runtime->locy = round(node.runtime->totr.ymin + hiddenrad + cosf(rad) * hiddenrad);
rad += drad;
}
}
@@ -632,8 +633,8 @@ static void node_update_hidden(bNode &node, uiBlock &block)
LISTBASE_FOREACH (bNodeSocket *, socket, &node.inputs) {
if (!nodeSocketIsHidden(socket)) {
/* Round the socket location to stop it from jiggling. */
- socket->locx = round(node.runtime->totr.xmin + hiddenrad + sinf(rad) * hiddenrad);
- socket->locy = round(node.runtime->totr.ymin + hiddenrad + cosf(rad) * hiddenrad);
+ socket->runtime->locx = round(node.runtime->totr.xmin + hiddenrad + sinf(rad) * hiddenrad);
+ socket->runtime->locy = round(node.runtime->totr.ymin + hiddenrad + cosf(rad) * hiddenrad);
rad += drad;
}
}
@@ -1172,7 +1173,7 @@ static void node_socket_draw_nested(const bContext &C,
const float size,
const bool selected)
{
- const float2 location(sock.locx, sock.locy);
+ const float2 location(sock.runtime->locx, sock.runtime->locy);
float color[4];
float outline_color[4];
@@ -1577,7 +1578,7 @@ static void node_draw_sockets(const View2D &v2d,
node_socket_color_get(C, ntree, node_ptr, *socket, color);
node_socket_outline_color_get(socket->flag & SELECT, socket->type, outline_color);
- const float2 location(socket->locx, socket->locy);
+ const float2 location(socket->runtime->locx, socket->runtime->locy);
node_socket_draw_multi_input(color, outline_color, width, height, location);
}
}
@@ -2618,7 +2619,7 @@ static void count_multi_input_socket_links(bNodeTree &ntree, SpaceNode &snode)
LISTBASE_FOREACH (bNode *, node, &ntree.nodes) {
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if (socket->flag & SOCK_MULTI_INPUT) {
- socket->total_inputs = counts.lookup_default(socket, 0);
+ socket->runtime->total_inputs = counts.lookup_default(socket, 0);
}
}
}
@@ -2682,12 +2683,12 @@ static void reroute_node_prepare_for_draw(bNode &node)
/* reroute node has exactly one input and one output, both in the same place */
bNodeSocket *socket = (bNodeSocket *)node.outputs.first;
- socket->locx = loc.x;
- socket->locy = loc.y;
+ socket->runtime->locx = loc.x;
+ socket->runtime->locy = loc.y;
socket = (bNodeSocket *)node.inputs.first;
- socket->locx = loc.x;
- socket->locy = loc.y;
+ socket->runtime->locx = loc.x;
+ socket->runtime->locy = loc.y;
const float size = 8.0f;
node.width = size * 2;
diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc
index 77cbd6a6793..7c9d350baa9 100644
--- a/source/blender/editors/space_node/node_edit.cc
+++ b/source/blender/editors/space_node/node_edit.cc
@@ -99,7 +99,8 @@ float node_socket_calculate_height(const bNodeSocket &socket)
{
float sock_height = NODE_SOCKSIZE * NODE_SOCKSIZE_DRAW_MULIPLIER;
if (socket.flag & SOCK_MULTI_INPUT) {
- sock_height += max_ii(NODE_MULTI_INPUT_LINK_GAP * 0.5f * socket.total_inputs, NODE_SOCKSIZE);
+ sock_height += max_ii(NODE_MULTI_INPUT_LINK_GAP * 0.5f * socket.runtime->total_inputs,
+ NODE_SOCKSIZE);
}
return sock_height;
}
@@ -1194,7 +1195,7 @@ void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set)
static bool cursor_isect_multi_input_socket(const float2 &cursor, const bNodeSocket &socket)
{
const float node_socket_height = node_socket_calculate_height(socket);
- const float2 location(socket.locx, socket.locy);
+ const float2 location(socket.runtime->locx, socket.runtime->locy);
/* `.xmax = socket->locx + NODE_SOCKSIZE * 5.5f`
* would be the same behavior as for regular sockets.
* But keep it smaller because for multi-input socket you
@@ -1244,7 +1245,7 @@ bool node_find_indicated_socket(SpaceNode &snode,
if (in_out & SOCK_IN) {
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
if (!nodeSocketIsHidden(sock)) {
- const float2 location(sock->locx, sock->locy);
+ 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)) {
if (!socket_is_occluded(location, *node, snode)) {
@@ -1267,7 +1268,7 @@ bool node_find_indicated_socket(SpaceNode &snode,
if (in_out & SOCK_OUT) {
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
if (!nodeSocketIsHidden(sock)) {
- const float2 location(sock->locx, sock->locy);
+ 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)) {
*nodep = node;
@@ -1295,8 +1296,8 @@ float node_link_dim_factor(const View2D &v2d, const bNodeLink &link)
return 1.0f;
}
- const float2 from(link.fr
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list