[Bf-blender-cvs] [18e8a12ef17] functions: use particle indices to access remaining durations

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


Commit: 18e8a12ef17d8e6094776ab4850504c644c809cf
Author: Jacques Lucke
Date:   Wed Jul 10 15:58:53 2019 +0200
Branches: functions
https://developer.blender.org/rB18e8a12ef17d8e6094776ab4850504c644c809cf

use particle indices to access remaining durations

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

M	source/blender/simulations/bparticles/action_interface.cpp
M	source/blender/simulations/bparticles/action_interface.hpp
M	source/blender/simulations/bparticles/actions.cpp
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/simulations/bparticles/action_interface.cpp b/source/blender/simulations/bparticles/action_interface.cpp
index 664cf50c3f6..2fdc99c2eec 100644
--- a/source/blender/simulations/bparticles/action_interface.cpp
+++ b/source/blender/simulations/bparticles/action_interface.cpp
@@ -10,12 +10,10 @@ void ActionInterface::execute_action_for_subset(ArrayRef<uint> indices,
                                                 std::unique_ptr<Action> &action)
 {
   SmallVector<float> sub_current_times;
-  SmallVector<float> sub_remaining_times;
   SmallVector<uint> particle_indices;
   for (uint i : indices) {
     particle_indices.append(m_particles.get_particle_index(i));
     sub_current_times.append(m_current_times[i]);
-    sub_remaining_times.append(m_remaining_times[i]);
   }
 
   ParticleSet sub_particles(m_particles.block(), particle_indices);
@@ -24,7 +22,7 @@ void ActionInterface::execute_action_for_subset(ArrayRef<uint> indices,
                                 sub_particles,
                                 m_attribute_offsets,
                                 sub_current_times,
-                                sub_remaining_times,
+                                m_remaining_times,
                                 m_event_info);
   action->execute(sub_interface);
 }
diff --git a/source/blender/simulations/bparticles/action_interface.hpp b/source/blender/simulations/bparticles/action_interface.hpp
index 5e0bd335199..d6483ae6568 100644
--- a/source/blender/simulations/bparticles/action_interface.hpp
+++ b/source/blender/simulations/bparticles/action_interface.hpp
@@ -84,7 +84,7 @@ class ActionInterface {
 
   ParticleSet &particles();
   AttributeArrays attribute_offsets();
-  float remaining_time_in_step(uint index);
+  float remaining_time_in_step(uint pindex);
   ArrayRef<float> current_times();
   void kill(ArrayRef<uint> particle_indices);
   void execute_action_for_subset(ArrayRef<uint> indices, std::unique_ptr<Action> &action);
@@ -134,9 +134,9 @@ inline AttributeArrays ActionInterface::attribute_offsets()
   return m_attribute_offsets;
 }
 
-inline float ActionInterface::remaining_time_in_step(uint index)
+inline float ActionInterface::remaining_time_in_step(uint pindex)
 {
-  return m_remaining_times[index];
+  return m_remaining_times[pindex];
 }
 
 inline ArrayRef<float> ActionInterface::current_times()
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index f9e314bd3bd..0ba0fed7168 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -42,7 +42,7 @@ class ChangeDirectionAction : public Action {
       float3 direction = fn_out.get<float3>(0);
 
       velocities[pindex] = direction;
-      position_offsets[pindex] = direction * interface.remaining_time_in_step(i);
+      position_offsets[pindex] = direction * interface.remaining_time_in_step(pindex);
       velocity_offsets[pindex] = float3(0);
     }
 
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 6a68bd1e82b..7d4a3a6f59c 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -118,6 +118,18 @@ BLI_NOINLINE static void update_remaining_attribute_offsets(
   }
 }
 
