[Bf-blender-cvs] [524df333bc7] functions: use correct wrapper for Object pointers

Jacques Lucke noreply at git.blender.org
Fri Sep 6 16:55:52 CEST 2019


Commit: 524df333bc7ced2b510d7dd0eac9d599d0319347
Author: Jacques Lucke
Date:   Fri Sep 6 12:49:42 2019 +0200
Branches: functions
https://developer.blender.org/rB524df333bc7ced2b510d7dd0eac9d599d0319347

use correct wrapper for Object pointers

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

M	source/blender/functions/backends/cpp/cpp_type_info.hpp
M	source/blender/functions/frontends/data_flow_nodes/mappings/socket_loaders.cpp
M	source/blender/functions/functions/object_input.cpp
M	source/blender/functions/types/external.cpp
M	source/blender/functions/types/external.hpp
M	source/blender/simulations/bparticles/node_frontend.cpp

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

diff --git a/source/blender/functions/backends/cpp/cpp_type_info.hpp b/source/blender/functions/backends/cpp/cpp_type_info.hpp
index af6e2544281..2211df83dd0 100644
--- a/source/blender/functions/backends/cpp/cpp_type_info.hpp
+++ b/source/blender/functions/backends/cpp/cpp_type_info.hpp
@@ -187,6 +187,39 @@ template<typename T> class CPPTypeInfoForType : public CPPTypeInfo {
 #endif
 };
 
+/**
+ * Use this when the pointer is owned by someone else. The main purpose of this class is to have a
+ * pointer that is nullptr when default-initialized.
+ */
+template<typename T> class ReferencedPointerWrapper {
+ private:
+  T *m_ptr;
+
+ public:
+  ReferencedPointerWrapper() : m_ptr(nullptr)
+  {
+  }
+
+  ReferencedPointerWrapper(T *ptr) : m_ptr(ptr)
+  {
+  }
+
+  ReferencedPointerWrapper(const ReferencedPointerWrapper &other) = default;
+  ReferencedPointerWrapper(ReferencedPointerWrapper &&other) = default;
+  ReferencedPointerWrapper &operator=(const ReferencedPointerWrapper &other) = default;
+  ReferencedPointerWrapper &operator=(ReferencedPointerWrapper &&other) = default;
+
+  T *operator->()
+  {
+    return m_ptr;
+  }
+
+  T *ptr()
+  {
+    return m_ptr;
+  }
+};
+
 /**
  * The class has to have a clone() method.
  */
diff --git a/source/blender/functions/frontends/data_flow_nodes/mappings/socket_loaders.cpp b/source/blender/functions/frontends/data_flow_nodes/mappings/socket_loaders.cpp
index d15eceeee3d..e1ab74e491d 100644
--- a/source/blender/functions/frontends/data_flow_nodes/mappings/socket_loaders.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/mappings/socket_loaders.cpp
@@ -41,8 +41,8 @@ static void LOAD_boolean(PointerRNA *rna, Tuple &tuple, uint index)
 
 static void LOAD_object(PointerRNA *rna, Tuple &tuple, uint index)
 {
-  Object *value = (Object *)RNA_pointer_get(rna, "value").data;
-  tuple.set<Object *>(index, value);
+  ObjectW value = (Object *)RNA_pointer_get(rna, "value").data;
+  tuple.move_in<ObjectW>(index, value);
 }
 
 static void LOAD_color(PointerRNA *rna, Tuple &tuple, uint index)
diff --git a/source/blender/functions/functions/object_input.cpp b/source/blender/functions/functions/object_input.cpp
index 03018fd7623..77058da9b73 100644
--- a/source/blender/functions/functions/object_input.cpp
+++ b/source/blender/functions/functions/object_input.cpp
@@ -16,7 +16,7 @@ using namespace Types;
 class ObjectLocation : public TupleCallBody {
   void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &UNUSED(ctx)) const override
   {
-    Object *object = fn_in.get<Object *>(0);
+    Object *object = fn_in.relocate_out<ObjectW>(0).ptr();
     if (object) {
       float3 position = object->loc;
       fn_out.set<float3>(0, position);
@@ -49,7 +49,7 @@ BLI_LAZY_INIT(SharedFunction, GET_FN_object_location)
 class ObjectMeshVertices : public TupleCallBody {
   void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &UNUSED(ctx)) const override
   {
-    Object *object = fn_in.get<Object *>(0);
+    Object *object = fn_in.relocate_out<ObjectW>(0).ptr();
     if (object == nullptr || object->type != OB_MESH) {
       auto empty_list = SharedList::New(TYPE_float);
       fn_out.move_in(0, empty_list);
diff --git a/source/blender/functions/types/external.cpp b/source/blender/functions/types/external.cpp
index eaa0cfdf55c..63ca74d896c 100644
--- a/source/blender/functions/types/external.cpp
+++ b/source/blender/functions/types/external.cpp
@@ -14,7 +14,7 @@ Type *TYPE_object_list = nullptr;
 void INIT_external(Vector<Type *> &types_to_free)
 {
   TYPE_object = new Type("Object");
-  TYPE_object->add_extension<CPPTypeInfoForType<Object *>>();
+  TYPE_object->add_extension<CPPTypeInfoForType<ObjectW>>();
   TYPE_object->add_extension<ReferencedPointerLLVMTypeInfo>();
 
   TYPE_object_list = new_list_type(TYPE_object);
diff --git a/source/blender/functions/types/external.hpp b/source/blender/functions/types/external.hpp
index c848cfd1d0c..eb5accbada1 100644
--- a/source/blender/functions/types/external.hpp
+++ b/source/blender/functions/types/external.hpp
@@ -1,10 +1,15 @@
 #pragma once
 
-#include "../FN_core.hpp"
+#include "FN_core.hpp"
+#include "FN_cpp.hpp"
+
+struct Object;
 
 namespace FN {
 namespace Types {
 
+using ObjectW = ReferencedPointerWrapper<Object>;
+
 void INIT_external(Vector<Type *> &types_to_free);
 
 extern Type *TYPE_object;
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index 4212f5864b2..e6f68d9594d 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -24,6 +24,7 @@ using FN::FunctionBuilder;
 using FN::FunctionGraph;
 using FN::SharedDataGraph;
 using FN::DataFlowNodes::VTreeDataGraph;
+using FN::Types::ObjectW;
 
 class BehaviorCollector {
  public:
@@ -303,7 +304,7 @@ static void PARSE_mesh_emitter(BehaviorCollector &collector,
   std::unique_ptr<Action> on_birth_action = build_action_list(
       vtree_data_graph, vnode, "Execute on Birth");
 
-  Object *object = body.get_output<Object *>(fn_out, 0, "Object");
+  Object *object = fn_out.relocate_out<ObjectW>(0).ptr();
   if (object == nullptr) {
     return;
   }
@@ -455,7 +456,7 @@ static void PARSE_mesh_collision(BehaviorCollector &collector,
     FN_TUPLE_CALL_ALLOC_TUPLES(body, fn_in, fn_out);
     body.call__setup_execution_context(fn_in, fn_out);
 
-    Object *object = body.get_output<Object *>(fn_out, 0, "Object");
+    Object *object = fn_out.relocate_out<ObjectW>(0).ptr();
     if (object == nullptr || object->type != OB_MESH) {
       return;
     }



More information about the Bf-blender-cvs mailing list