[Bf-blender-cvs] [485b07dc55f] functions: give action access to current time per particle
Jacques Lucke
noreply at git.blender.org
Fri Jun 28 12:31:13 CEST 2019
Commit: 485b07dc55fa0c3d7609f3b35a6f2c72411aa737
Author: Jacques Lucke
Date: Fri Jun 28 12:30:50 2019 +0200
Branches: functions
https://developer.blender.org/rB485b07dc55fa0c3d7609f3b35a6f2c72411aa737
give action access to current time per particle
===================================================================
M source/blender/simulations/bparticles/actions.cpp
M source/blender/simulations/bparticles/core.hpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index 2c526a724d6..35b63691f29 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -43,16 +43,19 @@ class SpawnAction : public Action {
SmallVector<float3> new_positions;
SmallVector<float3> new_velocities;
+ SmallVector<float> new_birth_times;
for (uint i : particles.range()) {
uint pindex = particles.get_particle_index(i);
new_positions.append(positions[pindex] + float3(20, 0, 0));
new_velocities.append(float3(1, 1, 10));
+ new_birth_times.append(interface.current_times()[i]);
}
auto &target = interface.request_emit_target(0, particles.size());
target.set_float3("Position", new_positions);
target.set_float3("Velocity", new_velocities);
+ target.set_float("Birth Time", new_birth_times);
}
};
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index c419df320d3..b16b37ddd49 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -72,6 +72,7 @@ class BlockAllocator {
public:
BlockAllocator(ParticlesState &state);
+ BlockAllocator(BlockAllocator &other) = delete;
ParticlesBlock &get_non_full_block(uint particle_type_id);
void allocate_block_ranges(uint particle_type_id,
@@ -346,10 +347,13 @@ class ActionInterface {
ParticleSet m_particles;
BlockAllocator &m_block_allocator;
SmallVector<InstantEmitTarget *> m_emit_targets;
+ ArrayRef<float> m_current_times;
public:
- ActionInterface(ParticleSet particles, BlockAllocator &block_allocator)
- : m_particles(particles), m_block_allocator(block_allocator)
+ ActionInterface(ParticleSet particles,
+ BlockAllocator &block_allocator,
+ ArrayRef<float> current_times)
+ : m_particles(particles), m_block_allocator(block_allocator), m_current_times(current_times)
{
}
@@ -371,6 +375,11 @@ class ActionInterface {
{
return m_emit_targets;
}
+
+ ArrayRef<float> current_times()
+ {
+ return m_current_times;
+ }
};
class Action {
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index fd027b91b0d..e2fc4f87658 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -4,6 +4,8 @@
#include "BLI_lazy_init.hpp"
#include "BLI_task.h"
+#define USE_THREADING true
+
namespace BParticles {
/* Static Data
@@ -121,20 +123,19 @@ BLI_NOINLINE static void find_unfinished_particles(
BLI_NOINLINE static void run_actions(BlockAllocator &block_allocator,
ParticlesBlock &block,
ArrayRef<SmallVector<uint>> particles_per_event,
+ ArrayRef<SmallVector<float>> current_time_per_particle,
ArrayRef<Event *> events,
ArrayRef<Action *> action_per_event)
{
for (uint event_index = 0; event_index < events.size(); event_index++) {
Action *action = action_per_event[event_index];
ParticleSet particles(block, particles_per_event[event_index]);
+ if (particles.size() == 0) {
+ continue;
+ }
- ActionInterface interface(particles, block_allocator);
+ ActionInterface interface(particles, block_allocator, current_time_per_particle[event_index]);
action->execute(interface);
-
- for (InstantEmitTarget *target_ptr : interface.emit_targets()) {
- InstantEmitTarget &target = *target_ptr;
- target.fill_float("Birth Time", block_allocator.particles_state().m_current_time);
- }
}
}
@@ -212,9 +213,20 @@ BLI_NOINLINE static void simulate_to_next_event(BlockAllocator &block_allocator,
SmallVector<SmallVector<uint>> particles_per_event(particle_type.events().size());
find_particles_per_event(particles.indices(), next_event_indices, particles_per_event);
+
+ SmallVector<SmallVector<float>> current_time_per_particle(particle_type.events().size());
+ for (uint i : particles.range()) {
+ int event_index = next_event_indices[i];
+ if (event_index != -1) {
+ current_time_per_particle[event_index].append(
+ end_time - durations[i] * (1.0f - time_factors_to_next_event[i]));
+ }
+ }
+
run_actions(block_allocator,
particles.block(),
particles_per_event,
+ current_time_per_particle,
particle_type.events(),
particle_type.action_per_event());
@@ -382,7 +394,7 @@ BLI_NOINLINE static void simulate_block_time_span_cb(void *__restrict userdata,
SimulateTimeSpanData *data = (SimulateTimeSpanData *)userdata;
ParticlesBlock &block = *data->blocks[index];
- BlockAllocator block_allocator = data->block_allocators.get_threadlocal_allocator(
+ BlockAllocator &block_allocator = data->block_allocators.get_threadlocal_allocator(
tls->thread_id);
ParticlesState &state = block_allocator.particles_state();
@@ -410,6 +422,7 @@ BLI_NOINLINE static void simulate_blocks_for_time_span(BlockAllocators &block_al
ParallelRangeSettings settings;
BLI_parallel_range_settings_defaults(&settings);
+ settings.use_threading = USE_THREADING;
uint block_size = blocks[0]->container().block_size();
SmallVector<float> all_durations(block_size);
@@ -435,7 +448,7 @@ BLI_NOINLINE static void simulate_block_from_birth_cb(void *__restrict userdata,
SimulateFromBirthData *data = (SimulateFromBirthData *)userdata;
ParticlesBlock &block = *data->blocks[index];
- BlockAllocator block_allocator = data->block_allocators.get_threadlocal_allocator(
+ BlockAllocator &block_allocator = data->block_allocators.get_threadlocal_allocator(
tls->thread_id);
ParticlesState &state = block_allocator.particles_state();
@@ -467,6 +480,7 @@ BLI_NOINLINE static void simulate_blocks_from_birth_to_current_time(
ParallelRangeSettings settings;
BLI_parallel_range_settings_defaults(&settings);
+ settings.use_threading = USE_THREADING;
SimulateFromBirthData data = {blocks, end_time, block_allocators, step_description};
BLI_task_parallel_range(
More information about the Bf-blender-cvs
mailing list