[Bf-blender-cvs] [28c4b3e6f82] functions: identify particle types with name instead of integer

Jacques Lucke noreply at git.blender.org
Thu Jul 4 16:45:44 CEST 2019


Commit: 28c4b3e6f8223f2371d07b59e6ee50f8cadcf132
Author: Jacques Lucke
Date:   Thu Jul 4 10:20:32 2019 +0200
Branches: functions
https://developer.blender.org/rB28c4b3e6f8223f2371d07b59e6ee50f8cadcf132

identify particle types with name instead of integer

While this might be less efficient, it is much more comfortable to work with.
Also it might be possible to make it a bit more efficient again in the future.

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

M	source/blender/simulations/bparticles/actions.cpp
M	source/blender/simulations/bparticles/actions.hpp
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/emitters.cpp
M	source/blender/simulations/bparticles/emitters.hpp
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index 5b48ef562f7..ba780ba2ae7 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -72,6 +72,15 @@ static float3 random_direction()
 }
 
 class ExplodeAction : public Action {
+ private:
+  std::string m_new_particle_name;
+
+ public:
+  ExplodeAction(StringRef new_particle_name)
+      : m_new_particle_name(new_particle_name.to_std_string())
+  {
+  }
+
   void execute(EventExecuteInterface &interface) override
   {
     ParticleSet &particles = interface.particles();
@@ -94,7 +103,7 @@ class ExplodeAction : public Action {
       }
     }
 
-    auto &target = interface.request_emit_target(1, original_indices);
+    auto &target = interface.request_emit_target(m_new_particle_name, original_indices);
     target.set_float3("Position", new_positions);
     target.set_float3("Velocity", new_velocities);
 
@@ -117,9 +126,9 @@ Action *ACTION_spawn()
   return new SpawnAction();
 }
 
