This patch adds an integer identifier to nodes that doesn't change when the node name changes. This identifier can be used by different systems to reference a node. This may be important to store caches and simulation states per node, because otherwise those would always be invalidated when a node name changes. Additionally, this kind of identifier could make some things more efficient, because with it an integer is enough to identify a node and one does not have to store the node name. I observed a 10% improvement in evaluation time in a file with an extreme number of simple math nodes, due to reduced logging overhead-- from 0.226s to 0.205s. Differential Revision: https://developer.blender.org/D15775
49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "DNA_node_types.h"
|
|
|
|
#include "BKE_compute_contexts.hh"
|
|
|
|
namespace blender::bke {
|
|
|
|
ModifierComputeContext::ModifierComputeContext(const ComputeContext *parent,
|
|
std::string modifier_name)
|
|
: ComputeContext(s_static_type, parent), modifier_name_(std::move(modifier_name))
|
|
{
|
|
hash_.mix_in(s_static_type, strlen(s_static_type));
|
|
hash_.mix_in(modifier_name_.data(), modifier_name_.size());
|
|
}
|
|
|
|
void ModifierComputeContext::print_current_in_line(std::ostream &stream) const
|
|
{
|
|
stream << "Modifier: " << modifier_name_;
|
|
}
|
|
|
|
NodeGroupComputeContext::NodeGroupComputeContext(const ComputeContext *parent, const int node_id)
|
|
: ComputeContext(s_static_type, parent), node_id_(node_id)
|
|
{
|
|
hash_.mix_in(s_static_type, strlen(s_static_type));
|
|
hash_.mix_in(&node_id_, sizeof(int32_t));
|
|
}
|
|
|
|
NodeGroupComputeContext::NodeGroupComputeContext(const ComputeContext *parent, const bNode &node)
|
|
: NodeGroupComputeContext(parent, node.identifier)
|
|
{
|
|
#ifdef DEBUG
|
|
debug_node_name_ = node.name;
|
|
#endif
|
|
}
|
|
|
|
void NodeGroupComputeContext::print_current_in_line(std::ostream &stream) const
|
|
{
|
|
#ifdef DEBUG
|
|
if (!debug_node_name_.empty()) {
|
|
stream << "Node: " << debug_node_name_;
|
|
return;
|
|
}
|
|
#endif
|
|
stream << "Node ID: " << node_id_;
|
|
}
|
|
|
|
} // namespace blender::bke
|