From 14326619a1a94af677c2d1d626b57d7ff2afbd21 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Sat, 25 Jul 2020 20:39:21 +0200 Subject: Cleanup: avoid using namespace name in many cases --- .../intern/simulation_collect_influences.cc | 168 +++++++++++---------- 1 file changed, 91 insertions(+), 77 deletions(-) (limited to 'source/blender') diff --git a/source/blender/simulation/intern/simulation_collect_influences.cc b/source/blender/simulation/intern/simulation_collect_influences.cc index 0fcaf78fe5b..539a9d689d5 100644 --- a/source/blender/simulation/intern/simulation_collect_influences.cc +++ b/source/blender/simulation/intern/simulation_collect_influences.cc @@ -31,34 +31,54 @@ namespace blender::sim { +using fn::GVSpan; +using fn::MFContextBuilder; +using fn::MFDataType; +using fn::MFInputSocket; +using fn::MFNetwork; +using fn::MFNetworkEvaluator; +using fn::MFNode; +using fn::MFOutputSocket; +using fn::MFParamsBuilder; +using fn::MFParamType; +using fn::MultiFunction; +using fn::VSpan; +using nodes::DerivedNodeTree; +using nodes::DInputSocket; +using nodes::DNode; +using nodes::DOutputSocket; +using nodes::DParentNode; +using nodes::MFNetworkTreeMap; +using nodes::NodeTreeRefMap; + struct DummyDataSources { - Map particle_attributes; + Map particle_attributes; }; extern "C" { void WM_clipboard_text_set(const char *buf, bool selection); } -static std::string dnode_to_path(const nodes::DNode &dnode) +static std::string dnode_to_path(const DNode &dnode) { std::string path; - for (const nodes::DParentNode *parent = dnode.parent(); parent; parent = parent->parent()) { + for (const DParentNode *parent = dnode.parent(); parent; parent = parent->parent()) { path = parent->node_ref().name() + "/" + path; } path = path + dnode.name(); return path; } -static Span get_particle_simulation_nodes(const nodes::DerivedNodeTree &tree) +static Span get_particle_simulation_nodes(const DerivedNodeTree &tree) { return tree.nodes_by_type("SimulationNodeParticleSimulation"); } /* Returns true on success. */ -static bool compute_global_inputs(nodes::MFNetworkTreeMap &network_map, +static bool compute_global_inputs(MFNetworkTreeMap &network_map, ResourceCollector &resources, - Span sockets, - MutableSpan r_results) + Span sockets, + MutableSpan r_results) { int amount = sockets.size(); if (amount == 0) { @@ -69,28 +89,28 @@ static bool compute_global_inputs(nodes::MFNetworkTreeMap &network_map, return false; } - fn::MFNetworkEvaluator network_fn{{}, sockets}; - fn::MFParamsBuilder params{network_fn, 1}; + MFNetworkEvaluator network_fn{{}, sockets}; + MFParamsBuilder params{network_fn, 1}; for (int param_index : network_fn.param_indices()) { - fn::MFParamType param_type = network_fn.param_type(param_index); - BLI_assert(param_type.category() == fn::MFParamType::Category::SingleOutput); /* For now. */ - const fn::CPPType &type = param_type.data_type().single_type(); + MFParamType param_type = network_fn.param_type(param_index); + BLI_assert(param_type.category() == MFParamType::Category::SingleOutput); /* For now. */ + const CPPType &type = param_type.data_type().single_type(); void *buffer = resources.linear_allocator().allocate(type.size(), type.alignment()); resources.add(buffer, type.destruct_cb(), AT); - fn::GMutableSpan span{type, buffer, 1}; + GMutableSpan span{type, buffer, 1}; r_results[param_index] = span; params.add_uninitialized_single_output(span); } - fn::MFContextBuilder context; + MFContextBuilder context; network_fn.call(IndexRange(1), params, context); return true; } static std::optional> compute_global_string_inputs( - nodes::MFNetworkTreeMap &network_map, Span sockets) + MFNetworkTreeMap &network_map, Span sockets) { ResourceCollector local_resources; - Array computed_values(sockets.size(), NoInitialization()); + Array computed_values(sockets.size(), NoInitialization()); if (!compute_global_inputs(network_map, local_resources, sockets, computed_values)) { return {}; } @@ -102,18 +122,17 @@ static std::optional> compute_global_string_inputs( return strings; } -static void find_and_deduplicate_particle_attribute_nodes(nodes::MFNetworkTreeMap &network_map, +static void find_and_deduplicate_particle_attribute_nodes(MFNetworkTreeMap &network_map, DummyDataSources &r_data_sources) { - fn::MFNetwork &network = network_map.network(); - const nodes::DerivedNodeTree &tree = network_map.tree(); + MFNetwork &network = network_map.network(); + const DerivedNodeTree &tree = network_map.tree(); - Span attribute_dnodes = tree.nodes_by_type( - "SimulationNodeParticleAttribute"); + 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)); + Vector name_sockets; + for (const DNode *dnode : attribute_dnodes) { + MFInputSocket &name_socket = network_map.lookup_dummy(dnode->input(0)); name_sockets.append(&name_socket); } @@ -123,23 +142,22 @@ static void find_and_deduplicate_particle_attribute_nodes(nodes::MFNetworkTreeMa return; } - MultiValueMap, fn::MFNode *> - attribute_nodes_by_name_and_type; + MultiValueMap, MFNode *> attribute_nodes_by_name_and_type; for (int i : attribute_names->index_range()) { attribute_nodes_by_name_and_type.add( {(*attribute_names)[i], name_sockets[i]->node().output(0).data_type()}, &name_sockets[i]->node()); } - Map attribute_inputs; + Map attribute_inputs; for (auto item : attribute_nodes_by_name_and_type.items()) { StringRef attribute_name = item.key.first; - fn::MFDataType data_type = item.key.second; - Span nodes = item.value; + MFDataType data_type = item.key.second; + Span nodes = item.value; - fn::MFOutputSocket &new_attribute_socket = network.add_input( - "Attribute '" + attribute_name + "'", data_type); - for (fn::MFNode *node : nodes) { + MFOutputSocket &new_attribute_socket = network.add_input("Attribute '" + attribute_name + "'", + data_type); + for (MFNode *node : nodes) { network.relink(node->output(0), new_attribute_socket); } network.remove(nodes); @@ -151,43 +169,43 @@ static void find_and_deduplicate_particle_attribute_nodes(nodes::MFNetworkTreeMa class ParticleAttributeInput : public ParticleFunctionInput { private: std::string attribute_name_; - const fn::CPPType &attribute_type_; + const CPPType &attribute_type_; public: - ParticleAttributeInput(std::string attribute_name, const fn::CPPType &attribute_type) + ParticleAttributeInput(std::string attribute_name, const CPPType &attribute_type) : attribute_name_(std::move(attribute_name)), attribute_type_(attribute_type) { } - void add_input(fn::AttributesRef attributes, - fn::MFParamsBuilder ¶ms, + void add_input(AttributesRef attributes, + MFParamsBuilder ¶ms, ResourceCollector &UNUSED(resources)) const override { - std::optional span = attributes.try_get(attribute_name_, attribute_type_); + std::optional span = attributes.try_get(attribute_name_, attribute_type_); if (span.has_value()) { params.add_readonly_single_input(*span); } else { - params.add_readonly_single_input(fn::GVSpan::FromDefault(attribute_type_)); + params.add_readonly_single_input(GVSpan::FromDefault(attribute_type_)); } } }; static const ParticleFunction *create_particle_function_for_inputs( - Span sockets_to_compute, + Span sockets_to_compute, ResourceCollector &resources, DummyDataSources &data_sources) { BLI_assert(sockets_to_compute.size() >= 1); - const fn::MFNetwork &network = sockets_to_compute[0]->node().network(); + const MFNetwork &network = sockets_to_compute[0]->node().network(); - VectorSet dummy_deps; - VectorSet unlinked_input_deps; + VectorSet dummy_deps; + VectorSet unlinked_input_deps; network.find_dependencies(sockets_to_compute, dummy_deps, unlinked_input_deps); BLI_assert(unlinked_input_deps.size() == 0); Vector per_particle_inputs; - for (const fn::MFOutputSocket *socket : dummy_deps) { + for (const MFOutputSocket *socket : dummy_deps) { const std::string *attribute_name = data_sources.particle_attributes.lookup_ptr(socket); if (attribute_name == nullptr) { return nullptr; @@ -196,7 +214,7 @@ static const ParticleFunction *create_particle_function_for_inputs( AT, *attribute_name, socket->data_type().single_type())); } - const fn::MultiFunction &per_particle_fn = resources.construct( + const MultiFunction &per_particle_fn = resources.construct( AT, dummy_deps.as_span(), sockets_to_compute); Array output_is_global(sockets_to_compute.size(), false); @@ -229,7 +247,7 @@ class ParticleFunctionForce : public ParticleForce { ParticleFunctionEvaluator evaluator{ particle_fn_, context.solve_context, context.particle_chunk_context}; evaluator.compute(); - fn::VSpan forces = evaluator.get(0, "Force"); + VSpan forces = evaluator.get(0, "Force"); for (int64_t i : mask) { r_combined_force[i] += forces[i]; @@ -237,22 +255,20 @@ class ParticleFunctionForce : public ParticleForce { } }; -static void create_forces_for_particle_simulation(const nodes::DNode &simulation_node, - nodes::MFNetworkTreeMap &network_map, +static void create_forces_for_particle_simulation(const DNode &simulation_node, + MFNetworkTreeMap &network_map, ResourceCollector &resources, DummyDataSources &data_sources, SimulationInfluences &r_influences) { Vector forces; - for (const nodes::DOutputSocket *origin_socket : - simulation_node.input(2, "Forces").linked_sockets()) { - const nodes::DNode &origin_node = origin_socket->node(); + for (const DOutputSocket *origin_socket : simulation_node.input(2, "Forces").linked_sockets()) { + const DNode &origin_node = origin_socket->node(); if (origin_node.idname() != "SimulationNodeForce") { continue; } - const fn::MFInputSocket &force_socket = network_map.lookup_dummy( - origin_node.input(0, "Force")); + const MFInputSocket &force_socket = network_map.lookup_dummy(origin_node.input(0, "Force")); const ParticleFunction *particle_fn = create_particle_function_for_inputs( {&force_socket}, resources, data_sources); @@ -269,22 +285,21 @@ static void create_forces_for_particle_simulation(const nodes::DNode &simulation r_influences.particle_forces.add_multiple(std::move(particle_name), forces); } -static void collect_forces(nodes::MFNetworkTreeMap &network_map, +static void collect_forces(MFNetworkTreeMap &network_map, ResourceCollector &resources, DummyDataSources &data_sources, SimulationInfluences &r_influences) { - for (const nodes::DNode *dnode : get_particle_simulation_nodes(network_map.tree())) { + for (const DNode *dnode : get_particle_simulation_nodes(network_map.tree())) { create_forces_for_particle_simulation( *dnode, network_map, resources, data_sources, r_influences); } } -static Vector find_linked_particle_simulations( - const nodes::DOutputSocket &output_socket) +static Vector find_linked_particle_simulations(const DOutputSocket &output_socket) { - Vector simulation_nodes; - for (const nodes::DInputSocket *target_socket : output_socket.linked_sockets()) { + Vector simulation_nodes; + for (const DInputSocket *target_socket : output_socket.linked_sockets()) { if (target_socket->node().idname() == "SimulationNodeParticleSimulation") { simulation_nodes.append(&target_socket->node()); } @@ -292,13 +307,12 @@ static Vector find_linked_particle_simulations( return simulation_nodes; } -static ParticleEmitter *create_particle_emitter(const nodes::DNode &dnode, +static ParticleEmitter *create_particle_emitter(const DNode &dnode, ResourceCollector &resources, - nodes::MFNetworkTreeMap &network_map, + MFNetworkTreeMap &network_map, RequiredStates &r_required_states) { - Vector simulation_dnodes = find_linked_particle_simulations( - dnode.output(0)); + Vector simulation_dnodes = find_linked_particle_simulations(dnode.output(0)); if (simulation_dnodes.size() == 0) { return nullptr; } @@ -308,7 +322,7 @@ static ParticleEmitter *create_particle_emitter(const nodes::DNode &dnode, names[i] = dnode_to_path(*simulation_dnodes[i]); } - Array input_sockets{dnode.inputs().size()}; + Array input_sockets{dnode.inputs().size()}; for (int i : input_sockets.index_range()) { input_sockets[i] = &network_map.lookup_dummy(dnode.input(i)); } @@ -317,8 +331,8 @@ static ParticleEmitter *create_particle_emitter(const nodes::DNode &dnode, return nullptr; } - fn::MultiFunction &inputs_fn = resources.construct( - AT, Span(), input_sockets.as_span()); + MultiFunction &inputs_fn = resources.construct( + AT, Span(), input_sockets.as_span()); std::string own_state_name = dnode_to_path(dnode); r_required_states.add(own_state_name, SIM_TYPE_NAME_PARTICLE_MESH_EMITTER); @@ -327,12 +341,12 @@ static ParticleEmitter *create_particle_emitter(const nodes::DNode &dnode, return &emitter; } -static void collect_emitters(nodes::MFNetworkTreeMap &network_map, +static void collect_emitters(MFNetworkTreeMap &network_map, ResourceCollector &resources, SimulationInfluences &r_influences, RequiredStates &r_required_states) { - for (const nodes::DNode *dnode : + for (const DNode *dnode : network_map.tree().nodes_by_type("SimulationNodeParticleMeshEmitter")) { ParticleEmitter *emitter = create_particle_emitter( *dnode, resources, network_map, r_required_states); @@ -360,24 +374,24 @@ class RandomizeVelocityAction : public ParticleAction { } }; -static void collect_birth_events(nodes::MFNetworkTreeMap &network_map, +static void collect_birth_events(MFNetworkTreeMap &network_map, ResourceCollector &resources, SimulationInfluences &r_influences) { RandomizeVelocityAction &action = resources.construct(AT); - for (const nodes::DNode *dnode : get_particle_simulation_nodes(network_map.tree())) { + for (const DNode *dnode : get_particle_simulation_nodes(network_map.tree())) { std::string particle_name = dnode_to_path(*dnode); r_influences.particle_birth_actions.add_as(std::move(particle_name), &action); } } -static void prepare_particle_attribute_builders(nodes::MFNetworkTreeMap &network_map, +static void prepare_particle_attribute_builders(MFNetworkTreeMap &network_map, ResourceCollector &resources, SimulationInfluences &r_influences) { - for (const nodes::DNode *dnode : get_particle_simulation_nodes(network_map.tree())) { + for (const DNode *dnode : get_particle_simulation_nodes(network_map.tree())) { std::string name = dnode_to_path(*dnode); - fn::AttributesInfoBuilder &builder = resources.construct(AT); + AttributesInfoBuilder &builder = resources.construct(AT); builder.add("Position", {0, 0, 0}); builder.add("Velocity", {0, 0, 0}); builder.add("ID", 0); @@ -395,11 +409,11 @@ void collect_simulation_influences(Simulation &simulation, SimulationInfluences &r_influences, RequiredStates &r_required_states) { - nodes::NodeTreeRefMap tree_refs; - const nodes::DerivedNodeTree tree{simulation.nodetree, tree_refs}; + NodeTreeRefMap tree_refs; + const DerivedNodeTree tree{simulation.nodetree, tree_refs}; - fn::MFNetwork &network = resources.construct(AT); - nodes::MFNetworkTreeMap network_map = insert_node_tree_into_mf_network(network, tree, resources); + MFNetwork &network = resources.construct(AT); + MFNetworkTreeMap network_map = insert_node_tree_into_mf_network(network, tree, resources); prepare_particle_attribute_builders(network_map, resources, r_influences); @@ -415,7 +429,7 @@ void collect_simulation_influences(Simulation &simulation, collect_emitters(network_map, resources, r_influences, r_required_states); collect_birth_events(network_map, resources, r_influences); - for (const nodes::DNode *dnode : get_particle_simulation_nodes(tree)) { + for (const DNode *dnode : get_particle_simulation_nodes(tree)) { r_required_states.add(dnode_to_path(*dnode), SIM_TYPE_NAME_PARTICLE_SIMULATION); } } -- cgit v1.2.3