[Bf-blender-cvs] [3f01ddd5d22] functions: don't use ParticleType abstraction in simulation code

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


Commit: 3f01ddd5d22ca4acbd827ca4bc2c07e8773d67eb
Author: Jacques Lucke
Date:   Mon Aug 26 11:09:31 2019 +0200
Branches: functions
https://developer.blender.org/rB3f01ddd5d22ca4acbd827ca4bc2c07e8773d67eb

don't use ParticleType abstraction in simulation code

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

M	source/blender/simulations/bparticles/node_frontend.cpp
M	source/blender/simulations/bparticles/simulate.cpp
M	source/blender/simulations/bparticles/simulate.hpp
M	source/blender/simulations/bparticles/step_description_interfaces.hpp

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

diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index d7dc0d39aea..169e6147c69 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -507,10 +507,20 @@ class NodeTreeStepSimulator : public StepSimulator {
     auto step_description = step_description_from_node_tree(
         vtree, simulation_state.world(), time_step);
 
-    simulate_particles(simulation_state.particles(),
-                       time_step,
-                       step_description->emitters(),
-                       step_description->particle_types());
+    StringMap<ParticleTypeInfo> types_to_simulate;
+    step_description->particle_types().foreach_key_value_pair(
+        [&types_to_simulate](StringRefNull name, ParticleType *type) {
+          ParticleTypeInfo type_info = {
+              &type->attributes(),
+              &type->integrator(),
+              type->events(),
+              type->offset_handlers(),
+          };
+          types_to_simulate.add_new(name, type_info);
+        });
+
+    simulate_particles(
+        simulation_state.particles(), time_step, step_description->emitters(), types_to_simulate);
     simulation_state.world().current_step_is_over();
   }
 };
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 5cc7ec72a2a..018eec5e3ba 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -29,6 +29,7 @@ static uint get_max_event_storage_size(ArrayRef<Event *> events)
 BLI_NOINLINE static void find_next_event_per_particle(
     BlockStepData &step_data,
     ArrayRef<uint> pindices,
+    ArrayRef<Event *> events,
     EventStorage &r_event_storage,
     MutableArrayRef<int> r_next_event_indices,
     MutableArrayRef<float> r_time_factors_to_next_event,
@@ -37,8 +38,6 @@ BLI_NOINLINE static void find_next_event_per_particle(
   r_next_event_indices.fill_indices(pindices, -1);
   r_time_factors_to_next_event.fill_indices(pindices, 1.0f);
 
-  ArrayRef<Event *> events = step_data.particle_type.events();
-
   for (uint event_index = 0; event_index < events.size(); event_index++) {
     Vector<uint> triggered_pindices;
     Vector<float> triggered_time_factors;
@@ -70,10 +69,13 @@ BLI_NOINLINE static void find_next_event_per_particle(
 }
 
 BLI_NOINLINE static void forward_particles_to_next_event_or_end(
-    BlockStepData &step_data, ArrayRef<uint> pindices, ArrayRef<float> time_factors_to_next_event)
+    BlockStepData &step_data,
+    ArrayRef<uint> pindices,
+    ArrayRef<float> time_factors_to_next_event,
+    ArrayRef<OffsetHandler *> offset_handlers)
 {
   OffsetHandlerInterface interface(step_data, pindices, time_factors_to_next_event);
-  for (OffsetHandler *handler : step_data.particle_type.offset_handlers()) {
+  for (OffsetHandler *handler : offset_handlers) {
     handler->execute(interface);
   }
 
@@ -168,10 +170,9 @@ BLI_NOINLINE static void find_unfinished_particles(ArrayRef<uint> pindices_with_
 BLI_NOINLINE static void execute_events(BlockStepData &step_data,
                                         ArrayRef<Vector<uint>> pindices_per_event,
                                         ArrayRef<float> current_times,
-                                        EventStorage &event_storage)
+                                        EventStorage &event_storage,
+                                        ArrayRef<Event *> events)
 {
-  ArrayRef<Event *> events = step_data.particle_type.events();
-
   BLI_assert(events.size() == pindices_per_event.size());
 
   for (uint event_index = 0; event_index < events.size(); event_index++) {
@@ -189,27 +190,28 @@ BLI_NOINLINE static void execute_events(BlockStepData &step_data,
 
 BLI_NOINLINE static void simulate_to_next_event(BlockStepData &step_data,
                                                 ArrayRef<uint> pindices,
+                                                ParticleTypeInfo &type_info,
                                                 VectorAdaptor<uint> &r_unfinished_pindices)
 {
-  ArrayRef<Event *> events = step_data.particle_type.events();
-
   uint amount = step_data.array_size();
   TemporaryArray<int> next_event_indices(amount);
   TemporaryArray<float> time_factors_to_next_event(amount);
   TemporaryVector<uint> pindices_with_event;
 
-  uint max_event_storage_size = std::max(get_max_event_storage_size(events), 1u);
+  uint max_event_storage_size = std::max(get_max_event_storage_size(type_info.events), 1u);
   TemporaryArray<uint8_t> event_storage_array(max_event_storage_size * amount);
   EventStorage event_storage((void *)event_storage_array.begin(), max_event_storage_size);
 
   find_next_event_per_particle(step_data,
                                pindices,
+                               type_info.events,
                                event_storage,
                                next_event_indices,
                                time_factors_to_next_event,
                                pindices_with_event);
 
-  forward_particles_to_next_event_or_end(step_data, pindices, time_factors_to_next_event);
+  forward_particles_to_next_event_or_end(
+      step_data, pindices, time_factors_to_next_event, type_info.offset_handlers);
 
   update_remaining_attribute_offsets(
       pindices_with_event, time_factors_to_next_event, step_data.attribute_offsets);
@@ -217,14 +219,14 @@ BLI_NOINLINE static void simulate_to_next_event(BlockStepData &step_data,
   update_remaining_durations(
       pindices_with_event, time_factors_to_next_event, step_data.remaining_durations);
 
-  Vector<Vector<uint>> particles_per_event(events.size());
+  Vector<Vector<uint>> particles_per_event(type_info.events.size());
   find_pindices_per_event(pindices_with_event, next_event_indices, particles_per_event);
 
   TemporaryArray<float> current_times(amount);
   compute_current_time_per_particle(
       pindices_with_event, step_data.remaining_durations, step_data.step_end_time, current_times);
 
-  execute_events(step_data, particles_per_event, current_times, event_storage);
+  execute_events(step_data, particles_per_event, current_times, event_storage, type_info.events);
 
   find_unfinished_particles(pindices_with_event,
                             time_factors_to_next_event,
@@ -234,6 +236,7 @@ BLI_NOINLINE static void simulate_to_next_event(BlockStepData &step_data,
 
 BLI_NOINLINE static void simulate_with_max_n_events(BlockStepData &step_data,
                                                     uint max_events,
+                                                    ParticleTypeInfo &type_info,
                                                     TemporaryVector<uint> &r_unfinished_pindices)
 {
   TemporaryArray<uint> pindices_A(step_data.array_size());
@@ -244,7 +247,8 @@ BLI_NOINLINE static void simulate_with_max_n_events(BlockStepData &step_data,
   {
     /* Handle first event separately to be able to use the static number range. */
     VectorAdaptor<uint> pindices_output(pindices_A.begin(), amount_left);
-    simulate_to_next_event(step_data, Range<uint>(0, amount_left).as_array_ref(), pindices_output);
+    simulate_to_next_event(
+        step_data, Range<uint>(0, amount_left).as_array_ref(), type_info, pindices_output);
     amount_left = pindices_output.size();
   }
 
@@ -252,7 +256,7 @@ BLI_NOINLINE static void simulate_with_max_n_events(BlockStepData &step_data,
     VectorAdaptor<uint> pindices_input(pindices_A.begin(), amount_left, amount_left);
     VectorAdaptor<uint> pindices_output(pindices_B.begin(), amount_left, 0);
 
-    simulate_to_next_event(step_data, pindices_input, pindices_output);
+    simulate_to_next_event(step_data, pindices_input, type_info, pindices_output);
     amount_left = pindices_output.size();
     std::swap(pindices_A, pindices_B);
   }
@@ -290,15 +294,16 @@ BLI_NOINLINE static void add_float3_arrays(ArrayRef<float3> base, ArrayRef<float
   }
 }
 
-BLI_NOINLINE static void apply_remaining_offsets(BlockStepData &step_data, ArrayRef<uint> pindices)
+BLI_NOINLINE static void apply_remaining_offsets(BlockStepData &step_data,
+                                                 ArrayRef<OffsetHandler *> offset_handlers,
+                                                 ArrayRef<uint> pindices)
 {
-  auto handlers = step_data.particle_type.offset_handlers();
-  if (handlers.size() > 0) {
+  if (offset_handlers.size() > 0) {
     TemporaryArray<float> time_factors(step_data.array_size());
     time_factors.fill_indices(pindices, 1.0f);
 
     OffsetHandlerInterface interface(step_data, pindices, time_factors);
-    for (OffsetHandler *handler : handlers) {
+    for (OffsetHandler *handler : offset_handlers) {
       handler->execute(interface);
     }
   }
@@ -326,14 +331,14 @@ BLI_NOINLINE static void apply_remaining_offsets(BlockStepData &step_data, Array
 
 BLI_NOINLINE static void simulate_block(ParticleAllocator &particle_allocator,
                                         ParticlesBlock &block,
-                                        ParticleType &particle_type,
+                                        ParticleTypeInfo &type_info,
                                         MutableArrayRef<float> remaining_durations,
                                         float end_time)
 {
   uint amount = block.active_amount();
   BLI_assert(amount == remaining_durations.size());
 
-  Integrator &integrator = particle_type.integrator();
+  Integrator &integrator = *type_info.integrator;
   AttributesInfo &offsets_info = integrator.offset_attributes_info();
   Vector<void *> offset_buffers;
   for (AttributeType type : offsets_info.types()) {
@@ -343,21 +348,22 @@ BLI_NOINLINE static void simulate_block(ParticleAllocator &particle_allocator,
   AttributeArrays attribute_offsets(offsets_info, offset_buffers, 0, amount);
 
   BlockStepData step_data = {
-      particle_allocator, block, particle_type, attribute_offsets, remaining_durations, end_time};
+      particle_allocator, block, attribute_offsets, remaining_durations, end_time};
 
   IntegratorInterface interface(step_data);
   integr

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list