[Bf-blender-cvs] [82c4bdc6d05] functions: move events and actions to separate files
Jacques Lucke
noreply at git.blender.org
Thu Jun 20 15:51:31 CEST 2019
Commit: 82c4bdc6d05ffcb188c5e98704d2be03ff7656b4
Author: Jacques Lucke
Date: Thu Jun 20 15:16:57 2019 +0200
Branches: functions
https://developer.blender.org/rB82c4bdc6d05ffcb188c5e98704d2be03ff7656b4
move events and actions to separate files
===================================================================
M source/blender/simulations/CMakeLists.txt
A source/blender/simulations/bparticles/actions.cpp
A source/blender/simulations/bparticles/actions.hpp
M source/blender/simulations/bparticles/c_wrapper.cpp
A source/blender/simulations/bparticles/events.cpp
A source/blender/simulations/bparticles/events.hpp
===================================================================
diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
index 18d05de52b6..b617ff09214 100644
--- a/source/blender/simulations/CMakeLists.txt
+++ b/source/blender/simulations/CMakeLists.txt
@@ -25,6 +25,10 @@ set(SRC
bparticles/emitters.cpp
bparticles/forces.hpp
bparticles/forces.cpp
+ bparticles/actions.hpp
+ bparticles/actions.cpp
+ bparticles/events.hpp
+ bparticles/events.cpp
bparticles/attributes.hpp
bparticles/attributes.cpp
bparticles/c_wrapper.cpp
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
new file mode 100644
index 00000000000..6e5a0fd59b7
--- /dev/null
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -0,0 +1,46 @@
+#include "actions.hpp"
+
+namespace BParticles {
+
+class KillAction : public Action {
+ void execute(AttributeArrays attributes, ArrayRef<uint> particle_indices) override
+ {
+ auto kill_states = attributes.get_byte("Kill State");
+ for (uint pindex : particle_indices) {
+ kill_states[pindex] = 1;
+ }
+ }
+};
+
+class MoveAction : public BParticles::Action {
+ private:
+ float3 m_offset;
+
+ public:
+ MoveAction(float3 offset) : m_offset(offset)
+ {
+ }
+
+ void execute(AttributeArrays attributes, ArrayRef<uint> particle_indices) override
+ {
+ auto positions = attributes.get_float3("Position");
+
+ for (uint pindex : particle_indices) {
+ positions[pindex] += m_offset;
+ }
+ }
+};
+
+std::unique_ptr<Action> ACTION_kill()
+{
+ Action *action = new KillAction();
+ return std::unique_ptr<Action>(action);
+}
+
+std::unique_ptr<Action> ACTION_move(float3 offset)
+{
+ Action *action = new MoveAction(offset);
+ return std::unique_ptr<Action>(action);
+}
+
+} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/actions.hpp b/source/blender/simulations/bparticles/actions.hpp
new file mode 100644
index 00000000000..e8edc9daa64
--- /dev/null
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -0,0 +1,10 @@
+#pragma once
+
+#include "core.hpp"
+
+namespace BParticles {
+
+std::unique_ptr<Action> ACTION_kill();
+std::unique_ptr<Action> ACTION_move(float3 offset);
+
+} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index c07b56835f7..0e9cad638e4 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -3,6 +3,8 @@
#include "particles_container.hpp"
#include "emitters.hpp"
#include "forces.hpp"
+#include "events.hpp"
+#include "actions.hpp"
#include "simulate.hpp"
#include "BLI_timeit.hpp"
@@ -52,69 +54,6 @@ void BParticles_state_free(BParticlesState state)
delete unwrap(state);
}
-class AgeReachedEvent : public Event {
- private:
- float m_age;
-
- public:
- AgeReachedEvent(float age) : m_age(age)
- {
- }
-
- void filter(AttributeArrays attributes,
- ArrayRef<uint> particle_indices,
- IdealOffsets &UNUSED(ideal_offsets),
- ArrayRef<float> durations,
- float end_time,
- SmallVector<uint> &r_filtered_indices,
- SmallVector<float> &r_time_factors) override
- {
- auto birth_times = attributes.get_float("Birth Time");
-
- for (uint i = 0; i < particle_indices.size(); i++) {
- uint pindex = particle_indices[i];
- float duration = 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) + 0.00001f;
- r_time_factors.append(time_factor);
- }
- }
- }
-};
-
-class KillAction : public Action {
- void execute(AttributeArrays attributes, ArrayRef<uint> particle_indices) override
- {
- auto kill_states = attributes.get_byte("Kill State");
- for (uint pindex : particle_indices) {
- kill_states[pindex] = 1;
- }
- }
-};
-
-class MoveAction : public BParticles::Action {
- private:
- float3 m_offset;
-
- public:
- MoveAction(float3 offset) : m_offset(offset)
- {
- }
-
- void execute(AttributeArrays attributes, ArrayRef<uint> particle_indices) override
- {
- auto positions = attributes.get_float3("Position");
-
- for (uint pindex : particle_indices) {
- positions[pindex] += m_offset;
- }
- }
-};
-
class ModifierStepParticleInfluences : public ParticleInfluences {
public:
SmallVector<Force *> m_forces;
@@ -191,10 +130,10 @@ void BParticles_simulate_modifier(NodeParticlesModifierData *npmd,
EMITTER_mesh_surface((Mesh *)npmd->emitter_object->data, npmd->control1).release());
}
description.m_influences.m_forces.append(FORCE_directional({0, 0, -2}).release());
- description.m_influences.m_events.append(new AgeReachedEvent(6.0f));
- description.m_influences.m_actions.append(new KillAction());
- description.m_influences.m_events.append(new AgeReachedEvent(3.0f));
- description.m_influences.m_actions.append(new MoveAction({0, 10, 0}));
+ description.m_influences.m_events.append(EVENT_age_reached(6.0f).release());
+ description.m_influences.m_actions.append(ACTION_kill().release());
+ description.m_influences.m_events.append(EVENT_age_reached(3.0f).release());
+ description.m_influences.m_actions.append(ACTION_move({0, 10, 0}).release());
simulate_step(state, description);
std::cout << "Active Blocks: " << state.m_container->active_blocks().size() << "\n";
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
new file mode 100644
index 00000000000..46340afef51
--- /dev/null
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -0,0 +1,45 @@
+#include "events.hpp"
+
+namespace BParticles {
+
+class AgeReachedEvent : public Event {
+ private:
+ float m_age;
+
+ public:
+ AgeReachedEvent(float age) : m_age(age)
+ {
+ }
+
+ void filter(AttributeArrays attributes,
+ ArrayRef<uint> particle_indices,
+ IdealOffsets &UNUSED(ideal_offsets),
+ ArrayRef<float> durations,
+ float end_time,
+ SmallVector<uint> &r_filtered_indices,
+ SmallVector<float> &r_time_factors) override
+ {
+ auto birth_times = attributes.get_float("Birth Time");
+
+ for (uint i = 0; i < particle_indices.size(); i++) {
+ uint pindex = particle_indices[i];
+ float duration = 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) + 0.00001f;
+ r_time_factors.append(time_factor);
+ }
+ }
+ }
+};
+
+std::unique_ptr<Event> EVENT_age_reached(float age)
+{
+ Event *event = new AgeReachedEvent(age);
+ return std::unique_ptr<Event>(event);
+}
+
+} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/events.hpp b/source/blender/simulations/bparticles/events.hpp
new file mode 100644
index 00000000000..89a5e576aad
--- /dev/null
+++ b/source/blender/simulations/bparticles/events.hpp
@@ -0,0 +1,7 @@
+#pragma once
+
+#include "core.hpp"
+
+namespace BParticles {
+std::unique_ptr<Event> EVENT_age_reached(float age);
+}
More information about the Bf-blender-cvs
mailing list