[Bf-blender-cvs] [3c541ff26c4] functions: initial step simulator abstraction

Jacques Lucke noreply at git.blender.org
Mon Aug 26 15:37:26 CEST 2019


Commit: 3c541ff26c4082e30686f14b033253394b86f016
Author: Jacques Lucke
Date:   Mon Aug 26 10:27:20 2019 +0200
Branches: functions
https://developer.blender.org/rB3c541ff26c4082e30686f14b033253394b86f016

initial step simulator abstraction

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

M	source/blender/simulations/CMakeLists.txt
M	source/blender/simulations/bparticles/c_wrapper.cpp
M	source/blender/simulations/bparticles/node_frontend.cpp
M	source/blender/simulations/bparticles/node_frontend.hpp
A	source/blender/simulations/bparticles/step_simulator.hpp

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

diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
index 628f55a515f..fe4dd3e480d 100644
--- a/source/blender/simulations/CMakeLists.txt
+++ b/source/blender/simulations/CMakeLists.txt
@@ -39,6 +39,7 @@ set(SRC
   bparticles/step_description.cpp
   bparticles/step_description_interfaces.hpp
   bparticles/step_description_interfaces.cpp
+  bparticles/step_simulator.hpp
   bparticles/simulation_state.hpp
   bparticles/world_state.hpp
   bparticles/integrator.hpp
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 10fd4dfb69e..3020aff5264 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -63,19 +63,11 @@ void BParticles_simulate_modifier(BParticlesModifierData *bpmd,
   SimulationState &simulation_state = *unwrap(state_c);
 
   bNodeTree *btree = (bNodeTree *)DEG_get_original_id((ID *)bpmd->bparticles_tree);
+  auto simulator = simulator_from_node_tree(btree);
 
-  VirtualNodeTree vtree;
-  vtree.add_all_of_tree(btree);
-  vtree.freeze_and_index();
+  simulator->simulate(simulation_state, time_step);
 
-  auto step_description = step_description_from_node_tree(
-      vtree, simulation_state.world(), time_step);
-
-  ParticlesState &particles_state = simulation_state.particles();
-  simulate_step(particles_state, *step_description);
-  simulation_state.world().current_step_is_over();
-
-  auto &containers = particles_state.particle_containers();
+  auto &containers = simulation_state.particles().particle_containers();
   containers.foreach_key_value_pair([](StringRefNull type_name, ParticlesContainer *container) {
     std::cout << "Particle Type: " << type_name << "\n";
     std::cout << "  Particles: " << container->count_active() << "\n";
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index c5e9bb8b34e..0c0b0ccc115 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -10,6 +10,7 @@
 #include "emitters.hpp"
 #include "events.hpp"
 #include "offset_handlers.hpp"
+#include "simulate.hpp"
 
 namespace BParticles {
 
@@ -434,9 +435,9 @@ BLI_LAZY_INIT_STATIC(StringMap<ParseNodeCallback>, get_node_parsers)
   return map;
 }
 
-std::unique_ptr<StepDescription> step_description_from_node_tree(VirtualNodeTree &vtree,
-                                                                 WorldState &world_state,
-                                                                 float time_step)
+static std::unique_ptr<StepDescription> step_description_from_node_tree(VirtualNodeTree &vtree,
+                                                                        WorldState &world_state,
+                                                                        float time_step)
 {
   SCOPED_TIMER(__func__);
 
@@ -488,4 +489,33 @@ std::unique_ptr<StepDescription> step_description_from_node_tree(VirtualNodeTree
   return std::unique_ptr<StepDescription>(step_description);
 }
 
+class NodeTreeStepSimulator : public StepSimulator {
+ private:
+  bNodeTree *m_btree;
+
+ public:
+  NodeTreeStepSimulator(bNodeTree *btree) : m_btree(btree)
+  {
+  }
+
+  void simulate(SimulationState &simulation_state, float time_step) const override
+  {
+    VirtualNodeTree vtree;
+    vtree.add_all_of_tree(m_btree);
+    vtree.freeze_and_index();
+
+    auto step_description = step_description_from_node_tree(
+        vtree, simulation_state.world(), time_step);
+
+    ParticlesState &particles_state = simulation_state.particles();
+    simulate_step(particles_state, *step_description);
+    simulation_state.world().current_step_is_over();
+  }
+};
+
+std::unique_ptr<StepSimulator> simulator_from_node_tree(bNodeTree *btree)
+{
+  return std::unique_ptr<StepSimulator>(new NodeTreeStepSimulator(btree));
+}
+
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/node_frontend.hpp b/source/blender/simulations/bparticles/node_frontend.hpp
index 33e53188526..7d12c3c21dc 100644
--- a/source/blender/simulations/bparticles/node_frontend.hpp
+++ b/source/blender/simulations/bparticles/node_frontend.hpp
@@ -4,13 +4,12 @@
 
 #include "world_state.hpp"
 #include "step_description.hpp"
+#include "step_simulator.hpp"
 
 namespace BParticles {
 
 using BKE::VirtualNodeTree;
 
-std::unique_ptr<StepDescription> step_description_from_node_tree(VirtualNodeTree &vtree,
-                                                                 WorldState &world_state,
-                                                                 float time_step);
+std::unique_ptr<StepSimulator> simulator_from_node_tree(bNodeTree *btree);
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/step_simulator.hpp b/source/blender/simulations/bparticles/step_simulator.hpp
new file mode 100644
index 00000000000..485ca8beaf3
--- /dev/null
+++ b/source/blender/simulations/bparticles/step_simulator.hpp
@@ -0,0 +1,12 @@
+#pragma once
+
+#include "simulation_state.hpp"
+
+namespace BParticles {
+
+class StepSimulator {
+ public:
+  virtual void simulate(SimulationState &simulation_state, float time_step) const = 0;
+};
+
+}  // namespace BParticles



More information about the Bf-blender-cvs mailing list