[Bf-blender-cvs] [6d208e31832] functions: remove indirection

Jacques Lucke noreply at git.blender.org
Mon Jul 15 18:12:54 CEST 2019


Commit: 6d208e318328f223ebef26eea3bdaa1244c30b2d
Author: Jacques Lucke
Date:   Mon Jul 15 16:54:47 2019 +0200
Branches: functions
https://developer.blender.org/rB6d208e318328f223ebef26eea3bdaa1244c30b2d

remove indirection

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

M	source/blender/simulations/bparticles/forces.cpp
M	source/blender/simulations/bparticles/forces.hpp
M	source/blender/simulations/bparticles/inserters.cpp

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

diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp
index d1ffcdd4785..28d00e9355d 100644
--- a/source/blender/simulations/bparticles/forces.cpp
+++ b/source/blender/simulations/bparticles/forces.cpp
@@ -8,77 +8,40 @@ Force::~Force()
 {
 }
 
-class GravityForce : public Force {
- private:
-  SharedFunction m_compute_acceleration_fn;
-  TupleCallBody *m_compute_acceleration_body;
-
- public:
-  GravityForce(SharedFunction &compute_acceleration_fn)
-      : m_compute_acceleration_fn(compute_acceleration_fn)
-  {
-    m_compute_acceleration_body = m_compute_acceleration_fn->body<TupleCallBody>();
-  }
-
-  void add_force(ParticlesBlock &block, ArrayRef<float3> r_force) override
-  {
-    FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_acceleration_body, fn_in, fn_out);
-
-    FN::ExecutionStack stack;
-    FN::ExecutionContext execution_context(stack);
-
-    m_compute_acceleration_body->call(fn_in, fn_out, execution_context);
+void GravityForce::add_force(ParticlesBlock &block, ArrayRef<float3> r_force)
+{
+  FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_acceleration_body, fn_in, fn_out);
 
-    float3 acceleration = fn_out.get<float3>(0);
+  FN::ExecutionStack stack;
+  FN::ExecutionContext execution_context(stack);
 
-    for (uint i = 0; i < block.active_amount(); i++) {
-      r_force[i] += acceleration;
-    }
-  };
-};
+  m_compute_acceleration_body->call(fn_in, fn_out, execution_context);
 
-class TurbulenceForce : public Force {
- private:
-  SharedFunction m_compute_strength_fn;
-  TupleCallBody *m_compute_strength_body;
+  float3 acceleration = fn_out.get<float3>(0);
 
- public:
-  TurbulenceForce(SharedFunction &compute_strength_fn) : m_compute_strength_fn(compute_strength_fn)
-  {
-    m_compute_strength_body = m_compute_strength_fn->body<TupleCallBody>();
+  for (uint i = 0; i < block.active_amount(); i++) {
+    r_force[i] += acceleration;
   }
+};
 
-  void add_force(ParticlesBlock &block, ArrayRef<float3> r_force) override
-  {
-    auto positions = block.attributes().get_float3("Position");
+void TurbulenceForce::add_force(ParticlesBlock &block, ArrayRef<float3> r_force)
+{
+  auto positions = block.attributes().get_float3("Position");
 
-    FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_strength_body, fn_in, fn_out);
-    FN::ExecutionStack stack;
-    FN::ExecutionContext execution_context(stack);
-    m_compute_strength_body->call(fn_in, fn_out, execution_context);
+  FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_strength_body, fn_in, fn_out);
+  FN::ExecutionStack stack;
+  FN::ExecutionContext execution_context(stack);
+  m_compute_strength_body->call(fn_in, fn_out, execution_context);
 
-    float3 strength = fn_out.get<float3>(0);
+  float3 strength = fn_out.get<float3>(0);
 
-    for (uint pindex = 0; pindex < block.active_amount(); pindex++) {
-      float3 pos = positions[pindex];
-      float x = (BLI_gNoise(0.5f, pos.x, pos.y, pos.z + 1000.0f, false, 1) - 0.5f) * strength.x;
-      float y = (BLI_gNoise(0.5f, pos.x, pos.y + 1000.0f, pos.z, false, 1) - 0.5f) * strength.y;
-      float z = (BLI_gNoise(0.5f, pos.x + 1000.0f, pos.y, pos.z, false, 1) - 0.5f) * strength.z;
-      r_force[pindex] += {x, y, z};
-    }
+  for (uint pindex = 0; pindex < block.active_amount(); pindex++) {
+    float3 pos = positions[pindex];
+    float x = (BLI_gNoise(0.5f, pos.x, pos.y, pos.z + 1000.0f, false, 1) - 0.5f) * strength.x;
+    float y = (BLI_gNoise(0.5f, pos.x, pos.y + 1000.0f, pos.z, false, 1) - 0.5f) * strength.y;
+    float z = (BLI_gNoise(0.5f, pos.x + 1000.0f, pos.y, pos.z, false, 1) - 0.5f) * strength.z;
+    r_force[pindex] += {x, y, z};
   }
-};
-
-std::unique_ptr<Force> FORCE_gravity(SharedFunction &compute_acceleration_fn)
-{
-  Force *force = new GravityForce(compute_acceleration_fn);
-  return std::unique_ptr<Force>(force);
-}
-
-std::unique_ptr<Force> FORCE_turbulence(SharedFunction &compute_strength_fn)
-{
-  Force *force = new TurbulenceForce(compute_strength_fn);
-  return std::unique_ptr<Force>(force);
 }
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/forces.hpp b/source/blender/simulations/bparticles/forces.hpp
index 862eee7f025..074bef42e71 100644
--- a/source/blender/simulations/bparticles/forces.hpp
+++ b/source/blender/simulations/bparticles/forces.hpp
@@ -11,7 +11,33 @@ class Force {
   virtual void add_force(ParticlesBlock &block, ArrayRef<float3> r_force) = 0;
 };
 
