[Bf-blender-cvs] [7b6d8ff6dd4] temp-derived-node-tree-refactor: simplify sockets
Jacques Lucke
noreply at git.blender.org
Thu Mar 4 16:55:55 CET 2021
Commit: 7b6d8ff6dd4de1c8a5fbea6198ce2982bf5fff45
Author: Jacques Lucke
Date: Thu Mar 4 16:33:33 2021 +0100
Branches: temp-derived-node-tree-refactor
https://developer.blender.org/rB7b6d8ff6dd4de1c8a5fbea6198ce2982bf5fff45
simplify sockets
===================================================================
M source/blender/modifiers/intern/MOD_nodes.cc
M source/blender/nodes/NOD_XXX_node_tree.hh
M source/blender/nodes/intern/xxx_node_tree.cc
===================================================================
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 14323b5a18d..ac3633f0041 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -362,7 +362,7 @@ class GeometryNodesEvaluator {
void compute_output_and_forward(const XXXOutputSocket socket_to_compute)
{
- const XXXNode node{socket_to_compute.context, &socket_to_compute->node()};
+ const XXXNode node{socket_to_compute.context(), &socket_to_compute->node()};
if (!socket_to_compute->is_available()) {
/* If the output is not available, use a default value. */
diff --git a/source/blender/nodes/NOD_XXX_node_tree.hh b/source/blender/nodes/NOD_XXX_node_tree.hh
index 422deb9ea87..54aa24f3c9d 100644
--- a/source/blender/nodes/NOD_XXX_node_tree.hh
+++ b/source/blender/nodes/NOD_XXX_node_tree.hh
@@ -64,15 +64,20 @@ struct XXXNode {
uint64_t hash() const;
};
-struct XXXSocket {
- const XXXNodeTreeContext *context = nullptr;
- const SocketRef *socket_ref = nullptr;
+class XXXSocket {
+ protected:
+ const XXXNodeTreeContext *context_ = nullptr;
+ const SocketRef *socket_ref_ = nullptr;
+ public:
XXXSocket() = default;
XXXSocket(const XXXNodeTreeContext *context, const SocketRef *socket);
XXXSocket(const XXXInputSocket &input_socket);
XXXSocket(const XXXOutputSocket &output_socket);
+ const XXXNodeTreeContext *context() const;
+ const SocketRef *socket_ref() const;
+
friend bool operator==(const XXXSocket &a, const XXXSocket &b);
friend bool operator!=(const XXXSocket &a, const XXXSocket &b);
@@ -82,44 +87,32 @@ struct XXXSocket {
uint64_t hash() const;
};
-struct XXXInputSocket {
- const XXXNodeTreeContext *context = nullptr;
- const InputSocketRef *socket_ref = nullptr;
-
+class XXXInputSocket : public XXXSocket {
+ public:
XXXInputSocket() = default;
XXXInputSocket(const XXXNodeTreeContext *context, const InputSocketRef *socket);
explicit XXXInputSocket(const XXXSocket &base_socket);
- friend bool operator==(const XXXInputSocket &a, const XXXInputSocket &b);
- friend bool operator!=(const XXXInputSocket &a, const XXXInputSocket &b);
+ const InputSocketRef *socket_ref() const;
- operator bool() const;
const InputSocketRef *operator->() const;
- uint64_t hash() const;
-
XXXOutputSocket get_corresponding_group_node_output() const;
XXXOutputSocket get_corresponding_group_input_socket() const;
void foreach_origin_socket(FunctionRef<void(XXXSocket)> callback) const;
};
-struct XXXOutputSocket {
- const XXXNodeTreeContext *context = nullptr;
- const OutputSocketRef *socket_ref = nullptr;
-
+class XXXOutputSocket : public XXXSocket {
+ public:
XXXOutputSocket() = default;
XXXOutputSocket(const XXXNodeTreeContext *context, const OutputSocketRef *socket);
explicit XXXOutputSocket(const XXXSocket &base_socket);
- friend bool operator==(const XXXOutputSocket &a, const XXXOutputSocket &b);
- friend bool operator!=(const XXXOutputSocket &a, const XXXOutputSocket &b);
+ const OutputSocketRef *socket_ref() const;
- operator bool() const;
const OutputSocketRef *operator->() const;
- uint64_t hash() const;
-
XXXInputSocket get_corresponding_group_node_input() const;
XXXInputSocket get_corresponding_group_output_socket() const;
@@ -233,24 +226,34 @@ inline uint64_t XXXNode::hash() const
*/
inline XXXSocket::XXXSocket(const XXXNodeTreeContext *context, const SocketRef *socket_ref)
- : context(context), socket_ref(socket_ref)
+ : context_(context), socket_ref_(socket_ref)
{
BLI_assert(socket_ref == nullptr || &socket_ref->tree() == &context->tree());
}
inline XXXSocket::XXXSocket(const XXXInputSocket &input_socket)
- : context(input_socket.context), socket_ref(input_socket.socket_ref)
+ : XXXSocket(input_socket.context_, input_socket.socket_ref_)
{
}
inline XXXSocket::XXXSocket(const XXXOutputSocket &output_socket)
- : context(output_socket.context), socket_ref(output_socket.socket_ref)
+ : XXXSocket(output_socket.context_, output_socket.socket_ref_)
+{
+}
+
+inline const XXXNodeTreeContext *XXXSocket::context() const
{
+ return context_;
+}
+
+inline const SocketRef *XXXSocket::socket_ref() const
+{
+ return socket_ref_;
}
inline bool operator==(const XXXSocket &a, const XXXSocket &b)
{
- return a.context == b.context && a.socket_ref == b.socket_ref;
+ return a.context_ == b.context_ && a.socket_ref_ == b.socket_ref_;
}
inline bool operator!=(const XXXSocket &a, const XXXSocket &b)
@@ -260,18 +263,18 @@ inline bool operator!=(const XXXSocket &a, const XXXSocket &b)
inline XXXSocket::operator bool() const
{
- return socket_ref != nullptr;
+ return socket_ref_ != nullptr;
}
inline const SocketRef *XXXSocket::operator->() const
{
- return socket_ref;
+ return socket_ref_;
}
inline uint64_t XXXSocket::hash() const
{
- return DefaultHash<const XXXNodeTreeContext *>{}(context) ^
- DefaultHash<const SocketRef *>{}(socket_ref);
+ return DefaultHash<const XXXNodeTreeContext *>{}(context_) ^
+ DefaultHash<const SocketRef *>{}(socket_ref_);
}
/* --------------------------------------------------------------------
@@ -280,41 +283,23 @@ inline uint64_t XXXSocket::hash() const
inline XXXInputSocket::XXXInputSocket(const XXXNodeTreeContext *context,
const InputSocketRef *socket_ref)
- : context(context), socket_ref(socket_ref)
-{
- BLI_assert(socket_ref == nullptr || &socket_ref->tree() == &context->tree());
-}
-
-inline XXXInputSocket::XXXInputSocket(const XXXSocket &base_socket)
- : context(base_socket.context), socket_ref(&base_socket.socket_ref->as_input())
-{
- BLI_assert(socket_ref == nullptr || &socket_ref->tree() == &context->tree());
-}
-
-inline bool operator==(const XXXInputSocket &a, const XXXInputSocket &b)
+ : XXXSocket(context, socket_ref)
{
- return a.context == b.context && a.socket_ref == b.socket_ref;
}
-inline bool operator!=(const XXXInputSocket &a, const XXXInputSocket &b)
+inline XXXInputSocket::XXXInputSocket(const XXXSocket &base_socket) : XXXSocket(base_socket)
{
- return !(a == b);
+ BLI_assert(base_socket->is_input());
}
-inline XXXInputSocket::operator bool() const
+inline const InputSocketRef *XXXInputSocket::socket_ref() const
{
- return socket_ref != nullptr;
+ return (const InputSocketRef *)socket_ref_;
}
inline const InputSocketRef *XXXInputSocket::operator->() const
{
- return socket_ref;
-}
-
-inline uint64_t XXXInputSocket::hash() const
-{
- return DefaultHash<const XXXNodeTreeContext *>{}(context) ^
- DefaultHash<const InputSocketRef *>{}(socket_ref);
+ return (const InputSocketRef *)socket_ref_;
}
/* --------------------------------------------------------------------
@@ -323,39 +308,23 @@ inline uint64_t XXXInputSocket::hash() const
inline XXXOutputSocket::XXXOutputSocket(const XXXNodeTreeContext *context,
const OutputSocketRef *socket_ref)
- : context(context), socket_ref(socket_ref)
+ : XXXSocket(context, socket_ref)
{
}
-inline XXXOutputSocket::XXXOutputSocket(const XXXSocket &base_socket)
- : context(base_socket.context), socket_ref(&base_socket.socket_ref->as_output())
+inline XXXOutputSocket::XXXOutputSocket(const XXXSocket &base_socket) : XXXSocket(base_socket)
{
+ BLI_assert(base_socket->is_output());
}
-inline bool operator==(const XXXOutputSocket &a, const XXXOutputSocket &b)
+inline const OutputSocketRef *XXXOutputSocket::socket_ref() const
{
- return a.context == b.context && a.socket_ref == b.socket_ref;
-}
-
-inline bool operator!=(const XXXOutputSocket &a, const XXXOutputSocket &b)
-{
- return !(a == b);
-}
-
-inline XXXOutputSocket::operator bool() const
-{
- return socket_ref != nullptr;
+ return (const OutputSocketRef *)socket_ref_;
}
inline const OutputSocketRef *XXXOutputSocket::operator->() const
{
- return socket_ref;
-}
-
-inline uint64_t XXXOutputSocket::hash() const
-{
- return DefaultHash<const XXXNodeTreeContext *>{}(context) ^
- DefaultHash<const OutputSocketRef *>{}(socket_ref);
+ return (const OutputSocketRef *)socket_ref_;
}
/* --------------------------------------------------------------------
diff --git a/source/blender/nodes/intern/xxx_node_tree.cc b/source/blender/nodes/intern/xxx_node_tree.cc
index 2d944f78d19..3170c26f490 100644
--- a/source/blender/nodes/intern/xxx_node_tree.cc
+++ b/source/blender/nodes/intern/xxx_node_tree.cc
@@ -92,82 +92,82 @@ void XXXNodeTree::foreach_node_in_context_recursive(const XXXNodeTreeContext &co
XXXOutputSocket XXXInputSocket::get_corresponding_group_node_output() const
{
BLI_assert(*this);
- BLI_assert(socket_ref->node().is_group_output_node());
- BLI_assert(socket_ref->index() < socket_ref->node().inputs().size() - 1);
+ BLI_assert(socket_ref_->node().is_group_output_node());
+ BLI_assert(socket_ref_->index() < socket_ref_->node().inputs().size() - 1);
- const XXXNodeTreeContext *parent_context = context->parent_context();
- const NodeRef *parent_node = context->parent_node();
+ 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_ref->index();
+ const int socket_index = socket_ref_->index();
return {parent_context, &parent_node->output(socket_index)};
}
XXXOutputSocket XXXInputSocket::get_corresponding_group_input_socket() const
{
BLI_assert(*this);
- BLI_assert(socket_ref->node().is_group_node());
+ BLI_assert(socket_ref_->node().is_group_node());
- const XXXNodeTreeContext *child_context = context->child_context(socket_ref->node());
+ const XXXNodeTreeContext *child_context = context_->child_context(socket_ref_->node());
BLI_assert(child_context != nullptr);
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_ref->
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list