[Bf-blender-cvs] [fd67b521b9f] master: Simulation: deduplicate code that finds particle simulation names

Jacques Lucke noreply at git.blender.org
Sat Jul 18 12:10:24 CEST 2020


Commit: fd67b521b9fa7ac61dfa41a90db1018c47992d89
Author: Jacques Lucke
Date:   Sat Jul 18 10:08:53 2020 +0200
Branches: master
https://developer.blender.org/rBfd67b521b9fa7ac61dfa41a90db1018c47992d89

Simulation: deduplicate code that finds particle simulation names

===================================================================

M	source/blender/simulation/intern/simulation_collect_influences.cc
M	source/blender/simulation/intern/simulation_collect_influences.hh
M	source/blender/simulation/intern/simulation_update.cc

===================================================================

diff --git a/source/blender/simulation/intern/simulation_collect_influences.cc b/source/blender/simulation/intern/simulation_collect_influences.cc
index 3feb0ccce5b..3231808df12 100644
--- a/source/blender/simulation/intern/simulation_collect_influences.cc
+++ b/source/blender/simulation/intern/simulation_collect_influences.cc
@@ -29,6 +29,16 @@ extern "C" {
 void WM_clipboard_text_set(const char *buf, bool selection);
 }
 
+static std::string dnode_to_path(const nodes::DNode &dnode)
+{
+  std::string path;
+  for (const nodes::DParentNode *parent = dnode.parent(); parent; parent = parent->parent()) {
+    path = parent->node_ref().name() + "/" + path;
+  }
+  path = path + dnode.name();
+  return path;
+}
+
 static Map<const fn::MFOutputSocket *, std::string> deduplicate_attribute_nodes(
     fn::MFNetwork &network,
     nodes::MFNetworkTreeMap &network_map,
@@ -217,10 +227,14 @@ static void collect_forces(nodes::MFNetworkTreeMap &network_map,
   }
 }
 
