Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/node_tree_update.cc
| Show First 20 Lines • Show All 1,360 Lines • ▼ Show 20 Lines | private: | ||||
| /** | /** | ||||
| * Computes a hash that changes when the node tree topology connected to an output node changes. | * Computes a hash that changes when the node tree topology connected to an output node changes. | ||||
| * Adding reroutes does not have an effect on the hash. | * Adding reroutes does not have an effect on the hash. | ||||
| */ | */ | ||||
| uint32_t get_combined_socket_topology_hash(const NodeTreeRef &tree, | uint32_t get_combined_socket_topology_hash(const NodeTreeRef &tree, | ||||
| Span<const SocketRef *> sockets) | Span<const SocketRef *> sockets) | ||||
| { | { | ||||
| if (tree.has_link_cycles()) { | |||||
| /* Return dummy value when the link has any cycles. The algorithm below could be improved to | |||||
| * handle cycles more gracefully. */ | |||||
| return 0; | |||||
| } | |||||
| Array<uint32_t> hashes = this->get_socket_topology_hashes(tree, sockets); | Array<uint32_t> hashes = this->get_socket_topology_hashes(tree, sockets); | ||||
| uint32_t combined_hash = 0; | uint32_t combined_hash = 0; | ||||
| for (uint32_t hash : hashes) { | for (uint32_t hash : hashes) { | ||||
| combined_hash = noise::hash(combined_hash, hash); | combined_hash = noise::hash(combined_hash, hash); | ||||
| } | } | ||||
| return combined_hash; | return combined_hash; | ||||
| } | } | ||||
| Array<uint32_t> get_socket_topology_hashes(const NodeTreeRef &tree, | Array<uint32_t> get_socket_topology_hashes(const NodeTreeRef &tree, | ||||
| Span<const SocketRef *> sockets) | Span<const SocketRef *> sockets) | ||||
| { | { | ||||
| BLI_assert(!tree.has_link_cycles()); | |||||
| Array<std::optional<uint32_t>> hash_by_socket_id(tree.sockets().size()); | Array<std::optional<uint32_t>> hash_by_socket_id(tree.sockets().size()); | ||||
| Stack<const SocketRef *> sockets_to_check = sockets; | Stack<const SocketRef *> sockets_to_check = sockets; | ||||
| while (!sockets_to_check.is_empty()) { | while (!sockets_to_check.is_empty()) { | ||||
| const SocketRef &in_out_socket = *sockets_to_check.peek(); | const SocketRef &in_out_socket = *sockets_to_check.peek(); | ||||
| const NodeRef &node = in_out_socket.node(); | const NodeRef &node = in_out_socket.node(); | ||||
| if (hash_by_socket_id[in_out_socket.id()].has_value()) { | if (hash_by_socket_id[in_out_socket.id()].has_value()) { | ||||
| ▲ Show 20 Lines • Show All 276 Lines • Show Last 20 Lines | |||||