[Bf-blender-cvs] [39765705391] functions: use particle function in Age Reached event

Jacques Lucke noreply at git.blender.org
Wed Jul 24 19:12:24 CEST 2019


Commit: 39765705391b10a784a8a1f999b73a4ab912657d
Author: Jacques Lucke
Date:   Wed Jul 24 19:07:55 2019 +0200
Branches: functions
https://developer.blender.org/rB39765705391b10a784a8a1f999b73a4ab912657d

use particle function in Age Reached event

===================================================================

M	source/blender/simulations/bparticles/events.cpp
M	source/blender/simulations/bparticles/events.hpp
M	source/blender/simulations/bparticles/inserters.cpp

===================================================================

diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index 1a657f071e6..f1fa082c1df 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -18,17 +18,15 @@ void AgeReachedEvent::filter(EventFilterInterface &interface)
 
   float end_time = interface.end_time();
 
-  FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_age_body, fn_in, fn_out);
-  FN::ExecutionStack stack;
-  FN::ExecutionContext execution_context(stack);
-  m_compute_age_body.call(fn_in, fn_out, execution_context);
-  float trigger_age = fn_out.get<float>(0);
+  auto inputs = m_compute_inputs.compute(interface);
 
   for (uint pindex : particles.pindices()) {
     if (was_activated_before[pindex]) {
       continue;
     }
 
+    float trigger_age = inputs->get<float>("Age", 0, pindex);
+
     float birth_time = birth_times[pindex];
     float age_at_end = end_time - birth_time;
 
diff --git a/source/blender/simulations/bparticles/events.hpp b/source/blender/simulations/bparticles/events.hpp
index 9ce72965fb9..b4a2ea659a5 100644
--- a/source/blender/simulations/bparticles/events.hpp
+++ b/source/blender/simulations/bparticles/events.hpp
@@ -19,17 +19,15 @@ using BLI::float4x4;
 class AgeReachedEvent : public Event {
  private:
   std::string m_identifier;
-  SharedFunction m_compute_age_fn;
-  TupleCallBody &m_compute_age_body;
+  ParticleFunction m_compute_inputs;
   std::unique_ptr<Action> m_action;
 
  public:
   AgeReachedEvent(StringRef identifier,
-                  SharedFunction &compute_age_fn,
+                  ParticleFunction compute_inputs,
                   std::unique_ptr<Action> action)
       : m_identifier(identifier.to_std_string()),
-        m_compute_age_fn(compute_age_fn),
-        m_compute_age_body(m_compute_age_fn->body<TupleCallBody>()),
+        m_compute_inputs(std::move(compute_inputs)),
         m_action(std::move(action))
   {
   }
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index 8d6f7f06710..ad6f22ecac8 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -54,22 +54,6 @@ static ValueOrError<SharedFunction> create_function__emitter_inputs(VirtualNode
   return fn;
 }
 
-static ValueOrError<SharedFunction> create_function__event_inputs(VirtualNode *event_vnode,
-                                                                  VTreeDataGraph &data_graph)
-{
-  Vector<DFGraphSocket> sockets_to_compute = find_input_data_sockets(event_vnode, data_graph);
-  auto dependencies = data_graph.find_placeholder_dependencies(sockets_to_compute);
-
-  if (dependencies.size() > 0) {
-    return BLI_ERROR_CREATE("Event inputs cannot have dependencies currently.");
-  }
-
-  FunctionGraph fgraph(data_graph.graph(), {}, sockets_to_compute);
-  SharedFunction fn = fgraph.new_function(event_vnode->name());
-  FN::fgraph_add_TupleCallBody(fn, fgraph);
-  return fn;
-}
-
 static ValueOrError<SharedFunction> create_function__action_inputs(VirtualNode *action_vnode,
                                                                    VTreeDataGraph &data_graph)
 {
@@ -117,6 +101,12 @@ static ValueOrError<SharedFunction> create_function__force_inputs(VirtualNode *f
   return create_function__action_inputs(force_vnode, data_graph);
 }
 
+static ValueOrError<SharedFunction> create_function__event_inputs(VirtualNode *event_vnode,
+                                                                  VTreeDataGraph &data_graph)
+{
+  return create_function__action_inputs(event_vnode, data_graph);
+}
+
 static std::unique_ptr<Action> build_action(BuildContext &ctx,
                                             VirtualSocket *start,
                                             VirtualSocket *trigger);
@@ -277,7 +267,8 @@ static std::unique_ptr<Event> BUILD_EVENT_age_reached(BuildContext &ctx, Virtual
 
   SharedFunction fn = fn_or_error.extract_value();
   auto action = build_action_for_trigger(ctx, vnode->output(0));
-  return std::unique_ptr<Event>(new AgeReachedEvent(vnode->name(), fn, std::move(action)));
+  return std::unique_ptr<Event>(
+      new AgeReachedEvent(vnode->name(), ParticleFunction(fn), std::move(action)));
 }
 
 static std::unique_ptr<Event> BUILD_EVENT_close_by_points(BuildContext &ctx, VirtualNode *vnode)



More information about the Bf-blender-cvs mailing list