[Bf-blender-cvs] [059639e3014] functions: new EventInterface abstraction
Jacques Lucke
noreply at git.blender.org
Mon Jun 24 12:38:17 CEST 2019
Commit: 059639e30147d8191c7cc4b3a7c909d031916ea3
Author: Jacques Lucke
Date: Mon Jun 24 12:37:27 2019 +0200
Branches: functions
https://developer.blender.org/rB059639e30147d8191c7cc4b3a7c909d031916ea3
new EventInterface abstraction
===================================================================
M source/blender/simulations/bparticles/core.hpp
M source/blender/simulations/bparticles/events.cpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 2753d4d2b6a..d26f1e4e33d 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -78,16 +78,70 @@ struct IdealOffsets {
ArrayRef<float3> velocity_offsets;
};
+class EventInterface {
+ private:
+ ParticleSet m_particles;
+ IdealOffsets &m_ideal_offsets;
+ ArrayRef<float> m_durations;
+ float m_end_time;
+
+ SmallVector<uint> &m_filtered_indices;
+ SmallVector<float> &m_filtered_time_factors;
+
+ public:
+ EventInterface(ParticleSet particles,
+ IdealOffsets &ideal_offsets,
+ ArrayRef<float> durations,
+ float end_time,
+ SmallVector<uint> &r_filtered_indices,
+ SmallVector<float> &r_filtered_time_factors)
+ : m_particles(particles),
+ m_ideal_offsets(ideal_offsets),
+ m_durations(durations),
+ m_end_time(end_time),
+ m_filtered_indices(r_filtered_indices),
+ m_filtered_time_factors(r_filtered_time_factors)
+ {
+ }
+
+ ParticleSet &particles()
+ {
+ return m_particles;
+ }
+
+ ArrayRef<float> durations()
+ {
+ return m_durations;
+ }
+
+ TimeSpan time_span(uint index)
+ {
+ float duration = m_durations[index];
+ return TimeSpan(m_end_time - duration, duration);
+ }
+
+ IdealOffsets &ideal_offsets()
+ {
+ return m_ideal_offsets;
+ }
+
+ float end_time()
+ {
+ return m_end_time;
+ }
+
+ void trigger_particle(uint index, float time_factor)
+ {
+ m_filtered_indices.append(index);
+ m_filtered_time_factors.append(time_factor);
+ }
+};
+
class Event {
public:
virtual ~Event();
- virtual void filter(ParticleSet particles,
- IdealOffsets &ideal_offsets,
- ArrayRef<float> durations,
- float end_time,
- SmallVector<uint> &r_filtered_indices,
- SmallVector<float> &r_time_factors) = 0;
+ virtual void filter(EventInterface &interface) = 0;
};
class Action {
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index cbe0f41479a..a3149d70d7f 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -15,24 +15,21 @@ class AgeReachedEvent : public Event {
{
}
- void filter(ParticleSet particles,
- IdealOffsets &UNUSED(ideal_offsets),
- ArrayRef<float> durations,
- float end_time,
- SmallVector<uint> &r_filtered_indices,
- SmallVector<float> &r_time_factors) override
+ void filter(EventInterface &interface) override
{
+ ParticleSet particles = interface.particles();
auto birth_times = particles.attributes().get_float("Birth Time");
+ float end_time = interface.end_time();
for (uint i : particles.range()) {
uint pindex = particles.get_particle_index(i);
- float duration = durations[i];
+ TimeSpan time_span = interface.time_span(i);
+ float duration = interface.durations()[i];
float birth_time = birth_times[pindex];
float age = end_time - birth_time;
if (age >= m_age && age - duration < m_age) {
- r_filtered_indices.append(i);
float time_factor = TimeSpan(end_time - duration, duration).get_factor(birth_time + m_age);
- r_time_factors.append(time_factor);
+ interface.trigger_particle(i, time_factor);
}
}
}
@@ -49,15 +46,11 @@ class MeshCollisionEvent : public Event {
{
}
- void filter(ParticleSet particles,
- IdealOffsets &ideal_offsets,
- ArrayRef<float> UNUSED(durations),
- float UNUSED(end_time),
- SmallVector<uint> &r_filtered_indices,
- SmallVector<float> &r_time_factors) override
+ void filter(EventInterface &interface) override
{
+ ParticleSet &particles = interface.particles();
auto positions = particles.attributes().get_float3("Position");
- auto position_offsets = ideal_offsets.position_offsets;
+ auto position_offsets = interface.ideal_offsets().position_offsets;
for (uint i : particles.range()) {
uint pindex = particles.get_particle_index(i);
@@ -79,8 +72,7 @@ class MeshCollisionEvent : public Event {
if (hit.index != -1) {
float time_factor = hit.dist / length;
- r_filtered_indices.append(i);
- r_time_factors.append(time_factor);
+ interface.trigger_particle(i, time_factor);
}
}
}
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 1cc072d6397..c4a373e0e26 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -39,8 +39,9 @@ BLI_NOINLINE static void find_next_event_per_particle(ParticleSet particles,
SmallVector<float> triggered_time_factors;
Event *event = events[event_index];
- event->filter(
+ EventInterface interface(
particles, ideal_offsets, durations, end_time, triggered_indices, triggered_time_factors);
+ event->filter(interface);
for (uint i = 0; i < triggered_indices.size(); i++) {
uint index = triggered_indices[i];
More information about the Bf-blender-cvs
mailing list