-void collect_simulation_influences(const nodes::DerivedNodeTree &tree,
+void collect_simulation_influences(Simulation &simulation,
                                    ResourceCollector &resources,
-                                   SimulationInfluences &r_influences)
+                                   SimulationInfluences &r_influences,
+                                   SimulationStatesInfo &r_states_info)
 {
+  nodes::NodeTreeRefMap tree_refs;
+  const nodes::DerivedNodeTree tree{simulation.nodetree, tree_refs};
+
   fn::MFNetwork &network = resources.construct<fn::MFNetwork>(AT);
   nodes::MFNetworkTreeMap network_map = insert_node_tree_into_mf_network(network, tree, resources);
   Map<const fn::MFOutputSocket *, std::string> attribute_inputs = deduplicate_attribute_nodes(
@@ -231,6 +245,10 @@ void collect_simulation_influences(const nodes::DerivedNodeTree &tree,
   // WM_clipboard_text_set(network.to_dot().c_str(), false);
 
   collect_forces(network_map, resources, attribute_inputs, r_influences);
+
+  for (const nodes::DNode *dnode : tree.nodes_by_type("SimulationNodeParticleSimulation")) {
+    r_states_info.particle_simulation_names.add(dnode_to_path(*dnode));
+  }
 }
 
 }  // namespace blender::sim
diff --git a/source/blender/simulation/intern/simulation_collect_influences.hh b/source/blender/simulation/intern/simulation_collect_influences.hh
index a02a6320419..cca396ffa66 100644
--- a/source/blender/simulation/intern/simulation_collect_influences.hh
+++ b/source/blender/simulation/intern/simulation_collect_influences.hh
@@ -25,20 +25,14 @@
 
 namespace blender::sim {
 
-void collect_simulation_influences(const nodes::DerivedNodeTree &tree,
+struct SimulationStatesInfo {
+  VectorSet<std::string> particle_simulation_names;
+};
+
+void collect_simulation_influences(Simulation &simulation,
                                    ResourceCollector &resources,
-                                   SimulationInfluences &r_influences);
-
-/* TODO: Move this to a better place. */
-inline std::string dnode_to_path(const nodes::DNode &dnode)
-{
-  std::string path;
-  for (const nodes::DParentNode *parent = dnode.parent(); parent; parent = parent->parent()) {
-    path = parent->node_ref().name() + "/" + path;
-  }
-  path = path + dnode.name();
-  return path;
-}
+                                   SimulationInfluences &r_influences,
+                                   SimulationStatesInfo &r_states_info);
 
 }  // namespace blender::sim
 
diff --git a/source/blender/simulation/intern/simulation_update.cc b/source/blender/simulation/intern/simulation_update.cc
index a3fddbbe18f..d8b7e1df19a 100644
--- a/source/blender/simulation/intern/simulation_update.cc
+++ b/source/blender/simulation/intern/simulation_update.cc
@@ -107,28 +107,18 @@ static void add_missing_particle_states(Simulation *simulation, Span<std::string
 }
 
 static void reinitialize_empty_simulation_states(Simulation *simulation,
-                                                 const nodes::DerivedNodeTree &tree)
+                                                 const SimulationStatesInfo &states_info)
 {
-  VectorSet<std::string> state_names;
-  for (const nodes::DNode *dnode : tree.nodes_by_type("SimulationNodeParticleSimulation")) {
-    state_names.add(dnode_to_path(*dnode));
-  }
-
-  remove_unused_states(simulation, state_names);
+  remove_unused_states(simulation, states_info.particle_simulation_names);
   reset_states(simulation);
-  add_missing_particle_states(simulation, state_names);
+  add_missing_particle_states(simulation, states_info.particle_simulation_names);
 }
 
 static void update_simulation_state_list(Simulation *simulation,
-                                         const nodes::DerivedNodeTree &tree)
+                                         const SimulationStatesInfo &states_info)
 {
-  VectorSet<std::string> state_names;
-  for (const nodes::DNode *dnode : tree.nodes_by_type("SimulationNodeParticleSimulation")) {
-    state_names.add(dnode_to_path(*dnode));
-  }
-
-  remove_unused_states(simulation, state_names);
-  add_missing_particle_states(simulation, state_names);
+  remove_unused_states(simulation, states_info.particle_simulation_names);
+  add_missing_particle_states(simulation, states_info.particle_simulation_names);
 }
 
 void update_simulation_in_depsgraph(Depsgraph *depsgraph,
@@ -147,16 +137,15 @@ void update_simulation_in_depsgraph(Depsgraph *depsgraph,
 
   Simulation *simulation_orig = (Simulation *)DEG_get_original_id(&simulation_cow->id);
 
-  nodes::NodeTreeRefMap tree_refs;
-  /* TODO: Use simulation_cow, but need to add depsgraph relations before that. */
-  const nodes::DerivedNodeTree tree{simulation_orig->nodetree, tree_refs};
-
   ResourceCollector resources;
   SimulationInfluences influences;
-  collect_simulation_influences(tree, resources, influences);
+  SimulationStatesInfo states_info;
+
+  /* TODO: Use simulation_cow, but need to add depsgraph relations before that. */
+  collect_simulation_influences(*simulation_orig, resources, influences, states_info);
 
   if (current_frame == 1) {
-    reinitialize_empty_simulation_states(simulation_orig, tree);
+    reinitialize_empty_simulation_states(simulation_orig, states_info);
 
     initialize_simulation_states(*simulation_orig, *depsgraph, influences);
     simulation_orig->current_frame = 1;
@@ -164,7 +153,7 @@ void update_simulation_in_depsgraph(Depsgraph *depsgraph,
     copy_states_to_cow(simulation_orig, simulation_cow);
   }
   else if (current_frame == simulation_orig->current_frame + 1) {
-    update_simulation_state_list(simulation_orig, tree);
+    update_simulation_state_list(simulation_orig, states_info);
 
     float time_step = 1.0f / 24.0f;
     solve_simulation_time_step(*simulation_orig, *depsgraph, influences, time_step);



More information about the Bf-blender-cvs mailing list