[Bf-blender-cvs] [bccd47ab4f5] functions: remove particle block from interfaces

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


Commit: bccd47ab4f5d358bf8f1e4b6ceb4b1e90936b1a8
Author: Jacques Lucke
Date:   Mon Aug 26 11:58:01 2019 +0200
Branches: functions
https://developer.blender.org/rBbccd47ab4f5d358bf8f1e4b6ceb4b1e90936b1a8

remove particle block from interfaces

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

M	source/blender/simulations/bparticles/action_interface.hpp
M	source/blender/simulations/bparticles/force_interface.hpp
M	source/blender/simulations/bparticles/forces.cpp
M	source/blender/simulations/bparticles/integrator.cpp
M	source/blender/simulations/bparticles/particle_allocator.cpp
M	source/blender/simulations/bparticles/particle_function.cpp
M	source/blender/simulations/bparticles/particle_set.hpp
M	source/blender/simulations/bparticles/simulate.cpp
M	source/blender/simulations/bparticles/step_description_interfaces.cpp
M	source/blender/simulations/bparticles/step_description_interfaces.hpp

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

diff --git a/source/blender/simulations/bparticles/action_interface.hpp b/source/blender/simulations/bparticles/action_interface.hpp
index bd6122b43ff..ae27995f628 100644
--- a/source/blender/simulations/bparticles/action_interface.hpp
+++ b/source/blender/simulations/bparticles/action_interface.hpp
@@ -97,7 +97,7 @@ inline void Action::execute_from_emitter(ParticleSets &particle_sets,
                                                                      *action_context;
 
   for (ParticleSet particles : particle_sets.sets()) {
-    uint min_array_size = particles.block().capacity();
+    uint min_array_size = particles.attributes().size();
     AttributeArrays offsets(info, buffers, 0, min_array_size);
     TemporaryArray<float> durations(min_array_size);
     durations.fill_indices(particles.pindices(), 0);
@@ -130,7 +130,7 @@ inline void Action::execute_from_event(EventExecuteInterface &event_interface,
 inline void Action::execute_for_subset(ArrayRef<uint> pindices, ActionInterface &action_interface)
 {
   ActionInterface sub_interface(action_interface.particle_allocator(),
-                                ParticleSet(action_interface.particles().block(), pindices),
+                                ParticleSet(action_interface.particles().attributes(), pindices),
                                 action_interface.attribute_offsets(),
                                 action_interface.current_times(),
                                 action_interface.remaining_durations(),
@@ -148,7 +148,7 @@ inline void Action::execute_for_new_particles(ParticleSets &particle_sets,
   EmptyEventInfo empty_context;
 
   for (ParticleSet particles : particle_sets.sets()) {
-    uint min_array_size = particles.block().capacity();
+    uint min_array_size = particles.attributes().size();
     AttributeArrays offsets(info, buffers, 0, min_array_size);
     TemporaryArray<float> durations(min_array_size);
     durations.fill_indices(particles.pindices(), 0);
@@ -171,7 +171,7 @@ inline void Action::execute_for_new_particles(ParticleSets &particle_sets,
   EmptyEventInfo empty_context;
 
   for (ParticleSet particles : particle_sets.sets()) {
-    uint min_array_size = particles.block().capacity();
+    uint min_array_size = particles.attributes().size();
     AttributeArrays offsets(info, buffers, 0, min_array_size);
     TemporaryArray<float> durations(min_array_size);
     durations.fill_indices(particles.pindices(), 0);
diff --git a/source/blender/simulations/bparticles/force_interface.hpp b/source/blender/simulations/bparticles/force_interface.hpp
index 26d863a7cb6..5ce7e37b22a 100644
--- a/source/blender/simulations/bparticles/force_interface.hpp
+++ b/source/blender/simulations/bparticles/force_interface.hpp
@@ -6,14 +6,22 @@ namespace BParticles {
 
 class ForceInterface : public BlockStepDataAccess {
  private:
+  ArrayRef<uint> m_pindices;
   MutableArrayRef<float3> m_destination;
 
  public:
-  ForceInterface(BlockStepData &step_data, MutableArrayRef<float3> destination)
-      : BlockStepDataAccess(step_data), m_destination(destination)
+  ForceInterface(BlockStepData &step_data,
+                 ArrayRef<uint> pindices,
+                 MutableArrayRef<float3> destination)
+      : BlockStepDataAccess(step_data), m_pindices(pindices), m_destination(destination)
   {
   }
 
+  ParticleSet particles()
+  {
+    return ParticleSet(this->attributes(), m_pindices);
+  }
+
   MutableArrayRef<float3> combined_destination()
   {
     return m_destination;
diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp
index 51b88d2efdf..c7efe2395be 100644
--- a/source/blender/simulations/bparticles/forces.cpp
+++ b/source/blender/simulations/bparticles/forces.cpp
@@ -10,12 +10,12 @@ Force::~Force()
 
 void GravityForce::add_force(ForceInterface &interface)
 {
-  ParticlesBlock &block = interface.block();
+  ParticleSet particles = interface.particles();
   MutableArrayRef<float3> destination = interface.combined_destination();
 
   auto inputs = m_compute_inputs->compute(interface);
 
-  for (uint pindex = 0; pindex < block.active_amount(); pindex++) {
+  for (uint pindex : particles.pindices()) {
     float3 acceleration = inputs->get<float3>("Direction", 0, pindex);
     destination[pindex] += acceleration;
   }
@@ -23,14 +23,14 @@ void GravityForce::add_force(ForceInterface &interface)
 
 void TurbulenceForce::add_force(ForceInterface &interface)
 {
-  ParticlesBlock &block = interface.block();
+  ParticleSet particles = interface.particles();
   MutableArrayRef<float3> destination = interface.combined_destination();
 
-  auto positions = block.attributes().get<float3>("Position");
+  auto positions = particles.attributes().get<float3>("Position");
 
   auto inputs = m_compute_inputs->compute(interface);
 
-  for (uint pindex = 0; pindex < block.active_amount(); pindex++) {
+  for (uint pindex : particles.pindices()) {
     float3 pos = positions[pindex];
     float3 strength = inputs->get<float3>("Strength", 0, pindex);
     float x = (BLI_gNoise(0.5f, pos.x, pos.y, pos.z + 1000.0f, false, 1) - 0.5f) * strength.x;
diff --git a/source/blender/simulations/bparticles/integrator.cpp b/source/blender/simulations/bparticles/integrator.cpp
index c715dc2449e..8a5de745657 100644
--- a/source/blender/simulations/bparticles/integrator.cpp
+++ b/source/blender/simulations/bparticles/integrator.cpp
@@ -16,12 +16,12 @@ AttributesInfo &ConstantVelocityIntegrator::offset_attributes_info()
 
 void ConstantVelocityIntegrator::integrate(IntegratorInterface &interface)
 {
-  ParticlesBlock &block = interface.block();
-  auto velocities = block.attributes().get<float3>("Velocity");
+  ParticleSet particles = interface.particles();
+  auto velocities = particles.attributes().get<float3>("Velocity");
   auto position_offsets = interface.attribute_offsets().get<float3>("Position");
   auto durations = interface.remaining_durations();
 
-  for (uint pindex = 0; pindex < block.active_amount(); pindex++) {
+  for (uint pindex : particles.pindices()) {
     position_offsets[pindex] = velocities[pindex] * durations[pindex];
   }
 }
@@ -54,7 +54,7 @@ void EulerIntegrator::integrate(IntegratorInterface &interface)
   TemporaryArray<float3> combined_force(interface.array_size());
   this->compute_combined_force(interface, combined_force);
 
-  auto last_velocities = interface.block().attributes().get<float3>("Velocity");
+  auto last_velocities = interface.attributes().get<float3>("Velocity");
 
   auto position_offsets = r_offsets.get<float3>("Position");
   auto velocity_offsets = r_offsets.get<float3>("Velocity");
@@ -67,7 +67,7 @@ BLI_NOINLINE void EulerIntegrator::compute_combined_force(IntegratorInterface &i
 {
   r_force.fill({0, 0, 0});
 
-  ForceInterface force_interface(interface.step_data(), r_force);
+  ForceInterface force_interface(interface.step_data(), interface.particles().pindices(), r_force);
 
   for (Force *force : m_forces) {
     force->add_force(force_interface);
diff --git a/source/blender/simulations/bparticles/particle_allocator.cpp b/source/blender/simulations/bparticles/particle_allocator.cpp
index 46d01622d81..2f03933477f 100644
--- a/source/blender/simulations/bparticles/particle_allocator.cpp
+++ b/source/blender/simulations/bparticles/particle_allocator.cpp
@@ -81,7 +81,7 @@ ParticleSets ParticleAllocator::request(StringRef particle_type_name, uint size)
 
   Vector<ParticleSet> sets;
   for (uint i = 0; i < blocks.size(); i++) {
-    sets.append(ParticleSet(*blocks[i], ranges[i].as_array_ref()));
+    sets.append(ParticleSet(blocks[i]->attributes(), ranges[i].as_array_ref()));
   }
 
   return ParticleSets(particle_type_name, attributes_info, sets);
diff --git a/source/blender/simulations/bparticles/particle_function.cpp b/source/blender/simulations/bparticles/particle_function.cpp
index 3e3af1ac1cf..9e13c42cfc9 100644
--- a/source/blender/simulations/bparticles/particle_function.cpp
+++ b/source/blender/simulations/bparticles/particle_function.cpp
@@ -65,8 +65,7 @@ std::unique_ptr<ParticleFunctionResult> ParticleFunction::compute(
 
 std::unique_ptr<ParticleFunctionResult> ParticleFunction::compute(ForceInterface &interface)
 {
-  ParticlesBlock &block = interface.block();
-  return this->compute(ParticleSet(block, block.active_range().as_array_ref()),
+  return this->compute(interface.particles(),
                        ParticleTimes::FromDurationsAndEnd(interface.remaining_durations(),
                                                           interface.step_end_time()),
                        nullptr);
diff --git a/source/blender/simulations/bparticles/particle_set.hpp b/source/blender/simulations/bparticles/particle_set.hpp
index f4c84f93b0f..4ca996a7ab0 100644
--- a/source/blender/simulations/bparticles/particle_set.hpp
+++ b/source/blender/simulations/bparticles/particle_set.hpp
@@ -9,7 +9,7 @@ namespace BParticles {
  */
 struct ParticleSet {
  private:
-  ParticlesBlock *m_block;
+  AttributeArrays m_attributes;
 
   /* Indices into the attribute arrays.
    * Invariants:
@@ -18,12 +18,7 @@ struct ParticleSet {
   ArrayRef<uint> m_pindices;
 
  public:
-  ParticleSet(ParticlesBlock &block, ArrayRef<uint> pindices);
-
-  /**
-   * Return the block that contains the particles of this set.
-   */
-  ParticlesBlock &block();
+  ParticleSet(AttributeArrays attributes, ArrayRef<uint> pindices);
 
   /**
    * Access the attributes of particles in the block on this set.
@@ -117,19 +112,14 @@ class ParticleSets {
 /* ParticleSet inline functions
  *******************************************/
 
-inline ParticleSet::ParticleSet(ParticlesBlock &block, ArrayRef<uint> pindices)
-    : m_block(&block), m_pindices(pindices)
-{
-}
-
-inline ParticlesBlock &ParticleSet::block()
+inline ParticleSet::ParticleSet(AttributeArrays attributes, ArrayRef<uint> pindices)
+    : m_attributes(attributes), m_pindices(pindices)
 {
-  return *m_block;
 }
 
 inline AttributeArrays ParticleSet::attributes()
 {
-  return m_block->attributes();
+  return m_attributes;
 }
 
 inline ArrayRef<uint> ParticleSet::pindices()
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list