[Bf-blender-cvs] [5d590fc1bbb] functions: extract method to simulate multiple events per step
Jacques Lucke
noreply at git.blender.org
Fri Jun 21 13:29:31 CEST 2019
Commit: 5d590fc1bbb38a54968d0195ed9e4643afb51b3f
Author: Jacques Lucke
Date: Fri Jun 21 11:00:48 2019 +0200
Branches: functions
https://developer.blender.org/rB5d590fc1bbb38a54968d0195ed9e4643afb51b3f
extract method to simulate multiple events per step
===================================================================
M source/blender/blenlib/BLI_math.hpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/blenlib/BLI_math.hpp b/source/blender/blenlib/BLI_math.hpp
index 42a4b84a587..a0da94136f7 100644
--- a/source/blender/blenlib/BLI_math.hpp
+++ b/source/blender/blenlib/BLI_math.hpp
@@ -54,6 +54,12 @@ struct float3 {
BLI_assert(b != 0);
return {a.x / b, a.y / b, a.z / b};
}
+
+ friend std::ostream &operator<<(std::ostream &stream, float3 v)
+ {
+ stream << "(" << v.x << ", " << v.y << ", " << v.z << ")";
+ return stream;
+ }
};
struct float4x4 {
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 8178d822c5b..13f61a0b3e4 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -210,6 +210,38 @@ BLI_NOINLINE static void simulate_to_next_event(AttributeArrays attributes,
r_remaining_durations);
}
+BLI_NOINLINE static void simulate_with_max_n_events(
+ uint max_events,
+ AttributeArrays attributes,
+ ArrayRef<uint> particle_indices,
+ ArrayRef<float> durations,
+ float end_time,
+ ParticleInfluences &influences,
+ SmallVector<uint> &r_unfinished_particle_indices,
+ SmallVector<float> &r_remaining_durations)
+{
+ for (uint iteration = 0; iteration < max_events; iteration++) {
+ r_unfinished_particle_indices.clear();
+ r_remaining_durations.clear();
+
+ simulate_to_next_event(attributes,
+ particle_indices,
+ durations,
+ end_time,
+ influences,
+ r_unfinished_particle_indices,
+ r_remaining_durations);
+ BLI_assert(r_unfinished_particle_indices.size() == r_remaining_durations.size());
+
+ if (r_unfinished_particle_indices.size() == 0) {
+ break;
+ }
+
+ particle_indices = r_unfinished_particle_indices;
+ durations = r_remaining_durations;
+ }
+}
+
BLI_NOINLINE static void simulate_ignoring_events(AttributeArrays attributes,
ArrayRef<uint> particle_indices,
ArrayRef<float> durations,
@@ -241,27 +273,14 @@ BLI_NOINLINE static void step_individual_particles(AttributeArrays attributes,
SmallVector<uint> unfinished_particle_indices;
SmallVector<float> remaining_durations;
- const uint max_events_per_particle = 10;
- for (uint iteration = 0; iteration < max_events_per_particle; iteration++) {
- unfinished_particle_indices.clear();
- remaining_durations.clear();
-
- simulate_to_next_event(attributes,
- particle_indices,
- durations,
- end_time,
- influences,
- unfinished_particle_indices,
- remaining_durations);
- BLI_assert(unfinished_particle_indices.size() == remaining_durations.size());
-
- if (unfinished_particle_indices.size() == 0) {
- break;
- }
-
- particle_indices = unfinished_particle_indices;
- durations = remaining_durations;
- }
+ simulate_with_max_n_events(10,
+ attributes,
+ particle_indices,
+ durations,
+ end_time,
+ influences,
+ unfinished_particle_indices,
+ remaining_durations);
simulate_ignoring_events(
attributes, unfinished_particle_indices, remaining_durations, influences);
More information about the Bf-blender-cvs
mailing list