[Bf-blender-cvs] [c6a00f46adc] functions: pass around Object handles instead of pointers

Jacques Lucke noreply at git.blender.org
Wed Dec 4 14:28:18 CET 2019


Commit: c6a00f46adcacc1c494bbffe926c2356fb2a0506
Author: Jacques Lucke
Date:   Wed Dec 4 13:33:49 2019 +0100
Branches: functions
https://developer.blender.org/rBc6a00f46adcacc1c494bbffe926c2356fb2a0506

pass around Object handles instead of pointers

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

M	source/blender/functions/intern/cpp_types.cc
M	source/blender/functions/intern/inlined_tree_multi_function_network/mappings_sockets.cc
M	source/blender/functions/intern/multi_functions/mixed.cc
M	source/blender/simulations/bparticles/node_frontend.cpp

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

diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc
index 95f13090e23..3c748db5172 100644
--- a/source/blender/functions/intern/cpp_types.cc
+++ b/source/blender/functions/intern/cpp_types.cc
@@ -1,8 +1,6 @@
 #include "FN_cpp_type.h"
 #include "cpp_types.h"
 
-#include "DNA_object_types.h"
-
 #include "BLI_math_cxx.h"
 
 #include "BKE_surface_location.h"
@@ -96,7 +94,8 @@ MAKE_CPP_TYPE(float, float)
 MAKE_CPP_TYPE(uint32_t, uint32_t)
 MAKE_CPP_TYPE(uint8_t, uint8_t)
 MAKE_CPP_TYPE(bool, bool)
-MAKE_CPP_TYPE(ObjectPtr, Object *)
+MAKE_CPP_TYPE(ObjectIDHandle, BKE::ObjectIDHandle)
+MAKE_CPP_TYPE(ImageIDHandle, BKE::ImageIDHandle)
 MAKE_CPP_TYPE(int32, int32_t)
 MAKE_CPP_TYPE(rgba_f, BLI::rgba_f)
 MAKE_CPP_TYPE(float3, BLI::float3)
diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_sockets.cc b/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_sockets.cc
index 8f3d0c69999..def570322bb 100644
--- a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_sockets.cc
+++ b/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_sockets.cc
@@ -47,7 +47,12 @@ static void INSERT_int_socket(VSocketMFNetworkBuilder &builder)
 static void INSERT_object_socket(VSocketMFNetworkBuilder &builder)
 {
   Object *value = (Object *)RNA_pointer_get(builder.rna(), "value").data;
-  builder.set_constant_value(value);
+  if (value == nullptr) {
+    builder.set_constant_value(BKE::ObjectIDHandle());
+  }
+  else {
+    builder.set_constant_value(BKE::ObjectIDHandle(value));
+  }
 }
 
 static void INSERT_text_socket(VSocketMFNetworkBuilder &builder)
@@ -158,7 +163,7 @@ void add_inlined_tree_socket_mapping_info(VTreeMultiFunctionMappings &mappings)
   add_basic_type<float>(mappings, "Float", INSERT_float_socket);
   add_basic_type<BLI::float3>(mappings, "Vector", INSERT_vector_socket);
   add_basic_type<int32_t>(mappings, "Integer", INSERT_int_socket);
-  add_basic_type<Object *>(mappings, "Object", INSERT_object_socket);
+  add_basic_type<BKE::ObjectIDHandle>(mappings, "Object", INSERT_object_socket);
   add_basic_type<std::string>(mappings, "Text", INSERT_text_socket);
   add_basic_type<bool>(mappings, "Boolean", INSERT_bool_socket);
   add_basic_type<BLI::rgba_f>(mappings, "Color", INSERT_color_socket);
