[Bf-blender-cvs] [34439f05ab6] master: Cleanup: remove use of persistent data handles in geometry nodes

Jacques Lucke noreply at git.blender.org
Sat May 8 14:55:06 CEST 2021


Commit: 34439f05ab68e0f6287c96d7391f38dca8e64205
Author: Jacques Lucke
Date:   Sat May 8 14:54:48 2021 +0200
Branches: master
https://developer.blender.org/rB34439f05ab68e0f6287c96d7391f38dca8e64205

Cleanup: remove use of persistent data handles in geometry nodes

Those were mostly just left over from previous work on particle nodes.
They solved the problem of keeping a reference to an object over
multiple frames and in a cache. Currently, we do not have this problem
in geometry nodes, so we can also remove this layer of complexity
for now.

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

D	source/blender/blenkernel/BKE_persistent_data_handle.hh
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/modifiers/intern/MOD_nodes.cc
M	source/blender/modifiers/intern/MOD_nodes_evaluator.cc
M	source/blender/modifiers/intern/MOD_nodes_evaluator.hh
M	source/blender/nodes/NOD_geometry_exec.hh
M	source/blender/nodes/geometry/nodes/node_geo_collection_info.cc
M	source/blender/nodes/geometry/nodes/node_geo_object_info.cc
M	source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
M	source/blender/nodes/geometry/nodes/node_geo_switch.cc
M	source/blender/nodes/intern/node_socket.cc

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

diff --git a/source/blender/blenkernel/BKE_persistent_data_handle.hh b/source/blender/blenkernel/BKE_persistent_data_handle.hh
deleted file mode 100644
index bbee09c7bf4..00000000000
--- a/source/blender/blenkernel/BKE_persistent_data_handle.hh
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#pragma once
-
-/** \file
- * \ingroup bke
- *
- * A PersistentDataHandle is a weak reference to some data in a Blender file. The handle itself is
- * just a number. A PersistentDataHandleMap is used to convert between handles and the actual data.
- */
-
-#include "BLI_map.hh"
-
-#include "DNA_ID.h"
-
-struct Collection;
-struct Object;
-
-namespace blender::bke {
-
-class PersistentDataHandleMap;
-
-class PersistentDataHandle {
- private:
-  /* Negative values indicate that the handle is "empty". */
-  int32_t handle_;
-
-  friend PersistentDataHandleMap;
-
- protected:
-  PersistentDataHandle(int handle) : handle_(handle)
-  {
-  }
-
- public:
-  PersistentDataHandle() : handle_(-1)
-  {
-  }
-
-  friend bool operator==(const PersistentDataHandle &a, const PersistentDataHandle &b)
-  {
-    return a.handle_ == b.handle_;
-  }
-
-  friend bool operator!=(const PersistentDataHandle &a, const PersistentDataHandle &b)
-  {
-    return !(a == b);
-  }
-
-  friend std::ostream &operator<<(std::ostream &stream, const PersistentDataHandle &a)
-  {
-    stream << a.handle_;
-    return stream;
-  }
-
-  uint64_t hash() const
-  {
-    return static_cast<uint64_t>(handle_);
-  }
-};
-
-class PersistentIDHandle : public PersistentDataHandle {
-  friend PersistentDataHandleMap;
-  using PersistentDataHandle::PersistentDataHandle;
-};
-
-class PersistentObjectHandle : public PersistentIDHandle {
-  friend PersistentDataHandleMap;
-  using PersistentIDHandle::PersistentIDHandle;
-};
-
-class PersistentCollectionHandle : public PersistentIDHandle {
-  friend PersistentDataHandleMap;
-  using PersistentIDHandle::PersistentIDHandle;
-};
-
-class PersistentDataHandleMap {
- private:
-  Map<int32_t, ID *> id_by_handle_;
-  Map<ID *, int32_t> handle_by_id_;
-
- public:
-  void add(int32_t handle, ID &id)
-  {
-    BLI_assert(handle >= 0);
-    handle_by_id_.add(&id, handle);
-    id_by_handle_.add(handle, &id);
-  }
-
-  PersistentIDHandle lookup(ID *id) const
-  {
-    const int handle = handle_by_id_.lookup_default(id, -1);
-    return PersistentIDHandle(handle);
-  }
-
-  PersistentObjectHandle lookup(Object *object) const
-  {
-    const int handle = handle_by_id_.lookup_default((ID *)object, -1);
-    return PersistentObjectHandle(handle);
-  }
-
-  PersistentCollectionHandle lookup(Collection *collection) const
-  {
-    const int handle = handle_by_id_.lookup_default((ID *)collection, -1);
-    return PersistentCollectionHandle(handle);
-  }
-
-  ID *lookup(const PersistentIDHandle &handle) const
-  {
-    ID *id = id_by_handle_.lookup_default(handle.handle_, nullptr);
-    return id;
-  }
-
-  Object *lookup(const PersistentObjectHandle &handle) const
-  {
-    ID *id = this->lookup((const PersistentIDHandle &)handle);
-    if (id == nullptr) {
-      return nullptr;
-    }
-    if (GS(id->name) != ID_OB) {
-      return nullptr;
-    }
-    return (Object *)id;
-  }
-
-  Collection *lookup(const PersistentCollectionHandle &handle) const
-  {
-    ID *id = this->lookup((const PersistentIDHandle &)handle);
-    if (id == nullptr) {
-      return nullptr;
-    }
-    if (GS(id->name) != ID_GR) {
-      return nullptr;
-    }
-    return (Collection *)id;
-  }
-};
-
-}  // namespace blender::bke
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index acd9d54cfbe..4dc2560f908 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -112,7 +112,7 @@ set(SRC
   intern/curve_convert.c
   intern/curve_decimate.c
   intern/curve_deform.c
-  intern/curve_eval.cc  
+  intern/curve_eval.cc
   intern/curveprofile.c
   intern/customdata.c
   intern/customdata_file.c
@@ -406,7 +406,6 @@ set(SRC
   BKE_paint.h
   BKE_particle.h
   BKE_pbvh.h
-  BKE_persistent_data_handle.hh
   BKE_pointcache.h
   BKE_pointcloud.h
   BKE_preferences.h
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 63541329563..39c4c0743e9 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -93,9 +93,6 @@ using blender::Span;
 using blender::StringRef;
 using blender::StringRefNull;
 using blender::Vector;
-using blender::bke::PersistentCollectionHandle;
-using blender::bke::PersistentDataHandleMap;
-using blender::bke::PersistentObjectHandle;
 using blender::fn::GMutablePointer;
 using blender::fn::GPointer;
 using blender::nodes::GeoNodeExecParams;
@@ -284,9 +281,7 @@ struct SocketPropertyType {
   IDProperty *(*create_default_ui_prop)(const bNodeSocket &socket, const char *name);
   PropertyType (*rna_subtype_get)(const bNodeSocket &socket);
   bool (*is_correct_type)(const IDProperty &property);
-  void (*init_cpp_value)(const IDProperty &property,
-                         const PersistentDataHandleMap &handles,
-                         void *r_value);
+  void (*init_cpp_value)(const IDProperty &property, void *r_value);
 };
 
 static IDProperty *socket_add_property(IDProperty *settings_prop_group,
@@ -379,9 +374,7 @@ static const SocketPropertyType *get_socket_property_type(const bNodeSocket &bso
             return (PropertyType)((bNodeSocketValueFloat *)socket.default_value)->subtype;
           },
           [](const IDProperty &property) { return ELEM(property.type, IDP_FLOAT, IDP_DOUBLE); },
-          [](const IDProperty &property,
-             const PersistentDataHandleMap &UNUSED(handles),
-             void *r_value) {
+          [](const IDProperty &property, void *r_value) {
             if (property.type == IDP_FLOAT) {
               *(float *)r_value = IDP_Float(&property);
             }
@@ -422,9 +415,7 @@ static const SocketPropertyType *get_socket_property_type(const bNodeSocket &bso
             return (PropertyType)((bNodeSocketValueInt *)socket.default_value)->subtype;
           },
           [](const IDProperty &property) { return property.type == IDP_INT; },
-          [](const IDProperty &property,
-             const PersistentDataHandleMap &UNUSED(handles),
-             void *r_value) { *(int *)r_value = IDP_Int(&property); },
+          [](const IDProperty &property, void *r_value) { *(int *)r_value = IDP_Int(&property); },
       };
       return &int_type;
     }
@@ -467,9 +458,9 @@ static const SocketPropertyType *get_socket_property_type(const bNodeSocket &bso
             return property.type == IDP_ARRAY && property.subtype == IDP_FLOAT &&
                    property.len == 3;
           },
-          [](const IDProperty &property,
-             const PersistentDataHandleMap &UNUSED(handles),
-             void *r_value) { copy_v3_v3((float *)r_value, (const float *)IDP_Array(&property)); },
+          [](const IDProperty &property, void *r_value) {
+            copy_v3_v3((float *)r_value, (const float *)IDP_Array(&property));
+          },
       };
       return &vector_type;
     }
@@ -499,9 +490,9 @@ static const SocketPropertyType *get_socket_property_type(const bNodeSocket &bso
           },
           nullptr,
           [](const IDProperty &property) { return property.type == IDP_INT; },
-          [](const IDProperty &property,
-             const PersistentDataHandleMap &UNUSED(handles),
-             void *r_value) { *(bool *)r_value = IDP_Int(&property) != 0; },
+          [](const IDProperty &property, void *r_value) {
+            *(bool *)r_value = IDP_Int(&property) != 0;
+          },
       };
       return &boolean_type;
     }
