[Bf-blender-cvs] [6e86e314eff] functions: move action interface to separate file

Jacques Lucke noreply at git.blender.org
Mon Jul 8 17:57:27 CEST 2019


Commit: 6e86e314eff82efc114d0a5f438165654b700eac
Author: Jacques Lucke
Date:   Mon Jul 8 16:56:27 2019 +0200
Branches: functions
https://developer.blender.org/rB6e86e314eff82efc114d0a5f438165654b700eac

move action interface to separate file

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

M	source/blender/simulations/CMakeLists.txt
A	source/blender/simulations/bparticles/action_interface.cpp
A	source/blender/simulations/bparticles/action_interface.hpp
M	source/blender/simulations/bparticles/actions.hpp

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

diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
index bd8f5aa8ee2..ef9e04f4ab0 100644
--- a/source/blender/simulations/CMakeLists.txt
+++ b/source/blender/simulations/CMakeLists.txt
@@ -28,6 +28,8 @@ set(SRC
   bparticles/forces.cpp
   bparticles/actions.hpp
   bparticles/actions.cpp
+  bparticles/action_interface.hpp
+  bparticles/action_interface.cpp
   bparticles/events.hpp
   bparticles/events.cpp
   bparticles/attributes.hpp
diff --git a/source/blender/simulations/bparticles/action_interface.cpp b/source/blender/simulations/bparticles/action_interface.cpp
new file mode 100644
index 00000000000..f6c4a5ea96e
--- /dev/null
+++ b/source/blender/simulations/bparticles/action_interface.cpp
@@ -0,0 +1,38 @@
+#include "action_interface.hpp"
+
+namespace BParticles {
+
+ParticleFunctionCaller ParticleFunction::get_caller(AttributeArrays attributes,
+                                                    EventInfo &event_info)
+{
+  ParticleFunctionCaller caller;
+  caller.m_body = m_tuple_call;
+
+  for (uint i = 0; i < m_function->input_amount(); i++) {
+    StringRef input_name = m_function->input_name(i);
+    void *ptr = nullptr;
+    uint stride = 0;
+    if (input_name.startswith("Event")) {
+      StringRef event_attribute_name = input_name.drop_prefix("Event: ");
+      ptr = event_info.get_info_array(event_attribute_name);
+      stride = sizeof(float3); /* TODO make not hardcoded */
+    }
+    else if (input_name.startswith("Attribute")) {
+      StringRef attribute_name = input_name.drop_prefix("Attribute: ");
+      uint index = attributes.attribute_index(attribute_name);
+      stride = attributes.attribute_stride(index);
+      ptr = attributes.get_ptr(index);
+    }
+    else {
+      BLI_assert(false);
+    }
+
+    BLI_assert(ptr);
+    caller.m_attribute_buffers.append(ptr);
+    caller.m_strides.append(stride);
+  }
+
+  return caller;
+}
+
+}  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/action_interface.hpp b/source/blender/simulations/bparticles/action_interface.hpp
new file mode 100644
index 00000000000..e66af2c06aa
--- /dev/null
+++ b/source/blender/simulations/bparticles/action_interface.hpp
@@ -0,0 +1,137 @@
+#pragma once
+
+#include "FN_tuple_call.hpp"
+
+#include "core.hpp"
+
+namespace BParticles {
+
+using FN::ExecutionContext;
+using FN::SharedFunction;
+using FN::Tuple;
+using FN::TupleCallBody;
+
+class EventInfo {
+ public:
+  virtual void *get_info_array(StringRef name) = 0;
+};
+
+class ParticleFunction;
+class Action;
+
+class ParticleFunctionCaller {
+ private:
+  TupleCallBody *m_body;
+  SmallVector<void *> m_attribute_buffers;
+  SmallVector<uint> m_strides;
+
+  friend ParticleFunction;
+
+ public:
+  void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &ctx, uint pindex)
+  {
+    BLI_assert(fn_in.size() == m_attribute_buffers.size());
+
+    for (uint i = 0; i < fn_in.size(); i++) {
+      void *ptr = POINTER_OFFSET(m_attribute_buffers[i], pindex * m_strides[i]);
+      fn_in.copy_in__dynamic(i, ptr);
+    }
+
+    m_body->call(fn_in, fn_out, ctx);
+  }
+
+  TupleCallBody *body() const
+  {
+    return m_body;
+  }
+};
+
+class ParticleFunction {
+ private:
+  SharedFunction m_function;
+  TupleCallBody *m_tuple_call;
+
+ public:
+  ParticleFunction(SharedFunction &fn) : m_function(fn)
+  {
+    m_tuple_call = fn->body<TupleCallBody>();
+    BLI_assert(m_tuple_call);
+  }
+
+  ParticleFunctionCaller get_caller(AttributeArrays attributes, EventInfo &event_info);
+};
+
+class ActionInterface {
+ private:
+  EventExecuteInterface &m_event_execute_interface;
+  EventInfo &m_event_info;
+
+ public:
+  ActionInterface(EventExecuteInterface &event_execute_interface, EventInfo &event_info);
+
+  EventInfo &event_info();
+
+  ParticleSet &particles();
+  AttributeArrays attribute_offsets();
+  float remaining_time_in_step(uint index);
+  ArrayRef<float> current_times();
+  void kill(ArrayRef<uint> particle_indices);
+  InstantEmitTarget &request_emit_target(StringRef particle_type_name,
+                                         ArrayRef<uint> original_indices);
+  void execute_action_for_subset(ArrayRef<uint> indices, std::unique_ptr<Action> &action);
+};
+
+class Action {
+ public:
+  virtual ~Action() = 0;
+
+  virtual void execute(ActionInterface &interface) = 0;
+};
+
+/* ActionInterface inline functions
+ *******************************************/
+
+inline ActionInterface::ActionInterface(EventExecuteInterface &event_execute_interface,
+                                        EventInfo &event_info)
+    : m_event_execute_interface(event_execute_interface), m_event_info(event_info)
+{
+}
+
+inline EventInfo &ActionInterface::event_info()
+{
+  return m_event_info;
+}
+
+inline ParticleSet &ActionInterface::particles()
+{
+  return m_event_execute_interface.particles();
+}
+
+inline AttributeArrays ActionInterface::attribute_offsets()
+{
+  return m_event_execute_interface.attribute_offsets();
+}
+
+inline float ActionInterface::remaining_time_in_step(uint index)
+{
+  return m_event_execute_interface.step_end_time() -
+         m_event_execute_interface.current_times()[index];
+}
+
+inline ArrayRef<float> ActionInterface::current_times()
+{
+  return m_event_execute_interface.current_times();
+}
+
+inline void ActionInterface::kill(ArrayRef<uint> particle_indices)
+{
+  m_event_execute_interface.kill(particle_indices);
+}
+
+inline InstantEmitTarget &ActionInterface::request_emit_target(StringRef particle_type_name,
+                                                               ArrayRef<uint> original_indices)
+{
+  return m_event_execute_interface.request_emit_target(particle_type_name, original_indices);
+}
+
+}  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/actions.hpp b/source/blender/simulations/bparticles/actions.hpp
index d33d20e3e47..d34febc951b 100644
--- a/source/blender/simulations/bparticles/actions.hpp
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -1,159 +1,9 @@
 #pragma once
 
