[Bf-blender-cvs] [5216bf60145] functions: get rid of particles.range()

Jacques Lucke noreply at git.blender.org
Wed Jul 10 17:18:27 CEST 2019


Commit: 5216bf60145ef7daeebc9aad908ee380ff3e3af5
Author: Jacques Lucke
Date:   Wed Jul 10 16:53:39 2019 +0200
Branches: functions
https://developer.blender.org/rB5216bf60145ef7daeebc9aad908ee380ff3e3af5

get rid of particles.range()

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

M	source/blender/simulations/bparticles/actions.cpp
M	source/blender/simulations/bparticles/core.cpp
M	source/blender/simulations/bparticles/core.hpp
M	source/blender/simulations/bparticles/events.cpp
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index f74d465a4bd..073df6faf83 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -35,7 +35,7 @@ class ChangeDirectionAction : public Action {
     FN::ExecutionStack stack;
     FN::ExecutionContext execution_context(stack);
 
-    for (uint pindex : particles.indices()) {
+    for (uint pindex : particles.pindices()) {
       caller.call(fn_in, fn_out, execution_context, pindex);
       float3 direction = fn_out.get<float3>(0);
 
@@ -51,7 +51,7 @@ class ChangeDirectionAction : public Action {
 class KillAction : public Action {
   void execute(ActionInterface &interface) override
   {
-    interface.kill(interface.particles().indices());
+    interface.kill(interface.particles().pindices());
   }
 };
 
@@ -99,7 +99,7 @@ class ExplodeAction : public Action {
     FN::ExecutionStack stack;
     FN::ExecutionContext execution_context(stack);
 
-    for (uint pindex : particles.indices()) {
+    for (uint pindex : particles.pindices()) {
       caller.call(fn_in, fn_out, execution_context, pindex);
       uint parts_amount = std::max(0, fn_out.get<int>(0));
       float speed = fn_out.get<float>(1);
@@ -145,7 +145,7 @@ class ConditionAction : public Action {
     this->compute_conditions(interface, conditions);
 
     SmallVector<uint> true_pindices, false_pindices;
-    for (uint pindex : particles.indices()) {
+    for (uint pindex : particles.pindices()) {
       if (conditions[pindex]) {
         true_pindices.append(pindex);
       }
@@ -167,7 +167,7 @@ class ConditionAction : public Action {
 
     FN::ExecutionStack stack;
     FN::ExecutionContext execution_context(stack);
-    for (uint pindex : particles.indices()) {
+    for (uint pindex : particles.pindices()) {
       caller.call(fn_in, fn_out, execution_context, pindex);
       bool condition = fn_out.get<bool>(0);
       r_conditions[pindex] = condition;
diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp
index b61a014d2e4..e7ca5598d38 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -144,8 +144,8 @@ void ParticleSets::set_elements(uint index, void *data)
     AttributeArrays attributes = particles.attributes();
     void *dst = attributes.get_ptr(index);
 
-    for (uint i : particles.range()) {
-      uint pindex = particles.get_particle_index(i);
+    for (uint i = 0; i < particles.size(); i++) {
+      uint pindex = particles.pindices()[i];
       memcpy(POINTER_OFFSET(dst, element_size * pindex),
              POINTER_OFFSET(remaining_data, element_size * i),
              element_size);
@@ -164,7 +164,7 @@ void ParticleSets::fill_elements(uint index, void *value)
     AttributeArrays attributes = particles.attributes();
     void *dst = attributes.get_ptr(index);
 
-    for (uint pindex : particles.indices()) {
+    for (uint pindex : particles.pindices()) {
       memcpy(POINTER_OFFSET(dst, element_size * pindex), value, element_size);
     }
   }
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 8745a2d58f5..a23bb99c94a 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -239,18 +239,7 @@ struct ParticleSet {
    * Access particle indices in the block that are part of the set.
    * Every value in this array is an index into the attribute arrays.
    */
-  ArrayRef<uint> indices();
-
-  /**
-   * Get the particle index of an index in this set. E.g. the 4th element in this set could be the
-   * 350th element in the block.
-   */
-  uint get_particle_index(uint i);
-
-  /**
-   * Utility to get [0, 1, ..., size() - 1].
-   */
-  Range<uint> range();
+  ArrayRef<uint> pindices();
 
   /**
    * Number of particles in this set.
@@ -258,7 +247,7 @@ struct ParticleSet {
   uint size();
 
   /**
-   * Returns true when get_particle_index(i) == i for all i, otherwise false.
+   * Returns true when pindices()[i] == i for all i, otherwise false.
    */
   bool indices_are_trivial();
 };
@@ -693,21 +682,11 @@ inline AttributeArrays ParticleSet::attributes()
   return m_block->attributes();
 }
 
-inline ArrayRef<uint> ParticleSet::indices()
+inline ArrayRef<uint> ParticleSet::pindices()
 {
   return m_pindices;
 }
 
-inline uint ParticleSet::get_particle_index(uint i)
-{
-  return m_pindices[i];
-}
-
-inline Range<uint> ParticleSet::range()
-{
-  return Range<uint>(0, m_pindices.size());
-}
-
 inline uint ParticleSet::size()
 {
   return m_pindices.size();
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index ca7c2d220c4..4859e2bbfff 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -52,8 +52,7 @@ class AgeReachedEvent : public Event {
     m_compute_age_body->call(fn_in, fn_out, execution_context);
     float trigger_age = fn_out.get<float>(0);
 
-    for (uint i : particles.range()) {
-      uint pindex = particles.get_particle_index(i);
+    for (uint pindex : particles.pindices()) {
       if (was_activated_before[pindex]) {
         continue;
       }
@@ -82,7 +81,7 @@ class AgeReachedEvent : public Event {
     ParticleSet particles = interface.particles();
 
     auto was_activated_before = particles.attributes().get_byte(m_identifier);
-    for (uint pindex : particles.indices()) {
+    for (uint pindex : particles.pindices()) {
       was_activated_before[pindex] = true;
     }
 
@@ -166,9 +165,7 @@ class MeshCollisionEventFilter : public Event {
     auto last_collision_times = particles.attributes().get_float(m_identifier);
     auto position_offsets = interface.attribute_offsets().get_float3("Position");
 
-    for (uint i : particles.range()) {
-      uint pindex = particles.get_particle_index(i);
-
+    for (uint pindex : particles.pindices()) {
       float3 ray_start = m_world_to_local.transform_position(positions[pindex]);
       float3 ray_direction = m_world_to_local.transform_direction(position_offsets[pindex]);
       float length = ray_direction.normalize_and_get_length();
@@ -211,11 +208,10 @@ class MeshCollisionEventFilter : public Event {
     SmallVector<float3> normals(particles.block().active_amount());
     auto last_collision_times = particles.attributes().get_float(m_identifier);
 
-    for (uint i : particles.range()) {
-      uint pindex = particles.get_particle_index(i);
+    for (uint pindex : particles.pindices()) {
       auto storage = interface.get_storage<EventStorage>(pindex);
       normals[pindex] = storage.normal;
-      last_collision_times[pindex] = interface.current_times()[i];
+      last_collision_times[pindex] = interface.current_times()[pindex];
     }
 
     CollisionEventInfo event_info(normals);
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 84dec3e312f..891f1e8458a 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -33,7 +33,7 @@ BLI_NOINLINE static void find_next_event_per_particle(ParticleSet particles,
                                                       ArrayRef<float> r_time_factors_to_next_event,
                                                       VectorAdaptor<uint> &r_pindices_with_event)
 {
-  for (uint pindex : particles.indices()) {
+  for (uint pindex : particles.pindices()) {
     r_next_event_indices[pindex] = -1;
     r_time_factors_to_next_event[pindex] = 1.0f;
   }
@@ -63,8 +63,7 @@ BLI_NOINLINE static void find_next_event_per_particle(ParticleSet particles,
     }
   }
 
-  for (uint index : particles.range()) {
-    uint pindex = particles.get_particle_index(index);
+  for (uint pindex : particles.pindices()) {
     if (r_next_event_indices[pindex] != -1) {
       r_pindices_with_event.append(pindex);
     }
@@ -83,14 +82,13 @@ BLI_NOINLINE static void forward_particles_to_next_event_or_end(
     auto offsets = attribute_offsets.get_float3(attribute_index);
 
     if (particles.indices_are_trivial()) {
-      for (uint pindex : particles.range()) {
+      for (uint pindex = 0; pindex < particles.size(); pindex++) {
         float time_factor = time_factors_to_next_event[pindex];
         values[pindex] += time_factor * offsets[pindex];
       }
     }
     else {
-      for (uint i : particles.range()) {
-        uint pindex = particles.get_particle_index(i);
+      for (uint pindex : particles.pindices()) {
         float time_factor = time_factors_to_next_event[pindex];
         values[pindex] += time_factor * offsets[pindex];
       }
@@ -341,7 +339,7 @@ BLI_NOINLINE static void apply_remaining_offsets(ParticleSet particles,
       add_float3_arrays(values.take_front(particles.size()), offsets.take_front(particles.size()));
     }
     else {
-      for (uint pindex : particles.indices()) {
+      for (uint pindex : particles.pindices()) {
         values[pindex] += offsets[pindex];
       }
     }



More information about the Bf-blender-cvs mailing list