-std::unique_ptr<Force> FORCE_gravity(SharedFunction &compute_acceleration_fn);
-std::unique_ptr<Force> FORCE_turbulence(SharedFunction &compute_strength_fn);
+class GravityForce : public Force {
+ private:
+  SharedFunction m_compute_acceleration_fn;
+  TupleCallBody *m_compute_acceleration_body;
+
+ public:
+  GravityForce(SharedFunction &compute_acceleration_fn)
+      : m_compute_acceleration_fn(compute_acceleration_fn)
+  {
+    m_compute_acceleration_body = m_compute_acceleration_fn->body<TupleCallBody>();
+  }
+
+  void add_force(ParticlesBlock &block, ArrayRef<float3> r_force) override;
+};
+
+class TurbulenceForce : public Force {
+ private:
+  SharedFunction m_compute_strength_fn;
+  TupleCallBody *m_compute_strength_body;
+
+ public:
+  TurbulenceForce(SharedFunction &compute_strength_fn) : m_compute_strength_fn(compute_strength_fn)
+  {
+    m_compute_strength_body = m_compute_strength_fn->body<TupleCallBody>();
+  }
+
+  void add_force(ParticlesBlock &block, ArrayRef<float3> r_force) override;
+};
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index 33cbffb7c02..358037e0395 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -198,13 +198,13 @@ static std::unique_ptr<Action> build_action(BuildContext &ctx, SocketWithNode st
 static std::unique_ptr<Force> BUILD_FORCE_gravity(BuildContext &ctx, bNode *bnode)
 {
   SharedFunction fn = create_function_for_data_inputs(bnode, ctx.indexed_tree, ctx.data_graph);
-  return FORCE_gravity(fn);
+  return std::unique_ptr<Force>(new GravityForce(fn));
 }
 
 static std::unique_ptr<Force> BUILD_FORCE_turbulence(BuildContext &ctx, bNode *bnode)
 {
   SharedFunction fn = create_function_for_data_inputs(bnode, ctx.indexed_tree, ctx.data_graph);
-  return FORCE_turbulence(fn);
+  return std::unique_ptr<Force>(new TurbulenceForce(fn));
 }
 
 static std::unique_ptr<Event> Build_EVENT_mesh_collision(BuildContext &ctx, bNode *bnode)



More information about the Bf-blender-cvs mailing list