[Bf-blender-cvs] [d0eed2a7ac2] functions: change how particle types declare which attributes they need

Jacques Lucke noreply at git.blender.org
Thu Jul 18 18:19:32 CEST 2019


Commit: d0eed2a7ac2491276545dbe831f114cd4fb99c46
Author: Jacques Lucke
Date:   Thu Jul 18 15:23:45 2019 +0200
Branches: functions
https://developer.blender.org/rBd0eed2a7ac2491276545dbe831f114cd4fb99c46

change how particle types declare which attributes they need

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

M	source/blender/simulations/bparticles/attributes.cpp
M	source/blender/simulations/bparticles/attributes.hpp
M	source/blender/simulations/bparticles/core.cpp
M	source/blender/simulations/bparticles/core.hpp
M	source/blender/simulations/bparticles/node_frontend.cpp
M	source/blender/simulations/bparticles/simulate.cpp
M	source/blender/simulations/bparticles/step_description.hpp

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

diff --git a/source/blender/simulations/bparticles/attributes.cpp b/source/blender/simulations/bparticles/attributes.cpp
index 8ed3fc6f9e9..626fb2e2ff2 100644
--- a/source/blender/simulations/bparticles/attributes.cpp
+++ b/source/blender/simulations/bparticles/attributes.cpp
@@ -2,6 +2,44 @@
 
 namespace BParticles {
 
+void AttributesDeclaration::join(AttributesDeclaration &other)
+{
+  for (uint i = 0; i < other.m_byte_names.size(); i++) {
+    if (m_byte_names.add(other.m_byte_names[i])) {
+      m_byte_defaults.append(other.m_byte_defaults[i]);
+    }
+  }
+  for (uint i = 0; i < other.m_float_names.size(); i++) {
+    if (m_float_names.add(other.m_float_names[i])) {
+      m_float_defaults.append(other.m_float_defaults[i]);
+    }
+  }
+  for (uint i = 0; i < other.m_float3_names.size(); i++) {
+    if (m_float3_names.add(other.m_float3_names[i])) {
+      m_float3_defaults.append(other.m_float3_defaults[i]);
+    }
+  }
+}
+
+void AttributesDeclaration::join(AttributesInfo &other)
+{
+  for (uint i : other.byte_attributes()) {
+    if (m_byte_names.add(other.name_of(i).to_std_string())) {
+      m_byte_defaults.append(*(uint8_t *)other.default_value_ptr(i));
+    }
+  }
+  for (uint i : other.float_attributes()) {
+    if (m_float_names.add(other.name_of(i).to_std_string())) {
+      m_float_defaults.append(*(float *)other.default_value_ptr(i));
+    }
+  }
+  for (uint i : other.float3_attributes()) {
+    if (m_float3_names.add(other.name_of(i).to_std_string())) {
+      m_float3_defaults.append(*(float3 *)other.default_value_ptr(i));
+    }
+  }
+}
+
 AttributesInfo::AttributesInfo(AttributesDeclaration &builder)
     : AttributesInfo(builder.m_byte_names,
                      builder.m_float_names,
diff --git a/source/blender/simulations/bparticles/attributes.hpp b/source/blender/simulations/bparticles/attributes.hpp
index 5f7f010255a..5cffb7fbbed 100644
--- a/source/blender/simulations/bparticles/attributes.hpp
+++ b/source/blender/simulations/bparticles/attributes.hpp
@@ -72,6 +72,9 @@ class AttributesDeclaration {
   void add_byte(StringRef name, uint8_t default_value);
   void add_float(StringRef name, float default_value);
   void add_float3(StringRef name, float3 default_value);
+
+  void join(AttributesDeclaration &other);
+  void join(AttributesInfo &other);
 };
 
 /**
diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp
index e66ba6373c6..ee666c130dc 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -14,6 +14,10 @@ Event::~Event()
 {
 }
 
+void Event::attributes(AttributesDeclaration &UNUSED(interface))
+{
+}
+
 OffsetHandler::~OffsetHandler()
 {
 }
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 7bc90cca030..414322d3205 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -148,7 +148,7 @@ class ParticleType {
   /**
    * Allows to define which attributes should exist for the type.
    */
-  virtual void attributes(AttributesDeclaration &interface);
+  virtual AttributesDeclaration &attributes() = 0;
 };
 
 /**
@@ -596,20 +596,6 @@ class OffsetHandlerInterface {
   TimeSpan time_span(uint pindex);
 };
 
-/* Event inline functions
- ********************************************/
-
-inline void Event::attributes(AttributesDeclaration &UNUSED(builder))
-{
-}
-
-/* ParticleType inline functions
- ********************************************/
-
-inline void ParticleType::attributes(AttributesDeclaration &UNUSED(builder))
-{
-}
-
 /* ParticlesState inline functions
  ********************************************/
 
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index 8260a45b1d2..74a46c6bc3c 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -37,6 +37,11 @@ std::unique_ptr<StepDescription> step_description_from_node_tree(IndexedNodeTree
     EulerIntegrator *integrator = new EulerIntegrator();
     euler_integrators.add_new(particle_type_node->name, integrator);
     type_builder.set_integrator(integrator);
+    auto &attributes = type_builder.attributes();
+    attributes.add_float3("Position", {0, 0, 0});
+    attributes.add_float3("Velocity", {0, 0, 0});
+    attributes.add_float("Size", 0.01f);
+    attributes.add_float3("Color", {1.0f, 1.0f, 1.0f});
   }
 
   auto data_graph = FN::DataFlowNodes::generate_graph(indexed_tree).value();
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index c4589ffa548..90f7116cd4e 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -546,10 +546,11 @@ BLI_NOINLINE static void ensure_required_containers_exist(ParticlesState &state,
 }
 
 BLI_NOINLINE static AttributesInfo build_attribute_info_for_type(ParticleType &type,
-                                                                 AttributesInfo &UNUSED(last_info))
+                                                                 AttributesInfo &last_info)
 {
   AttributesDeclaration builder;
-  type.attributes(builder);
+  builder.join(last_info);
+  builder.join(type.attributes());
 
   for (Event *event : type.events()) {
     event->attributes(builder);
diff --git a/source/blender/simulations/bparticles/step_description.hpp b/source/blender/simulations/bparticles/step_description.hpp
index 5e06e796613..fa61ae5b3da 100644
--- a/source/blender/simulations/bparticles/step_description.hpp
+++ b/source/blender/simulations/bparticles/step_description.hpp
@@ -9,6 +9,7 @@ class ModifierParticleType : public ParticleType {
   SmallVector<Event *> m_events;
   SmallVector<OffsetHandler *> m_offset_handlers;
   Integrator *m_integrator;
+  AttributesDeclaration m_attributes;
 
   ~ModifierParticleType()
   {
@@ -34,12 +35,9 @@ class ModifierParticleType : public ParticleType {
     return *m_integrator;
   }
 
-  void attributes(AttributesDeclaration &builder) override
+  AttributesDeclaration &attributes() override
   {
-    builder.add_float3("Position", {0, 0, 0});
-    builder.add_float3("Velocity", {0, 0, 0});
-    builder.add_float("Size", 0.01f);
-    builder.add_float3("Color", {1.0f, 1.0f, 1.0f});
+    return m_attributes;
   }
 };
 
@@ -80,6 +78,7 @@ class ParticleTypeBuilder {
   Integrator *m_integrator;
   SmallVector<Event *> m_events;
   SmallVector<OffsetHandler *> m_offset_handlers;
+  AttributesDeclaration m_attributes;
 
  public:
   ParticleTypeBuilder() = default;
@@ -99,6 +98,11 @@ class ParticleTypeBuilder {
     m_offset_handlers.append(offset_handler.release());
   }
 
+  AttributesDeclaration &attributes()
+  {
+    return m_attributes;
+  }
+
   ParticleType *build()
   {
     BLI_assert(m_integrator);
@@ -106,6 +110,7 @@ class ParticleTypeBuilder {
     type->m_integrator = m_integrator;
     type->m_events = m_events;
     type->m_offset_handlers = m_offset_handlers;
+    type->m_attributes = m_attributes;
     m_events.clear();
     m_offset_handlers.clear();
     return type;



More information about the Bf-blender-cvs mailing list