[Bf-blender-cvs] [1251ef30aa9] functions: gather required attributes from particle type and events

Jacques Lucke noreply at git.blender.org
Mon Jul 8 17:57:02 CEST 2019


Commit: 1251ef30aa91755f00bcb58e26c4de5fdfd2b824
Author: Jacques Lucke
Date:   Mon Jul 8 13:30:58 2019 +0200
Branches: functions
https://developer.blender.org/rB1251ef30aa91755f00bcb58e26c4de5fdfd2b824

gather required attributes from particle type and events

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

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

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

diff --git a/source/blender/simulations/bparticles/attributes.cpp b/source/blender/simulations/bparticles/attributes.cpp
index 3a7e25d66e6..9d25be9eeaa 100644
--- a/source/blender/simulations/bparticles/attributes.cpp
+++ b/source/blender/simulations/bparticles/attributes.cpp
@@ -7,9 +7,9 @@ AttributesInfo::AttributesInfo(ArrayRef<std::string> byte_names,
                                ArrayRef<std::string> float3_names)
 {
   m_indices = {};
-  m_indices.add_multiple(byte_names);
-  m_indices.add_multiple(float_names);
-  m_indices.add_multiple(float3_names);
+  m_indices.add_multiple_new(byte_names);
+  m_indices.add_multiple_new(float_names);
+  m_indices.add_multiple_new(float3_names);
   BLI_assert(m_indices.size() == byte_names.size() + float_names.size() + float3_names.size());
 
   m_byte_attributes = Range<uint>(0, byte_names.size());
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index f78d3d5b2dc..e59e342785a 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -161,13 +161,6 @@ class ModifierParticleType : public ParticleType {
   {
     interface.use(AttributeType::Float3, "Position");
     interface.use(AttributeType::Float3, "Velocity");
-
-    for (Event *event : m_events) {
-      CustomEvent *custom_event = dynamic_cast<CustomEvent *>(event);
-      if (custom_event != nullptr) {
-        custom_event->attributes(interface);
-      }
-    }
   }
 };
 
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index f67dd17f6a8..104945be238 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -64,6 +64,11 @@ class Event {
    * already. However, the attributes of new particles can be changed.
    */
   virtual void execute(EventExecuteInterface &interface) = 0;
+
+  /**
+   * Allows to define which attributes are required by the event.
+   */
+  virtual void attributes(TypeAttributeInterface &interface);
 };
 
 /**
@@ -128,10 +133,9 @@ class ParticleType {
   virtual ArrayRef<Event *> events() = 0;
 
   /**
-   * Determines which attributes have to be stored for particles of this type. The actual number of
-   * attributes might be larger.
+   * Allows to define which attributes should exist for the type.
    */
-  virtual void attributes(TypeAttributeInterface &interface) = 0;
+  virtual void attributes(TypeAttributeInterface &interface);
 };
 
 /**
@@ -673,6 +677,20 @@ class TypeAttributeInterface {
   ArrayRef<AttributeType> types();
 };
 
+/* Event inline functions
+ ********************************************/
+
+inline void Event::attributes(TypeAttributeInterface &UNUSED(interface))
+{
+}
+
+/* ParticleType inline functions
+ ********************************************/
+
+inline void ParticleType::attributes(TypeAttributeInterface &UNUSED(interface))
+{
+}
+
 /* ParticlesState inline functions
  ********************************************/
 
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index 02977d37ccf..47c15014479 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -8,11 +8,7 @@
 
 namespace BParticles {
 
-CustomEvent::~CustomEvent()
-{
-}
-
-class AgeReachedEvent : public CustomEvent {
+class AgeReachedEvent : public Event {
  private:
   std::string m_identifier;
   SharedFunction m_compute_age_fn;
@@ -162,9 +158,7 @@ class MeshCollisionEventFilter : public Event {
   }
 };
 
-CustomEvent *EVENT_age_reached(StringRef identifier,
-                               SharedFunction &compute_age_fn,
-                               Action *action)
+Event *EVENT_age_reached(StringRef identifier, SharedFunction &compute_age_fn, Action *action)
 {
   return new AgeReachedEvent(identifier, compute_age_fn, std::unique_ptr<Action>(action));
 }
diff --git a/source/blender/simulations/bparticles/events.hpp b/source/blender/simulations/bparticles/events.hpp
index 52fdeb30d10..9d42a5c740b 100644
--- a/source/blender/simulations/bparticles/events.hpp
+++ b/source/blender/simulations/bparticles/events.hpp
@@ -9,18 +9,7 @@ namespace BParticles {
 
 using BLI::float4x4;
 
-class CustomEvent : public Event {
- public:
-  virtual ~CustomEvent();
-
-  virtual void attributes(TypeAttributeInterface &UNUSED(interface))
-  {
-  }
-};
-
 Event *EVENT_mesh_collision(StringRef identifier, Object *object, Action *action);
-CustomEvent *EVENT_age_reached(StringRef identifier,
-                               SharedFunction &compute_age_fn,
-                               Action *action);
+Event *EVENT_age_reached(StringRef identifier, SharedFunction &compute_age_fn, Action *action);
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 5c666931e82..cd2754ac4e6 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -656,6 +656,10 @@ BLI_NOINLINE static AttributesInfo build_attribute_info_for_type(ParticleType &t
   TypeAttributeInterface interface;
   type.attributes(interface);
 
+  for (Event *event : type.events()) {
+    event->attributes(interface);
+  }
+
   SmallSetVector<std::string> byte_attributes = {"Kill State"};
   SmallSetVector<std::string> float_attributes = {"Birth Time"};
   SmallSetVector<std::string> float3_attributes = {};



More information about the Bf-blender-cvs mailing list