[Bf-blender-cvs] [d9f02f209b6] functions: further simplify usage of particle function

Jacques Lucke noreply at git.blender.org
Wed Jul 24 19:11:57 CEST 2019


Commit: d9f02f209b62b6a84fb05434704cb7561efd92cc
Author: Jacques Lucke
Date:   Wed Jul 24 15:09:55 2019 +0200
Branches: functions
https://developer.blender.org/rBd9f02f209b62b6a84fb05434704cb7561efd92cc

further simplify usage of particle function

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

M	source/blender/simulations/bparticles/actions.cpp
M	source/blender/simulations/bparticles/particle_function.cpp
M	source/blender/simulations/bparticles/particle_function.hpp

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

diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index fe285915c79..db210dd48b8 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -16,7 +16,7 @@ void ChangeDirectionAction::execute(ActionInterface &interface)
   auto velocity_offsets = interface.attribute_offsets().try_get_float3("Velocity");
 
   auto caller = m_compute_inputs.get_caller(interface);
-  auto new_directions = caller.add_output<float3>(interface.array_allocator());
+  auto new_directions = caller.add_output<float3>();
   caller.call(particles.pindices());
 
   for (uint pindex : particles.pindices()) {
@@ -63,8 +63,8 @@ void ExplodeAction::execute(ActionInterface &interface)
   Vector<float> new_birth_times;
 
   auto caller = m_compute_inputs.get_caller(interface);
-  auto parts_amounts = caller.add_output<int>(interface.array_allocator());
-  auto speeds = caller.add_output<float>(interface.array_allocator());
+  auto parts_amounts = caller.add_output<int>();
+  auto speeds = caller.add_output<float>();
   caller.call(particles.pindices());
 
   for (uint pindex : particles.pindices()) {
@@ -94,7 +94,7 @@ void ConditionAction::execute(ActionInterface &interface)
   ParticleSet particles = interface.particles();
 
   auto caller = m_compute_inputs.get_caller(interface);
-  auto conditions = caller.add_output<bool>(interface.array_allocator());
+  auto conditions = caller.add_output<bool>();
   caller.call(particles.pindices());
 
   Vector<uint> true_pindices, false_pindices;
diff --git a/source/blender/simulations/bparticles/particle_function.cpp b/source/blender/simulations/bparticles/particle_function.cpp
index c3c790f6c56..aec56857fe3 100644
--- a/source/blender/simulations/bparticles/particle_function.cpp
+++ b/source/blender/simulations/bparticles/particle_function.cpp
@@ -4,20 +4,19 @@ namespace BParticles {
 
 ParticleFunctionCaller ParticleFunction::get_caller(ActionInterface &action_interface)
 {
-  return this->get_caller(action_interface.particles().attributes(), &action_interface.context());
+  return this->get_caller(action_interface.array_allocator(),
+                          action_interface.particles().attributes(),
+                          &action_interface.context());
 }
 
-ParticleFunctionCaller ParticleFunction::get_caller(AttributeArrays attributes)
-{
-  return this->get_caller(attributes, nullptr);
-}
-
-ParticleFunctionCaller ParticleFunction::get_caller(AttributeArrays attributes,
+ParticleFunctionCaller ParticleFunction::get_caller(ArrayAllocator &array_allocator,
+                                                    AttributeArrays attributes,
                                                     ActionContext *action_context)
 {
   ParticleFunctionCaller caller;
   caller.m_body = m_body;
   caller.m_min_buffer_length = attributes.size();
+  caller.m_array_allocator = &array_allocator;
 
   for (uint i = 0; i < m_fn->input_amount(); i++) {
     StringRef input_name = m_fn->input_name(i);
diff --git a/source/blender/simulations/bparticles/particle_function.hpp b/source/blender/simulations/bparticles/particle_function.hpp
index 4a92d090fb1..8e11533385b 100644
--- a/source/blender/simulations/bparticles/particle_function.hpp
+++ b/source/blender/simulations/bparticles/particle_function.hpp
@@ -25,6 +25,7 @@ class ParticleFunctionCaller {
   Vector<void *> m_output_buffers;
   Vector<uint> m_input_strides;
   Vector<uint> m_output_strides;
+  ArrayAllocator *m_array_allocator;
 
   friend ParticleFunction;
 
@@ -44,9 +45,9 @@ class ParticleFunctionCaller {
     m_output_strides.append(sizeof(T));
   }
 
-  template<typename T> ArrayAllocator::Array<T> add_output(ArrayAllocator &allocator)
+  template<typename T> ArrayAllocator::Array<T> add_output()
   {
-    ArrayAllocator::Array<T> array(allocator);
+    ArrayAllocator::Array<T> array(*m_array_allocator);
     this->add_output(array.as_array_ref());
     return array;
   }
@@ -90,10 +91,10 @@ class ParticleFunction {
 
   ParticleFunctionCaller get_caller(ActionInterface &action_interface);
 
-  ParticleFunctionCaller get_caller(AttributeArrays attributes);
-
  private:
-  ParticleFunctionCaller get_caller(AttributeArrays attributes, ActionContext *action_context);
+  ParticleFunctionCaller get_caller(ArrayAllocator &array_allocator,
+                                    AttributeArrays attributes,
+                                    ActionContext *action_context);
 };
 
 }  // namespace BParticles



More information about the Bf-blender-cvs mailing list