[Bf-blender-cvs] [410599dca28] functions: reorganize where interfaces are declared
Jacques Lucke
noreply at git.blender.org
Mon Sep 2 19:02:31 CEST 2019
Commit: 410599dca28f5ef2dae5435d9ad2d9478f20d34e
Author: Jacques Lucke
Date: Mon Sep 2 19:01:33 2019 +0200
Branches: functions
https://developer.blender.org/rB410599dca28f5ef2dae5435d9ad2d9478f20d34e
reorganize where interfaces are declared
===================================================================
M source/blender/simulations/CMakeLists.txt
M source/blender/simulations/bparticles/action_interface.hpp
A source/blender/simulations/bparticles/block_step_data.hpp
M source/blender/simulations/bparticles/c_wrapper.cpp
A source/blender/simulations/bparticles/emitter_interface.hpp
M source/blender/simulations/bparticles/emitters.hpp
A source/blender/simulations/bparticles/event_interface.hpp
M source/blender/simulations/bparticles/events.hpp
M source/blender/simulations/bparticles/force_interface.hpp
M source/blender/simulations/bparticles/forces.hpp
M source/blender/simulations/bparticles/integrator.hpp
A source/blender/simulations/bparticles/integrator_interface.hpp
M source/blender/simulations/bparticles/node_frontend.hpp
A source/blender/simulations/bparticles/offset_handler_interface.hpp
M source/blender/simulations/bparticles/offset_handlers.hpp
M source/blender/simulations/bparticles/simulate.cpp
M source/blender/simulations/bparticles/simulate.hpp
D source/blender/simulations/bparticles/step_description.cpp
D source/blender/simulations/bparticles/step_description.hpp
D source/blender/simulations/bparticles/step_description_interfaces.cpp
D source/blender/simulations/bparticles/step_description_interfaces.hpp
===================================================================
diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
index c26d3ad2569..c33d47fc8fc 100644
--- a/source/blender/simulations/CMakeLists.txt
+++ b/source/blender/simulations/CMakeLists.txt
@@ -35,11 +35,12 @@ set(SRC
bparticles/events.cpp
bparticles/attributes.hpp
bparticles/attributes.cpp
+ bparticles/emitter_interface.hpp
+ bparticles/block_step_data.hpp
+ bparticles/event_interface.hpp
+ bparticles/integrator_interface.hpp
+ bparticles/offset_handler_interface.hpp
bparticles/c_wrapper.cpp
- bparticles/step_description.hpp
- bparticles/step_description.cpp
- bparticles/step_description_interfaces.hpp
- bparticles/step_description_interfaces.cpp
bparticles/step_simulator.hpp
bparticles/simulation_state.hpp
bparticles/world_state.hpp
diff --git a/source/blender/simulations/bparticles/action_interface.hpp b/source/blender/simulations/bparticles/action_interface.hpp
index bc3a29c7650..8f10e0821ec 100644
--- a/source/blender/simulations/bparticles/action_interface.hpp
+++ b/source/blender/simulations/bparticles/action_interface.hpp
@@ -3,7 +3,10 @@
#include "FN_tuple_call.hpp"
#include "BLI_array.hpp"
-#include "step_description.hpp"
+#include "particle_allocator.hpp"
+#include "emitter_interface.hpp"
+#include "event_interface.hpp"
+#include "offset_handler_interface.hpp"
namespace BParticles {
diff --git a/source/blender/simulations/bparticles/block_step_data.hpp b/source/blender/simulations/bparticles/block_step_data.hpp
new file mode 100644
index 00000000000..4194fc3000b
--- /dev/null
+++ b/source/blender/simulations/bparticles/block_step_data.hpp
@@ -0,0 +1,66 @@
+#pragma once
+
+#include "attributes.hpp"
+#include "time_span.hpp"
+
+namespace BParticles {
+
+struct BlockStepData {
+ AttributeArrays attributes;
+ AttributeArrays attribute_offsets;
+ MutableArrayRef<float> remaining_durations;
+ float step_end_time;
+
+ uint array_size()
+ {
+ return this->remaining_durations.size();
+ }
+};
+
+class BlockStepDataAccess {
+ protected:
+ BlockStepData &m_step_data;
+
+ public:
+ BlockStepDataAccess(BlockStepData &step_data) : m_step_data(step_data)
+ {
+ }
+
+ uint array_size() const
+ {
+ return m_step_data.array_size();
+ }
+
+ BlockStepData &step_data()
+ {
+ return m_step_data;
+ }
+
+ AttributeArrays attributes()
+ {
+ return m_step_data.attributes;
+ }
+
+ AttributeArrays attribute_offsets()
+ {
+ return m_step_data.attribute_offsets;
+ }
+
+ MutableArrayRef<float> remaining_durations()
+ {
+ return m_step_data.remaining_durations;
+ }
+
+ float step_end_time()
+ {
+ return m_step_data.step_end_time;
+ }
+
+ TimeSpan time_span(uint pindex)
+ {
+ float duration = m_step_data.remaining_durations[pindex];
+ return TimeSpan(m_step_data.step_end_time - duration, duration);
+ }
+};
+
+} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 5397db1d655..e91e7d7d55f 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -1,5 +1,4 @@
#include "BParticles.h"
-#include "step_description.hpp"
#include "simulate.hpp"
#include "world_state.hpp"
#include "simulation_state.hpp"
diff --git a/source/blender/simulations/bparticles/emitter_interface.hpp b/source/blender/simulations/bparticles/emitter_interface.hpp
new file mode 100644
index 00000000000..240b6da4b61
--- /dev/null
+++ b/source/blender/simulations/bparticles/emitter_interface.hpp
@@ -0,0 +1,69 @@
+#pragma once
+
+#include "particle_allocator.hpp"
+#include "time_span.hpp"
+
+namespace BParticles {
+
+class EmitterInterface {
+ private:
+ ParticleAllocator &m_particle_allocator;
+ TimeSpan m_time_span;
+
+ public:
+ EmitterInterface(ParticleAllocator &particle_allocator, TimeSpan time_span)
+ : m_particle_allocator(particle_allocator), m_time_span(time_span)
+ {
+ }
+
+ ~EmitterInterface() = default;
+
+ ParticleAllocator &particle_allocator()
+ {
+ return m_particle_allocator;
+ }
+
+ /**
+ * Time span that new particles should be emitted in.
+ */
+ TimeSpan time_span()
+ {
+ return m_time_span;
+ }
+
+ /**
+ * True when this is the first time step in a simulation, otherwise false.
+ */
+ bool is_first_step()
+ {
+ return m_time_span.start() == 0.0f;
+ }
+};
+
+/**
+ * An emitter creates new particles of possibly different types within a certain time span.
+ */
+class Emitter {
+ public:
+ virtual ~Emitter()
+ {
+ }
+
+ /**
+ * Create new particles within a time span.
+ *
+ * In general it works like so:
+ * 1. Prepare vectors with attribute values for e.g. position and velocity of the new
+ * particles.
+ * 2. Request an emit target that can contain a given amount of particles of a specific type.
+ * 3. Copy the prepared attribute arrays into the target. Other attributes are initialized with
+ * some default value.
+ * 4. Specify the exact birth times of every particle within the time span. This will allow the
+ * framework to simulate the new particles for partial time steps to avoid stepping.
+ *
+ * To create particles of different types, multiple emit targets have to be requested.
+ */
+ virtual void emit(EmitterInterface &interface) = 0;
+};
+
+} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/emitters.hpp b/source/blender/simulations/bparticles/emitters.hpp
index a86561d7808..4a12525acd7 100644
--- a/source/blender/simulations/bparticles/emitters.hpp
+++ b/source/blender/simulations/bparticles/emitters.hpp
@@ -2,9 +2,9 @@
#include "FN_tuple_call.hpp"
-#include "step_description.hpp"
#include "world_state.hpp"
#include "action_interface.hpp"
+#include "emitter_interface.hpp"
namespace BParticles {
diff --git a/source/blender/simulations/bparticles/event_interface.hpp b/source/blender/simulations/bparticles/event_interface.hpp
new file mode 100644
index 00000000000..383601aca83
--- /dev/null
+++ b/source/blender/simulations/bparticles/event_interface.hpp
@@ -0,0 +1,228 @@
+#pragma once
+
+#include "attributes.hpp"
+#include "block_step_data.hpp"
+#include "particle_allocator.hpp"
+
+namespace BParticles {
+
+/**
+ * Utility array wrapper that can hold different kinds of plain-old-data values.
+ */
+class EventStorage {
+ private:
+ void *m_array;
+ uint m_stride;
+
+ public:
+ EventStorage(void *array, uint stride) : m_array(array), m_stride(stride)
+ {
+ }
+
+ EventStorage(EventStorage &other) = delete;
+
+ void *operator[](uint index)
+ {
+ return POINTER_OFFSET(m_array, m_stride * index);
+ }
+
+ template<typename T> T &get(uint index)
+ {
+ return *(T *)(*this)[index];
+ }
+
+ uint max_element_size() const
+ {
+ return m_stride;
+ }
+};
+
+/**
+ * Interface between the Event->filter() function and the core simulation code.
+ */
+class EventFilterInterface : public BlockStepDataAccess {
+ private:
+ ArrayRef<uint> m_pindices;
+ ArrayRef<float> m_known_min_time_factors;
+
+ EventStorage &m_event_storage;
+ Vector<uint> &m_filtered_pindices;
+ Vector<float> &m_filtered_time_factors;
+
+ /* Size can be increased when necessary. */
+ char m_dummy_event_storage[64];
+
+ public:
+ EventFilterInterface(BlockStepData &step_data,
+ ArrayRef<uint> pindices,
+ ArrayRef<float> known_min_time_factors,
+ EventStorage &r_event_storage,
+ Vector<uint> &r_filtered_pindices,
+ Vector<float> &r_filtered_time_factors)
+ : BlockStepDataAccess(step_data),
+ m_pindices(pindices),
+ m_known_min_time_factors(known_min_time_factors),
+ m_event_storage(r_event_storage),
+ m_filtered_pindices(r_filtered_pindices),
+ m_filtered_time_factors(r_filtered_time_factors)
+ {
+ }
+
+ /**
+ * Return the indices that should be checked.
+ */
+ ArrayRef<uint> pindices()
+ {
+ return m_pindices;
+ }
+
+ /**
+ * Mark a particle as triggered by the event at a specific point in time.
+ * Note: The index must increase between consecutive calls to this function.
+ */
+ void trigger_particle(uint pindex, float time_factor)
+ {
+ BLI_assert(0.0f <= time_factor && time_factor <= 1.0f);
+
+ if (time_factor <= m_known_min_time_factors[pindex]) {
+ m_filtered_pindices.append(pindex);
+ m_filtered_time_factors.append(time_factor);
+ }
+ }
+
+ /**
+ * Same as above but returns a reference to a struct that can be used to pass data to the execute
+ * function. The reference might point to a dummy buffer when the time_factor is after a known
+ * other event.
+ */
+ template<typename T> T &trigger_particle(uint pindex, float time_factor)
+ {
+ BLI_STATIC_ASSERT(std::is_trivial<T>::value, "");
+ BLI_assert(sizeof(T) <= m_event_storage.max_element_size());
+ BLI_assert(sizeof(m_dummy_event_storage) >= m_event_storage.max_element_size());
+
+ if (time_factor <= m_known_min_time_factors[pindex]) {
+ this->trigger_particle(pindex, time_factor);
+ return m_event_storage.get<T>(pindex);
+ }
+ else {
+ return *(T *)m_dummy_event_storage;
+ }
+ }
+};
+
+/**
+ * Interface between the Event->execute() function and the core simulation code.
+ */
+class EventExecuteInterface : public BlockStepDataAccess {
+ private:
+ ArrayRef<uint> m_pindices;
+ ArrayRef<float> m_current_times;
+ EventStorage &m_event_storage;
+ ParticleAllocator &m_particle_allocator;
+
+ public:
+ EventExecuteInterface(BlockStepData &step_data,
+ ArrayRef<uint> pindices,
+ ArrayRef<float> current_times,
+ EventStorage &event_storage,
+ ParticleAllocator &particle_allocator)
+ : BlockStepDataAccess(step_data),
+ m_pindices(pindices),
+ m_current_times(current_times),
+ m_event_storage(event_storage),
+ m_particle_allocator(particle_allocator)
+ {
+ }
+
+ ~EventExecuteInterface() = default;
+
+ /**
+ * Access the indices that should be modified by thi
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list