Nodes: Make more node and socket declaration fields public

When these declarations are built without the help of the special
builder class, it's much more convenient to set them directly rather
than with a constructor, etc. In most other situations the declarations
should be const anyway, so theoretically this doesn't affect safety too
much. Most construction of declarations should still use the builder.
This commit is contained in:
Hans Goudey 2022-12-29 14:55:27 -05:00
parent a09accb496
commit c744d5453f
30 changed files with 181 additions and 207 deletions

View File

@ -3599,8 +3599,8 @@ static void update_socket_declarations(ListBase *sockets,
void nodeSocketDeclarationsUpdate(bNode *node)
{
BLI_assert(node->runtime->declaration != nullptr);
update_socket_declarations(&node->inputs, node->runtime->declaration->inputs());
update_socket_declarations(&node->outputs, node->runtime->declaration->outputs());
update_socket_declarations(&node->inputs, node->runtime->declaration->inputs);
update_socket_declarations(&node->outputs, node->runtime->declaration->outputs);
}
bool nodeDeclarationEnsureOnOutdatedNode(bNodeTree * /*ntree*/, bNode *node)

View File

@ -55,8 +55,8 @@ static InputSocketFieldType get_interface_input_field_type(const bNode &node,
BLI_assert(node_decl != nullptr);
/* Get the field type from the declaration. */
const SocketDeclaration &socket_decl = *node_decl->inputs()[socket.index()];
const InputSocketFieldType field_type = socket_decl.input_field_type();
const SocketDeclaration &socket_decl = *node_decl->inputs[socket.index()];
const InputSocketFieldType field_type = socket_decl.input_field_type;
return field_type;
}
@ -88,8 +88,8 @@ static OutputFieldDependency get_interface_output_field_dependency(const bNode &
BLI_assert(node_decl != nullptr);
/* Use the socket declaration. */
const SocketDeclaration &socket_decl = *node_decl->outputs()[socket.index()];
return socket_decl.output_field_dependency();
const SocketDeclaration &socket_decl = *node_decl->outputs[socket.index()];
return socket_decl.output_field_dependency;
}
static const FieldInferencingInterface &get_dummy_field_inferencing_interface(const bNode &node,

View File

@ -109,12 +109,12 @@ InputDescriptor input_descriptor_from_input_socket(const bNodeSocket *socket)
InputDescriptor input_descriptor;
input_descriptor.type = get_node_socket_result_type(socket);
const NodeDeclaration *node_declaration = socket->owner_node().declaration();
/* Not every node have a declaration, in which case, we assume the default values for the rest of
/* Not every node has a declaration, in which case we assume the default values for the rest of
* the properties. */
if (!node_declaration) {
return input_descriptor;
}
const SocketDeclarationPtr &socket_declaration = node_declaration->inputs()[socket->index()];
const SocketDeclarationPtr &socket_declaration = node_declaration->inputs[socket->index()];
input_descriptor.domain_priority = socket_declaration->compositor_domain_priority();
input_descriptor.skip_realization = socket_declaration->compositor_skip_realization();
input_descriptor.expects_single_value = socket_declaration->compositor_expects_single_value();

View File

@ -1276,7 +1276,7 @@ static bool socket_needs_attribute_search(bNode &node, bNodeSocket &socket)
return false;
}
const int socket_index = BLI_findindex(&node.inputs, &socket);
return node.runtime->declaration->inputs()[socket_index]->is_attribute_name();
return node.declaration()->inputs[socket_index]->is_attribute_name;
}
static void std_node_socket_draw(

View File

@ -991,7 +991,7 @@ static void create_inspection_string_for_geometry_info(const geo_log::GeometryIn
/* If the geometry declaration is null, as is the case for input to group output,
* or it is an output socket don't show supported types. */
if (socket_decl == nullptr || socket_decl->in_out() == SOCK_OUT) {
if (socket_decl == nullptr || socket_decl->in_out == SOCK_OUT) {
return;
}
@ -1078,7 +1078,7 @@ static bool node_socket_has_tooltip(const bNodeTree &ntree, const bNodeSocket &s
if (socket.runtime->declaration != nullptr) {
const nodes::SocketDeclaration &socket_decl = *socket.runtime->declaration;
return !socket_decl.description().is_empty();
return !socket_decl.description.empty();
}
return false;
@ -1100,7 +1100,7 @@ static char *node_socket_get_tooltip(const bContext *C,
std::stringstream output;
if (socket->runtime->declaration != nullptr) {
const blender::nodes::SocketDeclaration &socket_decl = *socket->runtime->declaration;
blender::StringRef description = socket_decl.description();
blender::StringRef description = socket_decl.description;
if (!description.is_empty()) {
output << TIP_(description.data());
}

View File

@ -2065,15 +2065,15 @@ bNodeSocket *get_main_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_
nodeDeclarationEnsure(&ntree, &node);
const nodes::NodeDeclaration *node_decl = node.declaration();
if (node_decl != nullptr) {
Span<nodes::SocketDeclarationPtr> socket_decls = (in_out == SOCK_IN) ? node_decl->inputs() :
node_decl->outputs();
Span<nodes::SocketDeclarationPtr> socket_decls = (in_out == SOCK_IN) ? node_decl->inputs :
node_decl->outputs;
int index;
LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, sockets, index) {
const nodes::SocketDeclaration &socket_decl = *socket_decls[index];
if (!socket->is_visible()) {
continue;
}
if (socket_decl.is_default_link_socket()) {
if (socket_decl.is_default_link_socket) {
return socket;
}
}

View File

@ -362,8 +362,8 @@ static Vector<NodeLinkItem> ui_node_link_items(NodeLinkArg *arg,
r_node_decl.emplace(NodeDeclaration());
blender::nodes::build_node_declaration(*arg->node_type, *r_node_decl);
Span<SocketDeclarationPtr> socket_decls = (in_out == SOCK_IN) ? r_node_decl->inputs() :
r_node_decl->outputs();
Span<SocketDeclarationPtr> socket_decls = (in_out == SOCK_IN) ? r_node_decl->inputs :
r_node_decl->outputs;
int index = 0;
for (const SocketDeclarationPtr &socket_decl_ptr : socket_decls) {
const SocketDeclaration &socket_decl = *socket_decl_ptr;
@ -408,7 +408,7 @@ static Vector<NodeLinkItem> ui_node_link_items(NodeLinkArg *arg,
else {
item.socket_type = SOCK_CUSTOM;
}
item.socket_name = socket_decl.name().c_str();
item.socket_name = socket_decl.name.c_str();
item.node_name = arg->node_type->ui_name;
items.append(item);
}

View File

@ -71,24 +71,24 @@ using ImplicitInputValueFn = std::function<void(const bNode &node, void *r_value
* Describes a single input or output socket. This is subclassed for different socket types.
*/
class SocketDeclaration {
protected:
std::string name_;
std::string identifier_;
std::string description_;
public:
std::string name;
std::string identifier;
std::string description;
/** Defined by whether the socket is part of the node's input or
* output socket declaration list. Included here for convenience. */
eNodeSocketInOut in_out_;
bool hide_label_ = false;
bool hide_value_ = false;
bool compact_ = false;
bool is_multi_input_ = false;
bool no_mute_links_ = false;
bool is_unavailable_ = false;
bool is_attribute_name_ = false;
bool is_default_link_socket_ = false;
eNodeSocketInOut in_out;
bool hide_label = false;
bool hide_value = false;
bool compact = false;
bool is_multi_input = false;
bool no_mute_links = false;
bool is_unavailable = false;
bool is_attribute_name = false;
bool is_default_link_socket = false;
InputSocketFieldType input_field_type_ = InputSocketFieldType::None;
OutputFieldDependency output_field_dependency_;
InputSocketFieldType input_field_type = InputSocketFieldType::None;
OutputFieldDependency output_field_dependency;
/** The priority of the input for determining the domain of the node. See
* realtime_compositor::InputDescriptor for more information. */
@ -132,16 +132,6 @@ class SocketDeclaration {
*/
void make_available(bNode &node) const;
StringRefNull name() const;
StringRefNull description() const;
StringRefNull identifier() const;
eNodeSocketInOut in_out() const;
bool is_attribute_name() const;
bool is_default_link_socket() const;
InputSocketFieldType input_field_type() const;
const OutputFieldDependency &output_field_dependency() const;
int compositor_domain_priority() const;
bool compositor_skip_realization() const;
bool compositor_expects_single_value() const;
@ -178,31 +168,31 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
public:
Self &hide_label(bool value = true)
{
decl_->hide_label_ = value;
decl_->hide_label = value;
return *(Self *)this;
}
Self &hide_value(bool value = true)
{
decl_->hide_value_ = value;
decl_->hide_value = value;
return *(Self *)this;
}
Self &multi_input(bool value = true)
{
decl_->is_multi_input_ = value;
decl_->is_multi_input = value;
return *(Self *)this;
}
Self &description(std::string value = "")
{
decl_->description_ = std::move(value);
decl_->description = std::move(value);
return *(Self *)this;
}
Self &no_muted_links(bool value = true)
{
decl_->no_mute_links_ = value;
decl_->no_mute_links = value;
return *(Self *)this;
}
@ -212,26 +202,26 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
*/
Self &unavailable(bool value = true)
{
decl_->is_unavailable_ = value;
decl_->is_unavailable = value;
return *(Self *)this;
}
Self &is_attribute_name(bool value = true)
{
decl_->is_attribute_name_ = value;
decl_->is_attribute_name = value;
return *(Self *)this;
}
Self &is_default_link_socket(bool value = true)
{
decl_->is_default_link_socket_ = value;
decl_->is_default_link_socket = value;
return *(Self *)this;
}
/** The input socket allows passing in a field. */
Self &supports_field()
{
decl_->input_field_type_ = InputSocketFieldType::IsSupported;
decl_->input_field_type = InputSocketFieldType::IsSupported;
return *(Self *)this;
}
@ -239,7 +229,7 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
Self &implicit_field(ImplicitInputValueFn fn)
{
this->hide_value();
decl_->input_field_type_ = InputSocketFieldType::Implicit;
decl_->input_field_type = InputSocketFieldType::Implicit;
decl_->implicit_input_fn_ = std::make_unique<ImplicitInputValueFn>(std::move(fn));
return *(Self *)this;
}
@ -247,21 +237,21 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
/** The output is always a field, regardless of any inputs. */
Self &field_source()
{
decl_->output_field_dependency_ = OutputFieldDependency::ForFieldSource();
decl_->output_field_dependency = OutputFieldDependency::ForFieldSource();
return *(Self *)this;
}
/** The output is a field if any of the inputs is a field. */
Self &dependent_field()
{
decl_->output_field_dependency_ = OutputFieldDependency::ForDependentField();
decl_->output_field_dependency = OutputFieldDependency::ForDependentField();
return *(Self *)this;
}
/** The output is a field if any of the inputs with indices in the given list is a field. */
Self &dependent_field(Vector<int> input_dependencies)
{
decl_->output_field_dependency_ = OutputFieldDependency::ForPartiallyDependentField(
decl_->output_field_dependency = OutputFieldDependency::ForPartiallyDependentField(
std::move(input_dependencies));
return *(Self *)this;
}
@ -306,17 +296,13 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
using SocketDeclarationPtr = std::unique_ptr<SocketDeclaration>;
class NodeDeclaration {
private:
Vector<SocketDeclarationPtr> inputs_;
Vector<SocketDeclarationPtr> outputs_;
public:
Vector<SocketDeclarationPtr> inputs;
Vector<SocketDeclarationPtr> outputs;
friend NodeDeclarationBuilder;
public:
bool matches(const bNode &node) const;
Span<SocketDeclarationPtr> inputs() const;
Span<SocketDeclarationPtr> outputs() const;
Span<SocketDeclarationPtr> sockets(eNodeSocketInOut in_out) const;
MEM_CXX_CLASS_ALLOC_FUNCS("NodeDeclaration")
@ -443,46 +429,6 @@ inline bool operator!=(const FieldInferencingInterface &a, const FieldInferencin
/** \name #SocketDeclaration Inline Methods
* \{ */
inline StringRefNull SocketDeclaration::name() const
{
return name_;
}
inline StringRefNull SocketDeclaration::identifier() const
{
return identifier_;
}
inline eNodeSocketInOut SocketDeclaration::in_out() const
{
return in_out_;
}
inline StringRefNull SocketDeclaration::description() const
{
return description_;
}
inline bool SocketDeclaration::is_attribute_name() const
{
return is_attribute_name_;
}
inline bool SocketDeclaration::is_default_link_socket() const
{
return is_default_link_socket_;
}
inline InputSocketFieldType SocketDeclaration::input_field_type() const
{
return input_field_type_;
}
inline const OutputFieldDependency &SocketDeclaration::output_field_dependency() const
{
return output_field_dependency_;
}
inline int SocketDeclaration::compositor_domain_priority() const
{
return compositor_domain_priority_;
@ -538,15 +484,15 @@ inline typename DeclType::Builder &NodeDeclarationBuilder::add_socket(StringRef
static_assert(std::is_base_of_v<SocketDeclaration, DeclType>);
using Builder = typename DeclType::Builder;
Vector<SocketDeclarationPtr> &declarations = in_out == SOCK_IN ? declaration_.inputs_ :
declaration_.outputs_;
Vector<SocketDeclarationPtr> &declarations = in_out == SOCK_IN ? declaration_.inputs :
declaration_.outputs;
std::unique_ptr<DeclType> socket_decl = std::make_unique<DeclType>();
std::unique_ptr<Builder> socket_decl_builder = std::make_unique<Builder>();
socket_decl_builder->decl_ = &*socket_decl;
socket_decl->name_ = name;
socket_decl->identifier_ = identifier.is_empty() ? name : identifier;
socket_decl->in_out_ = in_out;
socket_decl->name = name;
socket_decl->identifier = identifier.is_empty() ? name : identifier;
socket_decl->in_out = in_out;
declarations.append(std::move(socket_decl));
Builder &socket_decl_builder_ref = *socket_decl_builder;
builders_.append(std::move(socket_decl_builder));
@ -559,22 +505,12 @@ inline typename DeclType::Builder &NodeDeclarationBuilder::add_socket(StringRef
/** \name #NodeDeclaration Inline Methods
* \{ */
inline Span<SocketDeclarationPtr> NodeDeclaration::inputs() const
{
return inputs_;
}
inline Span<SocketDeclarationPtr> NodeDeclaration::outputs() const
{
return outputs_;
}
inline Span<SocketDeclarationPtr> NodeDeclaration::sockets(eNodeSocketInOut in_out) const
{
if (in_out == SOCK_IN) {
return inputs_;
return inputs;
}
return outputs_;
return outputs;
}
/** \} */

View File

@ -306,7 +306,7 @@ inline VectorBuilder &VectorBuilder::max(const float max)
inline VectorBuilder &VectorBuilder::compact()
{
decl_->compact_ = true;
decl_->compact = true;
return *this;
}

View File

@ -123,7 +123,7 @@ static void node_gather_link_search_ops(GatherLinkSearchOpParams &params)
params.update_and_connect_available_socket(node, "Max");
});
}
search_link_ops_for_declarations(params, declaration.inputs().take_back(3));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_back(3));
}
else {
params.add_item(IFACE_("Value"), [type](LinkSearchOpParams &params) {

View File

@ -82,8 +82,8 @@ static void node_update(bNodeTree *ntree, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
search_link_ops_for_declarations(params, declaration.outputs().take_front(1));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_front(1));
search_link_ops_for_declarations(params, declaration.outputs.as_span().take_front(1));
const bNodeType &node_type = params.node_type();
const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(

View File

@ -119,7 +119,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const bNodeType &node_type = params.node_type();
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.inputs().take_front(2));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_front(2));
const std::optional<eCustomDataType> type = node_type_from_other_socket(params.other_socket());
if (!type) {

View File

@ -77,7 +77,7 @@ static void node_init(bNodeTree * /*tree*/, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.inputs().take_back(2));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_back(2));
const bNodeType &node_type = params.node_type();
const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(

View File

@ -136,7 +136,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
if (params.in_out() == SOCK_OUT) {
search_link_ops_for_declarations(params, declaration.outputs());
search_link_ops_for_declarations(params, declaration.outputs);
}
else if (params.node_tree().typeinfo->validate_link(
eNodeSocketDatatype(params.other_socket().type), SOCK_FLOAT)) {

View File

@ -113,8 +113,8 @@ static void node_update(bNodeTree *ntree, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.inputs().take_front(4));
search_link_ops_for_declarations(params, declaration.outputs().take_front(3));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_front(4));
search_link_ops_for_declarations(params, declaration.outputs.as_span().take_front(3));
const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
eNodeSocketDatatype(params.other_socket().type));

View File

@ -92,8 +92,8 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.outputs());
search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
search_link_ops_for_declarations(params, declaration.outputs);
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_front(1));
if (params.in_out() == SOCK_IN) {
if (params.node_tree().typeinfo->validate_link(eNodeSocketDatatype(params.other_socket().type),

View File

@ -132,7 +132,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_front(1));
const bNodeType &node_type = params.node_type();
const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(

View File

@ -57,7 +57,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.inputs());
search_link_ops_for_declarations(params, declaration.inputs);
const bNodeType &node_type = params.node_type();
if (params.in_out() == SOCK_OUT) {

View File

@ -93,7 +93,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
if (params.in_out() == SOCK_OUT) {
search_link_ops_for_declarations(params, declaration.outputs());
search_link_ops_for_declarations(params, declaration.outputs);
return;
}
else if (params.node_tree().typeinfo->validate_link(

View File

@ -100,9 +100,9 @@ static void node_update(bNodeTree *ntree, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
search_link_ops_for_declarations(params, declaration.inputs().take_back(3));
search_link_ops_for_declarations(params, declaration.outputs().take_front(4));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_front(1));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_back(3));
search_link_ops_for_declarations(params, declaration.outputs.as_span().take_front(4));
const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
(eNodeSocketDatatype)params.other_socket().type);

View File

@ -88,8 +88,8 @@ static void node_update(bNodeTree *ntree, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.inputs().take_back(1));
search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_back(1));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_front(1));
const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
(eNodeSocketDatatype)params.other_socket().type);

View File

@ -81,8 +81,8 @@ static void node_update(bNodeTree *ntree, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.inputs().take_back(2));
search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_back(2));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_front(1));
const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
(eNodeSocketDatatype)params.other_socket().type);

View File

@ -89,9 +89,9 @@ static void node_update(bNodeTree *ntree, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.inputs().take_back(2));
search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
search_link_ops_for_declarations(params, declaration.outputs().take_back(1));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_back(2));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_front(1));
search_link_ops_for_declarations(params, declaration.outputs.as_span().take_back(1));
const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
eNodeSocketDatatype(params.other_socket().type));

View File

@ -70,8 +70,8 @@ static void node_update(bNodeTree *ntree, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.inputs().take_front(2));
search_link_ops_for_declarations(params, declaration.outputs().take_front(1));
search_link_ops_for_declarations(params, declaration.inputs.as_span().take_front(2));
search_link_ops_for_declarations(params, declaration.outputs.as_span().take_front(1));
if (params.in_out() == SOCK_IN) {
const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(

View File

@ -1252,7 +1252,7 @@ struct GeometryNodesLazyFunctionGraphBuilder {
if (socket_decl == nullptr) {
return false;
}
if (socket_decl->input_field_type() != InputSocketFieldType::Implicit) {
if (socket_decl->input_field_type != InputSocketFieldType::Implicit) {
return false;
}
const ImplicitInputValueFn *implicit_input_fn = socket_decl->implicit_input_fn();

View File

@ -17,13 +17,13 @@ void build_node_declaration(const bNodeType &typeinfo, NodeDeclaration &r_declar
void NodeDeclarationBuilder::finalize()
{
if (is_function_node_) {
for (SocketDeclarationPtr &socket_decl : declaration_.inputs_) {
if (socket_decl->input_field_type_ != InputSocketFieldType::Implicit) {
socket_decl->input_field_type_ = InputSocketFieldType::IsSupported;
for (SocketDeclarationPtr &socket_decl : declaration_.inputs) {
if (socket_decl->input_field_type != InputSocketFieldType::Implicit) {
socket_decl->input_field_type = InputSocketFieldType::IsSupported;
}
}
for (SocketDeclarationPtr &socket_decl : declaration_.outputs_) {
socket_decl->output_field_dependency_ = OutputFieldDependency::ForDependentField();
for (SocketDeclarationPtr &socket_decl : declaration_.outputs) {
socket_decl->output_field_dependency = OutputFieldDependency::ForDependentField();
}
}
}
@ -45,10 +45,10 @@ bool NodeDeclaration::matches(const bNode &node) const
return true;
};
if (!check_sockets(node.inputs, inputs_)) {
if (!check_sockets(node.inputs, inputs)) {
return false;
}
if (!check_sockets(node.outputs, outputs_)) {
if (!check_sockets(node.outputs, outputs)) {
return false;
}
return true;
@ -66,38 +66,38 @@ bNodeSocket &SocketDeclaration::update_or_build(bNodeTree &ntree,
void SocketDeclaration::set_common_flags(bNodeSocket &socket) const
{
SET_FLAG_FROM_TEST(socket.flag, compact_, SOCK_COMPACT);
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);
SET_FLAG_FROM_TEST(socket.flag, no_mute_links_, SOCK_NO_INTERNAL_LINK);
SET_FLAG_FROM_TEST(socket.flag, is_unavailable_, SOCK_UNAVAIL);
SET_FLAG_FROM_TEST(socket.flag, compact, SOCK_COMPACT);
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);
SET_FLAG_FROM_TEST(socket.flag, no_mute_links, SOCK_NO_INTERNAL_LINK);
SET_FLAG_FROM_TEST(socket.flag, is_unavailable, SOCK_UNAVAIL);
}
bool SocketDeclaration::matches_common_data(const bNodeSocket &socket) const
{
if (socket.name != name_) {
if (socket.name != this->name) {
return false;
}
if (socket.identifier != identifier_) {
if (socket.identifier != this->identifier) {
return false;
}
if (((socket.flag & SOCK_COMPACT) != 0) != compact_) {
if (((socket.flag & SOCK_COMPACT) != 0) != this->compact) {
return false;
}
if (((socket.flag & SOCK_HIDE_VALUE) != 0) != hide_value_) {
if (((socket.flag & SOCK_HIDE_VALUE) != 0) != this->hide_value) {
return false;
}
if (((socket.flag & SOCK_HIDE_LABEL) != 0) != hide_label_) {
if (((socket.flag & SOCK_HIDE_LABEL) != 0) != this->hide_label) {
return false;
}
if (((socket.flag & SOCK_MULTI_INPUT) != 0) != is_multi_input_) {
if (((socket.flag & SOCK_MULTI_INPUT) != 0) != this->is_multi_input) {
return false;
}
if (((socket.flag & SOCK_NO_INTERNAL_LINK) != 0) != no_mute_links_) {
if (((socket.flag & SOCK_NO_INTERNAL_LINK) != 0) != this->no_mute_links) {
return false;
}
if (((socket.flag & SOCK_UNAVAIL) != 0) != is_unavailable_) {
if (((socket.flag & SOCK_UNAVAIL) != 0) != this->is_unavailable) {
return false;
}
return true;

View File

@ -184,7 +184,7 @@ static void refresh_socket_list(bNodeTree &ntree,
bNodeSocket *old_socket_with_same_identifier = nullptr;
for (const int i : old_sockets.index_range()) {
bNodeSocket &old_socket = *old_sockets[i];
if (old_socket.identifier == socket_decl->identifier()) {
if (old_socket.identifier == socket_decl->identifier) {
old_sockets.remove_and_reorder(i);
old_socket_with_same_identifier = &old_socket;
break;
@ -196,7 +196,7 @@ static void refresh_socket_list(bNodeTree &ntree,
new_socket = &socket_decl->build(ntree, node);
}
else {
STRNCPY(old_socket_with_same_identifier->name, socket_decl->name().c_str());
STRNCPY(old_socket_with_same_identifier->name, socket_decl->name.c_str());
if (socket_decl->matches(*old_socket_with_same_identifier)) {
/* The existing socket matches exactly, just use it. */
new_socket = old_socket_with_same_identifier;
@ -208,7 +208,7 @@ static void refresh_socket_list(bNodeTree &ntree,
if (new_socket == old_socket_with_same_identifier) {
/* The existing socket has been updated, set the correct identifier again. */
STRNCPY(new_socket->identifier, socket_decl->identifier().c_str());
STRNCPY(new_socket->identifier, socket_decl->identifier.c_str());
}
else {
/* Move links to new socket with same identifier. */
@ -249,8 +249,8 @@ static void refresh_node(bNodeTree &ntree,
blender::nodes::NodeDeclaration &node_decl,
bool do_id_user)
{
refresh_socket_list(ntree, node, node.inputs, node_decl.inputs(), do_id_user);
refresh_socket_list(ntree, node, node.outputs, node_decl.outputs(), do_id_user);
refresh_socket_list(ntree, node, node.inputs, node_decl.inputs, do_id_user);
refresh_socket_list(ntree, node, node.outputs, node_decl.outputs, do_id_user);
}
void node_verify_sockets(bNodeTree *ntree, bNode *node, bool do_id_user)

View File

@ -18,8 +18,8 @@ namespace blender::nodes::decl {
static bool field_types_are_compatible(const SocketDeclaration &input,
const SocketDeclaration &output)
{
if (output.output_field_dependency().field_type() == OutputSocketFieldType::FieldSource) {
if (input.input_field_type() == InputSocketFieldType::None) {
if (output.output_field_dependency.field_type() == OutputSocketFieldType::FieldSource) {
if (input.input_field_type == InputSocketFieldType::None) {
return false;
}
}
@ -30,12 +30,12 @@ static bool sockets_can_connect(const SocketDeclaration &socket_decl,
const bNodeSocket &other_socket)
{
/* Input sockets cannot connect to input sockets, outputs cannot connect to outputs. */
if (socket_decl.in_out() == other_socket.in_out) {
if (socket_decl.in_out == other_socket.in_out) {
return false;
}
if (other_socket.runtime->declaration) {
if (socket_decl.in_out() == SOCK_IN) {
if (socket_decl.in_out == SOCK_IN) {
if (!field_types_are_compatible(socket_decl, *other_socket.runtime->declaration)) {
return false;
}
@ -70,8 +70,13 @@ 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, this->subtype, identifier_.c_str(), name_.c_str());
bNodeSocket &socket = *nodeAddStaticSocket(&ntree,
&node,
this->in_out,
SOCK_FLOAT,
this->subtype,
this->identifier.c_str(),
this->name.c_str());
this->set_common_flags(socket);
bNodeSocketValueFloat &value = *(bNodeSocketValueFloat *)socket.default_value;
value.min = this->soft_min_value;
@ -112,7 +117,7 @@ bool Float::can_connect(const bNodeSocket &socket) const
bNodeSocket &Float::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const
{
if (socket.type != SOCK_FLOAT) {
BLI_assert(socket.in_out == in_out_);
BLI_assert(socket.in_out == this->in_out);
return this->build(ntree, node);
}
if (socket.typeinfo->subtype != this->subtype) {
@ -134,8 +139,13 @@ 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, this->subtype, identifier_.c_str(), name_.c_str());
bNodeSocket &socket = *nodeAddStaticSocket(&ntree,
&node,
this->in_out,
SOCK_INT,
this->subtype,
this->identifier.c_str(),
this->name.c_str());
this->set_common_flags(socket);
bNodeSocketValueInt &value = *(bNodeSocketValueInt *)socket.default_value;
value.min = this->soft_min_value;
@ -176,7 +186,7 @@ bool Int::can_connect(const bNodeSocket &socket) const
bNodeSocket &Int::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const
{
if (socket.type != SOCK_INT) {
BLI_assert(socket.in_out == in_out_);
BLI_assert(socket.in_out == this->in_out);
return this->build(ntree, node);
}
if (socket.typeinfo->subtype != this->subtype) {
@ -198,8 +208,13 @@ 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, this->subtype, identifier_.c_str(), name_.c_str());
bNodeSocket &socket = *nodeAddStaticSocket(&ntree,
&node,
this->in_out,
SOCK_VECTOR,
this->subtype,
this->identifier.c_str(),
this->name.c_str());
this->set_common_flags(socket);
bNodeSocketValueVector &value = *(bNodeSocketValueVector *)socket.default_value;
copy_v3_v3(value.value, this->default_value);
@ -233,7 +248,7 @@ bool Vector::can_connect(const bNodeSocket &socket) const
bNodeSocket &Vector::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const
{
if (socket.type != SOCK_VECTOR) {
BLI_assert(socket.in_out == in_out_);
BLI_assert(socket.in_out == this->in_out);
return this->build(ntree, node);
}
if (socket.typeinfo->subtype != this->subtype) {
@ -242,7 +257,7 @@ bNodeSocket &Vector::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket
this->set_common_flags(socket);
bNodeSocketValueVector &value = *(bNodeSocketValueVector *)socket.default_value;
value.subtype = this->subtype;
STRNCPY(socket.name, name_.c_str());
STRNCPY(socket.name, this->name.c_str());
return socket;
}
@ -254,8 +269,13 @@ bNodeSocket &Vector::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket
bNodeSocket &Bool::build(bNodeTree &ntree, bNode &node) const
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out_, SOCK_BOOLEAN, PROP_NONE, identifier_.c_str(), name_.c_str());
bNodeSocket &socket = *nodeAddStaticSocket(&ntree,
&node,
this->in_out,
SOCK_BOOLEAN,
PROP_NONE,
this->identifier.c_str(),
this->name.c_str());
this->set_common_flags(socket);
bNodeSocketValueBoolean &value = *(bNodeSocketValueBoolean *)socket.default_value;
value.value = this->default_value;
@ -289,8 +309,13 @@ bool Bool::can_connect(const bNodeSocket &socket) const
bNodeSocket &Color::build(bNodeTree &ntree, bNode &node) const
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out_, SOCK_RGBA, PROP_NONE, identifier_.c_str(), name_.c_str());
bNodeSocket &socket = *nodeAddStaticSocket(&ntree,
&node,
this->in_out,
SOCK_RGBA,
PROP_NONE,
this->identifier.c_str(),
this->name.c_str());
this->set_common_flags(socket);
bNodeSocketValueRGBA &value = *(bNodeSocketValueRGBA *)socket.default_value;
copy_v4_v4(value.value, this->default_value);
@ -300,10 +325,10 @@ bNodeSocket &Color::build(bNodeTree &ntree, bNode &node) const
bool Color::matches(const bNodeSocket &socket) const
{
if (!this->matches_common_data(socket)) {
if (socket.name != name_) {
if (socket.name != this->name) {
return false;
}
if (socket.identifier != identifier_) {
if (socket.identifier != this->identifier) {
return false;
}
}
@ -329,8 +354,13 @@ bool Color::can_connect(const bNodeSocket &socket) const
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());
bNodeSocket &socket = *nodeAddStaticSocket(&ntree,
&node,
this->in_out,
SOCK_STRING,
PROP_NONE,
this->identifier.c_str(),
this->name.c_str());
STRNCPY(((bNodeSocketValueString *)socket.default_value)->value, this->default_value.c_str());
this->set_common_flags(socket);
return socket;
@ -361,7 +391,7 @@ bool String::can_connect(const bNodeSocket &socket) const
bNodeSocket &IDSocketDeclaration::build(bNodeTree &ntree, bNode &node) const
{
bNodeSocket &socket = *nodeAddSocket(
&ntree, &node, in_out_, this->idname, identifier_.c_str(), name_.c_str());
&ntree, &node, this->in_out, this->idname, this->identifier.c_str(), this->name.c_str());
this->set_common_flags(socket);
return socket;
}
@ -387,7 +417,7 @@ bNodeSocket &IDSocketDeclaration::update_or_build(bNodeTree &ntree,
bNodeSocket &socket) const
{
if (StringRef(socket.idname) != this->idname) {
BLI_assert(socket.in_out == in_out_);
BLI_assert(socket.in_out == this->in_out);
return this->build(ntree, node);
}
this->set_common_flags(socket);
@ -402,8 +432,12 @@ bNodeSocket &IDSocketDeclaration::update_or_build(bNodeTree &ntree,
bNodeSocket &Geometry::build(bNodeTree &ntree, bNode &node) const
{
bNodeSocket &socket = *nodeAddSocket(
&ntree, &node, in_out_, "NodeSocketGeometry", identifier_.c_str(), name_.c_str());
bNodeSocket &socket = *nodeAddSocket(&ntree,
&node,
this->in_out,
"NodeSocketGeometry",
this->identifier.c_str(),
this->name.c_str());
this->set_common_flags(socket);
return socket;
}
@ -472,8 +506,12 @@ GeometryBuilder &GeometryBuilder::only_instances(bool value)
bNodeSocket &Shader::build(bNodeTree &ntree, bNode &node) const
{
bNodeSocket &socket = *nodeAddSocket(
&ntree, &node, in_out_, "NodeSocketShader", identifier_.c_str(), name_.c_str());
bNodeSocket &socket = *nodeAddSocket(&ntree,
&node,
this->in_out,
"NodeSocketShader",
this->identifier.c_str(),
this->name.c_str());
this->set_common_flags(socket);
return socket;
}
@ -495,7 +533,7 @@ bool Shader::can_connect(const bNodeSocket &socket) const
return false;
}
/* Basic types can convert to shaders, but not the other way around. */
if (in_out_ == SOCK_IN) {
if (this->in_out == SOCK_IN) {
return ELEM(
socket.type, SOCK_VECTOR, SOCK_RGBA, SOCK_FLOAT, SOCK_INT, SOCK_BOOLEAN, SOCK_SHADER);
}

View File

@ -91,7 +91,7 @@ void search_link_ops_for_declarations(GatherLinkSearchOpParams &params,
Set<StringRef> socket_names;
for (const int i : declarations.index_range()) {
const SocketDeclaration &socket = *declarations[i];
if (!socket_names.add(socket.name())) {
if (!socket_names.add(socket.name)) {
/* Don't add sockets with the same name to the search. Needed to support being called from
* #search_link_ops_for_basic_node, which should have "okay" behavior for nodes with
* duplicate socket names. */
@ -100,7 +100,7 @@ void search_link_ops_for_declarations(GatherLinkSearchOpParams &params,
if (!socket.can_connect(params.other_socket())) {
continue;
}
if (socket.is_default_link_socket() || main_socket == nullptr) {
if (socket.is_default_link_socket || main_socket == nullptr) {
/* Either the first connectable or explicitly tagged socket is the main socket. */
main_socket = &socket;
}
@ -115,11 +115,11 @@ void search_link_ops_for_declarations(GatherLinkSearchOpParams &params,
* sockets. */
const int weight = (&socket == main_socket) ? 0 : -1 - i;
params.add_item(
IFACE_(socket.name().c_str()),
IFACE_(socket.name.c_str()),
[&node_type, &socket](LinkSearchOpParams &params) {
bNode &node = params.add_node(node_type);
socket.make_available(node);
params.update_and_connect_available_socket(node, socket.name());
params.update_and_connect_available_socket(node, socket.name);
},
weight);
}

View File

@ -281,7 +281,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
if (params.in_out() == SOCK_OUT) {
search_link_ops_for_declarations(params, declaration.outputs());
search_link_ops_for_declarations(params, declaration.outputs);
return;
}
if (params.node_tree().typeinfo->validate_link(