diff --git a/source/blender/functions/intern/multi_functions/mixed.cc b/source/blender/functions/intern/multi_functions/mixed.cc
index 634e170aa06..afc7835feeb 100644
--- a/source/blender/functions/intern/multi_functions/mixed.cc
+++ b/source/blender/functions/intern/multi_functions/mixed.cc
@@ -248,18 +248,19 @@ void MF_FloatRange::call(MFMask mask, MFParams params, MFContext UNUSED(context)
 MF_ObjectVertexPositions::MF_ObjectVertexPositions()
 {
   MFSignatureBuilder signature{"Object Vertex Positions"};
-  signature.single_input<Object *>("Object");
+  signature.single_input<ObjectIDHandle>("Object");
   signature.vector_output<float3>("Positions");
   this->set_signature(signature);
 }
 
-void MF_ObjectVertexPositions::call(MFMask mask, MFParams params, MFContext UNUSED(context)) const
+void MF_ObjectVertexPositions::call(MFMask mask, MFParams params, MFContext context) const
 {
-  VirtualListRef<Object *> objects = params.readonly_single_input<Object *>(0, "Object");
+  VirtualListRef<ObjectIDHandle> objects = params.readonly_single_input<ObjectIDHandle>(0,
+                                                                                        "Object");
   auto positions = params.vector_output<float3>(1, "Positions");
 
   for (uint i : mask.indices()) {
-    Object *object = objects[i];
+    Object *object = context.id_handle_lookup().lookup(objects[i]);
     if (object == nullptr || object->type != OB_MESH) {
       continue;
     }
@@ -523,19 +524,20 @@ void MF_GetImageColorOnSurface::call(MFMask mask, MFParams params, MFContext con
 MF_ObjectWorldLocation::MF_ObjectWorldLocation()
 {
   MFSignatureBuilder signature("Object Location");
-  signature.single_input<Object *>("Object");
+  signature.single_input<ObjectIDHandle>("Object");
   signature.single_output<float3>("Location");
   this->set_signature(signature);
 }
 
-void MF_ObjectWorldLocation::call(MFMask mask, MFParams params, MFContext UNUSED(context)) const
+void MF_ObjectWorldLocation::call(MFMask mask, MFParams params, MFContext context) const
 {
-  auto objects = params.readonly_single_input<Object *>(0, "Object");
+  auto objects = params.readonly_single_input<ObjectIDHandle>(0, "Object");
   auto locations = params.uninitialized_single_output<float3>(1, "Location");
 
   for (uint i : mask.indices()) {
-    if (objects[i] != nullptr) {
-      locations[i] = objects[i]->obmat[3];
+    Object *object = context.id_handle_lookup().lookup(objects[i]);
+    if (object != nullptr) {
+      locations[i] = object->obmat[3];
     }
     else {
       locations[i] = float3(0, 0, 0);
@@ -893,7 +895,7 @@ void MF_ParticleIsInGroup::call(MFMask mask, MFParams params, MFContext context)
 MF_ClosestLocationOnObject::MF_ClosestLocationOnObject()
 {
   MFSignatureBuilder signature("Closest Point on Object");
-  signature.single_input<Object *>("Object");
+  signature.single_input<ObjectIDHandle>("Object");
   signature.single_input<float3>("Position");
   signature.single_output<SurfaceLocation>("Closest Location");
   this->set_signature(signature);
@@ -929,7 +931,8 @@ void MF_ClosestLocationOnObject::call(MFMask mask, MFParams params, MFContext co
 {
   auto context_data = context.element_contexts().find_first<ExternalDataCacheContext>();
 
-  VirtualListRef<Object *> objects = params.readonly_single_input<Object *>(0, "Object");
+  VirtualListRef<ObjectIDHandle> objects = params.readonly_single_input<ObjectIDHandle>(0,
+                                                                                        "Object");
   VirtualListRef<float3> positions = params.readonly_single_input<float3>(1, "Position");
   MutableArrayRef<SurfaceLocation> r_surface_locations =
       params.uninitialized_single_output<SurfaceLocation>(2, "Closest Location");
@@ -940,7 +943,7 @@ void MF_ClosestLocationOnObject::call(MFMask mask, MFParams params, MFContext co
   }
 
   if (mask.indices().size() > 0 && objects.all_equal(mask.indices())) {
-    Object *object = objects[mask.indices()[0]];
+    Object *object = context.id_handle_lookup().lookup(objects[mask.indices()[0]]);
     if (object == nullptr) {
       r_surface_locations.fill_indices(mask.indices(), {});
       return;
@@ -972,7 +975,7 @@ void MF_ClosestLocationOnObject::call(MFMask mask, MFParams params, MFContext co
   }
   else {
     for (uint i : mask.indices()) {
-      Object *object = objects[i];
+      Object *object = context.id_handle_lookup().lookup(objects[i]);
       if (object == nullptr) {
         r_surface_locations[i] = {};
         continue;
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index ff13a8364d9..0357ac2851c 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -24,6 +24,8 @@
 
 namespace BParticles {
 
+using BKE::IDHandleLookup;
+using BKE::ObjectIDHandle;
 using BKE::XGroupInput;
 using BKE::XInputSocket;
 using BKE::XNode;
@@ -116,6 +118,11 @@ class VTreeData {
     return m_inlined_tree_data_graph;
   }
 
+  IDHandleLookup &id_handle_lookup()
+  {
+    return m_id_handle_lookup;
+  }
+
   template<typename T, typename... Args> T &construct(const char *name, Args &&... args)
   {
     void *buffer = m_resources.allocate(sizeof(T), alignof(T));
@@ -550,7 +557,8 @@ static void PARSE_mesh_emitter(InfluencesCollector &collector,
   Action &on_birth_action = inlined_tree_data.build_action_list(
       collector, xnode, "Execute on Birth");
 
-  Object *object = inputs->relocate_out<Object *>(0, "Object");
+  ObjectIDHandle object_handle = inputs->relocate_out<ObjectIDHandle>(0, "Object");
+  Object *object = inlined_tree_data.id_handle_lookup().lookup(object_handle);
   if (object == nullptr || object->type != OB_MESH) {
     return;
   }
@@ -674,7 +682,8 @@ static void PARSE_mesh_collision(InfluencesCollector &collector,
     return;
   }
 
-  Object *object = inputs->relocate_out<Object *>(0, "Object");
+  ObjectIDHandle object_handle = inputs->relocate_out<ObjectIDHandle>(0, "Object");
+  Object *object = inlined_tree_data.id_handle_lookup().lookup(object_handle);
   if (object == nullptr || object->type != OB_MESH) {
     return;
   }



More information about the Bf-blender-cvs mailing list