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 14:19:36 +0300
committerJacques Lucke <jacques@blender.org>2021-09-15 14:19:36 +0300
commit2ffa9569836ca28a7528a8224b9741e2eb95fc0d (patch)
tree8fdb387aa6910c6ffab4a622dfb8ca9382a20c67
parent19d2f7d9cf10e904ca4f554e5e40532eb2b27768 (diff)
cleanup
-rw-r--r--source/blender/nodes/NOD_node_declaration.hh7
-rw-r--r--source/blender/nodes/NOD_socket_declarations.hh38
-rw-r--r--source/blender/nodes/intern/node_declaration.cc29
-rw-r--r--source/blender/nodes/intern/node_socket_declarations.cc96
4 files changed, 95 insertions, 75 deletions
diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh
index 12791c78ea9..40df9d2e6d3 100644
--- a/source/blender/nodes/NOD_node_declaration.hh
+++ b/source/blender/nodes/NOD_node_declaration.hh
@@ -31,7 +31,7 @@ class SocketDeclaration {
protected:
std::string name_;
std::string identifier_;
- bool hide_label = false;
+ bool hide_label_ = false;
bool hide_value_ = false;
bool is_multi_input_ = false;
@@ -45,6 +45,9 @@ class SocketDeclaration {
virtual bool matches(const bNodeSocket &socket) const = 0;
virtual bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const;
+ void set_common_flags(bNodeSocket &socket) const;
+ bool matches_common_data(const bNodeSocket &socket) const;
+
StringRefNull name() const;
StringRefNull identifier() const;
};
@@ -66,7 +69,7 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
public:
Self &hide_label(bool value)
{
- decl_->hide_label = value;
+ decl_->hide_label_ = value;
return *(Self *)this;
}
diff --git a/source/blender/nodes/NOD_socket_declarations.hh b/source/blender/nodes/NOD_socket_declarations.hh
index 0524fd87a37..6dbc7b57ff7 100644
--- a/source/blender/nodes/NOD_socket_declarations.hh
+++ b/source/blender/nodes/NOD_socket_declarations.hh
@@ -216,18 +216,16 @@ struct CommonIDSocketData {
const char *idname;
};
-bNodeSocket &build_id_socket(bNodeTree &ntree,
+bNodeSocket &build_id_socket(const SocketDeclaration &decl,
+ bNodeTree &ntree,
bNode &node,
eNodeSocketInOut in_out,
- const CommonIDSocketData &data,
- StringRefNull name,
- StringRefNull identifier);
-bool matches_id_socket(const bNodeSocket &socket,
- const CommonIDSocketData &data,
- StringRefNull name,
- StringRefNull identifier);
-
-template<typename Subtype> class IDSocketDeclaration : public SocketDeclaration {
+ const CommonIDSocketData &data);
+bool matches_id_socket(const SocketDeclaration &decl,
+ const bNodeSocket &socket,
+ const CommonIDSocketData &data);
+
+class IDSocketDeclaration : public SocketDeclaration {
private:
CommonIDSocketData data_;
@@ -238,12 +236,12 @@ template<typename Subtype> class IDSocketDeclaration : public SocketDeclaration
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override
{
- return build_id_socket(ntree, node, in_out, data_, name_, identifier_);
+ return build_id_socket(*this, ntree, node, in_out, data_);
}
bool matches(const bNodeSocket &socket) const override
{
- return matches_id_socket(socket, data_, name_, identifier_);
+ return matches_id_socket(*this, socket, data_);
}
bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override
@@ -256,11 +254,11 @@ template<typename Subtype> class IDSocketDeclaration : public SocketDeclaration
};
} // namespace detail
-class Object : public detail::IDSocketDeclaration<Object> {
+class Object : public detail::IDSocketDeclaration {
public:
using Builder = class ObjectBuilder;
- Object() : detail::IDSocketDeclaration<Object>("NodeSocketObject")
+ Object() : detail::IDSocketDeclaration("NodeSocketObject")
{
}
};
@@ -268,11 +266,11 @@ class Object : public detail::IDSocketDeclaration<Object> {
class ObjectBuilder : public SocketDeclarationBuilder<Object> {
};
-class Material : public detail::IDSocketDeclaration<Material> {
+class Material : public detail::IDSocketDeclaration {
public:
using Builder = class MaterialBuilder;
- Material() : detail::IDSocketDeclaration<Material>("NodeSocketMaterial")
+ Material() : detail::IDSocketDeclaration("NodeSocketMaterial")
{
}
};
@@ -280,11 +278,11 @@ class Material : public detail::IDSocketDeclaration<Material> {
class MaterialBuilder : public SocketDeclarationBuilder<Material> {
};
-class Collection : public detail::IDSocketDeclaration<Collection> {
+class Collection : public detail::IDSocketDeclaration {
public:
using Builder = class CollectionBuilder;
- Collection() : detail::IDSocketDeclaration<Collection>("NodeSocketCollection")
+ Collection() : detail::IDSocketDeclaration("NodeSocketCollection")
{
}
};
@@ -292,11 +290,11 @@ class Collection : public detail::IDSocketDeclaration<Collection> {
class CollectionBuilder : public SocketDeclarationBuilder<Collection> {
};
-class Texture : public detail::IDSocketDeclaration<Texture> {
+class Texture : public detail::IDSocketDeclaration {
public:
using Builder = class TextureBuilder;
- Texture() : detail::IDSocketDeclaration<Texture>("NodeSocketTexture")
+ Texture() : detail::IDSocketDeclaration("NodeSocketTexture")
{
}
};
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 1fecf3e1137..08cf0de92d0 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) {
+ if (!this->matches_common_data(socket)) {
return false;
}
- if (socket.typeinfo->subtype != subtype_) {
- 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) {
+ if (!this->matches_common_data(socket)) {
return false;
}
- if (socket.name != name_) {
- 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;
@@ -268,30 +264,26 @@ bool String::matches(const bNodeSocket &socket) const
*/
namespace detail {
-bNodeSocket &build_id_socket(bNodeTree &ntree,
+bNodeSocket &build_id_socket(const SocketDeclaration &decl,
+ bNodeTree &ntree,
bNode &node,
eNodeSocketInOut in_out,
- const CommonIDSocketData &data,
- StringRefNull name,
- StringRefNull identifier)
+ const CommonIDSocketData &data)
{
bNodeSocket &socket = *nodeAddSocket(
- &ntree, &node, in_out, data.idname, identifier.c_str(), name.c_str());
+ &ntree, &node, in_out, data.idname, decl.identifier().c_str(), decl.name().c_str());
+ decl.set_common_flags(socket);
return socket;
}
-bool matches_id_socket(const bNodeSocket &socket,
- const CommonIDSocketData &data,
- StringRefNull name,
- StringRefNull identifier)
+bool matches_id_socket(const SocketDeclaration &decl,
+ const bNodeSocket &socket,
+ const CommonIDSocketData &data)
{
- if (!STREQ(socket.idname, data.idname)) {
+ if (!decl.matches_common_data(socket)) {
return false;
}
- if (socket.name != name) {
- return false;
- }
- if (socket.identifier != identifier) {
+ if (!STREQ(socket.idname, data.idname)) {
return false;
}
return true;
@@ -306,18 +298,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) {
- return false;
- }
- if (socket.name != name_) {
+ if (!this->matches_common_data(socket)) {
return false;
}
- if (socket.identifier != identifier_) {
+ if (socket.type != SOCK_GEOMETRY) {
return false;
}
return true;