[Bf-blender-cvs] [c2e13a2f94c] functions: combine event and action

Jacques Lucke noreply at git.blender.org
Sat Jun 29 16:26:01 CEST 2019


Commit: c2e13a2f94c377c7e96ac296bdc6bab9e4703d55
Author: Jacques Lucke
Date:   Sat Jun 29 15:51:38 2019 +0200
Branches: functions
https://developer.blender.org/rBc2e13a2f94c377c7e96ac296bdc6bab9e4703d55

combine event and action

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

M	source/blender/simulations/bparticles/c_wrapper.cpp
M	source/blender/simulations/bparticles/core.cpp
M	source/blender/simulations/bparticles/core.hpp
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 28dfd825384..8627f572072 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -107,31 +107,45 @@ class EulerIntegrator : public Integrator {
   }
 };
 
+class EventActionTest : public EventAction {
+ public:
+  Event *m_event;
+  Action *m_action;
+
+  ~EventActionTest()
+  {
+    delete m_event;
+    delete m_action;
+  }
+
+  void filter(EventInterface &interface) override
+  {
+    m_event->filter(interface);
+  }
+
+  void execute(ActionInterface &interface) override
+  {
+    m_action->execute(interface);
+  }
+};
+
 class ModifierParticleType : public ParticleType {
  public:
-  SmallVector<Event *> m_events;
-  SmallVector<Action *> m_actions;
+  SmallVector<EventAction *> m_event_actions;
   EulerIntegrator *m_integrator;
 
   ~ModifierParticleType()
   {
     delete m_integrator;
 
-    for (Event *event : m_events) {
-      delete event;
-    }
-    for (Action *action : m_actions) {
-      delete action;
+    for (EventAction *event_action : m_event_actions) {
+      delete event_action;
     }
   }
 
-  ArrayRef<Event *> events() override
+  ArrayRef<EventAction *> event_actions() override
   {
-    return m_events;
-  }
-  ArrayRef<Action *> action_per_event() override
-  {
-    return m_actions;
+    return m_event_actions;
   }
 
   Integrator &integrator() override
@@ -206,17 +220,24 @@ void BParticles_simulate_modifier(NodeParticlesModifierData *npmd,
   if (npmd->collision_object) {
     BKE_bvhtree_from_mesh_get(
         &treedata, (Mesh *)npmd->collision_object->data, BVHTREE_FROM_LOOPTRI, 4);
-    type0->m_events.append(
-        EVENT_mesh_collection(&treedata, npmd->collision_object->obmat).release());
-    type0->m_actions.append(ACTION_explode().release());
+
+    EventActionTest *event_action = new EventActionTest();
+    event_action->m_event =
+        EVENT_mesh_collection(&treedata, npmd->collision_object->obmat).release();
+    event_action->m_action = ACTION_explode().release();
+    type0->m_event_actions.append(event_action);
   }
   type0->m_integrator = new EulerIntegrator();
   type0->m_integrator->m_forces.append(FORCE_directional({0, 0, -2}).release());
 
   auto *type1 = new ModifierParticleType();
   description.m_types.add_new(1, type1);
-  type1->m_events.append(EVENT_age_reached(0.3f).release());
-  type1->m_actions.append(ACTION_kill().release());
+  {
+    EventActionTest *event_action = new EventActionTest();
+    event_action->m_event = EVENT_age_reached(0.3f).release();
+    event_action->m_action = ACTION_kill().release();
+    type1->m_event_actions.append(event_action);
+  }
   type1->m_integrator = new EulerIntegrator();
 
   simulate_step(state, description);
diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp
index b9f08ad883e..c79ad5cd9f1 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -22,6 +22,10 @@ Event::~Event()
 {
 }
 
+EventAction::~EventAction()
+{
+}
+
 ParticleType::~ParticleType()
 {
 }
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index e46660ca7ee..5f159172133 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -407,6 +407,14 @@ class Action {
   virtual void execute(ActionInterface &interface) = 0;
 };
 
+class EventAction {
+ public:
+  virtual ~EventAction();
+
+  virtual void filter(EventInterface &interface) = 0;
+  virtual void execute(ActionInterface &interface) = 0;
+};
+
 class Emitter {
  public:
   virtual ~Emitter();
@@ -429,9 +437,8 @@ class ParticleType {
  public:
   virtual ~ParticleType();
 
-  virtual ArrayRef<Event *> events() = 0;
-  virtual ArrayRef<Action *> action_per_event() = 0;
   virtual Integrator &integrator() = 0;
+  virtual ArrayRef<EventAction *> event_actions() = 0;
 
   virtual ArrayRef<std::string> byte_attributes()
   {
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index a311ba6c81a..499d53ed19f 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -36,7 +36,7 @@ BLI_NOINLINE static void find_next_event_per_particle(ParticleSet particles,
                                                       AttributeArrays &attribute_offsets,
                                                       ArrayRef<float> durations,
                                                       float end_time,
-                                                      ArrayRef<Event *> events,
+                                                      ArrayRef<EventAction *> event_actions,
                                                       ArrayRef<float> last_event_times,
                                                       ArrayRef<int> r_next_event_indices,
                                                       ArrayRef<float> r_time_factors_to_next_event,
@@ -45,18 +45,18 @@ BLI_NOINLINE static void find_next_event_per_particle(ParticleSet particles,
   r_next_event_indices.fill(-1);
   r_time_factors_to_next_event.fill(1.0f);
 
-  for (uint event_index = 0; event_index < events.size(); event_index++) {
+  for (uint event_index = 0; event_index < event_actions.size(); event_index++) {
     SmallVector<uint> triggered_indices;
     SmallVector<float> triggered_time_factors;
 
-    Event *event = events[event_index];
+    EventAction *event_action = event_actions[event_index];
     EventInterface interface(particles,
                              attribute_offsets,
                              durations,
                              end_time,
                              triggered_indices,
                              triggered_time_factors);
-    event->filter(interface);
+    event_action->filter(interface);
 
     for (uint i = 0; i < triggered_indices.size(); i++) {
       uint index = triggered_indices[i];
@@ -180,22 +180,20 @@ BLI_NOINLINE static void run_actions(BlockAllocator &block_allocator,
                                      ParticlesBlock &block,
                                      ArrayRef<SmallVector<uint>> particle_indices_per_event,
                                      ArrayRef<SmallVector<float>> current_time_per_particle,
-                                     ArrayRef<Event *> events,
-                                     ArrayRef<Action *> action_per_event)
+                                     ArrayRef<EventAction *> event_actions)
 {
-  BLI_assert(events.size() == particle_indices_per_event.size());
-  BLI_assert(events.size() == current_time_per_particle.size());
-  BLI_assert(events.size() == action_per_event.size());
+  BLI_assert(event_actions.size() == particle_indices_per_event.size());
+  BLI_assert(event_actions.size() == current_time_per_particle.size());
 
-  for (uint event_index = 0; event_index < events.size(); event_index++) {
-    Action *action = action_per_event[event_index];
+  for (uint event_index = 0; event_index < event_actions.size(); event_index++) {
+    EventAction *event_action = event_actions[event_index];
     ParticleSet particles(block, particle_indices_per_event[event_index]);
     if (particles.size() == 0) {
       continue;
     }
 
     ActionInterface interface(particles, block_allocator, current_time_per_particle[event_index]);
-    action->execute(interface);
+    event_action->execute(interface);
   }
 }
 
@@ -220,7 +218,7 @@ BLI_NOINLINE static void simulate_to_next_event(BlockAllocator &block_allocator,
                                attribute_offsets,
                                durations,
                                end_time,
-                               particle_type.events(),
+                               particle_type.event_actions(),
                                last_event_times,
                                next_event_indices,
                                time_factors_to_next_event,
@@ -237,11 +235,11 @@ BLI_NOINLINE static void simulate_to_next_event(BlockAllocator &block_allocator,
   update_remaining_attribute_offsets(
       particles_with_events, time_factors_to_next_event, attribute_offsets);
 
-  SmallVector<SmallVector<uint>> particles_per_event(particle_type.events().size());
+  SmallVector<SmallVector<uint>> particles_per_event(particle_type.event_actions().size());
   find_particle_indices_per_event(
       indices_with_event, particles.indices(), next_event_indices, particles_per_event);
 
-  SmallVector<SmallVector<float>> current_time_per_particle(particle_type.events().size());
+  SmallVector<SmallVector<float>> current_time_per_particle(particle_type.event_actions().size());
   compute_current_time_per_particle(indices_with_event,
                                     durations,
                                     end_time,
@@ -253,8 +251,7 @@ BLI_NOINLINE static void simulate_to_next_event(BlockAllocator &block_allocator,
               particles.block(),
               particles_per_event,
               current_time_per_particle,
-              particle_type.events(),
-              particle_type.action_per_event());
+              particle_type.event_actions());
 
   find_unfinished_particles(indices_with_event,
                             particles.indices(),



More information about the Bf-blender-cvs mailing list