[Bf-blender-cvs] [8ea9f576016] functions: simplify event execute interface
Jacques Lucke
noreply at git.blender.org
Wed Jul 10 17:17:47 CEST 2019
Commit: 8ea9f576016c1abe0a67d1786a90a93cff54d496
Author: Jacques Lucke
Date: Wed Jul 10 12:59:20 2019 +0200
Branches: functions
https://developer.blender.org/rB8ea9f576016c1abe0a67d1786a90a93cff54d496
simplify event execute interface
===================================================================
M source/blender/simulations/bparticles/action_interface.hpp
M source/blender/simulations/bparticles/actions.cpp
M source/blender/simulations/bparticles/core.cpp
M source/blender/simulations/bparticles/core.hpp
===================================================================
diff --git a/source/blender/simulations/bparticles/action_interface.hpp b/source/blender/simulations/bparticles/action_interface.hpp
index e66af2c06aa..b0a28e46a32 100644
--- a/source/blender/simulations/bparticles/action_interface.hpp
+++ b/source/blender/simulations/bparticles/action_interface.hpp
@@ -76,9 +76,8 @@ class ActionInterface {
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);
+ ParticleAllocator &particle_allocator();
};
class Action {
@@ -128,10 +127,9 @@ 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)
+inline ParticleAllocator &ActionInterface::particle_allocator()
{
- return m_event_execute_interface.request_emit_target(particle_type_name, original_indices);
+ return m_event_execute_interface.particle_allocator();
}
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index 752cd3fa334..ce4742e028f 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -93,7 +93,7 @@ class ExplodeAction : public Action {
SmallVector<float3> new_positions;
SmallVector<float3> new_velocities;
- SmallVector<uint> original_indices;
+ SmallVector<float> new_birth_times;
auto caller = m_compute_inputs.get_caller(particles.attributes(), interface.event_info());
FN_TUPLE_CALL_ALLOC_TUPLES(caller.body(), fn_in, fn_out);
@@ -109,16 +109,19 @@ class ExplodeAction : public Action {
float speed = fn_out.get<float>(1);
new_positions.append_n_times(positions[pindex], parts_amount);
- original_indices.append_n_times(i, parts_amount);
+ new_birth_times.append_n_times(interface.current_times()[i], parts_amount);
for (uint j = 0; j < parts_amount; j++) {
new_velocities.append(random_direction() * speed);
}
}
- auto &target = interface.request_emit_target(m_new_particle_name, original_indices);
- target.set_float3("Position", new_positions);
- target.set_float3("Velocity", new_velocities);
+ auto target = interface.particle_allocator().request(m_new_particle_name,
+ new_birth_times.size());
+ target->set_float3("Position", new_positions);
+ target->set_float3("Velocity", new_velocities);
+ target->fill_float("Size", 0.1f);
+ target->set_float("Birth Time", new_birth_times);
m_post_action->execute(interface);
}
diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp
index 675b549f052..69101c8fcf4 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -112,35 +112,6 @@ EmitterInterface::EmitterInterface(ParticleAllocator &particle_allocator, TimeSp
/* Action Interface
**************************************/
-EventExecuteInterface::~EventExecuteInterface()
-{
- for (InstantEmitTarget *target : m_emit_targets) {
- delete target;
- }
-}
-
-InstantEmitTarget &EventExecuteInterface::request_emit_target(StringRef particle_type_name,
- ArrayRef<uint> original_indices)
-{
- uint size = original_indices.size();
-
- SmallVector<ParticlesBlock *> blocks;
- SmallVector<Range<uint>> ranges;
- m_particle_allocator.allocate_block_ranges(particle_type_name, size, blocks, ranges);
- AttributesInfo &attributes_info = m_particle_allocator.attributes_info(particle_type_name);
-
- auto *target = new InstantEmitTarget(particle_type_name, attributes_info, blocks, ranges);
- m_emit_targets.append(target);
-
- SmallVector<float> birth_times(size);
- for (uint i = 0; i < size; i++) {
- birth_times[i] = m_current_times[original_indices[i]];
- }
- target->set_float("Birth Time", birth_times);
-
- return *target;
-}
-
/* EmitTarget
******************************************/
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 6445689467f..ad3992b3732 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -305,7 +305,18 @@ class ParticleAllocator {
public:
ParticleAllocator(ParticlesState &state);
ParticleAllocator(ParticleAllocator &other) = delete;
+ ParticleAllocator(ParticleAllocator &&other) = delete;
+ /**
+ * Access all blocks that have been allocated by this allocator.
+ */
+ ArrayRef<ParticlesBlock *> allocated_blocks();
+
+ std::unique_ptr<EmitTargetBase> request(StringRef particle_type_name, uint size);
+
+ ParticlesState &particles_state();
+
+ private:
/**
* Return a block that can hold new particles. It might create an entirely new one or use a
* cached block.
@@ -322,14 +333,6 @@ class ParticleAllocator {
SmallVector<Range<uint>> &r_ranges);
AttributesInfo &attributes_info(StringRef particle_type_name);
- ParticlesState &particles_state();
-
- /**
- * Access all blocks that have been allocated by this allocator.
- */
- ArrayRef<ParticlesBlock *> allocated_blocks();
-
- std::unique_ptr<EmitTargetBase> request(StringRef particle_type_name, uint size);
};
/**
@@ -503,7 +506,6 @@ class EventExecuteInterface {
private:
ParticleSet m_particles;
ParticleAllocator &m_particle_allocator;
- SmallVector<InstantEmitTarget *> m_emit_targets;
ArrayRef<float> m_current_times;
ArrayRef<uint8_t> m_kill_states;
EventStorage &m_event_storage;
@@ -518,7 +520,7 @@ class EventExecuteInterface {
AttributeArrays attribute_offsets,
float step_end_time);
- ~EventExecuteInterface();
+ ~EventExecuteInterface() = default;
/**
* Access the set of particles that should be modified by this event.
@@ -546,15 +548,6 @@ class EventExecuteInterface {
*/
AttributeArrays attribute_offsets();
- /**
- * Get a new emit target that allows creating new particles. Every new particle is mapped to some
- * original particle. Multiple new particles can be mapped to the same original particle.
- * This mapping is necessary to ensure that the new particles are create at the right moments in
- * time.
- */
- InstantEmitTarget &request_emit_target(StringRef particle_type_name,
- ArrayRef<uint> original_indices);
-
/**
* Kill all particles with the given indices in the current block.
*/
More information about the Bf-blender-cvs
mailing list