@@ -521,9 +512,9 @@ static const SocketPropertyType *get_socket_property_type(const bNodeSocket &bso
           },
           nullptr,
           [](const IDProperty &property) { return property.type == IDP_STRING; },
-          [](const IDProperty &property,
-             const PersistentDataHandleMap &UNUSED(handles),
-             void *r_value) { new (r_value) std::string(IDP_String(&property)); },
+          [](const IDProperty &property, void *r_value) {
+            new (r_value) std::string(IDP_String(&property));
+          },
       };
       return &string_type;
     }
@@ -540,10 +531,10 @@ static const SocketPropertyType *get_socket_property_type(const bNodeSocket &bso
           nullptr,
           nullptr,
           [](const IDProperty &property) { return property.type == IDP_ID; },
-          [](const IDProperty &property, const PersistentDataHandleMap &handles, void *r_value) {
+          [](const IDProperty &property, void *r_value) {
             ID *id = IDP_Id(&property);
             Object *object = (id && GS(id->name) == ID_OB) ? (Object *)id : nullptr;
-            new (r_value) PersistentObjectHandle(handles.lookup(object));
+            *(Object **)r_value = object;
           },
       };
       return &object_type;
@@ -561,10 +552,10 @@ static const SocketPropertyType *get_socket_property_type(const bNodeSocket &bso
           nullptr,
           nullptr,
           [](const IDProperty &property) { return property.type == IDP_ID; },
-          [](const IDProperty &property, const PersistentDataHandleMap &handles, void *r_value) {
+          [](const IDProperty &property, void *r_value) {
             ID *id = IDP_Id(&property);
             Collection *collection = (id && GS(i

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list