+BLI_NOINLINE static void update_remaining_durations(ArrayRef<uint> indices_with_event,
+                                                    ArrayRef<uint> particle_indices_with_event,
+                                                    ArrayRef<float> time_factors_to_next_event,
+                                                    ArrayRef<float> remaining_durations)
+{
+  for (uint i = 0; i < indices_with_event.size(); i++) {
+    uint index = indices_with_event[i];
+    uint pindex = particle_indices_with_event[i];
+    remaining_durations[pindex] *= (1.0f - time_factors_to_next_event[index]);
+  }
+}
+
 BLI_NOINLINE static void find_particle_indices_per_event(
     ArrayRef<uint> indices_with_events,
     ArrayRef<uint> particle_indices_with_events,
@@ -136,19 +148,18 @@ BLI_NOINLINE static void find_particle_indices_per_event(
 
 BLI_NOINLINE static void compute_current_time_per_particle(
     ArrayRef<uint> indices_with_events,
-    ArrayRef<float> durations,
+    ArrayRef<uint> particle_indices_with_event,
+    ArrayRef<float> remaining_durations,
     float end_time,
     ArrayRef<int> next_event_indices,
-    ArrayRef<float> time_factors_to_next_event,
-    ArrayRef<SmallVector<float>> r_current_time_per_particle,
-    ArrayRef<SmallVector<float>> r_remaining_time_per_particle)
+    ArrayRef<SmallVector<float>> r_current_time_per_particle)
 {
-  for (uint i : indices_with_events) {
-    int event_index = next_event_indices[i];
+  for (uint i = 0; i < indices_with_events.size(); i++) {
+    uint index = indices_with_events[i];
+    uint pindex = particle_indices_with_event[i];
+    int event_index = next_event_indices[index];
     BLI_assert(event_index >= 0);
-    float remaining_duration = durations[i] * (1.0f - time_factors_to_next_event[i]);
-    r_current_time_per_particle[event_index].append(end_time - remaining_duration);
-    r_remaining_time_per_particle[event_index].append(remaining_duration);
+    r_current_time_per_particle[event_index].append(end_time - remaining_durations[pindex]);
   }
 }
 
@@ -156,10 +167,8 @@ BLI_NOINLINE static void find_unfinished_particles(
     ArrayRef<uint> indices_with_event,
     ArrayRef<uint> particle_indices,
     ArrayRef<float> time_factors_to_next_event,
-    ArrayRef<float> durations,
     ArrayRef<uint8_t> kill_states,
-    VectorAdaptor<uint> &r_unfinished_particle_indices,
-    VectorAdaptor<float> &r_remaining_durations)
+    VectorAdaptor<uint> &r_unfinished_particle_indices)
 {
 
   for (uint i : indices_with_event) {
@@ -168,9 +177,7 @@ BLI_NOINLINE static void find_unfinished_particles(
       float time_factor = time_factors_to_next_event[i];
 
       if (time_factor < 1.0f) {
-        float remaining_duration = durations[i] * (1.0f - time_factor);
         r_unfinished_particle_indices.append(pindex);
-        r_remaining_durations.append(remaining_duration);
       }
     }
   }
@@ -181,7 +188,7 @@ BLI_NOINLINE static void execute_events(ParticleAllocator &particle_allocator,
                                         ParticlesBlock &block,
                                         ArrayRef<SmallVector<uint>> particle_indices_per_event,
                                         ArrayRef<SmallVector<float>> current_time_per_particle,
-                                        ArrayRef<SmallVector<float>> remaining_time_per_particle,
+                                        ArrayRef<float> remaining_durations,
                                         ArrayRef<Event *> events,
                                         EventStorage &event_storage,
                                         AttributeArrays attribute_offsets)
@@ -200,7 +207,7 @@ BLI_NOINLINE static void execute_events(ParticleAllocator &particle_allocator,
                                     particle_allocator,
                                     array_allocator,
                                     current_time_per_particle[event_index],
-                                    remaining_time_per_particle[event_index],
+                                    remaining_durations,
                                     event_storage,
                                     attribute_offsets);
     event->execute(interface);
@@ -211,11 +218,10 @@ BLI_NOINLINE static void simulate_to_next_event(ArrayAllocator &array_allocator,
                                                 ParticleAllocator &particle_allocator,
                                                 ParticleSet particles,
                                                 AttributeArrays attribute_offsets,
-                                                ArrayRef<float> durations,
+                                                ArrayRef<float> remaining_durations,
                                                 float end_time,
                                                 ArrayRef<Event *> events,
-                                                VectorAdaptor<uint> &r_unfinished_particle_indices,
-                                                VectorAdaptor<float> &r_remaining_durations)
+                                                VectorAdaptor<uint> &r_unfinished_particle_indices)
 {
   uint amount = particles.size();
   BLI_assert(array_allocator.array_size() >= amount);
@@ -231,7 +237,7 @@ BLI_NOINLINE static void simulate_to_next_event(ArrayAllocator &array_allocator,
 
   find_next_event_per_particle(particles,
                                attribute_offsets,
-                               durations,
+                               remaining_durations,
                                end_time,
                                events,
                                event_storage,
@@ -247,26 +253,29 @@ BLI_NOINLINE static void simulate_to_next_event(ArrayAllocator &array_allocator,
                                      time_factors_to_next_event,
                                      attribute_offsets);
 
+  update_remaining_durations(indices_with_event,
+                             particle_indices_with_event,
+                             time_factors_to_next_event,
+                             remaining_durations);
+
   SmallVector<SmallVector<uint>> particles_per_event(events.size());
   find_particle_indices_per_event(
       indices_with_event, particle_indices_with_event, next_event_indices, particles_per_event);
 
   SmallVector<SmallVector<float>> current_time_per_particle(events.size());
-  SmallVector<SmallVector<float>> remaining_time_per_particle(events.size());
   compute_current_time_per_particle(indices_with_event,
-                                    durations,
+                                    particle_indices_with_event,
+                                    remaining_durations,
                                     end_time,
                                     next_event_indices,
-                                    tim

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list