-Action *ACTION_explode()
+Action *ACTION_explode(StringRef new_particle_name)
 {
-  return new ExplodeAction();
+  return new ExplodeAction(new_particle_name);
 }
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/actions.hpp b/source/blender/simulations/bparticles/actions.hpp
index 92da0bf0f39..f38da1726c1 100644
--- a/source/blender/simulations/bparticles/actions.hpp
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -14,6 +14,6 @@ class Action {
 Action *ACTION_kill();
 Action *ACTION_move(float3 offset);
 Action *ACTION_spawn();
-Action *ACTION_explode();
+Action *ACTION_explode(StringRef new_particle_name);
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 2cd2dcfce42..688ed9edeaa 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -190,9 +190,9 @@ class ModifierParticleType : public ParticleType {
 class ModifierStepDescription : public StepDescription {
  public:
   float m_duration;
-  SmallMap<uint, ModifierParticleType *> m_types;
+  SmallMap<std::string, ModifierParticleType *> m_types;
   SmallVector<Emitter *> m_emitters;
-  SmallVector<uint> m_particle_type_ids;
+  SmallVector<std::string> m_particle_type_names;
 
   ~ModifierStepDescription()
   {
@@ -214,14 +214,14 @@ class ModifierStepDescription : public StepDescription {
     return m_emitters;
   }
 
-  ArrayRef<uint> particle_type_ids() override
+  ArrayRef<std::string> particle_type_names() override
   {
-    return m_particle_type_ids;
+    return m_particle_type_names;
   }
 
-  ParticleType &particle_type(uint type_id) override
+  ParticleType &particle_type(StringRef type_name) override
   {
-    return *m_types.lookup(type_id);
+    return *m_types.lookup(type_name.to_std_string());
   }
 };
 
@@ -253,17 +253,16 @@ static ModifierStepDescription *step_description_from_node_tree(bNodeTree *btree
   ModifierStepDescription *step_description = new ModifierStepDescription();
   BParticlesTreeQuery btree_query(btree);
 
-  SmallMap<bNode *, uint> id_per_type_node;
-
   auto type_nodes = btree_query.type_nodes();
   for (uint i = 0; i < type_nodes.size(); i++) {
     bNode *particle_type_node = type_nodes[i];
 
     ModifierParticleType *type = new ModifierParticleType();
     type->m_integrator = new EulerIntegrator();
-    step_description->m_types.add_new(i, type);
-    step_description->m_particle_type_ids.append(i);
-    id_per_type_node.add_new(particle_type_node, i);
+
+    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 emitter_nodes = btree_query.emitter_nodes();
@@ -271,8 +270,6 @@ static ModifierStepDescription *step_description_from_node_tree(bNodeTree *btree
     bNodeSocket *emitter_output = (bNodeSocket *)emitter_node->outputs.first;
     auto connected_nodes = btree_query.nodes_connected_to_socket(emitter_output);
     for (bNode *connected_node : connected_nodes) {
-      uint type_id = id_per_type_node.lookup(connected_node);
-
       PointerRNA rna;
       RNA_pointer_create(&btree->id, &RNA_Node, emitter_node, &rna);
       Object *object = (Object *)RNA_pointer_get(&rna, "object").id.data;
@@ -281,7 +278,7 @@ static ModifierStepDescription *step_description_from_node_tree(bNodeTree *btree
       }
 
       Emitter *emitter = EMITTER_mesh_surface(
-          type_id, (Mesh *)object->data, object->obmat, object->obmat, 1.0f);
+          connected_node->name, (Mesh *)object->data, object->obmat, object->obmat, 1.0f);
       step_description->m_emitters.append(emitter);
     }
   }
diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp
index f5831ee5372..e063e853f94 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -36,9 +36,9 @@ BlockAllocator::BlockAllocator(ParticlesState &state) : m_state(state)
 {
 }
 
-ParticlesBlock &BlockAllocator::get_non_full_block(uint particle_type_id)
+ParticlesBlock &BlockAllocator::get_non_full_block(StringRef particle_type_name)
 {
-  ParticlesContainer &container = m_state.particle_container(particle_type_id);
+  ParticlesContainer &container = m_state.particle_container(particle_type_name);
 
   uint index = 0;
   while (index < m_non_full_cache.size()) {
@@ -59,14 +59,14 @@ ParticlesBlock &BlockAllocator::get_non_full_block(uint particle_type_id)
   return block;
 }
 
-void BlockAllocator::allocate_block_ranges(uint particle_type_id,
+void BlockAllocator::allocate_block_ranges(StringRef particle_type_name,
                                            uint size,
                                            SmallVector<ParticlesBlock *> &r_blocks,
                                            SmallVector<Range<uint>> &r_ranges)
 {
   uint remaining_size = size;
   while (remaining_size > 0) {
-    ParticlesBlock &block = this->get_non_full_block(particle_type_id);
+    ParticlesBlock &block = this->get_non_full_block(particle_type_name);
 
     uint size_to_use = std::min(block.unused_amount(), remaining_size);
     Range<uint> range(block.active_amount(), block.active_amount() + size_to_use);
@@ -84,9 +84,9 @@ void BlockAllocator::allocate_block_ranges(uint particle_type_id,
   }
 }
 
-AttributesInfo &BlockAllocator::attributes_info(uint particle_type_id)
+AttributesInfo &BlockAllocator::attributes_info(StringRef particle_type_name)
 {
-  return m_state.particle_container(particle_type_id).attributes_info();
+  return m_state.particle_container(particle_type_name).attributes_info();
 }
 
 /* Emitter Interface
@@ -104,15 +104,15 @@ EmitterInterface::~EmitterInterface()
   }
 }
 
-TimeSpanEmitTarget &EmitterInterface::request(uint particle_type_id, uint size)
+TimeSpanEmitTarget &EmitterInterface::request(StringRef particle_type_name, uint size)
 {
   SmallVector<ParticlesBlock *> blocks;
   SmallVector<Range<uint>> ranges;
-  m_block_allocator.allocate_block_ranges(particle_type_id, size, blocks, ranges);
-  AttributesInfo &attributes_info = m_block_allocator.attributes_info(particle_type_id);
+  m_block_allocator.allocate_block_ranges(particle_type_name, size, blocks, ranges);
+  AttributesInfo &attributes_info = m_block_allocator.attributes_info(particle_type_name);
 
   auto *target = new TimeSpanEmitTarget(
-      particle_type_id, attributes_info, blocks, ranges, m_time_span);
+      particle_type_name, attributes_info, blocks, ranges, m_time_span);
   m_targets.append(target);
   return *target;
 }
@@ -127,17 +127,17 @@ EventExecuteInterface::~EventExecuteInterface()
   }
 }
 
-InstantEmitTarget &EventExecuteInterface::request_emit_target(uint particle_type_id,
+InstantEmitTarget &EventExecuteInterface::request_emit_target(StringRef particle_type_name,
                                                               ArrayRef<uint> original_indices)
 {
   uint size = original_indices.size();
 
   SmallVector<ParticlesBlock *> blocks;
   SmallVector<Range<uint>> ranges;
-  m_block_allocator.allocate_block_ranges(particle_type_id, size, blocks, ranges);
-  AttributesInfo &attributes_info = m_block_allocator.attributes_info(particle_type_id);
+  m_block_allocator.allocate_block_ranges(particle_type_name, size, blocks, ranges);
+  AttributesInfo &attributes_info = m_block_allocator.attributes_info(particle_type_name);
 
-  auto *target = new InstantEmitTarget(particle_type_id, attributes_info, blocks, ranges);
+  auto *target = new InstantEmitTarget(particle_type_name, attributes_info, blocks, ranges);
   m_emit_targets.append(target);
 
   SmallVector<float> birth_times(size);
@@ -152,11 +152,11 @@ InstantEmitTarget &EventExecuteInterface::request_emit_target(uint particle_type
 /* EmitTarget
  ******************************************/
 
-EmitTargetBase::EmitTargetBase(uint particle_type_id,
+EmitTargetBase::EmitTargetBase(StringRef particle_type_name,
                                AttributesInfo &attributes_info,
                                ArrayRef<ParticlesBlock *> blocks,
                                ArrayRef<Range<uint>> ranges)
-    : m_particle_type_id(particle_type_id),
+    : m_particle_type_name(particle_type_name.to_std_string()),
       m_attributes_info(attributes_info),
       m_blocks(blocks),
       m_ranges(ranges)
@@ -167,20 +167,20 @@ EmitTargetBase::EmitTargetBase(uint particle_type_id,
   }
 }
 
-InstantEmitTarget::InstantEmitTarget(uint particle_type_id,
+InstantEmitTarget::InstantEmitTarget(StringRef particle_type_name,
                                      AttributesInfo &attributes_info,
                                      ArrayRef<ParticlesBlock *> blocks,
                                      ArrayRef<Range<uint>> ranges)
-    : EmitTargetBase(particle_type_id, attributes_info, blocks, ranges)
+    : EmitTargetBase(particle_type_name, attributes_info, blocks, ranges)
 {
 }
 
-TimeSpanEmitTarget::TimeSpanEmitTarget(uint particle_type_id,
+TimeSpanEmitTarget::TimeSpa

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list