Files
test/source/blender/nodes/NOD_geometry.hh
Jacques Lucke 19912457c6 Nodes: use auto registration for nodes
The goal here is to reduce the number of files that need to be edited when
adding a new node. To register a node, one currently has to add a line to
`node_geometry_register.cc` and `node_geometry_register.hh` (for geometry
nodes). Those files can be generated automatically.

There is a new `NOD_REGISTER_NODE` macro that nodes can use to register
themselves. The macro is then discovered by `discover_nodes.py` that generates
code that calls all the registration functions. The script also works when the
register functions are in arbitrary namespaces. This allows simplifying the node
code as well.

In the past I tried a few times to get auto-registration working without resorting to
code generation, but that never ended up working. The general idea for that would
be to use non-trivial initialization for static variables. The issue always ends up
being that the linker just discards those variables, because they are unused and it
doesn't care if there are side effects in the initialization.

Related discussion regarding using Python for code generation:
https://devtalk.blender.org/t/code-generation-with-python/30558

Pull Request: https://projects.blender.org/blender/blender/pulls/110686
2023-08-09 22:01:03 +02:00

85 lines
4.0 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "BKE_node.h"
extern bNodeTreeType *ntreeType_Geometry;
void register_node_tree_type_geo();
void register_node_type_geo_custom_group(bNodeType *ntype);
/* -------------------------------------------------------------------- */
/** \name Simulation Input Node
* \{ */
bNode *NOD_geometry_simulation_input_get_paired_output(bNodeTree *node_tree,
const bNode *simulation_input_node);
/**
* Pair a simulation input node with an output node.
* \return True if pairing the node was successful.
*/
bool NOD_geometry_simulation_input_pair_with_output(const bNodeTree *node_tree,
bNode *simulation_input_node,
const bNode *simulation_output_node);
bool NOD_geometry_repeat_input_pair_with_output(const bNodeTree *node_tree,
bNode *repeat_input_node,
const bNode *repeat_output_node);
/** \} */
/* -------------------------------------------------------------------- */
/** \name Simulation Output Node
* \{ */
bool NOD_geometry_simulation_output_item_socket_type_supported(eNodeSocketDatatype socket_type);
/**
* Set a unique item name.
* \return True if the unique name differs from the original name.
*/
bool NOD_geometry_simulation_output_item_set_unique_name(NodeGeometrySimulationOutput *sim,
NodeSimulationItem *item,
const char *name,
const char *defname);
/**
* Find the node owning this simulation state item.
*/
bNode *NOD_geometry_simulation_output_find_node_by_item(bNodeTree *ntree,
const NodeSimulationItem *item);
bool NOD_geometry_simulation_output_contains_item(NodeGeometrySimulationOutput *sim,
const NodeSimulationItem *item);
NodeSimulationItem *NOD_geometry_simulation_output_get_active_item(
NodeGeometrySimulationOutput *sim);
void NOD_geometry_simulation_output_set_active_item(NodeGeometrySimulationOutput *sim,
NodeSimulationItem *item);
NodeSimulationItem *NOD_geometry_simulation_output_find_item(NodeGeometrySimulationOutput *sim,
const char *name);
NodeSimulationItem *NOD_geometry_simulation_output_add_item(NodeGeometrySimulationOutput *sim,
short socket_type,
const char *name);
NodeSimulationItem *NOD_geometry_simulation_output_insert_item(NodeGeometrySimulationOutput *sim,
short socket_type,
const char *name,
int index);
NodeSimulationItem *NOD_geometry_simulation_output_add_item_from_socket(
NodeGeometrySimulationOutput *sim, const bNode *from_node, const bNodeSocket *from_sock);
NodeSimulationItem *NOD_geometry_simulation_output_insert_item_from_socket(
NodeGeometrySimulationOutput *sim,
const bNode *from_node,
const bNodeSocket *from_sock,
int index);
void NOD_geometry_simulation_output_remove_item(NodeGeometrySimulationOutput *sim,
NodeSimulationItem *item);
void NOD_geometry_simulation_output_clear_items(NodeGeometrySimulationOutput *sim);
void NOD_geometry_simulation_output_move_item(NodeGeometrySimulationOutput *sim,
int from_index,
int to_index);
/** \} */