diff options
author | Jacques Lucke <jacques@blender.org> | 2021-03-03 18:24:05 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-03-03 18:24:05 +0300 |
commit | a1653184c0a36a547920e4340f3328deaf88c95c (patch) | |
tree | 0162ca14c697a98e1fb91ea0c36e1920dca4202a | |
parent | 4658bd0342cd7bf27d0c1d0ae6fcbd8f97f2f8d4 (diff) |
cleanup context
-rw-r--r-- | source/blender/modifiers/intern/MOD_nodes.cc | 10 | ||||
-rw-r--r-- | source/blender/nodes/NOD_XXX_node_tree.hh | 140 | ||||
-rw-r--r-- | source/blender/nodes/intern/xxx_node_tree.cc | 78 |
3 files changed, 86 insertions, 142 deletions
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index e06d6199cb8..c4afa8cfc64 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -368,7 +368,7 @@ class GeometryNodesEvaluator { const NodeRef &linked_node = linked_socket->node(); XXXOutputSocket linked_xxx_socket{to_socket.context, linked_socket}; if (linked_node.is_group_input_node()) { - if (to_socket.context.info().is_root()) { + if (to_socket.context->is_root()) { callback(linked_xxx_socket); } else { @@ -604,7 +604,7 @@ class GeometryNodesEvaluator { const NodeRef &linked_node = linked_socket->node(); XXXInputSocket linked_xxx_socket{from_socket.context, linked_socket}; if (linked_node.is_group_output_node()) { - if (from_socket.context.info().is_root()) { + if (from_socket.context->is_root()) { callback(linked_xxx_socket); } else { @@ -1058,7 +1058,7 @@ static void fill_data_handle_map(const NodesModifierSettings &settings, { Set<ID *> used_ids; find_used_ids_from_settings(settings, used_ids); - find_used_ids_from_nodes(*tree.root_context_info().tree().btree(), used_ids); + find_used_ids_from_nodes(*tree.root_context().tree().btree(), used_ids); int current_handle = 0; for (ID *id : used_ids) { @@ -1101,7 +1101,7 @@ static GeometrySet compute_geometry(const XXXNodeTree &tree, Map<XXXOutputSocket, GMutablePointer> group_inputs; - XXXNodeTreeContext root_context{&tree.root_context_info()}; + const XXXNodeTreeContext *root_context = &tree.root_context(); if (group_input_sockets.size() > 0) { Span<const OutputSocketRef *> remaining_input_sockets = group_input_sockets; @@ -1209,7 +1209,7 @@ static void modifyGeometry(ModifierData *md, return; } - const NodeTreeRef &root_tree_ref = xxx_tree.root_context_info().tree(); + const NodeTreeRef &root_tree_ref = xxx_tree.root_context().tree(); Span<const NodeRef *> input_nodes = root_tree_ref.nodes_by_type("NodeGroupInput"); Span<const NodeRef *> output_nodes = root_tree_ref.nodes_by_type("NodeGroupOutput"); diff --git a/source/blender/nodes/NOD_XXX_node_tree.hh b/source/blender/nodes/NOD_XXX_node_tree.hh index 675784c858b..a9d8d99c34f 100644 --- a/source/blender/nodes/NOD_XXX_node_tree.hh +++ b/source/blender/nodes/NOD_XXX_node_tree.hh @@ -22,7 +22,6 @@ namespace blender::nodes { -class XXXNodeTreeContextInfo; class XXXNodeTreeContext; class XXXNodeTree; @@ -31,47 +30,29 @@ struct XXXSocket; struct XXXInputSocket; struct XXXOutputSocket; -class XXXNodeTreeContextInfo { +class XXXNodeTreeContext { private: - XXXNodeTreeContextInfo *parent_context_info_; + XXXNodeTreeContext *parent_context_; const NodeRef *parent_node_; const NodeTreeRef *tree_; - Map<const NodeRef *, XXXNodeTreeContextInfo *> children_; + Map<const NodeRef *, XXXNodeTreeContext *> children_; friend XXXNodeTree; public: const NodeTreeRef &tree() const; - const XXXNodeTreeContextInfo *parent_context_info() const; + const XXXNodeTreeContext *parent_context() const; const NodeRef *parent_node() const; - const XXXNodeTreeContextInfo *child_context_info(const NodeRef &node) const; + const XXXNodeTreeContext *child_context(const NodeRef &node) const; bool is_root() const; }; -class XXXNodeTreeContext { - private: - const XXXNodeTreeContextInfo *context_info_ = nullptr; - - friend XXXNodeTree; - - public: - XXXNodeTreeContext() = default; - XXXNodeTreeContext(const XXXNodeTreeContextInfo *context_info); - - friend bool operator==(const XXXNodeTreeContext &a, const XXXNodeTreeContext &b); - friend bool operator!=(const XXXNodeTreeContext &a, const XXXNodeTreeContext &b); - - uint64_t hash() const; - - const XXXNodeTreeContextInfo &info() const; -}; - struct XXXNode { - XXXNodeTreeContext context; + const XXXNodeTreeContext *context = nullptr; const NodeRef *node = nullptr; XXXNode() = default; - XXXNode(XXXNodeTreeContext context, const NodeRef *node); + XXXNode(const XXXNodeTreeContext *context, const NodeRef *node); friend bool operator==(const XXXNode &a, const XXXNode &b); friend bool operator!=(const XXXNode &a, const XXXNode &b); @@ -83,11 +64,11 @@ struct XXXNode { }; struct XXXSocket { - XXXNodeTreeContext context; - const SocketRef *socket; + const XXXNodeTreeContext *context = nullptr; + const SocketRef *socket = nullptr; XXXSocket() = default; - XXXSocket(XXXNodeTreeContext context, const SocketRef *socket); + XXXSocket(const XXXNodeTreeContext *context, const SocketRef *socket); XXXSocket(const XXXInputSocket &input_socket); XXXSocket(const XXXOutputSocket &output_socket); @@ -101,11 +82,11 @@ struct XXXSocket { }; struct XXXInputSocket { - XXXNodeTreeContext context; + const XXXNodeTreeContext *context = nullptr; const InputSocketRef *socket = nullptr; XXXInputSocket() = default; - XXXInputSocket(XXXNodeTreeContext context, const InputSocketRef *socket); + XXXInputSocket(const XXXNodeTreeContext *context, const InputSocketRef *socket); explicit XXXInputSocket(const XXXSocket &base_socket); friend bool operator==(const XXXInputSocket &a, const XXXInputSocket &b); @@ -123,11 +104,11 @@ struct XXXInputSocket { }; struct XXXOutputSocket { - XXXNodeTreeContext context; + const XXXNodeTreeContext *context = nullptr; const OutputSocketRef *socket = nullptr; XXXOutputSocket() = default; - XXXOutputSocket(XXXNodeTreeContext context, const OutputSocketRef *socket); + XXXOutputSocket(const XXXNodeTreeContext *context, const OutputSocketRef *socket); explicit XXXOutputSocket(const XXXSocket &base_socket); friend bool operator==(const XXXOutputSocket &a, const XXXOutputSocket &b); @@ -145,21 +126,20 @@ struct XXXOutputSocket { class XXXNodeTree { private: LinearAllocator<> allocator_; - XXXNodeTreeContextInfo *root_context_info_; + XXXNodeTreeContext *root_context_; public: XXXNodeTree(bNodeTree &btree, NodeTreeRefMap &node_tree_refs); ~XXXNodeTree(); - const XXXNodeTreeContextInfo &root_context_info() const; + const XXXNodeTreeContext &root_context() const; private: - XXXNodeTreeContextInfo &construct_context_info_recursively( - XXXNodeTreeContextInfo *parent_context_info, - const NodeRef *parent_node, - bNodeTree &btree, - NodeTreeRefMap &node_tree_refs); - void destruct_context_info_recursively(XXXNodeTreeContextInfo *context_info); + XXXNodeTreeContext &construct_context_recursively(XXXNodeTreeContext *parent_context, + const NodeRef *parent_node, + bNodeTree &btree, + NodeTreeRefMap &node_tree_refs); + void destruct_context_recursively(XXXNodeTreeContext *context); }; namespace xxx_node_tree_types { @@ -168,78 +148,47 @@ using nodes::XXXInputSocket; using nodes::XXXNode; using nodes::XXXNodeTree; using nodes::XXXNodeTreeContext; -using nodes::XXXNodeTreeContextInfo; using nodes::XXXOutputSocket; using nodes::XXXSocket; } // namespace xxx_node_tree_types /* -------------------------------------------------------------------- - * XXXNodeTreeContextInfo inline methods. + * XXXNodeTreeContext inline methods. */ -inline const NodeTreeRef &XXXNodeTreeContextInfo::tree() const +inline const NodeTreeRef &XXXNodeTreeContext::tree() const { return *tree_; } -inline const XXXNodeTreeContextInfo *XXXNodeTreeContextInfo::parent_context_info() const +inline const XXXNodeTreeContext *XXXNodeTreeContext::parent_context() const { - return parent_context_info_; + return parent_context_; } -inline const NodeRef *XXXNodeTreeContextInfo::parent_node() const +inline const NodeRef *XXXNodeTreeContext::parent_node() const { return parent_node_; } -inline const XXXNodeTreeContextInfo *XXXNodeTreeContextInfo::child_context_info( - const NodeRef &node) const +inline const XXXNodeTreeContext *XXXNodeTreeContext::child_context(const NodeRef &node) const { return children_.lookup_default(&node, nullptr); } -inline bool XXXNodeTreeContextInfo::is_root() const -{ - return parent_context_info_ == nullptr; -} - -/* -------------------------------------------------------------------- - * XXXNodeTreeContext inline methods. - */ - -inline XXXNodeTreeContext::XXXNodeTreeContext(const XXXNodeTreeContextInfo *context_info) - : context_info_(context_info) -{ -} - -inline bool operator==(const XXXNodeTreeContext &a, const XXXNodeTreeContext &b) -{ - return a.context_info_ == b.context_info_; -} - -inline bool operator!=(const XXXNodeTreeContext &a, const XXXNodeTreeContext &b) -{ - return !(a == b); -} - -inline uint64_t XXXNodeTreeContext::hash() const -{ - return DefaultHash<XXXNodeTreeContextInfo *>{}(context_info_); -} - -inline const XXXNodeTreeContextInfo &XXXNodeTreeContext::info() const +inline bool XXXNodeTreeContext::is_root() const { - return *context_info_; + return parent_context_ == nullptr; } /* -------------------------------------------------------------------- * XXXNode inline methods. */ -inline XXXNode::XXXNode(XXXNodeTreeContext context, const NodeRef *node) +inline XXXNode::XXXNode(const XXXNodeTreeContext *context, const NodeRef *node) : context(context), node(node) { - BLI_assert(node == nullptr || &node->tree() == &context.info().tree()); + BLI_assert(node == nullptr || &node->tree() == &context->tree()); } inline bool operator==(const XXXNode &a, const XXXNode &b) @@ -264,17 +213,17 @@ inline const NodeRef *XXXNode::operator->() const inline uint64_t XXXNode::hash() const { - return DefaultHash<XXXNodeTreeContext>{}(context) ^ DefaultHash<const NodeRef *>{}(node); + return DefaultHash<const XXXNodeTreeContext *>{}(context) ^ DefaultHash<const NodeRef *>{}(node); } /* -------------------------------------------------------------------- * XXXSocket inline methods. */ -inline XXXSocket::XXXSocket(XXXNodeTreeContext context, const SocketRef *socket) +inline XXXSocket::XXXSocket(const XXXNodeTreeContext *context, const SocketRef *socket) : context(context), socket(socket) { - BLI_assert(socket == nullptr || &socket->tree() == &context.info().tree()); + BLI_assert(socket == nullptr || &socket->tree() == &context->tree()); } inline XXXSocket::XXXSocket(const XXXInputSocket &input_socket) @@ -309,23 +258,25 @@ inline const SocketRef *XXXSocket::operator->() const inline uint64_t XXXSocket::hash() const { - return DefaultHash<XXXNodeTreeContext>{}(context) ^ DefaultHash<const SocketRef *>{}(socket); + return DefaultHash<const XXXNodeTreeContext *>{}(context) ^ + DefaultHash<const SocketRef *>{}(socket); } /* -------------------------------------------------------------------- * XXXInputSocket inline methods. */ -inline XXXInputSocket::XXXInputSocket(XXXNodeTreeContext context, const InputSocketRef *socket) +inline XXXInputSocket::XXXInputSocket(const XXXNodeTreeContext *context, + const InputSocketRef *socket) : context(context), socket(socket) { - BLI_assert(socket == nullptr || &socket->tree() == &context.info().tree()); + BLI_assert(socket == nullptr || &socket->tree() == &context->tree()); } inline XXXInputSocket::XXXInputSocket(const XXXSocket &base_socket) : context(base_socket.context), socket(&base_socket.socket->as_input()) { - BLI_assert(socket == nullptr || &socket->tree() == &context.info().tree()); + BLI_assert(socket == nullptr || &socket->tree() == &context->tree()); } inline bool operator==(const XXXInputSocket &a, const XXXInputSocket &b) @@ -350,7 +301,7 @@ inline const InputSocketRef *XXXInputSocket::operator->() const inline uint64_t XXXInputSocket::hash() const { - return DefaultHash<XXXNodeTreeContext>{}(context) ^ + return DefaultHash<const XXXNodeTreeContext *>{}(context) ^ DefaultHash<const InputSocketRef *>{}(socket); } @@ -358,7 +309,8 @@ inline uint64_t XXXInputSocket::hash() const * XXXOutputSocket inline methods. */ -inline XXXOutputSocket::XXXOutputSocket(XXXNodeTreeContext context, const OutputSocketRef *socket) +inline XXXOutputSocket::XXXOutputSocket(const XXXNodeTreeContext *context, + const OutputSocketRef *socket) : context(context), socket(socket) { } @@ -390,7 +342,7 @@ inline const OutputSocketRef *XXXOutputSocket::operator->() const inline uint64_t XXXOutputSocket::hash() const { - return DefaultHash<XXXNodeTreeContext>{}(context) ^ + return DefaultHash<const XXXNodeTreeContext *>{}(context) ^ DefaultHash<const OutputSocketRef *>{}(socket); } @@ -398,9 +350,9 @@ inline uint64_t XXXOutputSocket::hash() const * XXXNodeTree inline methods. */ -inline const XXXNodeTreeContextInfo &XXXNodeTree::root_context_info() const +inline const XXXNodeTreeContext &XXXNodeTree::root_context() const { - return *root_context_info_; + return *root_context_; } } // namespace blender::nodes diff --git a/source/blender/nodes/intern/xxx_node_tree.cc b/source/blender/nodes/intern/xxx_node_tree.cc index 5e9a487c241..c5b946e63aa 100644 --- a/source/blender/nodes/intern/xxx_node_tree.cc +++ b/source/blender/nodes/intern/xxx_node_tree.cc @@ -20,48 +20,46 @@ namespace blender::nodes { XXXNodeTree::XXXNodeTree(bNodeTree &btree, NodeTreeRefMap &node_tree_refs) { - root_context_info_ = &this->construct_context_info_recursively( - nullptr, nullptr, btree, node_tree_refs); + root_context_ = &this->construct_context_recursively(nullptr, nullptr, btree, node_tree_refs); } -XXXNodeTreeContextInfo &XXXNodeTree::construct_context_info_recursively( - XXXNodeTreeContextInfo *parent_context_info, - const NodeRef *parent_node, - bNodeTree &btree, - NodeTreeRefMap &node_tree_refs) +XXXNodeTreeContext &XXXNodeTree::construct_context_recursively(XXXNodeTreeContext *parent_context, + const NodeRef *parent_node, + bNodeTree &btree, + NodeTreeRefMap &node_tree_refs) { - XXXNodeTreeContextInfo &context_info = *allocator_.construct<XXXNodeTreeContextInfo>(); - context_info.parent_context_info_ = parent_context_info; - context_info.parent_node_ = parent_node; - context_info.tree_ = &get_tree_ref_from_map(node_tree_refs, btree); + XXXNodeTreeContext &context = *allocator_.construct<XXXNodeTreeContext>(); + context.parent_context_ = parent_context; + context.parent_node_ = parent_node; + context.tree_ = &get_tree_ref_from_map(node_tree_refs, btree); - for (const NodeRef *node : context_info.tree_->nodes()) { + for (const NodeRef *node : context.tree_->nodes()) { if (node->is_group_node()) { bNode *bnode = node->bnode(); bNodeTree *child_btree = reinterpret_cast<bNodeTree *>(bnode->id); if (child_btree != nullptr) { - XXXNodeTreeContextInfo &child = this->construct_context_info_recursively( - &context_info, node, *child_btree, node_tree_refs); - context_info.children_.add_new(node, &child); + XXXNodeTreeContext &child = this->construct_context_recursively( + &context, node, *child_btree, node_tree_refs); + context.children_.add_new(node, &child); } } } - return context_info; + return context; } XXXNodeTree::~XXXNodeTree() { /* Has to be destructed manually, because the context info is allocated in a linear allocator. */ - this->destruct_context_info_recursively(root_context_info_); + this->destruct_context_recursively(root_context_); } -void XXXNodeTree::destruct_context_info_recursively(XXXNodeTreeContextInfo *context_info) +void XXXNodeTree::destruct_context_recursively(XXXNodeTreeContext *context) { - for (XXXNodeTreeContextInfo *child : context_info->children_.values()) { - destruct_context_info_recursively(child); + for (XXXNodeTreeContext *child : context->children_.values()) { + destruct_context_recursively(child); } - context_info->~XXXNodeTreeContextInfo(); + context->~XXXNodeTreeContext(); } XXXOutputSocket XXXInputSocket::try_get_single_origin() const @@ -81,14 +79,13 @@ XXXOutputSocket XXXInputSocket::get_corresponding_group_node_output() const BLI_assert(socket->node().is_group_output_node()); BLI_assert(socket->index() < socket->node().inputs().size() - 1); - const XXXNodeTreeContextInfo &context_info = context.info(); - const XXXNodeTreeContextInfo *parent_context_info = context_info.parent_context_info(); - const NodeRef *parent_node = context_info.parent_node(); - BLI_assert(parent_context_info != nullptr); + const XXXNodeTreeContext *parent_context = context->parent_context(); + const NodeRef *parent_node = context->parent_node(); + BLI_assert(parent_context != nullptr); BLI_assert(parent_node != nullptr); const int socket_index = socket->index(); - return {parent_context_info, &parent_node->output(socket_index)}; + return {parent_context, &parent_node->output(socket_index)}; } XXXOutputSocket XXXInputSocket::get_corresponding_group_input_socket() const @@ -96,17 +93,15 @@ XXXOutputSocket XXXInputSocket::get_corresponding_group_input_socket() const BLI_assert(*this); BLI_assert(socket->node().is_group_node()); - const XXXNodeTreeContextInfo &context_info = context.info(); - const XXXNodeTreeContextInfo *child_context_info = context_info.child_context_info( - socket->node()); - BLI_assert(child_context_info != nullptr); + const XXXNodeTreeContext *child_context = context->child_context(socket->node()); + BLI_assert(child_context != nullptr); - const NodeTreeRef &child_tree = child_context_info->tree(); + const NodeTreeRef &child_tree = child_context->tree(); Span<const NodeRef *> group_input_nodes = child_tree.nodes_by_type("NodeGroupInput"); BLI_assert(!group_input_nodes.is_empty()); const int socket_index = socket->index(); - return {child_context_info, &group_input_nodes[0]->output(socket_index)}; + return {child_context, &group_input_nodes[0]->output(socket_index)}; } XXXInputSocket XXXOutputSocket::get_corresponding_group_node_input() const @@ -115,14 +110,13 @@ XXXInputSocket XXXOutputSocket::get_corresponding_group_node_input() const BLI_assert(socket->node().is_group_input_node()); BLI_assert(socket->index() < socket->node().outputs().size() - 1); - const XXXNodeTreeContextInfo &context_info = context.info(); - const XXXNodeTreeContextInfo *parent_context_info = context_info.parent_context_info(); - const NodeRef *parent_node = context_info.parent_node(); - BLI_assert(parent_context_info != nullptr); + const XXXNodeTreeContext *parent_context = context->parent_context(); + const NodeRef *parent_node = context->parent_node(); + BLI_assert(parent_context != nullptr); BLI_assert(parent_node != nullptr); const int socket_index = socket->index(); - return {parent_context_info, &parent_node->input(socket_index)}; + return {parent_context, &parent_node->input(socket_index)}; } XXXInputSocket XXXOutputSocket::get_corresponding_group_output_socket() const @@ -130,17 +124,15 @@ XXXInputSocket XXXOutputSocket::get_corresponding_group_output_socket() const BLI_assert(*this); BLI_assert(socket->node().is_group_node()); - const XXXNodeTreeContextInfo &context_info = context.info(); - const XXXNodeTreeContextInfo *child_context_info = context_info.child_context_info( - socket->node()); - BLI_assert(child_context_info != nullptr); + const XXXNodeTreeContext *child_context = context->child_context(socket->node()); + BLI_assert(child_context != nullptr); - const NodeTreeRef &child_tree = child_context_info->tree(); + const NodeTreeRef &child_tree = child_context->tree(); Span<const NodeRef *> group_output_nodes = child_tree.nodes_by_type("NodeGroupOutput"); BLI_assert(!group_output_nodes.is_empty()); const int socket_index = socket->index(); - return {child_context_info, &group_output_nodes[0]->input(socket_index)}; + return {child_context, &group_output_nodes[0]->input(socket_index)}; } } // namespace blender::nodes |