Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-09-15 17:09:00 +0300
committerJacques Lucke <jacques@blender.org>2021-09-15 17:09:00 +0300
commit46fff97604ae167473ecd4c0cd9108dc20ba22e3 (patch)
treefe814c66a0525f76d403719ace3fe56c2a39ed73 /source/blender/nodes/intern
parent5c6cc931b2203d97aa9d570ff3b353c2a3dfebed (diff)
Nodes: refactor socket declarations
This commits adds a few common flags to `SocketDeclaration` so that they are available for all socket types (hide label, hide value, is multi input). This allows porting over the remaining geometry nodes to the new declaration system. Furthermore, this commit separates the concepts of the socket declaration and corresponding builders. The builders are used by nodes to declare which sockets they have (e.g. `FloatBuilder`). The ready build socket declarations can then be consumed by other systems such as the versioning code. Both use cases need different APIs and those will change for independent reasons, so it makes sense to separate the classes.
Diffstat (limited to 'source/blender/nodes/intern')
-rw-r--r--source/blender/nodes/intern/node_declaration.cc29
-rw-r--r--source/blender/nodes/intern/node_socket_declarations.cc115
2 files changed, 81 insertions, 63 deletions
diff --git a/source/blender/nodes/intern/node_declaration.cc b/source/blender/nodes/intern/node_declaration.cc
index dff92d5884f..f6b6cc49b2e 100644
--- a/source/blender/nodes/intern/node_declaration.cc
+++ b/source/blender/nodes/intern/node_declaration.cc
@@ -16,6 +16,8 @@
#include "NOD_node_declaration.hh"
+#include "BKE_node.h"
+
namespace blender::nodes {
void NodeDeclaration::build(bNodeTree &ntree, bNode &node) const
@@ -62,4 +64,31 @@ bNodeSocket &SocketDeclaration::update_or_build(bNodeTree &ntree,
return this->build(ntree, node, (eNodeSocketInOut)socket.in_out);
}
+void SocketDeclaration::set_common_flags(bNodeSocket &socket) const
+{
+ SET_FLAG_FROM_TEST(socket.flag, hide_value_, SOCK_HIDE_VALUE);
+ SET_FLAG_FROM_TEST(socket.flag, hide_label_, SOCK_HIDE_LABEL);
+ SET_FLAG_FROM_TEST(socket.flag, is_multi_input_, SOCK_MULTI_INPUT);
+}
+
+bool SocketDeclaration::matches_common_data(const bNodeSocket &socket) const
+{
+ if (socket.name != name_) {
+ return false;
+ }
+ if (socket.identifier != identifier_) {
+ return false;
+ }
+ if (((socket.flag & SOCK_HIDE_VALUE) != 0) != hide_value_) {
+ return false;
+ }
+ if (((socket.flag & SOCK_HIDE_LABEL) != 0) != hide_label_) {
+ return false;
+ }
+ if (((socket.flag & SOCK_MULTI_INPUT) != 0) != is_multi_input_) {
+ return false;
+ }
+ return true;
+}
+
} // namespace blender::nodes
diff --git a/source/blender/nodes/intern/node_socket_declarations.cc b/source/blender/nodes/intern/node_socket_declarations.cc
index e17b0fd5579..4b0dbad3cff 100644
--- a/source/blender/nodes/intern/node_socket_declarations.cc
+++ b/source/blender/nodes/intern/node_socket_declarations.cc
@@ -38,6 +38,7 @@ bNodeSocket &Float::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out, SOCK_FLOAT, subtype_, identifier_.c_str(), name_.c_str());
+ this->set_common_flags(socket);
bNodeSocketValueFloat &value = *(bNodeSocketValueFloat *)socket.default_value;
value.min = soft_min_value_;
value.max = soft_max_value_;
@@ -47,16 +48,13 @@ bNodeSocket &Float::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out
bool Float::matches(const bNodeSocket &socket) const
{
- if (socket.type != SOCK_FLOAT) {
- return false;
- }
- if (socket.typeinfo->subtype != subtype_) {
+ if (!this->matches_common_data(socket)) {
return false;
}
- if (socket.name != name_) {
+ if (socket.type != SOCK_FLOAT) {
return false;
}
- if (socket.identifier != identifier_) {
+ if (socket.typeinfo->subtype != subtype_) {
return false;
}
bNodeSocketValueFloat &value = *(bNodeSocketValueFloat *)socket.default_value;
@@ -77,6 +75,7 @@ bNodeSocket &Float::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &
if (socket.typeinfo->subtype != subtype_) {
modify_subtype_except_for_storage(socket, subtype_);
}
+ this->set_common_flags(socket);
bNodeSocketValueFloat &value = *(bNodeSocketValueFloat *)socket.default_value;
value.min = soft_min_value_;
value.max = soft_max_value_;
@@ -92,6 +91,7 @@ bNodeSocket &Int::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out)
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out, SOCK_INT, subtype_, identifier_.c_str(), name_.c_str());
+ this->set_common_flags(socket);
bNodeSocketValueInt &value = *(bNodeSocketValueInt *)socket.default_value;
value.min = soft_min_value_;
value.max = soft_max_value_;
@@ -101,16 +101,13 @@ bNodeSocket &Int::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out)
bool Int::matches(const bNodeSocket &socket) const
{
- if (socket.type != SOCK_INT) {
- return false;
- }
- if (socket.typeinfo->subtype != subtype_) {
+ if (!this->matches_common_data(socket)) {
return false;
}
- if (socket.name != name_) {
+ if (socket.type != SOCK_INT) {
return false;
}
- if (socket.identifier != identifier_) {
+ if (socket.typeinfo->subtype != subtype_) {
return false;
}
bNodeSocketValueInt &value = *(bNodeSocketValueInt *)socket.default_value;
@@ -131,6 +128,7 @@ bNodeSocket &Int::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &so
if (socket.typeinfo->subtype != subtype_) {
modify_subtype_except_for_storage(socket, subtype_);
}
+ this->set_common_flags(socket);
bNodeSocketValueInt &value = *(bNodeSocketValueInt *)socket.default_value;
value.min = soft_min_value_;
value.max = soft_max_value_;
@@ -146,6 +144,7 @@ bNodeSocket &Vector::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_ou
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out, SOCK_VECTOR, subtype_, identifier_.c_str(), name_.c_str());
+ this->set_common_flags(socket);
bNodeSocketValueVector &value = *(bNodeSocketValueVector *)socket.default_value;
copy_v3_v3(value.value, default_value_);
value.min = soft_min_value_;
@@ -155,16 +154,13 @@ bNodeSocket &Vector::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_ou
bool Vector::matches(const bNodeSocket &socket) const
{
- if (socket.type != SOCK_VECTOR) {
- return false;
- }
- if (socket.typeinfo->subtype != subtype_) {
+ if (!this->matches_common_data(socket)) {
return false;
}
- if (socket.name != name_) {
+ if (socket.type != SOCK_VECTOR) {
return false;
}
- if (socket.identifier != identifier_) {
+ if (socket.typeinfo->subtype != subtype_) {
return false;
}
return true;
@@ -178,6 +174,7 @@ bNodeSocket &Vector::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket
if (socket.typeinfo->subtype != subtype_) {
modify_subtype_except_for_storage(socket, subtype_);
}
+ this->set_common_flags(socket);
bNodeSocketValueVector &value = *(bNodeSocketValueVector *)socket.default_value;
value.subtype = subtype_;
STRNCPY(socket.name, name_.c_str());
@@ -192,6 +189,7 @@ bNodeSocket &Bool::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out)
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out, SOCK_BOOLEAN, PROP_NONE, identifier_.c_str(), name_.c_str());
+ this->set_common_flags(socket);
bNodeSocketValueBoolean &value = *(bNodeSocketValueBoolean *)socket.default_value;
value.value = default_value_;
return socket;
@@ -199,13 +197,10 @@ bNodeSocket &Bool::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out)
bool Bool::matches(const bNodeSocket &socket) const
{
- if (socket.type != SOCK_BOOLEAN) {
- return false;
- }
- if (socket.name != name_) {
+ if (!this->matches_common_data(socket)) {
return false;
}
- if (socket.identifier != identifier_) {
+ if (socket.type != SOCK_BOOLEAN) {
return false;
}
return true;
@@ -219,6 +214,7 @@ bNodeSocket &Color::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out, SOCK_RGBA, PROP_NONE, identifier_.c_str(), name_.c_str());
+ this->set_common_flags(socket);
bNodeSocketValueRGBA &value = *(bNodeSocketValueRGBA *)socket.default_value;
copy_v4_v4(value.value, default_value_);
return socket;
@@ -226,13 +222,15 @@ bNodeSocket &Color::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out
bool Color::matches(const bNodeSocket &socket) const
{
- if (socket.type != SOCK_RGBA) {
- return false;
- }
- if (socket.name != name_) {
- return false;
+ if (!this->matches_common_data(socket)) {
+ if (socket.name != name_) {
+ return false;
+ }
+ if (socket.identifier != identifier_) {
+ return false;
+ }
}
- if (socket.identifier != identifier_) {
+ if (socket.type != SOCK_RGBA) {
return false;
}
return true;
@@ -246,18 +244,16 @@ bNodeSocket &String::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_ou
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out, SOCK_STRING, PROP_NONE, identifier_.c_str(), name_.c_str());
+ this->set_common_flags(socket);
return socket;
}
bool String::matches(const bNodeSocket &socket) const
{
- if (socket.type != SOCK_STRING) {
- return false;
- }
- if (socket.name != name_) {
+ if (!this->matches_common_data(socket)) {
return false;
}
- if (socket.identifier != identifier_) {
+ if (socket.type != SOCK_STRING) {
return false;
}
return true;
@@ -267,42 +263,37 @@ bool String::matches(const bNodeSocket &socket) const
* IDSocketDeclaration.
*/
-namespace detail {
-bNodeSocket &build_id_socket(bNodeTree &ntree,
- bNode &node,
- eNodeSocketInOut in_out,
- const CommonIDSocketData &data,
- StringRefNull name,
- StringRefNull identifier)
+bNodeSocket &IDSocketDeclaration::build(bNodeTree &ntree,
+ bNode &node,
+ eNodeSocketInOut in_out) const
{
bNodeSocket &socket = *nodeAddSocket(
- &ntree, &node, in_out, data.idname, identifier.c_str(), name.c_str());
- if (data.hide_label) {
- socket.flag |= SOCK_HIDE_LABEL;
- }
+ &ntree, &node, in_out, idname_, identifier_.c_str(), name_.c_str());
+ this->set_common_flags(socket);
return socket;
}
-bool matches_id_socket(const bNodeSocket &socket,
- const CommonIDSocketData &data,
- StringRefNull name,
- StringRefNull identifier)
+bool IDSocketDeclaration::matches(const bNodeSocket &socket) const
{
- if (!STREQ(socket.idname, data.idname)) {
+ if (!this->matches_common_data(socket)) {
return false;
}
- if (data.hide_label != ((socket.flag & SOCK_HIDE_LABEL) != 0)) {
- return false;
- }
- if (socket.name != name) {
- return false;
- }
- if (socket.identifier != identifier) {
+ if (!STREQ(socket.idname, idname_)) {
return false;
}
return true;
}
-} // namespace detail
+
+bNodeSocket &IDSocketDeclaration::update_or_build(bNodeTree &ntree,
+ bNode &node,
+ bNodeSocket &socket) const
+{
+ if (StringRef(socket.idname) != idname_) {
+ return this->build(ntree, node, (eNodeSocketInOut)socket.in_out);
+ }
+ this->set_common_flags(socket);
+ return socket;
+}
/* --------------------------------------------------------------------
* Geometry.
@@ -312,18 +303,16 @@ bNodeSocket &Geometry::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_
{
bNodeSocket &socket = *nodeAddSocket(
&ntree, &node, in_out, "NodeSocketGeometry", identifier_.c_str(), name_.c_str());
+ this->set_common_flags(socket);
return socket;
}
bool Geometry::matches(const bNodeSocket &socket) const
{
- if (socket.type != SOCK_GEOMETRY) {
+ if (!this->matches_common_data(socket)) {
return false;
}
- if (socket.name != name_) {
- return false;
- }
- if (socket.identifier != identifier_) {
+ if (socket.type != SOCK_GEOMETRY) {
return false;
}
return true;