Cleanup: move some data from bNodeSocket to run-time data
No functional changes are expected.
This commit is contained in:
parent
5938e97a24
commit
356373ff7a
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.fromsock->locx, link.fromsock->locy);
|
||||
const float2 to(link.tosock->locx, link.tosock->locy);
|
||||
const float2 from(link.fromsock->runtime->locx, link.fromsock->runtime->locy);
|
||||
const float2 to(link.tosock->runtime->locx, link.tosock->runtime->locy);
|
||||
|
||||
const float min_endpoint_distance = std::min(
|
||||
std::max(BLI_rctf_length_x(&v2d.cur, from.x), BLI_rctf_length_y(&v2d.cur, from.y)),
|
||||
|
|
|
@ -300,12 +300,12 @@ static void sort_multi_input_socket_links_with_drag(bNode &node,
|
|||
if (!socket->is_multi_input()) {
|
||||
continue;
|
||||
}
|
||||
const float2 &socket_location = {socket->locx, socket->locy};
|
||||
const float2 &socket_location = {socket->runtime->locx, socket->runtime->locy};
|
||||
|
||||
Vector<LinkAndPosition, 8> links;
|
||||
for (bNodeLink *link : socket->directly_linked_links()) {
|
||||
const float2 location = node_link_calculate_multi_input_position(
|
||||
socket_location, link->multi_input_socket_index, link->tosock->total_inputs);
|
||||
socket_location, link->multi_input_socket_index, link->tosock->runtime->total_inputs);
|
||||
links.append({link, location});
|
||||
};
|
||||
|
||||
|
@ -645,8 +645,8 @@ static int view_socket(const bContext &C,
|
|||
}
|
||||
if (viewer_node == nullptr) {
|
||||
const int viewer_type = get_default_viewer_type(&C);
|
||||
const float2 location{bsocket_to_view.locx / UI_DPI_FAC + 100,
|
||||
bsocket_to_view.locy / UI_DPI_FAC};
|
||||
const float2 location{bsocket_to_view.runtime->locx / UI_DPI_FAC + 100,
|
||||
bsocket_to_view.runtime->locy / UI_DPI_FAC};
|
||||
viewer_node = add_static_node(C, viewer_type, location);
|
||||
}
|
||||
|
||||
|
|
|
@ -126,12 +126,6 @@ typedef struct bNodeSocket {
|
|||
/** Runtime type identifier. */
|
||||
char idname[64];
|
||||
|
||||
/**
|
||||
* The location of the sockets, in the view-space of the node editor.
|
||||
* \note These are runtime data-- only calculated when drawing, and could be removed from DNA.
|
||||
*/
|
||||
float locx, locy;
|
||||
|
||||
/** Default input value used for unlinked sockets. */
|
||||
void *default_value;
|
||||
|
||||
|
@ -143,10 +137,7 @@ typedef struct bNodeSocket {
|
|||
* output. */
|
||||
char attribute_domain;
|
||||
|
||||
char _pad[2];
|
||||
|
||||
/* Runtime-only cache of the number of input links, for multi-input sockets. */
|
||||
short total_inputs;
|
||||
char _pad[4];
|
||||
|
||||
/** Custom dynamic defined label, MAX_NAME. */
|
||||
char label[64];
|
||||
|
@ -160,9 +151,6 @@ typedef struct bNodeSocket {
|
|||
*/
|
||||
char *default_attribute_name;
|
||||
|
||||
/** Cached data from execution. */
|
||||
void *cache;
|
||||
|
||||
/* internal data to retrieve relations and groups
|
||||
* DEPRECATED, now uses the generic identifier string instead
|
||||
*/
|
||||
|
|
|
@ -65,8 +65,8 @@ static void foreach_nodeclass(Scene * /*scene*/, void *calldata, bNodeClassCallb
|
|||
static void free_node_cache(bNodeTree * /*ntree*/, bNode *node)
|
||||
{
|
||||
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
|
||||
if (sock->cache) {
|
||||
sock->cache = nullptr;
|
||||
if (sock->runtime->cache) {
|
||||
sock->runtime->cache = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,8 +140,8 @@ static void local_merge(Main *bmain, bNodeTree *localtree, bNodeTree *ntree)
|
|||
|
||||
for (lsock = (bNodeSocket *)lnode->outputs.first; lsock; lsock = lsock->next) {
|
||||
if (bNodeSocket *orig_socket = nodeFindSocket(orig_node, SOCK_OUT, lsock->identifier)) {
|
||||
orig_socket->cache = lsock->cache;
|
||||
lsock->cache = nullptr;
|
||||
orig_socket->runtime->cache = lsock->runtime->cache;
|
||||
lsock->runtime->cache = nullptr;
|
||||
orig_socket = nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ bool cmp_node_poll_default(bNodeType * /*ntype*/, bNodeTree *ntree, const char *
|
|||
void cmp_node_update_default(bNodeTree * /*ntree*/, bNode *node)
|
||||
{
|
||||
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
|
||||
if (sock->cache) {
|
||||
if (sock->runtime->cache) {
|
||||
// free_compbuf(sock->cache);
|
||||
// sock->cache = nullptr;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "BKE_colortools.h"
|
||||
#include "BKE_node.h"
|
||||
#include "BKE_node_runtime.hh"
|
||||
#include "BKE_node_tree_update.h"
|
||||
|
||||
#include "RNA_access.h"
|
||||
|
@ -336,7 +337,7 @@ void node_insert_link_default(bNodeTree *ntree, bNode *node, bNodeLink *link)
|
|||
/* If we're not at the link limit of the target socket, we can skip
|
||||
* trying to move existing links to another socket. */
|
||||
const int to_link_limit = nodeSocketLinkLimit(socket);
|
||||
if (socket->total_inputs + 1 < to_link_limit) {
|
||||
if (socket->runtime->total_inputs + 1 < to_link_limit) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue