Fix #106235: Use first link of multi-input socket for internal link #119280

Merged
Jacques Lucke merged 4 commits from mod_moder/blender:fix_multi_input_internal_links_all into blender-v4.1-release 2024-03-11 15:39:11 +01:00
1 changed files with 6 additions and 7 deletions
Showing only changes of commit 1519dd0c9d - Show all commits

View File

@ -619,9 +619,9 @@ class NodeTreeMainUpdater {
struct InternalLink {
bNodeSocket *from;
bNodeSocket *to;
int input_index = 0;
int multi_input_socket_index = 0;
mod_moder marked this conversation as resolved Outdated

Call it multi_input_socket_index. It should be renamed at the same time when we rename bNodeLink::multi_input_socket_index.

Call it `multi_input_socket_index`. It should be renamed at the same time when we rename `bNodeLink::multi_input_socket_index`.
BLI_STRUCT_EQUALITY_OPERATORS_3(InternalLink, from, to, input_index);
BLI_STRUCT_EQUALITY_OPERATORS_3(InternalLink, from, to, multi_input_socket_index);
};
const bNodeLink *first_non_dangling_link(const bNodeTree &ntree,
@ -660,12 +660,11 @@ class NodeTreeMainUpdater {
continue;
}
mod_moder marked this conversation as resolved Outdated

These are not "legacy". We will still change the name from index to sort_id but the values will stay the same.

These are not "legacy". We will still change the name from `index` to `sort_id` but the values will stay the same.

Reason why i don't like sort_id in the fact that order of sort_id is not explicit, and somewhere should be noted that order is reversed enumeration. How i should comment (if i should) the fact that i have to inverse index here?

Reason why i don't like sort_id in the fact that order of sort_id is not explicit, and somewhere should be noted that order is reversed enumeration. How i should comment (if i should) the fact that i have to inverse index here?

That comment still has to be added to the dna property. I'm also fine with just using the exact same name that's used in dna for now.

That comment still has to be added to the dna property. I'm also fine with just using the exact same name that's used in dna for now.
/* Multi-input index of link. */
const Span<const bNodeLink *> connected_links = input_socket->directly_linked_links();
mod_moder marked this conversation as resolved Outdated

This comment seems to be at the wrong line.

This comment seems to be at the wrong line.

This comment is about all below lines, but i think now this one is just redundant.

This comment is about all below lines, but i think now this one is just redundant.
const bNodeLink *connected_link = first_non_dangling_link(ntree, connected_links);
mod_moder marked this conversation as resolved Outdated

Use the index stored in the connected link instead of trying to compute it here.

Use the index stored in the connected link instead of trying to compute it here.

That is idea.

That is idea.
const int index = connected_link ? connected_link->multi_input_socket_index :
math::max<int>(0, connected_links.size() - 1);
std::max<int>(0, connected_links.size() - 1);
expected_internal_links.append(InternalLink{const_cast<bNodeSocket *>(input_socket),
mod_moder marked this conversation as resolved Outdated

Can use std::max here. I also get a compile error with math::max, probably because of a missing include.

Can use `std::max` here. I also get a compile error with `math::max`, probably because of a missing include.
const_cast<bNodeSocket *>(output_socket),
index});
@ -677,7 +676,7 @@ class NodeTreeMainUpdater {
continue;
}
const bool skip = std::all_of(
const bool all_expected_internal_links_exist = std::all_of(
node->runtime->internal_links.begin(),
mod_moder marked this conversation as resolved Outdated

skip -> all_expected_internal_links_exist

`skip` -> `all_expected_internal_links_exist`
node->runtime->internal_links.end(),
[&](const bNodeLink &link) {
@ -686,7 +685,7 @@ class NodeTreeMainUpdater {
return expected_internal_links.as_span().contains(internal_link);
});
if (skip) {
if (all_expected_internal_links_exist) {
continue;
}
@ -740,7 +739,7 @@ class NodeTreeMainUpdater {
link.fromsock = internal_link.from;
link.tonode = &node;
link.tosock = internal_link.to;
link.multi_input_socket_index = internal_link.input_index;
link.multi_input_socket_index = internal_link.multi_input_socket_index;
link.flag |= NODE_LINK_VALID;
node.runtime->internal_links.append(link);
}