[Bf-blender-cvs] [b5af31fb578] functions: use particle indices to trigger particles

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


Commit: b5af31fb578397c8ecebd3a76f82668b37c33cdc
Author: Jacques Lucke
Date:   Wed Jul 10 16:28:43 2019 +0200
Branches: functions
https://developer.blender.org/rBb5af31fb578397c8ecebd3a76f82668b37c33cdc

use particle indices to trigger particles

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

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/core.cpp b/source/blender/simulations/bparticles/core.cpp
index e8f6b574fa7..aa59051f4ae 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -247,7 +247,7 @@ EventFilterInterface::EventFilterInterface(ParticleSet particles,
                                            float end_time,
                                            ArrayRef<float> known_min_time_factors,
                                            EventStorage &r_event_storage,
-                                           SmallVector<uint> &r_filtered_indices,
+                                           SmallVector<uint> &r_filtered_particle_indices,
                                            SmallVector<float> &r_filtered_time_factors)
     : m_particles(particles),
       m_attribute_offsets(attribute_offsets),
@@ -255,7 +255,7 @@ EventFilterInterface::EventFilterInterface(ParticleSet particles,
       m_end_time(end_time),
       m_known_min_time_factors(known_min_time_factors),
       m_event_storage(r_event_storage),
-      m_filtered_indices(r_filtered_indices),
+      m_filtered_particle_indices(r_filtered_particle_indices),
       m_filtered_time_factors(r_filtered_time_factors)
 {
 }
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index a5aebec156a..b02b6b17f90 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -402,7 +402,7 @@ class EventFilterInterface {
   ArrayRef<float> m_known_min_time_factors;
 
   EventStorage &m_event_storage;
-  SmallVector<uint> &m_filtered_indices;
+  SmallVector<uint> &m_filtered_particle_indices;
   SmallVector<float> &m_filtered_time_factors;
 
   /* Size can be increased when necessary. */
@@ -415,7 +415,7 @@ class EventFilterInterface {
                        float end_time,
                        ArrayRef<float> known_min_time_factors,
                        EventStorage &r_event_storage,
-                       SmallVector<uint> &r_filtered_indices,
+                       SmallVector<uint> &r_filtered_particle_indices,
                        SmallVector<float> &r_filtered_time_factors);
 
   /**
@@ -447,14 +447,14 @@ class EventFilterInterface {
    * Mark a particle as triggered by the event at a specific point in time.
    * Note: The index must increase between consecutive calls to this function.
    */
-  void trigger_particle(uint index, float time_factor);
+  void trigger_particle(uint pindex, float time_factor);
 
   /**
    * Same as above but returns a reference to a struct that can be used to pass data to the execute
    * function. The reference might point to a dummy buffer when the time_factor is after a known
    * other event.
    */
-  template<typename T> T &trigger_particle(uint index, float time_factor);
+  template<typename T> T &trigger_particle(uint pindex, float time_factor);
 };
 
 /**
@@ -776,28 +776,26 @@ inline float EventFilterInterface::end_time()
   return m_end_time;
 }
 
-inline void EventFilterInterface::trigger_particle(uint index, float time_factor)
+inline void EventFilterInterface::trigger_particle(uint pindex, float time_factor)
 {
   BLI_assert(0.0f <= time_factor && time_factor <= 1.0f);
 
-  uint pindex = m_particles.get_particle_index(index);
   if (time_factor <= m_known_min_time_factors[pindex]) {
-    m_filtered_indices.append(index);
+    m_filtered_particle_indices.append(pindex);
     m_filtered_time_factors.append(time_factor);
   }
 }
 
 template<typename T>
-inline T &EventFilterInterface::trigger_particle(uint index, float time_factor)
+inline T &EventFilterInterface::trigger_particle(uint pindex, float time_factor)
 {
   BLI_STATIC_ASSERT(std::is_trivial<T>::value, "");
   BLI_assert(sizeof(T) <= m_event_storage.max_element_size());
   BLI_assert(sizeof(m_dummy_event_storage) >= m_event_storage.max_element_size());
 
-  uint pindex = m_particles.get_particle_index(index);
   if (time_factor <= m_known_min_time_factors[pindex]) {
-    this->trigger_particle(index, time_factor);
-    return m_event_storage.get<T>(m_particles.get_particle_index(index));
+    this->trigger_particle(pindex, time_factor);
+    return m_event_storage.get<T>(pindex);
   }
   else {
     return *(T *)m_dummy_event_storage;
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index ac1f76b5d37..00b8633b902 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -66,12 +66,12 @@ class AgeReachedEvent : public Event {
 
         float age_at_start = age_at_end - time_span.duration();
         if (trigger_age < age_at_start) {
-          interface.trigger_particle(i, 0.0f);
+          interface.trigger_particle(pindex, 0.0f);
         }
         else {
           float time_factor = time_span.get_factor_safe(birth_time + trigger_age);
           CLAMP(time_factor, 0.0f, 1.0f);
-          interface.trigger_particle(i, time_factor);
+          interface.trigger_particle(pindex, time_factor);
         }
       }
     }
@@ -180,7 +180,7 @@ class MeshCollisionEventFilter : public Event {
         if (std::abs(last_collision_times[pindex] - time) < 0.0001f) {
           continue;
         }
-        auto &storage = interface.trigger_particle<EventStorage>(i, time_factor);
+        auto &storage = interface.trigger_particle<EventStorage>(pindex, time_factor);
         if (float3::dot(result.normal, ray_direction) > 0) {
           result.normal = -result.normal;
         }
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 074a356fdd2..9cd1cbe4db2 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -40,7 +40,7 @@ BLI_NOINLINE static void find_next_event_per_particle(
   }
 
   for (uint event_index = 0; event_index < events.size(); event_index++) {
-    SmallVector<uint> triggered_indices;
+    SmallVector<uint> triggered_particle_indices;
     SmallVector<float> triggered_time_factors;
 
     Event *event = events[event_index];
@@ -50,13 +50,12 @@ BLI_NOINLINE static void find_next_event_per_particle(
                                    end_time,
                                    r_time_factors_to_next_event,
                                    r_event_storage,
-                                   triggered_indices,
+                                   triggered_particle_indices,
                                    triggered_time_factors);
     event->filter(interface);
 
-    for (uint i = 0; i < triggered_indices.size(); i++) {
-      uint index = triggered_indices[i];
-      uint pindex = particles.get_particle_index(index);
+    for (uint i = 0; i < triggered_particle_indices.size(); i++) {
+      uint pindex = triggered_particle_indices[i];
       float time_factor = triggered_time_factors[i];
       BLI_assert(time_factor <= r_time_factors_to_next_event[pindex]);



More information about the Bf-blender-cvs mailing list