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/NOD_socket_declarations.hh
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/NOD_socket_declarations.hh')
-rw-r--r--source/blender/nodes/NOD_socket_declarations.hh220
1 files changed, 116 insertions, 104 deletions
diff --git a/source/blender/nodes/NOD_socket_declarations.hh b/source/blender/nodes/NOD_socket_declarations.hh
index 11352111356..3d0cfdb5d5d 100644
--- a/source/blender/nodes/NOD_socket_declarations.hh
+++ b/source/blender/nodes/NOD_socket_declarations.hh
@@ -25,6 +25,8 @@
namespace blender::nodes::decl {
+class FloatBuilder;
+
class Float : public SocketDeclaration {
private:
float default_value_ = 0.0f;
@@ -32,36 +34,45 @@ class Float : public SocketDeclaration {
float soft_max_value_ = FLT_MAX;
PropertySubType subtype_ = PROP_NONE;
+ friend FloatBuilder;
+
public:
- Float &min(const float value)
+ using Builder = FloatBuilder;
+
+ bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
+ bool matches(const bNodeSocket &socket) const override;
+ bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
+};
+
+class FloatBuilder : public SocketDeclarationBuilder<Float> {
+ public:
+ FloatBuilder &min(const float value)
{
- soft_min_value_ = value;
+ decl_->soft_min_value_ = value;
return *this;
}
- Float &max(const float value)
+ FloatBuilder &max(const float value)
{
- soft_max_value_ = value;
+ decl_->soft_max_value_ = value;
return *this;
}
- Float &default_value(const float value)
+ FloatBuilder &default_value(const float value)
{
- default_value_ = value;
+ decl_->default_value_ = value;
return *this;
}
- Float &subtype(PropertySubType subtype)
+ FloatBuilder &subtype(PropertySubType subtype)
{
- subtype_ = subtype;
+ decl_->subtype_ = subtype;
return *this;
}
-
- bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
- bool matches(const bNodeSocket &socket) const override;
- bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
};
+class IntBuilder;
+
class Int : public SocketDeclaration {
private:
int default_value_ = 0;
@@ -69,36 +80,45 @@ class Int : public SocketDeclaration {
int soft_max_value_ = INT32_MAX;
PropertySubType subtype_ = PROP_NONE;
+ friend IntBuilder;
+
public:
- Int &min(const int value)
+ using Builder = IntBuilder;
+
+ bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
+ bool matches(const bNodeSocket &socket) const override;
+ bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
+};
+
+class IntBuilder : public SocketDeclarationBuilder<Int> {
+ public:
+ IntBuilder &min(const int value)
{
- soft_min_value_ = value;
+ decl_->soft_min_value_ = value;
return *this;
}
- Int &max(const int value)
+ IntBuilder &max(const int value)
{
- soft_max_value_ = value;
+ decl_->soft_max_value_ = value;
return *this;
}
- Int &default_value(const int value)
+ IntBuilder &default_value(const int value)
{
- default_value_ = value;
+ decl_->default_value_ = value;
return *this;
}
- Int &subtype(PropertySubType subtype)
+ IntBuilder &subtype(PropertySubType subtype)
{
- subtype_ = subtype;
+ decl_->subtype_ = subtype;
return *this;
}
-
- bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
- bool matches(const bNodeSocket &socket) const override;
- bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
};
+class VectorBuilder;
+
class Vector : public SocketDeclaration {
private:
float3 default_value_ = {0, 0, 0};
@@ -106,160 +126,152 @@ class Vector : public SocketDeclaration {
float soft_max_value_ = FLT_MAX;
PropertySubType subtype_ = PROP_NONE;
+ friend VectorBuilder;
+
+ public:
+ using Builder = VectorBuilder;
+
+ bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
+ bool matches(const bNodeSocket &socket) const override;
+ bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
+};
+
+class VectorBuilder : public SocketDeclarationBuilder<Vector> {
public:
- Vector &default_value(const float3 value)
+ VectorBuilder &default_value(const float3 value)
{
- default_value_ = value;
+ decl_->default_value_ = value;
return *this;
}
- Vector &subtype(PropertySubType subtype)
+ VectorBuilder &subtype(PropertySubType subtype)
{
- subtype_ = subtype;
+ decl_->subtype_ = subtype;
return *this;
}
- Vector &min(const float min)
+ VectorBuilder &min(const float min)
{
- soft_min_value_ = min;
+ decl_->soft_min_value_ = min;
return *this;
}
- Vector &max(const float max)
+ VectorBuilder &max(const float max)
{
- soft_max_value_ = max;
+ decl_->soft_max_value_ = max;
return *this;
}
-
- bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
- bool matches(const bNodeSocket &socket) const override;
- bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
};
+class BoolBuilder;
+
class Bool : public SocketDeclaration {
private:
bool default_value_ = false;
+ friend BoolBuilder;
public:
- Bool &default_value(const bool value)
- {
- default_value_ = value;
- return *this;
- }
+ using Builder = BoolBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
};
+class BoolBuilder : public SocketDeclarationBuilder<Bool> {
+ public:
+ BoolBuilder &default_value(const bool value)
+ {
+ decl_->default_value_ = value;
+ return *this;
+ }
+};
+
+class ColorBuilder;
+
class Color : public SocketDeclaration {
private:
ColorGeometry4f default_value_;
+ friend ColorBuilder;
+
public:
- Color &default_value(const ColorGeometry4f value)
- {
- default_value_ = value;
- return *this;
- }
+ using Builder = ColorBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
};
+class ColorBuilder : public SocketDeclarationBuilder<Color> {
+ public:
+ ColorBuilder &default_value(const ColorGeometry4f value)
+ {
+ decl_->default_value_ = value;
+ return *this;
+ }
+};
+
class String : public SocketDeclaration {
public:
+ using Builder = SocketDeclarationBuilder<String>;
+
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
};
-namespace detail {
-struct CommonIDSocketData {
- const char *idname;
- bool hide_label = false;
-};
-
-bNodeSocket &build_id_socket(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 {
+class IDSocketDeclaration : public SocketDeclaration {
private:
- CommonIDSocketData data_;
+ const char *idname_;
public:
- IDSocketDeclaration(const char *idname) : data_({idname})
- {
- }
-
- Subtype &hide_label(bool value)
- {
- data_.hide_label = value;
- return *(Subtype *)this;
- }
-
- bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override
- {
- return build_id_socket(ntree, node, in_out, data_, name_, identifier_);
- }
-
- bool matches(const bNodeSocket &socket) const override
+ IDSocketDeclaration(const char *idname) : idname_(idname)
{
- return matches_id_socket(socket, data_, name_, identifier_);
}
- bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override
- {
- if (StringRef(socket.idname) != data_.idname) {
- return this->build(ntree, node, (eNodeSocketInOut)socket.in_out);
- }
- if (data_.hide_label) {
- socket.flag |= SOCK_HIDE_LABEL;
- }
- else {
- socket.flag &= ~SOCK_HIDE_LABEL;
- }
- return socket;
- }
+ bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
+ bool matches(const bNodeSocket &socket) const override;
+ bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
};
-} // namespace detail
-class Object : public detail::IDSocketDeclaration<Object> {
+class Object : public IDSocketDeclaration {
public:
- Object() : detail::IDSocketDeclaration<Object>("NodeSocketObject")
+ using Builder = SocketDeclarationBuilder<Object>;
+
+ Object() : IDSocketDeclaration("NodeSocketObject")
{
}
};
-class Material : public detail::IDSocketDeclaration<Material> {
+class Material : public IDSocketDeclaration {
public:
- Material() : detail::IDSocketDeclaration<Material>("NodeSocketMaterial")
+ using Builder = SocketDeclarationBuilder<Material>;
+
+ Material() : IDSocketDeclaration("NodeSocketMaterial")
{
}
};
-class Collection : public detail::IDSocketDeclaration<Collection> {
+class Collection : public IDSocketDeclaration {
public:
- Collection() : detail::IDSocketDeclaration<Collection>("NodeSocketCollection")
+ using Builder = SocketDeclarationBuilder<Collection>;
+
+ Collection() : IDSocketDeclaration("NodeSocketCollection")
{
}
};
-class Texture : public detail::IDSocketDeclaration<Texture> {
+class Texture : public IDSocketDeclaration {
public:
- Texture() : detail::IDSocketDeclaration<Texture>("NodeSocketTexture")
+ using Builder = SocketDeclarationBuilder<Texture>;
+
+ Texture() : IDSocketDeclaration("NodeSocketTexture")
{
}
};
class Geometry : public SocketDeclaration {
public:
+ using Builder = SocketDeclarationBuilder<Geometry>;
+
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
};