From fe49e4139cd3f78f126b60ea4240a0294eac9483 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Sat, 18 Jul 2020 10:51:38 +0200 Subject: Simulation: cleanup deduplicating attribute input nodes --- .../intern/simulation_collect_influences.cc | 55 ++++++++++++++-------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'source/blender/simulation/intern/simulation_collect_influences.cc') diff --git a/source/blender/simulation/intern/simulation_collect_influences.cc b/source/blender/simulation/intern/simulation_collect_influences.cc index 84188096081..3e35b040dbe 100644 --- a/source/blender/simulation/intern/simulation_collect_influences.cc +++ b/source/blender/simulation/intern/simulation_collect_influences.cc @@ -43,44 +43,61 @@ static std::string dnode_to_path(const nodes::DNode &dnode) return path; } -static Map find_and_deduplicate_particle_attribute_nodes( - nodes::MFNetworkTreeMap &network_map, DummyDataSources &r_data_sources) +static std::optional> compute_global_string_inputs( + nodes::MFNetworkTreeMap &network_map, Span sockets) { - fn::MFNetwork &network = network_map.network(); - const nodes::DerivedNodeTree &tree = network_map.tree(); - - Span attribute_dnodes = tree.nodes_by_type( - "SimulationNodeParticleAttribute"); - uint amount = attribute_dnodes.size(); + uint amount = sockets.size(); if (amount == 0) { - return {}; + return Array(); } - Vector name_sockets; - for (const nodes::DNode *dnode : attribute_dnodes) { - fn::MFInputSocket &name_socket = network_map.lookup_dummy(dnode->input(0)); - name_sockets.append(&name_socket); + if (network_map.network().have_dummy_or_unlinked_dependencies(sockets)) { + return {}; } - fn::MFNetworkEvaluator network_fn{{}, name_sockets.as_span()}; + fn::MFNetworkEvaluator network_fn{{}, sockets}; fn::MFParamsBuilder params{network_fn, 1}; - Array attribute_names{amount, NoInitialization()}; + Array strings(amount, NoInitialization()); for (uint i : IndexRange(amount)) { params.add_uninitialized_single_output( - fn::GMutableSpan(fn::CPPType::get(), attribute_names.data() + i, 1)); + fn::GMutableSpan(fn::CPPType::get(), strings.data() + i, 1)); } fn::MFContextBuilder context; - /* Todo: Check that the names don't depend on dummy nodes. */ network_fn.call({0}, params, context); + return strings; +} + +static void find_and_deduplicate_particle_attribute_nodes(nodes::MFNetworkTreeMap &network_map, + DummyDataSources &r_data_sources) +{ + fn::MFNetwork &network = network_map.network(); + const nodes::DerivedNodeTree &tree = network_map.tree(); + + Span attribute_dnodes = tree.nodes_by_type( + "SimulationNodeParticleAttribute"); + + Vector name_sockets; + for (const nodes::DNode *dnode : attribute_dnodes) { + fn::MFInputSocket &name_socket = network_map.lookup_dummy(dnode->input(0)); + name_sockets.append(&name_socket); + } + + std::optional> attribute_names = compute_global_string_inputs(network_map, + name_sockets); + if (!attribute_names.has_value()) { + return; + } + Map, Vector> attribute_nodes_by_name_and_type; - for (uint i : IndexRange(amount)) { + for (uint i : attribute_names->index_range()) { attribute_nodes_by_name_and_type - .lookup_or_add_default({attribute_names[i], name_sockets[i]->node().output(0).data_type()}) + .lookup_or_add_default( + {(*attribute_names)[i], name_sockets[i]->node().output(0).data_type()}) .append(&name_sockets[i]->node()); } -- cgit v1.2.3