Nodes: Avoid unnecessary sorting when selecting or moving nodes

Previously the nodes were sorted wven when there was no change.
This is a fixed version of e3ef6a6660, which was reverted by
dc937c5aee.
This commit is contained in:
Hans Goudey 2022-09-12 18:21:04 -05:00
parent 50913d719c
commit 400151833d
2 changed files with 45 additions and 42 deletions

View File

@ -1727,32 +1727,34 @@ static int node_attach_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent
SpaceNode &snode = *CTX_wm_space_node(C);
bNodeTree &ntree = *snode.edittree;
bNode *frame = node_find_frame_to_attach(region, ntree, event->mval);
if (frame == nullptr) {
/* Return "finished" so that auto offset operator macros can work. */
return OPERATOR_FINISHED;
}
if (frame) {
LISTBASE_FOREACH_BACKWARD (bNode *, node, &ntree.nodes) {
if (node->flag & NODE_SELECT) {
if (node->parent == nullptr) {
/* disallow moving a parent into its child */
if (nodeAttachNodeCheck(frame, node) == false) {
/* attach all unparented nodes */
nodeAttachNode(node, frame);
LISTBASE_FOREACH_BACKWARD (bNode *, node, &ntree.nodes) {
if (node->flag & NODE_SELECT) {
if (node->parent == nullptr) {
/* disallow moving a parent into its child */
if (nodeAttachNodeCheck(frame, node) == false) {
/* attach all unparented nodes */
nodeAttachNode(node, frame);
}
}
else {
/* attach nodes which share parent with the frame */
bNode *parent;
for (parent = frame->parent; parent; parent = parent->parent) {
if (parent == node->parent) {
break;
}
}
else {
/* attach nodes which share parent with the frame */
bNode *parent;
for (parent = frame->parent; parent; parent = parent->parent) {
if (parent == node->parent) {
break;
}
}
if (parent) {
/* disallow moving a parent into its child */
if (nodeAttachNodeCheck(frame, node) == false) {
nodeDetachNode(node);
nodeAttachNode(node, frame);
}
if (parent) {
/* disallow moving a parent into its child */
if (nodeAttachNodeCheck(frame, node) == false) {
nodeDetachNode(node);
nodeAttachNode(node, frame);
}
}
}

View File

@ -644,28 +644,29 @@ static bool node_mouse_select(bContext *C,
}
}
/* update node order */
if (changed || found) {
bool active_texture_changed = false;
bool viewer_node_changed = false;
if ((node != nullptr) && (node_was_selected == false || params->select_passthrough == false)) {
viewer_node_changed = (node->flag & NODE_DO_OUTPUT) == 0 && node->type == GEO_NODE_VIEWER;
ED_node_set_active(&bmain, &snode, snode.edittree, node, &active_texture_changed);
}
else if (node != nullptr && node->type == GEO_NODE_VIEWER) {
ED_spreadsheet_context_paths_set_geometry_node(&bmain, &snode, node);
}
ED_node_set_active_viewer_key(&snode);
node_sort(*snode.edittree);
if ((active_texture_changed && has_workbench_in_texture_color(wm, scene, ob)) ||
viewer_node_changed) {
DEG_id_tag_update(&snode.edittree->id, ID_RECALC_COPY_ON_WRITE);
}
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
if (!(changed || found)) {
return false;
}
return changed || found;
bool active_texture_changed = false;
bool viewer_node_changed = false;
if ((node != nullptr) && (node_was_selected == false || params->select_passthrough == false)) {
viewer_node_changed = (node->flag & NODE_DO_OUTPUT) == 0 && node->type == GEO_NODE_VIEWER;
ED_node_set_active(&bmain, &snode, snode.edittree, node, &active_texture_changed);
}
else if (node != nullptr && node->type == GEO_NODE_VIEWER) {
ED_spreadsheet_context_paths_set_geometry_node(&bmain, &snode, node);
}
ED_node_set_active_viewer_key(&snode);
node_sort(*snode.edittree);
if ((active_texture_changed && has_workbench_in_texture_color(wm, scene, ob)) ||
viewer_node_changed) {
DEG_id_tag_update(&snode.edittree->id, ID_RECALC_COPY_ON_WRITE);
}
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
return true;
}
static int node_select_exec(bContext *C, wmOperator *op)