[Bf-blender-cvs] [317158e106f] functions: reintroduce unique_ptr for actions and events

Jacques Lucke noreply at git.blender.org
Mon Jul 8 17:57:29 CEST 2019


Commit: 317158e106f767be880a21f1cfb98a0ecf7f77ad
Author: Jacques Lucke
Date:   Mon Jul 8 17:08:31 2019 +0200
Branches: functions
https://developer.blender.org/rB317158e106f767be880a21f1cfb98a0ecf7f77ad

reintroduce unique_ptr for actions and events

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

M	source/blender/simulations/bparticles/actions.cpp
M	source/blender/simulations/bparticles/actions.hpp
M	source/blender/simulations/bparticles/c_wrapper.cpp
M	source/blender/simulations/bparticles/events.cpp
M	source/blender/simulations/bparticles/events.hpp

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

diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index 9309037ae1f..2349660de82 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -43,17 +43,12 @@ class NoneAction : public Action {
 class ChangeDirectionAction : public Action {
  private:
   ParticleFunction m_compute_inputs;
-  Action *m_post_action;
+  std::unique_ptr<Action> m_post_action;
 
  public:
-  ChangeDirectionAction(ParticleFunction &compute_inputs, Action *post_action)
-      : m_compute_inputs(compute_inputs), m_post_action(post_action)
-  {
-  }
-
-  ~ChangeDirectionAction()
+  ChangeDirectionAction(ParticleFunction &compute_inputs, std::unique_ptr<Action> post_action)
+      : m_compute_inputs(compute_inputs), m_post_action(std::move(post_action))
   {
-    delete m_post_action;
   }
 
   void execute(ActionInterface &interface) override
@@ -213,35 +208,40 @@ class ConditionAction : public Action {
   }
 };
 
-Action *ACTION_none()
+std::unique_ptr<Action> ACTION_none()
 {
-  return new NoneAction();
+  Action *action = new NoneAction();
+  return std::unique_ptr<Action>(action);
 }
 
-Action *ACTION_change_direction(ParticleFunction &compute_inputs, Action *post_action)
+std::unique_ptr<Action> ACTION_change_direction(ParticleFunction &compute_inputs,
+                                                std::unique_ptr<Action> post_action)
 {
-  return new ChangeDirectionAction(compute_inputs, post_action);
+  Action *action = new ChangeDirectionAction(compute_inputs, std::move(post_action));
+  return std::unique_ptr<Action>(action);
 }
 
-Action *ACTION_kill()
+std::unique_ptr<Action> ACTION_kill()
 {
-  return new KillAction();
+  Action *action = new KillAction();
+  return std::unique_ptr<Action>(action);
 }
 
-Action *ACTION_explode(StringRef new_particle_name,
-                       ParticleFunction &compute_inputs,
-                       Action *post_action)
+std::unique_ptr<Action> ACTION_explode(StringRef new_particle_name,
+                                       ParticleFunction &compute_inputs,
+                                       std::unique_ptr<Action> post_action)
 {
-  return new ExplodeAction(
-      new_particle_name, compute_inputs, std::unique_ptr<Action>(post_action));
+  Action *action = new ExplodeAction(new_particle_name, compute_inputs, std::move(post_action));
+  return std::unique_ptr<Action>(action);
 }
 
-Action *ACTION_condition(ParticleFunction &compute_inputs,
-                         Action *true_action,
-                         Action *false_action)
+std::unique_ptr<Action> ACTION_condition(ParticleFunction &compute_inputs,
+                                         std::unique_ptr<Action> true_action,
+                                         std::unique_ptr<Action> false_action)
 {
-  return new ConditionAction(
-      compute_inputs, std::unique_ptr<Action>(true_action), std::unique_ptr<Action>(false_action));
+  Action *action = new ConditionAction(
+      compute_inputs, std::move(true_action), std::move(false_action));
+  return std::unique_ptr<Action>(action);
 }
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/actions.hpp b/source/blender/simulations/bparticles/actions.hpp
index d34febc951b..ddc49f7466a 100644
--- a/source/blender/simulations/bparticles/actions.hpp
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -4,14 +4,15 @@
 
 namespace BParticles {
 
-Action *ACTION_none();
-Action *ACTION_change_direction(ParticleFunction &compute_inputs, Action *post_action);
-Action *ACTION_kill();
-Action *ACTION_explode(StringRef new_particle_name,
-                       ParticleFunction &compute_inputs,
-                       Action *post_action);
-Action *ACTION_condition(ParticleFunction &compute_inputs,
-                         Action *true_action,
-                         Action *false_action);
+std::unique_ptr<Action> ACTION_none();
+std::unique_ptr<Action> ACTION_change_direction(ParticleFunction &compute_inputs,
+                                                std::unique_ptr<Action> post_action);
+std::unique_ptr<Action> ACTION_kill();
+std::unique_ptr<Action> ACTION_explode(StringRef new_particle_name,
+                                       ParticleFunction &compute_inputs,
+                                       std::unique_ptr<Action> post_action);
+std::unique_ptr<Action> ACTION_condition(ParticleFunction &compute_inputs,
+                                         std::unique_ptr<Action> true_action,
+                                         std::unique_ptr<Action> false_action);
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index b3658e07884..0665ae4dedc 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -291,10 +291,10 @@ static SharedFunction create_function(IndexedNodeTree &indexed_tree,
   return fn;
 }
 
-static Action *build_action(SocketWithNode start,
-                            IndexedNodeTree &indexed_tree,
-                            FN::DataFlowNodes::GeneratedGraph &data_graph,
-                            ModifierStepDescription &step_description)
+static std::unique_ptr<Action> build_action(SocketWithNode start,
+                                            IndexedNodeTree &indexed_tree,
+                                            FN::DataFlowNodes::GeneratedGraph &data_graph,
+                                            ModifierStepDescription &step_description)
 {
   if (start.socket->in_out == SOCK_OUT) {
     auto linked = indexed_tree.linked(start.socket);
@@ -334,11 +334,11 @@ static Action *build_action(SocketWithNode start,
     char name[65];
     RNA_string_get(&rna, "particle_type_name", name);
 
-    Action *post_action = build_action(
+    auto post_action = build_action(
         {node_outputs.get(0), bnode}, indexed_tree, data_graph, step_description);
 
     if (step_description.m_types.contains(name)) {
-      return ACTION_explode(name, particle_fn, post_action);
+      return ACTION_explode(name, particle_fn, std::move(post_action));
     }
     else {
       return post_action;
@@ -349,12 +349,12 @@ static Action *build_action(SocketWithNode start,
         indexed_tree, data_graph, {node_inputs.get(1)}, bnode->name);
     ParticleFunction particle_fn(fn);
 
-    Action *true_action = build_action(
+    auto true_action = build_action(
         {node_outputs.get(0), bnode}, indexed_tree, data_graph, step_description);
-    Action *false_action = build_action(
+    auto false_action = build_action(
         {node_outputs.get(1), bnode}, indexed_tree, data_graph, step_description);
 
-    return ACTION_condition(particle_fn, true_action, false_action);
+    return ACTION_condition(particle_fn, std::move(true_action), std::move(false_action));
   }
   else {
     return nullptr;
@@ -428,14 +428,14 @@ static void INSERT_EVENT_age_reached(bNode *event_node,
       continue;
     }
 
-    Action *action = build_action({(bNodeSocket *)event_node->outputs.first, event_node},
-                                  indexed_tree,
-                                  data_graph,
-                                  step_description);
-    Event *event = EVENT_age_reached(event_node->name, fn, action);
+    auto action = build_action({(bNodeSocket *)event_node->outputs.first, event_node},
+                               indexed_tree,
+                               data_graph,
+                               step_description);
+    auto event = EVENT_age_reached(event_node->name, fn, std::move(action));
 
     bNode *type_node = linked.node;
-    step_description.m_types.lookup_ref(type_node->name)->m_events.append(event);
+    step_description.m_types.lookup_ref(type_node->name)->m_events.append(event.release());
   }
 }
 
@@ -458,14 +458,14 @@ static void INSERT_EVENT_mesh_collision(bNode *event_node,
       continue;
     }
 
-    Action *action = build_action({(bNodeSocket *)event_node->outputs.first, event_node},
-                                  indexed_tree,
-                                  data_graph,
-                                  step_description);
-    Event *event = EVENT_mesh_collision(event_node->name, object, action);
+    auto action = build_action({(bNodeSocket *)event_node->outputs.first, event_node},
+                               indexed_tree,
+                               data_graph,
+                               step_description);
+    auto event = EVENT_mesh_collision(event_node->name, object, std::move(action));
 
     bNode *type_node = linked.node;
-    step_description.m_types.lookup_ref(type_node->name)->m_events.append(event);
+    step_description.m_types.lookup_ref(type_node->name)->m_events.append(event.release());
   }
 }
 
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index a8a03eaa61d..ca142a58a15 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -218,14 +218,20 @@ class MeshCollisionEventFilter : public Event {
   }
 };
 
-Event *EVENT_age_reached(StringRef identifier, SharedFunction &compute_age_fn, Action *action)
+std::unique_ptr<Event> EVENT_age_reached(StringRef identifier,
+                                         SharedFunction &compute_age_fn,
+                                         std::unique_ptr<Action> action)
 {
-  return new AgeReachedEvent(identifier, compute_age_fn, std::unique_ptr<Action>(action));
+  Event *event = new AgeReachedEvent(identifier, compute_age_fn, std::move(action));
+  return std::unique_ptr<Event>(event);
 }
 
-Event *EVENT_mesh_collision(StringRef identifier, Object *object, Action *action)
+std::unique_ptr<Event> EVENT_mesh_collision(StringRef identifier,
+                                            Object *object,
+                                            std::unique_ptr<Action> action)
 {
-  return new MeshCollisionEventFilter(identifier, object, std::unique_ptr<Action>(action));
+  Event *event = new MeshCollisionEventFilter(iden

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list