[Bf-blender-cvs] [7a62e775bb2] functions: simplify calling action from emitter

Jacques Lucke noreply at git.blender.org
Thu Jul 11 17:15:17 CEST 2019


Commit: 7a62e775bb2d398ae4c88bb90bfe72aa89fd4086
Author: Jacques Lucke
Date:   Thu Jul 11 11:46:10 2019 +0200
Branches: functions
https://developer.blender.org/rB7a62e775bb2d398ae4c88bb90bfe72aa89fd4086

simplify calling action from emitter

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

M	source/blender/simulations/bparticles/action_interface.hpp
M	source/blender/simulations/bparticles/emitters.cpp

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

diff --git a/source/blender/simulations/bparticles/action_interface.hpp b/source/blender/simulations/bparticles/action_interface.hpp
index 6e56f8cf346..a520ce6f1cf 100644
--- a/source/blender/simulations/bparticles/action_interface.hpp
+++ b/source/blender/simulations/bparticles/action_interface.hpp
@@ -80,6 +80,11 @@ class ActionInterface {
                   ArrayRef<float> remaining_times,
                   EventInfo &event_info);
 
+  static void RunFromEmitter(std::unique_ptr<Action> &action,
+                             ParticleSets &particle_sets,
+                             EmitterInterface &emitter_interface,
+                             EventInfo *event_info = nullptr);
+
   EventInfo &event_info();
 
   ParticleSet &particles();
@@ -119,6 +124,39 @@ inline ActionInterface::ActionInterface(ParticleAllocator &particle_allocator,
 {
 }
 
+class EmptyEventinfo : public EventInfo {
+  void *get_info_array(StringRef UNUSED(name))
+  {
+    return nullptr;
+  }
+};
+
+inline void ActionInterface::RunFromEmitter(std::unique_ptr<Action> &action,
+                                            ParticleSets &particle_sets,
+                                            EmitterInterface &emitter_interface,
+                                            EventInfo *event_info)
+{
+  AttributesInfo info;
+  AttributeArraysCore offsets_core(info, {}, 0);
+  AttributeArrays offsets = offsets_core.slice_all();
+
+  EmptyEventinfo empty_event_info;
+  EventInfo &used_event_info = (event_info == nullptr) ? empty_event_info : *event_info;
+
+  for (ParticleSet particles : particle_sets.sets()) {
+    ArrayAllocator::Array<float> durations(emitter_interface.array_allocator());
+    ArrayRef<float>(durations).fill_indices(particles.pindices(), 0);
+    ActionInterface action_interface(emitter_interface.particle_allocator(),
+                                     emitter_interface.array_allocator(),
+                                     particles,
+                                     offsets,
+                                     particles.attributes().get_float("Birth Time"),
+                                     durations,
+                                     used_event_info);
+    action->execute(action_interface);
+  }
+}
+
 inline EventInfo &ActionInterface::event_info()
 {
   return m_event_info;
diff --git a/source/blender/simulations/bparticles/emitters.cpp b/source/blender/simulations/bparticles/emitters.cpp
index 442b1ae7cec..53596bc3629 100644
--- a/source/blender/simulations/bparticles/emitters.cpp
+++ b/source/blender/simulations/bparticles/emitters.cpp
@@ -59,13 +59,6 @@ class SurfaceEmitter : public Emitter {
     m_compute_inputs_body = m_compute_inputs_fn->body<TupleCallBody>();
   }
 
-  class EmitSurfaceEventInfo : public EventInfo {
-    void *get_info_array(StringRef name)
-    {
-      return nullptr;
-    }
-  };
-
   void emit(EmitterInterface &interface) override
   {
     FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_inputs_body, fn_in, fn_out);
@@ -146,24 +139,7 @@ class SurfaceEmitter : public Emitter {
     target.set_float("Size", sizes);
     target.set_float("Birth Time", birth_times);
 
-    AttributesInfo info;
-    AttributeArraysCore offsets_core(info, {}, 0);
-    AttributeArrays offsets = offsets_core.slice_all();
-
-    EmitSurfaceEventInfo event_info;
-
-    for (ParticleSet particles : target.sets()) {
-      ArrayAllocator::Array<float> durations(interface.array_allocator());
-      ArrayRef<float>(durations).fill_indices(particles.pindices(), 0);
-      ActionInterface action_interface(interface.particle_allocator(),
-                                       interface.array_allocator(),
-                                       particles,
-                                       offsets,
-                                       particles.attributes().get_float("Birth Time"),
-                                       durations,
-                                       event_info);
-      m_action->execute(action_interface);
-    }
+    ActionInterface::RunFromEmitter(m_action, target, interface);
   }
 
   float3 random_point_in_triangle(float3 a, float3 b, float3 c)



More information about the Bf-blender-cvs mailing list