WIP: DNA: experiment for dealing with C++ and DNA #109619

Draft
Jacques Lucke wants to merge 6 commits from JacquesLucke/blender:dna-cpp-test into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
17 changed files with 177 additions and 162 deletions
Showing only changes of commit eea75e4053 - Show all commits

View File

@ -18,6 +18,7 @@
/* for FOREACH_NODETREE_BEGIN */
#include "DNA_node_types.h"
#include "DNA_node_types.hh"
#include "RNA_types.h"

View File

@ -669,10 +669,10 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree)
}
}
if (node->type == GEO_NODE_SIMULATION_OUTPUT) {
const NodeGeometrySimulationOutput &storage =
*static_cast<const NodeGeometrySimulationOutput *>(node->storage);
const auto &storage = *static_cast<const blender::dna::NodeGeometrySimulationOutput *>(
node->storage);
BLO_write_struct_array(writer, NodeSimulationItem, storage.items_num, storage.items);
for (const NodeSimulationItem &item : Span(storage.items, storage.items_num)) {
for (const blender::dna::NodeSimulationItem &item : Span(storage.items, storage.items_num)) {
BLO_write_string(writer, item.name);
}
}
@ -864,10 +864,11 @@ void ntreeBlendReadData(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree)
break;
}
case GEO_NODE_SIMULATION_OUTPUT: {
NodeGeometrySimulationOutput &storage = *static_cast<NodeGeometrySimulationOutput *>(
auto &storage = *static_cast<blender::dna::NodeGeometrySimulationOutput *>(
node->storage);
BLO_read_data_address(reader, &storage.items);
for (const NodeSimulationItem &item : Span(storage.items, storage.items_num)) {
for (const blender::dna::NodeSimulationItem &item :
Span(storage.items, storage.items_num)) {
BLO_read_data_address(reader, &item.name);
}
break;

View File

@ -287,7 +287,7 @@ static Vector<const bNode *> get_implicit_origin_nodes(const bNodeTree &ntree, b
for (const bNode *sim_input_node :
ntree.runtime->nodes_by_type.lookup(nodeTypeFind("GeometryNodeSimulationInput")))
{
const auto &storage = *static_cast<const NodeGeometrySimulationInput *>(
const auto &storage = *static_cast<const dna::NodeGeometrySimulationInput *>(
sim_input_node->storage);
if (storage.output_node_id == node.identifier) {
origin_nodes.append(sim_input_node);
@ -301,7 +301,7 @@ static Vector<const bNode *> get_implicit_target_nodes(const bNodeTree &ntree, b
{
Vector<const bNode *> target_nodes;
if (node.type == GEO_NODE_SIMULATION_INPUT) {
const auto &storage = *static_cast<const NodeGeometrySimulationInput *>(node.storage);
const auto &storage = *static_cast<const dna::NodeGeometrySimulationInput *>(node.storage);
if (const bNode *sim_output_node = ntree.node_by_id(storage.output_node_id)) {
target_nodes.append(sim_output_node);
}

View File

@ -330,8 +330,7 @@ static bool propagate_special_data_requirements(
/* Sync field state between simulation nodes and schedule another pass if necessary. */
if (node.type == GEO_NODE_SIMULATION_INPUT) {
const NodeGeometrySimulationInput &data = *static_cast<const NodeGeometrySimulationInput *>(
node.storage);
const auto &data = *static_cast<const dna::NodeGeometrySimulationInput *>(node.storage);
if (const bNode *output_node = tree.node_by_id(data.output_node_id)) {
const eFieldStateSyncResult sync_result = simulation_nodes_field_state_sync(
node, *output_node, field_state_by_socket_id);
@ -342,7 +341,7 @@ static bool propagate_special_data_requirements(
}
else if (node.type == GEO_NODE_SIMULATION_OUTPUT) {
for (const bNode *input_node : tree.nodes_by_type("GeometryNodeSimulationInput")) {
const NodeGeometrySimulationInput &data = *static_cast<const NodeGeometrySimulationInput *>(
const auto &data = *static_cast<const dna::NodeGeometrySimulationInput *>(
input_node->storage);
if (node.identifier == data.output_node_id) {
const eFieldStateSyncResult sync_result = simulation_nodes_field_state_sync(

View File

@ -580,8 +580,7 @@ class NodeTreeMainUpdater {
}
/* Check paired simulation zone nodes. */
if (node.type == GEO_NODE_SIMULATION_INPUT) {
const NodeGeometrySimulationInput *data = static_cast<const NodeGeometrySimulationInput *>(
node.storage);
const auto *data = static_cast<const dna::NodeGeometrySimulationInput *>(node.storage);
if (const bNode *output_node = ntree.node_by_id(data->output_node_id)) {
if (output_node->runtime->changed_flag & NTREE_CHANGED_NODE_PROPERTY) {
return true;

View File

@ -42,7 +42,7 @@ static Vector<std::unique_ptr<bNodeTreeZone>> find_zone_nodes(
zones.append_and_get_index(std::move(zone));
}
for (const bNode *node : tree.nodes_by_type("GeometryNodeSimulationInput")) {
const auto &storage = *static_cast<NodeGeometrySimulationInput *>(node->storage);
const auto &storage = *static_cast<dna::NodeGeometrySimulationInput *>(node->storage);
if (const bNode *sim_output_node = tree.node_by_id(storage.output_node_id)) {
if (bNodeTreeZone *zone = r_zone_by_inout_node.lookup_default(sim_output_node, nullptr)) {
zone->input_node = node;

View File

@ -1280,8 +1280,7 @@ void remap_node_pairing(bNodeTree &dst_tree, const Map<const bNode *, bNode *> &
for (bNode *dst_node : node_map.values()) {
if (dst_node->type == GEO_NODE_SIMULATION_INPUT) {
NodeGeometrySimulationInput *data = static_cast<NodeGeometrySimulationInput *>(
dst_node->storage);
auto *data = static_cast<dna::NodeGeometrySimulationInput *>(dst_node->storage);
if (const bNode *output_node = dst_output_node_map.lookup_default(data->output_node_id,
nullptr)) {
data->output_node_id = output_node->identifier;

View File

@ -148,8 +148,7 @@ static void remap_pairing(bNodeTree &dst_tree,
{
for (bNode *dst_node : nodes) {
if (dst_node->type == GEO_NODE_SIMULATION_INPUT) {
NodeGeometrySimulationInput *data = static_cast<NodeGeometrySimulationInput *>(
dst_node->storage);
auto *data = static_cast<dna::NodeGeometrySimulationInput *>(dst_node->storage);
if (data->output_node_id == 0) {
continue;
}
@ -777,8 +776,8 @@ static bool node_group_make_test_selected(bNodeTree &ntree,
* Simulation input or output nodes can only be grouped together with the paired node.
*/
for (bNode *input_node : ntree.nodes_by_type("GeometryNodeSimulationInput")) {
const NodeGeometrySimulationInput &input_data =
*static_cast<const NodeGeometrySimulationInput *>(input_node->storage);
const auto &input_data = *static_cast<const dna::NodeGeometrySimulationInput *>(
input_node->storage);
if (bNode *output_node = ntree.node_by_id(input_data.output_node_id)) {
const bool input_selected = nodes_to_group.contains(input_node);

View File

@ -317,7 +317,8 @@ void node_deselect_all_output_sockets(bNodeTree &node_tree, const bool deselect_
void node_select_paired(bNodeTree &node_tree)
{
for (bNode *input_node : node_tree.nodes_by_type("GeometryNodeSimulationInput")) {
const auto *storage = static_cast<const NodeGeometrySimulationInput *>(input_node->storage);
const auto *storage = static_cast<const dna::NodeGeometrySimulationInput *>(
input_node->storage);
if (bNode *output_node = node_tree.node_by_id(storage->output_node_id)) {
if (input_node->flag & NODE_SELECT) {
output_node->flag |= NODE_SELECT;

View File

@ -1707,39 +1707,6 @@ typedef struct NodeGeometryViewer {
int8_t domain;
} NodeGeometryViewer;
typedef struct NodeSimulationItem {
char *name;
/** #eNodeSocketDatatype. */
short socket_type;
/** #eAttrDomain. */
short attribute_domain;
/**
* Generates unique identifier for sockets which stays the same even when the item order or
* names change.
*/
int identifier;
} NodeSimulationItem;
typedef struct NodeGeometrySimulationInput {
/** bNode.identifier of the corresponding output node. */
int32_t output_node_id;
} NodeGeometrySimulationInput;
typedef struct NodeGeometrySimulationOutput {
NodeSimulationItem *items;
int items_num;
int active_index;
/** Number to give unique IDs to state items. */
int next_identifier;
int _pad;
#ifdef __cplusplus
blender::Span<NodeSimulationItem> items_span() const;
blender::MutableSpan<NodeSimulationItem> items_span();
blender::IndexRange items_range() const;
#endif
} NodeGeometrySimulationOutput;
typedef struct NodeGeometryDistributePointsInVolume {
/** #GeometryNodePointDistributeVolumeMode. */
uint8_t mode;

View File

@ -17,4 +17,37 @@ struct NodeGeometryUVUnwrap {
uint8_t method;
};
typedef struct NodeSimulationItem {
char *name;
/** #eNodeSocketDatatype. */
short socket_type;
/** #eAttrDomain. */
short attribute_domain;
/**
* Generates unique identifier for sockets which stays the same even when the item order or
* names change.
*/
int identifier;
} NodeSimulationItem;
typedef struct NodeGeometrySimulationInput {
/** bNode.identifier of the corresponding output node. */
int32_t output_node_id;
} NodeGeometrySimulationInput;
typedef struct NodeGeometrySimulationOutput {
NodeSimulationItem *items;
int items_num;
int active_index;
/** Number to give unique IDs to state items. */
int next_identifier;
int _pad;
#ifdef __cplusplus
blender::Span<NodeSimulationItem> items_span() const;
blender::MutableSpan<NodeSimulationItem> items_span();
blender::IndexRange items_range() const;
#endif
} NodeGeometrySimulationOutput;
} // namespace blender::dna

View File

@ -4255,7 +4255,7 @@ static void rna_NodeCryptomatte_update_remove(Main *bmain, Scene *scene, Pointer
static void rna_SimulationStateItem_update(Main *bmain, Scene * /*scene*/, PointerRNA *ptr)
{
bNodeTree *ntree = reinterpret_cast<bNodeTree *>(ptr->owner_id);
NodeSimulationItem *item = static_cast<NodeSimulationItem *>(ptr->data);
auto *item = static_cast<blender::dna::NodeSimulationItem *>(ptr->data);
bNode *node = NOD_geometry_simulation_output_find_node_by_item(ntree, item);
BKE_ntree_update_tag_node_property(ntree, node);
@ -4281,9 +4281,9 @@ static const EnumPropertyItem *rna_SimulationStateItem_socket_type_itemf(bContex
static void rna_SimulationStateItem_name_set(PointerRNA *ptr, const char *value)
{
bNodeTree *ntree = reinterpret_cast<bNodeTree *>(ptr->owner_id);
NodeSimulationItem *item = static_cast<NodeSimulationItem *>(ptr->data);
auto *item = static_cast<blender::dna::NodeSimulationItem *>(ptr->data);
bNode *node = NOD_geometry_simulation_output_find_node_by_item(ntree, item);
NodeGeometrySimulationOutput *sim = static_cast<NodeGeometrySimulationOutput *>(node->storage);
auto *sim = static_cast<blender::dna::NodeGeometrySimulationOutput *>(node->storage);
const char *defname = nodeStaticSocketLabel(item->socket_type, 0);
NOD_geometry_simulation_output_item_set_unique_name(sim, item, value, defname);
@ -4291,7 +4291,7 @@ static void rna_SimulationStateItem_name_set(PointerRNA *ptr, const char *value)
static void rna_SimulationStateItem_color_get(PointerRNA *ptr, float *values)
{
NodeSimulationItem *item = static_cast<NodeSimulationItem *>(ptr->data);
auto *item = static_cast<blender::dna::NodeSimulationItem *>(ptr->data);
const char *socket_type_idname = nodeStaticSocketType(item->socket_type, 0);
ED_node_type_draw_color(socket_type_idname, values);
@ -4328,11 +4328,11 @@ static bool rna_GeometryNodeSimulationInput_pair_with_output(
return true;
}
static NodeSimulationItem *rna_NodeGeometrySimulationOutput_items_new(
static blender::dna::NodeSimulationItem *rna_NodeGeometrySimulationOutput_items_new(
ID *id, bNode *node, Main *bmain, ReportList *reports, int socket_type, const char *name)
{
NodeGeometrySimulationOutput *sim = static_cast<NodeGeometrySimulationOutput *>(node->storage);
NodeSimulationItem *item = NOD_geometry_simulation_output_add_item(
auto *sim = static_cast<blender::dna::NodeGeometrySimulationOutput *>(node->storage);
blender::dna::NodeSimulationItem *item = NOD_geometry_simulation_output_add_item(
sim, (short)socket_type, name);
if (item == nullptr) {
@ -4349,9 +4349,9 @@ static NodeSimulationItem *rna_NodeGeometrySimulationOutput_items_new(
}
static void rna_NodeGeometrySimulationOutput_items_remove(
ID *id, bNode *node, Main *bmain, ReportList *reports, NodeSimulationItem *item)
ID *id, bNode *node, Main *bmain, ReportList *reports, blender::dna::NodeSimulationItem *item)
{
NodeGeometrySimulationOutput *sim = static_cast<NodeGeometrySimulationOutput *>(node->storage);
auto *sim = static_cast<blender::dna::NodeGeometrySimulationOutput *>(node->storage);
if (!NOD_geometry_simulation_output_contains_item(sim, item)) {
BKE_reportf(reports, RPT_ERROR, "Unable to locate item '%s' in node", item->name);
}
@ -4367,7 +4367,7 @@ static void rna_NodeGeometrySimulationOutput_items_remove(
static void rna_NodeGeometrySimulationOutput_items_clear(ID *id, bNode *node, Main *bmain)
{
NodeGeometrySimulationOutput *sim = static_cast<NodeGeometrySimulationOutput *>(node->storage);
auto *sim = static_cast<blender::dna::NodeGeometrySimulationOutput *>(node->storage);
NOD_geometry_simulation_output_clear_items(sim);
bNodeTree *ntree = reinterpret_cast<bNodeTree *>(id);
@ -4379,7 +4379,7 @@ static void rna_NodeGeometrySimulationOutput_items_clear(ID *id, bNode *node, Ma
static void rna_NodeGeometrySimulationOutput_items_move(
ID *id, bNode *node, Main *bmain, int from_index, int to_index)
{
NodeGeometrySimulationOutput *sim = static_cast<NodeGeometrySimulationOutput *>(node->storage);
auto *sim = static_cast<blender::dna::NodeGeometrySimulationOutput *>(node->storage);
if (from_index < 0 || from_index >= sim->items_num || to_index < 0 || to_index >= sim->items_num)
{
@ -4397,8 +4397,8 @@ static void rna_NodeGeometrySimulationOutput_items_move(
static PointerRNA rna_NodeGeometrySimulationOutput_active_item_get(PointerRNA *ptr)
{
bNode *node = static_cast<bNode *>(ptr->data);
NodeGeometrySimulationOutput *sim = static_cast<NodeGeometrySimulationOutput *>(node->storage);
NodeSimulationItem *item = NOD_geometry_simulation_output_get_active_item(sim);
auto *sim = static_cast<blender::dna::NodeGeometrySimulationOutput *>(node->storage);
blender::dna::NodeSimulationItem *item = NOD_geometry_simulation_output_get_active_item(sim);
PointerRNA r_ptr;
RNA_pointer_create(ptr->owner_id, &RNA_SimulationStateItem, item, &r_ptr);
return r_ptr;
@ -4409,9 +4409,9 @@ static void rna_NodeGeometrySimulationOutput_active_item_set(PointerRNA *ptr,
ReportList * /*reports*/)
{
bNode *node = static_cast<bNode *>(ptr->data);
NodeGeometrySimulationOutput *sim = static_cast<NodeGeometrySimulationOutput *>(node->storage);
NOD_geometry_simulation_output_set_active_item(sim,
static_cast<NodeSimulationItem *>(value.data));
auto *sim = static_cast<blender::dna::NodeGeometrySimulationOutput *>(node->storage);
NOD_geometry_simulation_output_set_active_item(
sim, static_cast<blender::dna::NodeSimulationItem *>(value.data));
}
/* ******** Node Socket Types ******** */

View File

@ -6,7 +6,7 @@
#include "BKE_node.h"
extern struct bNodeTreeType *ntreeType_Geometry;
extern bNodeTreeType *ntreeType_Geometry;
void register_node_type_geo_custom_group(bNodeType *ntype);
@ -14,16 +14,16 @@ void register_node_type_geo_custom_group(bNodeType *ntype);
/** \name Simulation Input Node
* \{ */
struct bNode *NOD_geometry_simulation_input_get_paired_output(
struct bNodeTree *node_tree, const struct bNode *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 struct bNodeTree *node_tree,
struct bNode *simulation_input_node,
const struct bNode *simulation_output_node);
bool NOD_geometry_simulation_input_pair_with_output(const bNodeTree *node_tree,
bNode *simulation_input_node,
const bNode *simulation_output_node);
/** \} */
@ -37,42 +37,46 @@ bool NOD_geometry_simulation_output_item_socket_type_supported(eNodeSocketDataty
* 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(struct NodeGeometrySimulationOutput *sim,
struct NodeSimulationItem *item,
const char *name,
const char *defname);
bool NOD_geometry_simulation_output_item_set_unique_name(
blender::dna::NodeGeometrySimulationOutput *sim,
blender::dna::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(struct bNodeTree *ntree,
const struct NodeSimulationItem *item);
bNode *NOD_geometry_simulation_output_find_node_by_item(
bNodeTree *ntree, const blender::dna::NodeSimulationItem *item);
bool NOD_geometry_simulation_output_contains_item(struct NodeGeometrySimulationOutput *sim,
const struct NodeSimulationItem *item);
struct NodeSimulationItem *NOD_geometry_simulation_output_get_active_item(
struct NodeGeometrySimulationOutput *sim);
void NOD_geometry_simulation_output_set_active_item(struct NodeGeometrySimulationOutput *sim,
struct NodeSimulationItem *item);
struct NodeSimulationItem *NOD_geometry_simulation_output_find_item(
struct NodeGeometrySimulationOutput *sim, const char *name);
struct NodeSimulationItem *NOD_geometry_simulation_output_add_item(
struct NodeGeometrySimulationOutput *sim, short socket_type, const char *name);
struct NodeSimulationItem *NOD_geometry_simulation_output_insert_item(
struct NodeGeometrySimulationOutput *sim, short socket_type, const char *name, int index);
struct NodeSimulationItem *NOD_geometry_simulation_output_add_item_from_socket(
struct NodeGeometrySimulationOutput *sim,
const struct bNode *from_node,
const struct bNodeSocket *from_sock);
struct NodeSimulationItem *NOD_geometry_simulation_output_insert_item_from_socket(
struct NodeGeometrySimulationOutput *sim,
const struct bNode *from_node,
const struct bNodeSocket *from_sock,
bool NOD_geometry_simulation_output_contains_item(blender::dna::NodeGeometrySimulationOutput *sim,
const blender::dna::NodeSimulationItem *item);
blender::dna::NodeSimulationItem *NOD_geometry_simulation_output_get_active_item(
blender::dna::NodeGeometrySimulationOutput *sim);
void NOD_geometry_simulation_output_set_active_item(
blender::dna::NodeGeometrySimulationOutput *sim, blender::dna::NodeSimulationItem *item);
blender::dna::NodeSimulationItem *NOD_geometry_simulation_output_find_item(
blender::dna::NodeGeometrySimulationOutput *sim, const char *name);
blender::dna::NodeSimulationItem *NOD_geometry_simulation_output_add_item(
blender::dna::NodeGeometrySimulationOutput *sim, short socket_type, const char *name);
blender::dna::NodeSimulationItem *NOD_geometry_simulation_output_insert_item(
blender::dna::NodeGeometrySimulationOutput *sim,
short socket_type,
const char *name,
int index);
void NOD_geometry_simulation_output_remove_item(struct NodeGeometrySimulationOutput *sim,
struct NodeSimulationItem *item);
void NOD_geometry_simulation_output_clear_items(struct NodeGeometrySimulationOutput *sim);
void NOD_geometry_simulation_output_move_item(struct NodeGeometrySimulationOutput *sim,
blender::dna::NodeSimulationItem *NOD_geometry_simulation_output_add_item_from_socket(
blender::dna::NodeGeometrySimulationOutput *sim,
const bNode *from_node,
const bNodeSocket *from_sock);
blender::dna::NodeSimulationItem *NOD_geometry_simulation_output_insert_item_from_socket(
blender::dna::NodeGeometrySimulationOutput *sim,
const bNode *from_node,
const bNodeSocket *from_sock,
int index);
void NOD_geometry_simulation_output_remove_item(blender::dna::NodeGeometrySimulationOutput *sim,
blender::dna::NodeSimulationItem *item);
void NOD_geometry_simulation_output_clear_items(blender::dna::NodeGeometrySimulationOutput *sim);
void NOD_geometry_simulation_output_move_item(blender::dna::NodeGeometrySimulationOutput *sim,
int from_index,
int to_index);

View File

@ -133,16 +133,16 @@ class EvaluateAtIndexInput final : public bke::GeometryFieldInput {
}
};
std::string socket_identifier_for_simulation_item(const NodeSimulationItem &item);
std::string socket_identifier_for_simulation_item(const dna::NodeSimulationItem &item);
void socket_declarations_for_simulation_items(Span<NodeSimulationItem> items,
void socket_declarations_for_simulation_items(Span<dna::NodeSimulationItem> items,
NodeDeclaration &r_declaration);
const CPPType &get_simulation_item_cpp_type(eNodeSocketDatatype socket_type);
const CPPType &get_simulation_item_cpp_type(const NodeSimulationItem &item);
void values_to_simulation_state(const Span<NodeSimulationItem> node_simulation_items,
const CPPType &get_simulation_item_cpp_type(const dna::NodeSimulationItem &item);
void values_to_simulation_state(const Span<dna::NodeSimulationItem> node_simulation_items,
const Span<void *> input_values,
bke::sim::SimulationZoneState &r_zone_state);
void simulation_state_to_values(const Span<NodeSimulationItem> node_simulation_items,
void simulation_state_to_values(const Span<dna::NodeSimulationItem> node_simulation_items,
const bke::sim::SimulationZoneState &zone_state,
const Object &self_object,
const ComputeContext &compute_context,

View File

@ -17,7 +17,10 @@
namespace blender::nodes::node_geo_simulation_input_cc {
NODE_STORAGE_FUNCS(NodeGeometrySimulationInput);
NODE_STORAGE_FUNCS(dna::NodeGeometrySimulationInput);
using dna::NodeGeometrySimulationInput;
using dna::NodeGeometrySimulationOutput;
using dna::NodeSimulationItem;
class LazyFunctionForSimulationInputNode final : public LazyFunction {
const bNode &node_;
@ -33,8 +36,7 @@ class LazyFunctionForSimulationInputNode final : public LazyFunction {
debug_name_ = "Simulation Input";
output_node_id_ = node_storage(node).output_node_id;
const bNode &output_node = *node_tree.node_by_id(output_node_id_);
const NodeGeometrySimulationOutput &storage = *static_cast<NodeGeometrySimulationOutput *>(
output_node.storage);
const auto &storage = *static_cast<NodeGeometrySimulationOutput *>(output_node.storage);
simulation_items_ = {storage.items, storage.items_num};
MutableSpan<int> lf_index_by_bsocket = own_lf_graph_info.mapping.lf_index_by_bsocket;
@ -143,14 +145,13 @@ static void node_declare_dynamic(const bNodeTree &node_tree,
delta_time->in_out = SOCK_OUT;
r_declaration.outputs.append(std::move(delta_time));
const NodeGeometrySimulationOutput &storage = *static_cast<const NodeGeometrySimulationOutput *>(
output_node->storage);
const auto &storage = *static_cast<const NodeGeometrySimulationOutput *>(output_node->storage);
socket_declarations_for_simulation_items({storage.items, storage.items_num}, r_declaration);
}
static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometrySimulationInput *data = MEM_cnew<NodeGeometrySimulationInput>(__func__);
auto *data = MEM_cnew<NodeGeometrySimulationInput>(__func__);
/* Needs to be initialized for the node to work. */
data->output_node_id = 0;
node->storage = data;
@ -163,8 +164,7 @@ static bool node_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *link)
return true;
}
NodeGeometrySimulationOutput &storage = *static_cast<NodeGeometrySimulationOutput *>(
output_node->storage);
auto &storage = *static_cast<NodeGeometrySimulationOutput *>(output_node->storage);
if (link->tonode == node) {
if (link->tosock->identifier == StringRef("__extend__")) {
@ -223,7 +223,8 @@ bNode *NOD_geometry_simulation_input_get_paired_output(bNodeTree *node_tree,
{
namespace file_ns = blender::nodes::node_geo_simulation_input_cc;
const NodeGeometrySimulationInput &data = file_ns::node_storage(*simulation_input_node);
const blender::dna::NodeGeometrySimulationInput &data = file_ns::node_storage(
*simulation_input_node);
return node_tree->node_by_id(data.output_node_id);
}
@ -241,14 +242,15 @@ bool NOD_geometry_simulation_input_pair_with_output(const bNodeTree *node_tree,
/* Allow only one input paired to an output. */
for (const bNode *other_input_node : node_tree->nodes_by_type("GeometryNodeSimulationInput")) {
if (other_input_node != sim_input_node) {
const NodeGeometrySimulationInput &other_storage = file_ns::node_storage(*other_input_node);
const blender::dna::NodeGeometrySimulationInput &other_storage = file_ns::node_storage(
*other_input_node);
if (other_storage.output_node_id == sim_output_node->identifier) {
return false;
}
}
}
NodeGeometrySimulationInput &storage = file_ns::node_storage(*sim_input_node);
blender::dna::NodeGeometrySimulationInput &storage = file_ns::node_storage(*sim_input_node);
storage.output_node_id = sim_output_node->identifier;
return true;
}

View File

@ -31,6 +31,10 @@
namespace blender::nodes {
using dna::NodeGeometrySimulationInput;
using dna::NodeGeometrySimulationOutput;
using dna::NodeSimulationItem;
std::string socket_identifier_for_simulation_item(const NodeSimulationItem &item)
{
return "Item_" + std::to_string(item.identifier);
@ -993,6 +997,8 @@ void register_node_type_geo_simulation_output()
nodeRegisterType(&ntype);
}
namespace blender::dna {
blender::Span<NodeSimulationItem> NodeGeometrySimulationOutput::items_span() const
{
return blender::Span<NodeSimulationItem>(items, items_num);
@ -1008,6 +1014,8 @@ blender::IndexRange NodeGeometrySimulationOutput::items_range() const
return blender::IndexRange(items_num);
}
} // namespace blender::dna
bool NOD_geometry_simulation_output_item_socket_type_supported(
const eNodeSocketDatatype socket_type)
{
@ -1022,12 +1030,12 @@ bool NOD_geometry_simulation_output_item_socket_type_supported(
SOCK_GEOMETRY);
}
bNode *NOD_geometry_simulation_output_find_node_by_item(bNodeTree *ntree,
const NodeSimulationItem *item)
bNode *NOD_geometry_simulation_output_find_node_by_item(
bNodeTree *ntree, const blender::dna::NodeSimulationItem *item)
{
ntree->ensure_topology_cache();
for (bNode *node : ntree->nodes_by_type("GeometryNodeSimulationOutput")) {
NodeGeometrySimulationOutput *sim = static_cast<NodeGeometrySimulationOutput *>(node->storage);
auto *sim = static_cast<blender::dna::NodeGeometrySimulationOutput *>(node->storage);
if (sim->items_span().contains_ptr(item)) {
return node;
}
@ -1035,10 +1043,11 @@ bNode *NOD_geometry_simulation_output_find_node_by_item(bNodeTree *ntree,
return nullptr;
}
bool NOD_geometry_simulation_output_item_set_unique_name(NodeGeometrySimulationOutput *sim,
NodeSimulationItem *item,
const char *name,
const char *defname)
bool NOD_geometry_simulation_output_item_set_unique_name(
blender::dna::NodeGeometrySimulationOutput *sim,
blender::dna::NodeSimulationItem *item,
const char *name,
const char *defname)
{
char unique_name[MAX_NAME + 4];
STRNCPY(unique_name, name);
@ -1055,14 +1064,14 @@ bool NOD_geometry_simulation_output_item_set_unique_name(NodeGeometrySimulationO
return name_changed;
}
bool NOD_geometry_simulation_output_contains_item(NodeGeometrySimulationOutput *sim,
const NodeSimulationItem *item)
bool NOD_geometry_simulation_output_contains_item(blender::dna::NodeGeometrySimulationOutput *sim,
const blender::dna::NodeSimulationItem *item)
{
return sim->items_span().contains_ptr(item);
}
NodeSimulationItem *NOD_geometry_simulation_output_get_active_item(
NodeGeometrySimulationOutput *sim)
blender::dna::NodeSimulationItem *NOD_geometry_simulation_output_get_active_item(
blender::dna::NodeGeometrySimulationOutput *sim)
{
if (!sim->items_range().contains(sim->active_index)) {
return nullptr;
@ -1070,18 +1079,18 @@ NodeSimulationItem *NOD_geometry_simulation_output_get_active_item(
return &sim->items[sim->active_index];
}
void NOD_geometry_simulation_output_set_active_item(NodeGeometrySimulationOutput *sim,
NodeSimulationItem *item)
void NOD_geometry_simulation_output_set_active_item(
blender::dna::NodeGeometrySimulationOutput *sim, blender::dna::NodeSimulationItem *item)
{
if (sim->items_span().contains_ptr(item)) {
sim->active_index = item - sim->items;
}
}
NodeSimulationItem *NOD_geometry_simulation_output_find_item(NodeGeometrySimulationOutput *sim,
const char *name)
blender::dna::NodeSimulationItem *NOD_geometry_simulation_output_find_item(
blender::dna::NodeGeometrySimulationOutput *sim, const char *name)
{
for (NodeSimulationItem &item : sim->items_span()) {
for (blender::dna::NodeSimulationItem &item : sim->items_span()) {
if (STREQ(item.name, name)) {
return &item;
}
@ -1089,25 +1098,25 @@ NodeSimulationItem *NOD_geometry_simulation_output_find_item(NodeGeometrySimulat
return nullptr;
}
NodeSimulationItem *NOD_geometry_simulation_output_add_item(NodeGeometrySimulationOutput *sim,
const short socket_type,
const char *name)
blender::dna::NodeSimulationItem *NOD_geometry_simulation_output_add_item(
blender::dna::NodeGeometrySimulationOutput *sim, const short socket_type, const char *name)
{
return NOD_geometry_simulation_output_insert_item(sim, socket_type, name, sim->items_num);
}
NodeSimulationItem *NOD_geometry_simulation_output_insert_item(NodeGeometrySimulationOutput *sim,
const short socket_type,
const char *name,
int index)
blender::dna::NodeSimulationItem *NOD_geometry_simulation_output_insert_item(
blender::dna::NodeGeometrySimulationOutput *sim,
const short socket_type,
const char *name,
int index)
{
if (!NOD_geometry_simulation_output_item_socket_type_supported(eNodeSocketDatatype(socket_type)))
{
return nullptr;
}
NodeSimulationItem *old_items = sim->items;
sim->items = MEM_cnew_array<NodeSimulationItem>(sim->items_num + 1, __func__);
blender::dna::NodeSimulationItem *old_items = sim->items;
sim->items = MEM_cnew_array<blender::dna::NodeSimulationItem>(sim->items_num + 1, __func__);
for (const int i : blender::IndexRange(index)) {
sim->items[i] = old_items[i];
}
@ -1116,7 +1125,7 @@ NodeSimulationItem *NOD_geometry_simulation_output_insert_item(NodeGeometrySimul
}
const char *defname = nodeStaticSocketLabel(socket_type, 0);
NodeSimulationItem &added_item = sim->items[index];
blender::dna::NodeSimulationItem &added_item = sim->items[index];
added_item.identifier = sim->next_identifier++;
NOD_geometry_simulation_output_item_set_unique_name(sim, &added_item, name, defname);
added_item.socket_type = socket_type;
@ -1127,15 +1136,17 @@ NodeSimulationItem *NOD_geometry_simulation_output_insert_item(NodeGeometrySimul
return &added_item;
}
NodeSimulationItem *NOD_geometry_simulation_output_add_item_from_socket(
NodeGeometrySimulationOutput *sim, const bNode * /*from_node*/, const bNodeSocket *from_sock)
blender::dna::NodeSimulationItem *NOD_geometry_simulation_output_add_item_from_socket(
blender::dna::NodeGeometrySimulationOutput *sim,
const bNode * /*from_node*/,
const bNodeSocket *from_sock)
{
return NOD_geometry_simulation_output_insert_item(
sim, from_sock->type, from_sock->name, sim->items_num);
}
NodeSimulationItem *NOD_geometry_simulation_output_insert_item_from_socket(
NodeGeometrySimulationOutput *sim,
blender::dna::NodeSimulationItem *NOD_geometry_simulation_output_insert_item_from_socket(
blender::dna::NodeGeometrySimulationOutput *sim,
const bNode * /*from_node*/,
const bNodeSocket *from_sock,
int index)
@ -1143,16 +1154,16 @@ NodeSimulationItem *NOD_geometry_simulation_output_insert_item_from_socket(
return NOD_geometry_simulation_output_insert_item(sim, from_sock->type, from_sock->name, index);
}
void NOD_geometry_simulation_output_remove_item(NodeGeometrySimulationOutput *sim,
NodeSimulationItem *item)
void NOD_geometry_simulation_output_remove_item(blender::dna::NodeGeometrySimulationOutput *sim,
blender::dna::NodeSimulationItem *item)
{
const int index = item - sim->items;
if (index < 0 || index >= sim->items_num) {
return;
}
NodeSimulationItem *old_items = sim->items;
sim->items = MEM_cnew_array<NodeSimulationItem>(sim->items_num - 1, __func__);
blender::dna::NodeSimulationItem *old_items = sim->items;
sim->items = MEM_cnew_array<blender::dna::NodeSimulationItem>(sim->items_num - 1, __func__);
for (const int i : blender::IndexRange(index)) {
sim->items[i] = old_items[i];
}
@ -1166,9 +1177,9 @@ void NOD_geometry_simulation_output_remove_item(NodeGeometrySimulationOutput *si
MEM_SAFE_FREE(old_items);
}
void NOD_geometry_simulation_output_clear_items(NodeGeometrySimulationOutput *sim)
void NOD_geometry_simulation_output_clear_items(blender::dna::NodeGeometrySimulationOutput *sim)
{
for (NodeSimulationItem &item : sim->items_span()) {
for (blender::dna::NodeSimulationItem &item : sim->items_span()) {
MEM_SAFE_FREE(item.name);
}
MEM_SAFE_FREE(sim->items);
@ -1176,7 +1187,7 @@ void NOD_geometry_simulation_output_clear_items(NodeGeometrySimulationOutput *si
sim->items_num = 0;
}
void NOD_geometry_simulation_output_move_item(NodeGeometrySimulationOutput *sim,
void NOD_geometry_simulation_output_move_item(blender::dna::NodeGeometrySimulationOutput *sim,
int from_index,
int to_index)
{
@ -1188,14 +1199,14 @@ void NOD_geometry_simulation_output_move_item(NodeGeometrySimulationOutput *sim,
}
if (from_index < to_index) {
const NodeSimulationItem tmp = sim->items[from_index];
const blender::dna::NodeSimulationItem tmp = sim->items[from_index];
for (int i = from_index; i < to_index; ++i) {
sim->items[i] = sim->items[i + 1];
}
sim->items[to_index] = tmp;
}
else /* from_index > to_index */ {
const NodeSimulationItem tmp = sim->items[from_index];
const blender::dna::NodeSimulationItem tmp = sim->items[from_index];
for (int i = from_index; i > to_index; --i) {
sim->items[i] = sim->items[i - 1];
}

View File

@ -2660,8 +2660,7 @@ struct GeometryNodesLazyFunctionGraphBuilder {
const bNode &bnode,
BuildGraphParams &graph_params)
{
const NodeGeometrySimulationInput *storage = static_cast<const NodeGeometrySimulationInput *>(
bnode.storage);
const auto *storage = static_cast<const dna::NodeGeometrySimulationInput *>(bnode.storage);
if (node_tree.node_by_id(storage->output_node_id) == nullptr) {
return nullptr;
}