-#include "FN_tuple_call.hpp"
-
-#include "core.hpp"
+#include "action_interface.hpp"
 
 namespace BParticles {
 
-using FN::ExecutionContext;
-using FN::SharedFunction;
-using FN::Tuple;
-using FN::TupleCallBody;
-
-class EventInfo {
- public:
-  virtual void *get_info_array(StringRef name) = 0;
-};
-
-class ParticleFunction;
-class Action;
-
-class ParticleFunctionCaller {
- private:
-  TupleCallBody *m_body;
-  SmallVector<void *> m_attribute_buffers;
-  SmallVector<uint> m_strides;
-
-  friend ParticleFunction;
-
- public:
-  void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &ctx, uint pindex)
-  {
-    BLI_assert(fn_in.size() == m_attribute_buffers.size());
-
-    for (uint i = 0; i < fn_in.size(); i++) {
-      void *ptr = POINTER_OFFSET(m_attribute_buffers[i], pindex * m_strides[i]);
-      fn_in.copy_in__dynamic(i, ptr);
-    }
-
-    m_body->call(fn_in, fn_out, ctx);
-  }
-
-  TupleCallBody *body() const
-  {
-    return m_body;
-  }
-};
-
-class ParticleFunction {
- private:
-  SharedFunction m_function;
-  TupleCallBody *m_tuple_call;
-
- public:
-  ParticleFunction(SharedFunction &fn) : m_function(fn)
-  {
-    m_tuple_call = fn->body<TupleCallBody>();
-    BLI_assert(m_tuple_call);
-  }
-
-  ParticleFunctionCaller get_caller(AttributeArrays attributes, EventInfo &event_info)
-  {
-    ParticleFunctionCaller caller;
-    caller.m_body = m_tuple_call;
-
-    for (uint i = 0; i < m_function->input_amount(); i++) {
-      StringRef input_name = m_function->input_name(i);
-      void *ptr = nullptr;
-      uint stride = 0;
-      if (input_name.startswith("Event")) {
-        StringRef event_attribute_name = input_name.drop_prefix("Event: ");
-        ptr = event_info.get_info_array(event_attribute_name);
-        stride = sizeof(float3); /* TODO make not hardcoded */
-      }
-      else if (input_name.startswith("Attribute")) {
-        StringRef attribute_name = input_name.drop_prefix("Attribute: ");
-        uint index = attributes.attribute_index(attribute_name);
-        stride = attributes.attribute_stride(index);
-        ptr = attributes.get_ptr(index);
-      }
-      else {
-        BLI_assert(false);
-      }
-
-      BLI_assert(ptr);
-      caller.m_attribute_buffers.append(ptr);
-      caller.m_strides.append(stride);
-    }
-
-    return caller;
-  }
-};
-
-class ActionInterface {
- private:
-  EventExecuteInterface &m_event_execute_interface;
-  EventInfo &m_event_info;
-
- public:
-  ActionInterface(EventExecuteInterface &event_execute_interface, EventInfo &event_info)
-      : m_event_execute_interface(event_execute_interface), m_event_info(event_info)
-  {
-  }
-
-  EventExecuteInterface &execute_interface()
-  {
-    return m_event_execute_interface;
-  }
-
-  EventInfo &event_info()
-  {
-    return m_event_info;
-  }
-
-  ParticleSet &particles()
-  {
-    return m_event_execute_interface.particles();
-  }
-
-  AttributeArrays attribute_offsets()
-  {
-    return m_event_execute_interface.attribute_offsets();
-  }
-
-  float remaining_time_in_step(uint index)
-  {
-    return m_event_execute_interface.step_end_time() -
-           m_event_execute_interface.current_times()[index];
-  }
-
-  ArrayRef<float> current_times()
-  {
-    return m_event_execute_interface.current_times();
-  }
-
-  void kill(ArrayRef<uint> particle_indices)
-  {
-    m_event_execute_interface.kill(particle_indices);
-  }
-
-  InstantEmitTarget &request_emit_target(StringRef particle_type_name,
-                                         ArrayRef<uint> original_indices)
-  {
-    return m_event_execute_interface.request_emit_target(particle_type_name, original_indices);
-  }
-
-  void execute_action_for_subset(ArrayRef<uint> indices, std::unique_ptr<Action> &action);
-};
-
-class Action {
- public:
-  virtual ~Action() = 0;
-
-  virtual void execute(ActionInterface &interface) = 0;
-};
-
 Action *ACTION_none();
 Action *ACTION_change_direction(ParticleFunction &compute_inputs, Action *post_action);
 Action *ACTION_kill();



More information about the Bf-blender-cvs mailing list