Cleanup: Don't do recursion where possible in node.cc #105394
|
@ -2051,10 +2051,16 @@ bool nodeFindNodeTry(bNodeTree *ntree, bNodeSocket *sock, bNode **r_node, int *r
|
|||
|
||||
bNode *nodeFindRootParent(bNode *node)
|
||||
{
|
||||
if (node->parent) {
|
||||
return nodeFindRootParent(node->parent);
|
||||
bNode *t_node = node;
|
||||
while (t_node->parent != nullptr) {
|
||||
t_node = t_node->parent;
|
||||
}
|
||||
return node->type == NODE_FRAME ? node : nullptr;
|
||||
|
||||
if (t_node->type != NODE_FRAME) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return t_node;
|
||||
}
|
||||
|
||||
bool nodeIsChildOf(const bNode *parent, const bNode *child)
|
||||
|
@ -2062,9 +2068,16 @@ bool nodeIsChildOf(const bNode *parent, const bNode *child)
|
|||
if (parent == child) {
|
||||
mod_moder marked this conversation as resolved
|
||||
return true;
|
||||
}
|
||||
if (child->parent) {
|
||||
return nodeIsChildOf(parent, child->parent);
|
||||
|
||||
const bNode *t_child = child;
|
||||
while (t_child->parent != nullptr) {
|
||||
t_child = t_child->parent;
|
||||
|
||||
if (t_child == parent) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2547,28 +2560,42 @@ void nodeInternalRelink(bNodeTree *ntree, bNode *node)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Location mapping in parent frame node space.
|
||||
*/
|
||||
static void nodeViewMapping(const bNode *node, float &mapping_x, float &mapping_y)
|
||||
{
|
||||
const bNode *t_node = node;
|
||||
|
||||
mapping_x += t_node->locx;
|
||||
mapping_y += t_node->locy;
|
||||
|
||||
while (t_node->parent != nullptr) {
|
||||
t_node = t_node->parent;
|
||||
|
||||
mapping_x += t_node->locx;
|
||||
mapping_y += t_node->locy;
|
||||
}
|
||||
}
|
||||
|
||||
void nodeToView(const bNode *node, float x, float y, float *rx, float *ry)
|
||||
{
|
||||
if (node->parent) {
|
||||
nodeToView(node->parent, x + node->locx, y + node->locy, rx, ry);
|
||||
}
|
||||
else {
|
||||
*rx = x + node->locx;
|
||||
*ry = y + node->locy;
|
||||
}
|
||||
float mapping_x = 0.0f;
|
||||
float mapping_y = 0.0f;
|
||||
nodeViewMapping(node, mapping_x, mapping_y);
|
||||
|
||||
*rx = mapping_x + x;
|
||||
*ry = mapping_y + y;
|
||||
}
|
||||
|
||||
void nodeFromView(const bNode *node, float x, float y, float *rx, float *ry)
|
||||
{
|
||||
if (node->parent) {
|
||||
nodeFromView(node->parent, x, y, rx, ry);
|
||||
*rx -= node->locx;
|
||||
*ry -= node->locy;
|
||||
}
|
||||
else {
|
||||
*rx = x - node->locx;
|
||||
*ry = y - node->locy;
|
||||
}
|
||||
float mapping_x = 0.0f;
|
||||
float mapping_y = 0.0f;
|
||||
nodeViewMapping(node, mapping_x, mapping_y);
|
||||
|
||||
*rx = -mapping_x + x;
|
||||
*ry = -mapping_y + y;
|
||||
}
|
||||
|
||||
bool nodeAttachNodeCheck(const bNode *node, const bNode *parent)
|
||||
|
|
Loading…
Reference in New Issue
I think
nodeIsChildOf
andnodeAttachNodeCheck
do the same thing - just the order of child and parent in the function parameters is different.Maybe this can be deduplicated? I think the naming
nodeIsChildOf
is much better anyway.nodeAttachNodeCheck
doesn't really tell you what it's doing.Hello, yes, I am also a little frustrated by this state of affairs.
It seems like it would be much better to put the data about parenting in a separate structure that would belong to the node tree ... although I don't see much benefit here either /
The difference is that one loop just looks for the root and the other does the comparison of each element in the process...
The most general solution would be a template iterator over all nodes of this singly linked list.
But here I'm not sure that for the sake of 4 functions of working with parents, we need to make an iterator function for all parents, like something like
@lone_noel I once again delved into the code, and realized that I was blind and reading your comment, i simply did not understand that you pointed to a function that I did not even touch on in this PR!
I'm looking at the related code, and I'm having a nightmare with parts that are always inaccessible and so on... well, I'll try to look into it. But for now, it seems like it could be a separate cleanup.