[Bf-blender-cvs] [9a965af5291] functions: move offset handlers to separate file

Jacques Lucke noreply at git.blender.org
Thu Jul 18 18:20:01 CEST 2019


Commit: 9a965af52918ef3a19baa1bc282b9243222e651f
Author: Jacques Lucke
Date:   Thu Jul 18 17:34:40 2019 +0200
Branches: functions
https://developer.blender.org/rB9a965af52918ef3a19baa1bc282b9243222e651f

move offset handlers to separate file

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

M	source/blender/simulations/CMakeLists.txt
M	source/blender/simulations/bparticles/forces.cpp
M	source/blender/simulations/bparticles/forces.hpp
M	source/blender/simulations/bparticles/inserters.cpp
A	source/blender/simulations/bparticles/offset_handlers.cpp
A	source/blender/simulations/bparticles/offset_handlers.hpp

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

diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
index cae36d8c2f6..44a431cce2b 100644
--- a/source/blender/simulations/CMakeLists.txt
+++ b/source/blender/simulations/CMakeLists.txt
@@ -50,6 +50,8 @@ set(SRC
   bparticles/particles_state.cpp
   bparticles/particle_allocator.hpp
   bparticles/particle_allocator.cpp
+  bparticles/offset_handlers.hpp
+  bparticles/offset_handlers.cpp
 )
 
 set(LIB
diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp
index 1d859a3adc4..28d00e9355d 100644
--- a/source/blender/simulations/bparticles/forces.cpp
+++ b/source/blender/simulations/bparticles/forces.cpp
@@ -44,38 +44,4 @@ void TurbulenceForce::add_force(ParticlesBlock &block, ArrayRef<float3> r_force)
   }
 }
 
-void CreateTrailHandler::execute(OffsetHandlerInterface &interface)
-{
-  if (m_rate <= 0.0f) {
-    return;
-  }
-
-  ParticleSet particles = interface.particles();
-  auto positions = particles.attributes().get_float3("Position");
-  auto position_offsets = interface.offsets().get_float3("Position");
-
-  float frequency = 1.0f / m_rate;
-
-  SmallVector<float3> new_positions;
-  SmallVector<float> new_birth_times;
-  for (uint pindex : particles.pindices()) {
-    float time_factor = interface.time_factors()[pindex];
-    TimeSpan time_span = interface.time_span(pindex);
-    float current_time = frequency * (std::floor(time_span.start() / frequency) + 1.0f);
-
-    float3 total_offset = position_offsets[pindex] * time_factor;
-    while (current_time < time_span.end()) {
-      float factor = time_span.get_factor_safe(current_time);
-      new_positions.append(positions[pindex] + total_offset * factor);
-      new_birth_times.append(current_time);
-      current_time += frequency;
-    }
-  }
-
-  auto new_particles = interface.particle_allocator().request(m_particle_type_name,
-                                                              new_positions.size());
-  new_particles.set_float3("Position", new_positions);
-  new_particles.set_float("Birth Time", new_birth_times);
-}
-
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/forces.hpp b/source/blender/simulations/bparticles/forces.hpp
index 6ad7cbbbe2a..fe44ea9cc1a 100644
--- a/source/blender/simulations/bparticles/forces.hpp
+++ b/source/blender/simulations/bparticles/forces.hpp
@@ -40,18 +40,4 @@ class TurbulenceForce : public Force {
   void add_force(ParticlesBlock &block, ArrayRef<float3> r_force) override;
 };
 
-class CreateTrailHandler : public OffsetHandler {
- private:
-  std::string m_particle_type_name;
-  float m_rate;
-
- public:
-  CreateTrailHandler(StringRef particle_type_name, float rate)
-      : m_particle_type_name(particle_type_name.to_std_string()), m_rate(rate)
-  {
-  }
-
-  void execute(OffsetHandlerInterface &interface) override;
-};
-
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index 239e6d86741..494351fd100 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -14,6 +14,7 @@
 #include "events.hpp"
 #include "forces.hpp"
 #include "integrator.hpp"
+#include "offset_handlers.hpp"
 
 namespace BParticles {
 
diff --git a/source/blender/simulations/bparticles/offset_handlers.cpp b/source/blender/simulations/bparticles/offset_handlers.cpp
new file mode 100644
index 00000000000..2997eb18a7d
--- /dev/null
+++ b/source/blender/simulations/bparticles/offset_handlers.cpp
@@ -0,0 +1,39 @@
+#include "offset_handlers.hpp"
+
+namespace BParticles {
+
+void CreateTrailHandler::execute(OffsetHandlerInterface &interface)
+{
+  if (m_rate <= 0.0f) {
+    return;
+  }
+
+  ParticleSet particles = interface.particles();
+  auto positions = particles.attributes().get_float3("Position");
+  auto position_offsets = interface.offsets().get_float3("Position");
+
+  float frequency = 1.0f / m_rate;
+
+  SmallVector<float3> new_positions;
+  SmallVector<float> new_birth_times;
+  for (uint pindex : particles.pindices()) {
+    float time_factor = interface.time_factors()[pindex];
+    TimeSpan time_span = interface.time_span(pindex);
+    float current_time = frequency * (std::floor(time_span.start() / frequency) + 1.0f);
+
+    float3 total_offset = position_offsets[pindex] * time_factor;
+    while (current_time < time_span.end()) {
+      float factor = time_span.get_factor_safe(current_time);
+      new_positions.append(positions[pindex] + total_offset * factor);
+      new_birth_times.append(current_time);
+      current_time += frequency;
+    }
+  }
+
+  auto new_particles = interface.particle_allocator().request(m_particle_type_name,
+                                                              new_positions.size());
+  new_particles.set_float3("Position", new_positions);
+  new_particles.set_float("Birth Time", new_birth_times);
+}
+
+}  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/offset_handlers.hpp b/source/blender/simulations/bparticles/offset_handlers.hpp
new file mode 100644
index 00000000000..2ec28a65796
--- /dev/null
+++ b/source/blender/simulations/bparticles/offset_handlers.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "step_description.hpp"
+
+namespace BParticles {
+
+class CreateTrailHandler : public OffsetHandler {
+ private:
+  std::string m_particle_type_name;
+  float m_rate;
+
+ public:
+  CreateTrailHandler(StringRef particle_type_name, float rate)
+      : m_particle_type_name(particle_type_name.to_std_string()), m_rate(rate)
+  {
+  }
+
+  void execute(OffsetHandlerInterface &interface) override;
+};
+
+}  // namespace BParticles



More information about the Bf-blender-cvs mailing list