[Bf-blender-cvs] [24c5a219774] functions: remove redundant particle type name storage

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


Commit: 24c5a2197748137834c15ca3995ed68f2eecc848
Author: Jacques Lucke
Date:   Thu Jul 18 14:30:53 2019 +0200
Branches: functions
https://developer.blender.org/rB24c5a2197748137834c15ca3995ed68f2eecc848

remove redundant particle type name storage

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

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/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 625266df706..27941ae8ba2 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -168,15 +168,7 @@ class StepDescription {
    */
   virtual ArrayRef<Emitter *> emitters() = 0;
 
-  /**
-   * Return the particle type ids that will be modified in this step.
-   */
-  virtual ArrayRef<std::string> particle_type_names() = 0;
-
-  /**
-   * Return the description of a particle type based on its id.
-   */
-  virtual ParticleType &particle_type(StringRef name) = 0;
+  virtual StringMap<ParticleType *> &particle_types() = 0;
 };
 
 /* Classes used by the interface
@@ -229,7 +221,7 @@ class ParticlesState {
   /**
    * Get the name of a container in the context of this particle state.
    */
-  StringRefNull particle_container_id(ParticlesContainer &container);
+  StringRefNull particle_container_name(ParticlesContainer &container);
 };
 
 /**
@@ -631,7 +623,7 @@ inline ParticlesContainer &ParticlesState::particle_container(StringRef name)
   return *m_container_by_id.lookup(name.to_std_string());
 }
 
-inline StringRefNull ParticlesState::particle_container_id(ParticlesContainer &container)
+inline StringRefNull ParticlesState::particle_container_name(ParticlesContainer &container)
 {
   for (auto item : m_container_by_id.items()) {
     if (item.value == &container) {
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index b259f66a4fd..bd437459609 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -37,7 +37,6 @@ std::unique_ptr<StepDescription> step_description_from_node_tree(IndexedNodeTree
 
     std::string type_name = particle_type_node->name;
     step_description->m_types.add_new(type_name, type);
-    step_description->m_particle_type_names.append(type_name);
   }
 
   auto data_graph = FN::DataFlowNodes::generate_graph(indexed_tree).value();
@@ -51,9 +50,9 @@ std::unique_ptr<StepDescription> step_description_from_node_tree(IndexedNodeTree
         if (is_particle_type_node(linked.node)) {
           auto force = item.value(ctx, bnode);
           if (force) {
-            EulerIntegrator *integrator = reinterpret_cast<EulerIntegrator *>(
-                step_description->m_types.lookup_ref(linked.node->name)->m_integrator);
-            integrator->add_force(std::move(force));
+            EulerIntegrator &integrator = reinterpret_cast<EulerIntegrator &>(
+                step_description->m_types.lookup_ref(linked.node->name)->integrator());
+            integrator.add_force(std::move(force));
           }
         }
       }
@@ -67,8 +66,9 @@ std::unique_ptr<StepDescription> step_description_from_node_tree(IndexedNodeTree
         if (is_particle_type_node(linked.node)) {
           auto listener = item.value(ctx, bnode);
           if (listener) {
-            step_description->m_types.lookup_ref(linked.node->name)
-                ->m_offset_handlers.append(listener.release());
+            ModifierParticleType &particle_type =
+                *(ModifierParticleType *)step_description->m_types.lookup(linked.node->name);
+            particle_type.m_offset_handlers.append(listener.release());
           }
         }
       }
@@ -82,8 +82,9 @@ std::unique_ptr<StepDescription> step_description_from_node_tree(IndexedNodeTree
         if (is_particle_type_node(linked.node)) {
           auto event = item.value(ctx, bnode);
           if (event) {
-            step_description->m_types.lookup_ref(linked.node->name)
-                ->m_events.append(event.release());
+            ModifierParticleType &particle_type =
+                *(ModifierParticleType *)step_description->m_types.lookup(linked.node->name);
+            particle_type.m_events.append(event.release());
           }
         }
       }
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index f3f62f1c9d9..951aaf8335f 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -430,8 +430,9 @@ BLI_NOINLINE static void simulate_blocks_for_time_span(ParticleAllocators &block
       /* Process individual element. */
       [&step_description, time_span](ParticlesBlock *block, ThreadLocalData *local_data) {
         ParticlesState &state = local_data->particle_allocator.particles_state();
-        StringRef particle_type_name = state.particle_container_id(block->container());
-        ParticleType &particle_type = step_description.particle_type(particle_type_name);
+        StringRef particle_type_name = state.particle_container_name(block->container());
+        ParticleType &particle_type = *step_description.particle_types().lookup(
+            particle_type_name);
 
         ArrayAllocator &array_allocator = local_data->array_allocator;
         ArrayAllocator::Array<float> remaining_durations(array_allocator, block->active_amount());
@@ -471,8 +472,9 @@ BLI_NOINLINE static void simulate_blocks_from_birth_to_current_time(
       /* Process individual element. */
       [&step_description, end_time](ParticlesBlock *block, ThreadLocalData *local_data) {
         ParticlesState &state = local_data->particle_allocator.particles_state();
-        StringRef particle_type_id = state.particle_container_id(block->container());
-        ParticleType &particle_type = step_description.particle_type(particle_type_id);
+        StringRef particle_type_name = state.particle_container_name(block->container());
+        ParticleType &particle_type = *step_description.particle_types().lookup(
+            particle_type_name);
 
         uint active_amount = block->active_amount();
         SmallVector<float> durations(active_amount);
@@ -498,11 +500,11 @@ BLI_NOINLINE static void simulate_blocks_from_birth_to_current_time(
       USE_THREADING);
 }
 
-BLI_NOINLINE static SmallVector<ParticlesBlock *> get_all_blocks(
-    ParticlesState &state, ArrayRef<std::string> particle_type_names)
+BLI_NOINLINE static SmallVector<ParticlesBlock *> get_all_blocks(ParticlesState &state,
+                                                                 StepDescription &step_description)
 {
   SmallVector<ParticlesBlock *> blocks;
-  for (StringRef particle_type_name : particle_type_names) {
+  for (auto particle_type_name : step_description.particle_types().keys()) {
     ParticlesContainer &container = state.particle_container(particle_type_name);
     for (ParticlesBlock *block : container.active_blocks()) {
       blocks.append(block);
@@ -535,7 +537,7 @@ BLI_NOINLINE static void ensure_required_containers_exist(ParticlesState &state,
 {
   auto &containers = state.particle_containers();
 
-  for (std::string &type_name : description.particle_type_names()) {
+  for (std::string type_name : description.particle_types().keys()) {
     if (!containers.contains(type_name)) {
       ParticlesContainer *container = new ParticlesContainer({}, 100);
       containers.add_new(type_name, container);
@@ -564,12 +566,11 @@ BLI_NOINLINE static void ensure_required_attributes_exist(ParticlesState &state,
 {
   auto &containers = state.particle_containers();
 
-  for (std::string &type_name : description.particle_type_names()) {
-    ParticleType &type = description.particle_type(type_name);
-    ParticlesContainer &container = *containers.lookup(type_name);
+  for (auto item : description.particle_types().items()) {
+    ParticlesContainer &container = *containers.lookup(item.key);
 
     AttributesInfo new_attributes_info = build_attribute_info_for_type(
-        type, container.attributes_info());
+        *item.value, container.attributes_info());
     container.update_attributes(new_attributes_info);
   }
 }
@@ -580,8 +581,7 @@ BLI_NOINLINE static void simulate_all_existing_blocks(ParticlesState &state,
                                                       TimeSpan time_span,
                                                       uint max_block_size)
 {
-  SmallVector<ParticlesBlock *> blocks = get_all_blocks(state,
-                                                        step_description.particle_type_names());
+  SmallVector<ParticlesBlock *> blocks = get_all_blocks(state, step_description);
   simulate_blocks_for_time_span(
       block_allocators, blocks, step_description, time_span, max_block_size);
 }
diff --git a/source/blender/simulations/bparticles/step_description.hpp b/source/blender/simulations/bparticles/step_description.hpp
index 161d6ead182..8baab3a109b 100644
--- a/source/blender/simulations/bparticles/step_description.hpp
+++ b/source/blender/simulations/bparticles/step_description.hpp
@@ -46,9 +46,8 @@ class ModifierParticleType : public ParticleType {
 class ModifierStepDescription : public StepDescription {
  public:
   float m_duration;
-  StringMap<ModifierParticleType *> m_types;
+  StringMap<ParticleType *> m_types;
   SmallVector<Emitter *> m_emitters;
-  SmallVector<std::string> m_particle_type_names;
 
   ~ModifierStepDescription()
   {
@@ -70,14 +69,9 @@ class ModifierStepDescription : public StepDescription {
     return m_emitters;
   }
 
-  ArrayRef<std::string> particle_type_names() override
+  StringMap<ParticleType *> &particle_types() override
   {
-    return m_particle_type_names;
-  }
-
-  ParticleType &particle_type(StringRef type_name) override
-  {
-    return *m_types.lookup(type_name.to_std_string());
+    return m_types;
   }
 };



More information about the Bf-blender-cvs mailing list