[Bf-blender-cvs] [b293739f1fc] functions: initial event info
Jacques Lucke
noreply at git.blender.org
Mon Jul 8 17:57:12 CEST 2019
Commit: b293739f1fcf24f86a752626c697c6e726bc8b57
Author: Jacques Lucke
Date: Mon Jul 8 14:23:08 2019 +0200
Branches: functions
https://developer.blender.org/rBb293739f1fcf24f86a752626c697c6e726bc8b57
initial event info
===================================================================
M source/blender/simulations/bparticles/actions.cpp
M source/blender/simulations/bparticles/actions.hpp
M source/blender/simulations/bparticles/events.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index 3dfdee3f1d6..9f14399d001 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -9,7 +9,7 @@ Action::~Action()
}
class NoneAction : public Action {
- void execute(EventExecuteInterface &UNUSED(interface)) override
+ void execute(EventExecuteInterface &UNUSED(interface), EventInfo &UNUSED(event_info)) override
{
}
};
@@ -30,14 +30,14 @@ class ChangeDirectionAction : public Action {
delete m_post_action;
}
- void execute(EventExecuteInterface &interface) override
+ void execute(EventExecuteInterface &interface, EventInfo &event_info) override
{
ParticleSet particles = interface.particles();
auto velocities = particles.attributes().get_float3("Velocity");
auto position_offsets = interface.attribute_offsets().get_float3("Position");
auto velocity_offsets = interface.attribute_offsets().get_float3("Velocity");
- auto caller = m_compute_inputs.get_caller(particles.attributes());
+ auto caller = m_compute_inputs.get_caller(particles.attributes(), event_info);
FN_TUPLE_CALL_ALLOC_TUPLES(caller.body(), fn_in, fn_out);
@@ -55,61 +55,17 @@ class ChangeDirectionAction : public Action {
velocity_offsets[pindex] = float3(0);
}
- m_post_action->execute(interface);
+ m_post_action->execute(interface, event_info);
}
};
class KillAction : public Action {
- void execute(EventExecuteInterface &interface) override
+ void execute(EventExecuteInterface &interface, EventInfo &UNUSED(event_info)) override
{
interface.kill(interface.particles().indices());
}
};
-class MoveAction : public Action {
- private:
- float3 m_offset;
-
- public:
- MoveAction(float3 offset) : m_offset(offset)
- {
- }
-
- void execute(EventExecuteInterface &interface) override
- {
- ParticleSet &particles = interface.particles();
-
- auto positions = particles.attributes().get_float3("Position");
- for (uint pindex : particles.indices()) {
- positions[pindex] += m_offset;
- }
- }
-};
-
-class SpawnAction : public Action {
- void execute(EventExecuteInterface &interface) override
- {
- ParticleSet &particles = interface.particles();
-
- auto positions = particles.attributes().get_float3("Position");
-
- SmallVector<float3> new_positions;
- SmallVector<float3> new_velocities;
- SmallVector<uint> original_indices;
-
- 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));
- original_indices.append(i);
- }
-
- auto &target = interface.request_emit_target(0, original_indices);
- target.set_float3("Position", new_positions);
- target.set_float3("Velocity", new_velocities);
- }
-};
-
static float random_number()
{
static uint number = 0;
@@ -138,7 +94,7 @@ class ExplodeAction : public Action {
{
}
- void execute(EventExecuteInterface &interface) override
+ void execute(EventExecuteInterface &interface, EventInfo &event_info) override
{
ParticleSet &particles = interface.particles();
@@ -148,7 +104,7 @@ class ExplodeAction : public Action {
SmallVector<float3> new_velocities;
SmallVector<uint> original_indices;
- auto caller = m_compute_inputs.get_caller(particles.attributes());
+ auto caller = m_compute_inputs.get_caller(particles.attributes(), event_info);
FN_TUPLE_CALL_ALLOC_TUPLES(caller.body(), fn_in, fn_out);
FN::ExecutionStack stack;
@@ -173,7 +129,7 @@ class ExplodeAction : public Action {
target.set_float3("Position", new_positions);
target.set_float3("Velocity", new_velocities);
- m_post_action->execute(interface);
+ m_post_action->execute(interface, event_info);
}
};
@@ -192,16 +148,6 @@ Action *ACTION_kill()
return new KillAction();
}
-Action *ACTION_move(float3 offset)
-{
- return new MoveAction(offset);
-}
-
-Action *ACTION_spawn()
-{
- return new SpawnAction();
-}
-
Action *ACTION_explode(StringRef new_particle_name,
ParticleFunction &compute_inputs,
Action *post_action)
diff --git a/source/blender/simulations/bparticles/actions.hpp b/source/blender/simulations/bparticles/actions.hpp
index 62b2ea5a9a0..fce6ac6b650 100644
--- a/source/blender/simulations/bparticles/actions.hpp
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -11,11 +11,9 @@ using FN::SharedFunction;
using FN::Tuple;
using FN::TupleCallBody;
-class Action {
+class EventInfo {
public:
- virtual ~Action() = 0;
-
- virtual void execute(EventExecuteInterface &interface) = 0;
+ virtual void *get_info_array(StringRef name) = 0;
};
class ParticleFunction;
@@ -59,17 +57,27 @@ class ParticleFunction {
BLI_assert(m_tuple_call);
}
- ParticleFunctionCaller get_caller(AttributeArrays attributes)
+ ParticleFunctionCaller get_caller(AttributeArrays attributes, EventInfo &event_info)
{
ParticleFunctionCaller caller;
caller.m_body = m_tuple_call;
for (uint i = 0; i < m_function->input_amount(); i++) {
StringRef input_name = m_function->input_name(i);
- uint index = attributes.attribute_index(input_name);
- uint stride = attributes.attribute_stride(index);
- void *ptr = attributes.get_ptr(index);
-
+ void *ptr;
+ uint stride;
+ if (input_name.startswith("EVENT")) {
+ StringRef event_attribute_name = input_name.drop_prefix("EVENT");
+ ptr = event_info.get_info_array(event_attribute_name);
+ stride = sizeof(float3); /* TODO make not hardcoded */
+ }
+ else {
+ uint index = attributes.attribute_index(input_name);
+ stride = attributes.attribute_stride(index);
+ ptr = attributes.get_ptr(index);
+ }
+
+ BLI_assert(ptr);
caller.m_attribute_buffers.append(ptr);
caller.m_strides.append(stride);
}
@@ -78,11 +86,16 @@ class ParticleFunction {
}
};
+class Action {
+ public:
+ virtual ~Action() = 0;
+
+ virtual void execute(EventExecuteInterface &interface, EventInfo &event_info) = 0;
+};
+
Action *ACTION_none();
Action *ACTION_change_direction(ParticleFunction &compute_inputs, Action *post_action);
Action *ACTION_kill();
-Action *ACTION_move(float3 offset);
-Action *ACTION_spawn();
Action *ACTION_explode(StringRef new_particle_name,
ParticleFunction &compute_inputs,
Action *post_action);
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index 47c15014479..3a8112a4223 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -8,6 +8,13 @@
namespace BParticles {
+class EmptyEventInfo : public EventInfo {
+ void *get_info_array(StringRef UNUSED(name)) override
+ {
+ return nullptr;
+ }
+};
+
class AgeReachedEvent : public Event {
private:
std::string m_identifier;
@@ -79,7 +86,8 @@ class AgeReachedEvent : public Event {
was_activated_before[pindex] = true;
}
- m_action->execute(interface);
+ EmptyEventInfo event_info;
+ m_action->execute(interface, event_info);
}
};
@@ -154,7 +162,8 @@ class MeshCollisionEventFilter : public Event {
void execute(EventExecuteInterface &interface) override
{
- m_action->execute(interface);
+ EmptyEventInfo event_info;
+ m_action->execute(interface, event_info);
}
};
More information about the Bf-blender-cvs
mailing list