Nodes: Make socket declaration member variables public

This is the best way I found to make building socket declarations without
the builder helper class work. Besides a vague hope for non-leaky
abstractions, I don't think there's any reason for these fields not to be
accessible directly.

Ref D16850
This commit is contained in:
Hans Goudey 2022-12-27 11:50:17 -05:00
parent 6aad3c7297
commit d7dad425c0
Notes: blender-bot 2023-02-14 11:28:39 +01:00
Referenced by issue #103521, Blender crashes on open when using Metal GPU Backend
2 changed files with 79 additions and 86 deletions

View File

@ -14,15 +14,14 @@ namespace blender::nodes::decl {
class FloatBuilder;
class Float : public SocketDeclaration {
private:
float default_value_ = 0.0f;
float soft_min_value_ = -FLT_MAX;
float soft_max_value_ = FLT_MAX;
PropertySubType subtype_ = PROP_NONE;
public:
float default_value = 0.0f;
float soft_min_value = -FLT_MAX;
float soft_max_value = FLT_MAX;
PropertySubType subtype = PROP_NONE;
friend FloatBuilder;
public:
using Builder = FloatBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@ -42,15 +41,14 @@ class FloatBuilder : public SocketDeclarationBuilder<Float> {
class IntBuilder;
class Int : public SocketDeclaration {
private:
int default_value_ = 0;
int soft_min_value_ = INT32_MIN;
int soft_max_value_ = INT32_MAX;
PropertySubType subtype_ = PROP_NONE;
public:
int default_value = 0;
int soft_min_value = INT32_MIN;
int soft_max_value = INT32_MAX;
PropertySubType subtype = PROP_NONE;
friend IntBuilder;
public:
using Builder = IntBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@ -70,15 +68,14 @@ class IntBuilder : public SocketDeclarationBuilder<Int> {
class VectorBuilder;
class Vector : public SocketDeclaration {
private:
float3 default_value_ = {0, 0, 0};
float soft_min_value_ = -FLT_MAX;
float soft_max_value_ = FLT_MAX;
PropertySubType subtype_ = PROP_NONE;
public:
float3 default_value = {0, 0, 0};
float soft_min_value = -FLT_MAX;
float soft_max_value = FLT_MAX;
PropertySubType subtype = PROP_NONE;
friend VectorBuilder;
public:
using Builder = VectorBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@ -99,11 +96,10 @@ class VectorBuilder : public SocketDeclarationBuilder<Vector> {
class BoolBuilder;
class Bool : public SocketDeclaration {
private:
bool default_value_ = false;
public:
bool default_value = false;
friend BoolBuilder;
public:
using Builder = BoolBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@ -119,12 +115,11 @@ class BoolBuilder : public SocketDeclarationBuilder<Bool> {
class ColorBuilder;
class Color : public SocketDeclaration {
private:
ColorGeometry4f default_value_;
public:
ColorGeometry4f default_value;
friend ColorBuilder;
public:
using Builder = ColorBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@ -140,12 +135,11 @@ class ColorBuilder : public SocketDeclarationBuilder<Color> {
class StringBuilder;
class String : public SocketDeclaration {
private:
std::string default_value_;
public:
std::string default_value;
friend StringBuilder;
public:
using Builder = StringBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@ -159,8 +153,8 @@ class StringBuilder : public SocketDeclarationBuilder<String> {
};
class IDSocketDeclaration : public SocketDeclaration {
private:
const char *idname_;
public:
const char *idname;
public:
IDSocketDeclaration(const char *idname);
@ -209,10 +203,9 @@ class Image : public IDSocketDeclaration {
class ShaderBuilder;
class Shader : public SocketDeclaration {
private:
public:
friend ShaderBuilder;
public:
using Builder = ShaderBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
@ -229,25 +222,25 @@ class ShaderBuilder : public SocketDeclarationBuilder<Shader> {
inline FloatBuilder &FloatBuilder::min(const float value)
{
decl_->soft_min_value_ = value;
decl_->soft_min_value = value;
return *this;
}
inline FloatBuilder &FloatBuilder::max(const float value)
{
decl_->soft_max_value_ = value;
decl_->soft_max_value = value;
return *this;
}
inline FloatBuilder &FloatBuilder::default_value(const float value)
{
decl_->default_value_ = value;
decl_->default_value = value;
return *this;
}
inline FloatBuilder &FloatBuilder::subtype(PropertySubType subtype)
{
decl_->subtype_ = subtype;
decl_->subtype = subtype;
return *this;
}
@ -259,25 +252,25 @@ inline FloatBuilder &FloatBuilder::subtype(PropertySubType subtype)
inline IntBuilder &IntBuilder::min(const int value)
{
decl_->soft_min_value_ = value;
decl_->soft_min_value = value;
return *this;
}
inline IntBuilder &IntBuilder::max(const int value)
{
decl_->soft_max_value_ = value;
decl_->soft_max_value = value;
return *this;
}
inline IntBuilder &IntBuilder::default_value(const int value)
{
decl_->default_value_ = value;
decl_->default_value = value;
return *this;
}
inline IntBuilder &IntBuilder::subtype(PropertySubType subtype)
{
decl_->subtype_ = subtype;
decl_->subtype = subtype;
return *this;
}
@ -289,25 +282,25 @@ inline IntBuilder &IntBuilder::subtype(PropertySubType subtype)
inline VectorBuilder &VectorBuilder::default_value(const float3 value)
{
decl_->default_value_ = value;
decl_->default_value = value;
return *this;
}
inline VectorBuilder &VectorBuilder::subtype(PropertySubType subtype)
{
decl_->subtype_ = subtype;
decl_->subtype = subtype;
return *this;
}
inline VectorBuilder &VectorBuilder::min(const float min)
{
decl_->soft_min_value_ = min;
decl_->soft_min_value = min;
return *this;
}
inline VectorBuilder &VectorBuilder::max(const float max)
{
decl_->soft_max_value_ = max;
decl_->soft_max_value = max;
return *this;
}
@ -325,7 +318,7 @@ inline VectorBuilder &VectorBuilder::compact()
inline BoolBuilder &BoolBuilder::default_value(const bool value)
{
decl_->default_value_ = value;
decl_->default_value = value;
return *this;
}
@ -337,7 +330,7 @@ inline BoolBuilder &BoolBuilder::default_value(const bool value)
inline ColorBuilder &ColorBuilder::default_value(const ColorGeometry4f value)
{
decl_->default_value_ = value;
decl_->default_value = value;
return *this;
}
@ -349,7 +342,7 @@ inline ColorBuilder &ColorBuilder::default_value(const ColorGeometry4f value)
inline StringBuilder &StringBuilder::default_value(std::string value)
{
decl_->default_value_ = std::move(value);
decl_->default_value = std::move(value);
return *this;
}
@ -359,7 +352,7 @@ inline StringBuilder &StringBuilder::default_value(std::string value)
/** \name #IDSocketDeclaration and Children Inline Methods
* \{ */
inline IDSocketDeclaration::IDSocketDeclaration(const char *idname) : idname_(idname)
inline IDSocketDeclaration::IDSocketDeclaration(const char *idname) : idname(idname)
{
}

View File

@ -71,12 +71,12 @@ static void modify_subtype_except_for_storage(bNodeSocket &socket, int new_subty
bNodeSocket &Float::build(bNodeTree &ntree, bNode &node) const
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out_, SOCK_FLOAT, subtype_, identifier_.c_str(), name_.c_str());
&ntree, &node, in_out_, SOCK_FLOAT, this->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_;
value.value = default_value_;
value.min = this->soft_min_value;
value.max = this->soft_max_value;
value.value = this->default_value;
return socket;
}
@ -88,14 +88,14 @@ bool Float::matches(const bNodeSocket &socket) const
if (socket.type != SOCK_FLOAT) {
return false;
}
if (socket.typeinfo->subtype != subtype_) {
if (socket.typeinfo->subtype != this->subtype) {
return false;
}
bNodeSocketValueFloat &value = *(bNodeSocketValueFloat *)socket.default_value;
if (value.min != soft_min_value_) {
if (value.min != this->soft_min_value) {
return false;
}
if (value.max != soft_max_value_) {
if (value.max != this->soft_max_value) {
return false;
}
return true;
@ -115,14 +115,14 @@ bNodeSocket &Float::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &
BLI_assert(socket.in_out == in_out_);
return this->build(ntree, node);
}
if (socket.typeinfo->subtype != subtype_) {
modify_subtype_except_for_storage(socket, subtype_);
if (socket.typeinfo->subtype != this->subtype) {
modify_subtype_except_for_storage(socket, this->subtype);
}
this->set_common_flags(socket);
bNodeSocketValueFloat &value = *(bNodeSocketValueFloat *)socket.default_value;
value.min = soft_min_value_;
value.max = soft_max_value_;
value.subtype = subtype_;
value.min = this->soft_min_value;
value.max = this->soft_max_value;
value.subtype = this->subtype;
return socket;
}
@ -135,12 +135,12 @@ bNodeSocket &Float::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &
bNodeSocket &Int::build(bNodeTree &ntree, bNode &node) const
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out_, SOCK_INT, subtype_, identifier_.c_str(), name_.c_str());
&ntree, &node, in_out_, SOCK_INT, this->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_;
value.value = default_value_;
value.min = this->soft_min_value;
value.max = this->soft_max_value;
value.value = this->default_value;
return socket;
}
@ -152,14 +152,14 @@ bool Int::matches(const bNodeSocket &socket) const
if (socket.type != SOCK_INT) {
return false;
}
if (socket.typeinfo->subtype != subtype_) {
if (socket.typeinfo->subtype != this->subtype) {
return false;
}
bNodeSocketValueInt &value = *(bNodeSocketValueInt *)socket.default_value;
if (value.min != soft_min_value_) {
if (value.min != this->soft_min_value) {
return false;
}
if (value.max != soft_max_value_) {
if (value.max != this->soft_max_value) {
return false;
}
return true;
@ -179,14 +179,14 @@ bNodeSocket &Int::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &so
BLI_assert(socket.in_out == in_out_);
return this->build(ntree, node);
}
if (socket.typeinfo->subtype != subtype_) {
modify_subtype_except_for_storage(socket, subtype_);
if (socket.typeinfo->subtype != this->subtype) {
modify_subtype_except_for_storage(socket, this->subtype);
}
this->set_common_flags(socket);
bNodeSocketValueInt &value = *(bNodeSocketValueInt *)socket.default_value;
value.min = soft_min_value_;
value.max = soft_max_value_;
value.subtype = subtype_;
value.min = this->soft_min_value;
value.max = this->soft_max_value;
value.subtype = this->subtype;
return socket;
}
@ -199,12 +199,12 @@ bNodeSocket &Int::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &so
bNodeSocket &Vector::build(bNodeTree &ntree, bNode &node) const
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out_, SOCK_VECTOR, subtype_, identifier_.c_str(), name_.c_str());
&ntree, &node, in_out_, SOCK_VECTOR, this->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_;
value.max = soft_max_value_;
copy_v3_v3(value.value, this->default_value);
value.min = this->soft_min_value;
value.max = this->soft_max_value;
return socket;
}
@ -216,7 +216,7 @@ bool Vector::matches(const bNodeSocket &socket) const
if (socket.type != SOCK_VECTOR) {
return false;
}
if (socket.typeinfo->subtype != subtype_) {
if (socket.typeinfo->subtype != this->subtype) {
return false;
}
return true;
@ -236,12 +236,12 @@ bNodeSocket &Vector::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket
BLI_assert(socket.in_out == in_out_);
return this->build(ntree, node);
}
if (socket.typeinfo->subtype != subtype_) {
modify_subtype_except_for_storage(socket, subtype_);
if (socket.typeinfo->subtype != this->subtype) {
modify_subtype_except_for_storage(socket, this->subtype);
}
this->set_common_flags(socket);
bNodeSocketValueVector &value = *(bNodeSocketValueVector *)socket.default_value;
value.subtype = subtype_;
value.subtype = this->subtype;
STRNCPY(socket.name, name_.c_str());
return socket;
}
@ -258,7 +258,7 @@ bNodeSocket &Bool::build(bNodeTree &ntree, bNode &node) const
&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_;
value.value = this->default_value;
return socket;
}
@ -293,7 +293,7 @@ bNodeSocket &Color::build(bNodeTree &ntree, bNode &node) const
&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_);
copy_v4_v4(value.value, this->default_value);
return socket;
}
@ -331,7 +331,7 @@ bNodeSocket &String::build(bNodeTree &ntree, bNode &node) const
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out_, SOCK_STRING, PROP_NONE, identifier_.c_str(), name_.c_str());
STRNCPY(((bNodeSocketValueString *)socket.default_value)->value, default_value_.c_str());
STRNCPY(((bNodeSocketValueString *)socket.default_value)->value, this->default_value.c_str());
this->set_common_flags(socket);
return socket;
}
@ -361,7 +361,7 @@ bool String::can_connect(const bNodeSocket &socket) const
bNodeSocket &IDSocketDeclaration::build(bNodeTree &ntree, bNode &node) const
{
bNodeSocket &socket = *nodeAddSocket(
&ntree, &node, in_out_, idname_, identifier_.c_str(), name_.c_str());
&ntree, &node, in_out_, this->idname, identifier_.c_str(), name_.c_str());
this->set_common_flags(socket);
return socket;
}
@ -371,7 +371,7 @@ bool IDSocketDeclaration::matches(const bNodeSocket &socket) const
if (!this->matches_common_data(socket)) {
return false;
}
if (!STREQ(socket.idname, idname_)) {
if (!STREQ(socket.idname, this->idname)) {
return false;
}
return true;
@ -379,14 +379,14 @@ bool IDSocketDeclaration::matches(const bNodeSocket &socket) const
bool IDSocketDeclaration::can_connect(const bNodeSocket &socket) const
{
return sockets_can_connect(*this, socket) && STREQ(socket.idname, idname_);
return sockets_can_connect(*this, socket) && STREQ(socket.idname, this->idname);
}
bNodeSocket &IDSocketDeclaration::update_or_build(bNodeTree &ntree,
bNode &node,
bNodeSocket &socket) const
{
if (StringRef(socket.idname) != idname_) {
if (StringRef(socket.idname) != this->idname) {
BLI_assert(socket.in_out == in_out_);
return this->build(ntree, node);
}