[Bf-blender-cvs] [b666848b75a] new-object-types: Cleanup: move hair, pointcloud, volume to IDTypeInfo

Brecht Van Lommel noreply at git.blender.org
Fri Mar 6 15:22:50 CET 2020


Commit: b666848b75a4d1b37b9c06738b059d8f72164ccf
Author: Brecht Van Lommel
Date:   Fri Mar 6 15:17:38 2020 +0100
Branches: new-object-types
https://developer.blender.org/rBb666848b75a4d1b37b9c06738b059d8f72164ccf

Cleanup: move hair, pointcloud, volume to IDTypeInfo

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

M	source/blender/blenkernel/BKE_hair.h
M	source/blender/blenkernel/BKE_idtype.h
M	source/blender/blenkernel/BKE_pointcloud.h
M	source/blender/blenkernel/BKE_volume.h
M	source/blender/blenkernel/intern/hair.c
M	source/blender/blenkernel/intern/idtype.c
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/blenkernel/intern/lib_id_delete.c
M	source/blender/blenkernel/intern/pointcloud.c
M	source/blender/blenkernel/intern/volume.cc

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

diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h
index fe290a4777c..0cb26581aef 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -38,15 +38,8 @@ struct Main;
 struct Object;
 struct Scene;
 
-void BKE_hair_init(struct Hair *hair);
 void *BKE_hair_add(struct Main *bmain, const char *name);
-void BKE_hair_copy_data(struct Main *bmain,
-                        struct Hair *hair_dst,
-                        const struct Hair *hair_src,
-                        const int flag);
 struct Hair *BKE_hair_copy(struct Main *bmain, const struct Hair *hair);
-void BKE_hair_make_local(struct Main *bmain, struct Hair *hair, const bool lib_local);
-void BKE_hair_free(struct Hair *hair);
 
 struct BoundBox *BKE_hair_boundbox_get(struct Object *ob);
 
diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index 75c8a0aafd4..a7c90851e41 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -26,6 +26,8 @@
  * ID type structure, helping to factorize common operations and data for all data-block types.
  */
 
+#include "BLI_sys_types.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -70,7 +72,7 @@ typedef struct IDTypeInfo {
    * Bitflag matching id_code, used for filtering (e.g. in file browser), see DNA_ID.h's
    * FILTER_ID_XX enums.
    */
-  int id_filter;
+  int64_t id_filter;
 
   /**
    * Define the position of this data-block type in the virtual list of all data in a Main that is
@@ -160,6 +162,9 @@ extern IDTypeInfo IDType_ID_BR;
 // extern IDTypeInfo IDType_ID_CF;
 // extern IDTypeInfo IDType_ID_WS;
 extern IDTypeInfo IDType_ID_LP;
+extern IDTypeInfo IDType_ID_HA;
+extern IDTypeInfo IDType_ID_PT;
+extern IDTypeInfo IDType_ID_VO;
 
 /* ********** Helpers/Utils API. ********** */
 
diff --git a/source/blender/blenkernel/BKE_pointcloud.h b/source/blender/blenkernel/BKE_pointcloud.h
index 003e25b8342..972795e2ae1 100644
--- a/source/blender/blenkernel/BKE_pointcloud.h
+++ b/source/blender/blenkernel/BKE_pointcloud.h
@@ -38,17 +38,8 @@ struct Object;
 struct PointCloud;
 struct Scene;
 
-void BKE_pointcloud_init(struct PointCloud *pointcloud);
 void *BKE_pointcloud_add(struct Main *bmain, const char *name);
-void BKE_pointcloud_copy_data(struct Main *bmain,
-                              struct PointCloud *pointcloud_dst,
-                              const struct PointCloud *pointcloud_src,
-                              const int flag);
 struct PointCloud *BKE_pointcloud_copy(struct Main *bmain, const struct PointCloud *pointcloud);
-void BKE_pointcloud_make_local(struct Main *bmain,
-                               struct PointCloud *pointcloud,
-                               const bool lib_local);
-void BKE_pointcloud_free(struct PointCloud *pointcloud);
 
 struct BoundBox *BKE_pointcloud_boundbox_get(struct Object *ob);
 
diff --git a/source/blender/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h
index 84802bd1390..b9845397d84 100644
--- a/source/blender/blenkernel/BKE_volume.h
+++ b/source/blender/blenkernel/BKE_volume.h
@@ -45,16 +45,9 @@ void BKE_volumes_init(void);
 
 /* Datablock Management */
 
-void BKE_volume_init(struct Volume *volume);
 void BKE_volume_init_grids(struct Volume *volume);
 void *BKE_volume_add(struct Main *bmain, const char *name);
-void BKE_volume_copy_data(struct Main *bmain,
-                          struct Volume *volume_dst,
-                          const struct Volume *volume_src,
-                          const int flag);
 struct Volume *BKE_volume_copy(struct Main *bmain, const struct Volume *volume);
-void BKE_volume_make_local(struct Main *bmain, struct Volume *volume, const bool lib_local);
-void BKE_volume_free(struct Volume *volume);
 
 struct BoundBox *BKE_volume_boundbox_get(struct Object *ob);
 
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index 795d7d371a5..2769bb2ce74 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -36,6 +36,7 @@
 
 #include "BKE_animsys.h"
 #include "BKE_customdata.h"
+#include "BKE_idtype.h"
 #include "BKE_global.h"
 #include "BKE_hair.h"
 #include "BKE_lib_id.h"
@@ -45,6 +46,8 @@
 #include "BKE_modifier.h"
 #include "BKE_object.h"
 
+#include "BLT_translation.h"
+
 #include "DEG_depsgraph_query.h"
 
 /* Hair datablock */
@@ -94,8 +97,9 @@ static void hair_random(Hair *hair)
   BLI_rng_free(rng);
 }
 
-void BKE_hair_init(Hair *hair)
+static void hair_init_data(ID *id)
 {
+  Hair *hair = (Hair *)id;
   BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(hair, id));
 
   MEMCPY_STRUCT_AFTER(hair, DNA_struct_default_get(Hair), id);
@@ -115,13 +119,15 @@ void *BKE_hair_add(Main *bmain, const char *name)
 {
   Hair *hair = BKE_libblock_alloc(bmain, ID_HA, name, 0);
 
-  BKE_hair_init(hair);
+  hair_init_data(&hair->id);
 
   return hair;
 }
 
-void BKE_hair_copy_data(Main *UNUSED(bmain), Hair *hair_dst, const Hair *hair_src, const int flag)
+static void hair_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
 {
+  Hair *hair_dst = (Hair *)id_dst;
+  const Hair *hair_src = (const Hair *)id_src;
   hair_dst->mat = MEM_dupallocN(hair_dst->mat);
 
   const eCDAllocType alloc_type = (flag & LIB_ID_COPY_CD_REFERENCE) ? CD_REFERENCE : CD_DUPLICATE;
@@ -139,14 +145,15 @@ Hair *BKE_hair_copy(Main *bmain, const Hair *hair)
   return hair_copy;
 }
 
-void BKE_hair_make_local(Main *bmain, Hair *hair, const bool lib_local)
+static void hair_make_local(Main *bmain, ID *id, const int flags)
 {
-  BKE_id_make_local_generic(bmain, &hair->id, true, lib_local);
+  BKE_lib_id_make_local_generic(bmain, id, flags);
 }
 
-void BKE_hair_free(Hair *hair)
+static void hair_free_data(ID *id)
 {
-  BKE_animdata_free((ID *)hair, false);
+  Hair *hair = (Hair *)id;
+  BKE_animdata_free(&hair->id, false);
 
   BKE_hair_batch_cache_free(hair);
 
@@ -156,6 +163,22 @@ void BKE_hair_free(Hair *hair)
   MEM_SAFE_FREE(hair->mat);
 }
 
+IDTypeInfo IDType_ID_HA = {
+    .id_code = ID_HA,
+    .id_filter = FILTER_ID_HA,
+    .main_listbase_index = INDEX_ID_HA,
+    .struct_size = sizeof(Hair),
+    .name = "Hair",
+    .name_plural = "hairs",
+    .translation_context = BLT_I18NCONTEXT_ID_HAIR,
+    .flags = 0,
+
+    .init_data = hair_init_data,
+    .copy_data = hair_copy_data,
+    .free_data = hair_free_data,
+    .make_local = hair_make_local,
+};
+
 BoundBox *BKE_hair_boundbox_get(Object *ob)
 {
   BLI_assert(ob->type == OB_HAIR);
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index fb3d967a0bb..dd6ea098e68 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -87,6 +87,9 @@ static void id_type_init(void)
   // INIT_TYPE(ID_CF);
   // INIT_TYPE(ID_WS);
   INIT_TYPE(ID_LP);
+  INIT_TYPE(ID_HA);
+  INIT_TYPE(ID_PT);
+  INIT_TYPE(ID_VO);
 
 #undef INIT_TYPE
 }
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 9e7ade0a461..aeb6fb3c69d 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -609,19 +609,13 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags
       }
       return true;
     case ID_HA:
-      if (!test) {
-        BKE_hair_make_local(bmain, (Hair *)id, lib_local);
-      }
+      BLI_assert(0);
       return true;
     case ID_PT:
-      if (!test) {
-        BKE_pointcloud_make_local(bmain, (PointCloud *)id, lib_local);
-      }
+      BLI_assert(0);
       return true;
     case ID_VO:
-      if (!test) {
-        BKE_volume_make_local(bmain, (Volume *)id, lib_local);
-      }
+      BLI_assert(0);
       return true;
     case ID_WS:
     case ID_SCR:
@@ -832,13 +826,13 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
         BKE_vfont_copy_data(bmain, (VFont *)*r_newid, (VFont *)id, flag);
         break;
       case ID_HA:
-        BKE_hair_copy_data(bmain, (Hair *)*r_newid, (Hair *)id, flag);
+        BLI_assert(0);
         break;
       case ID_PT:
-        BKE_pointcloud_copy_data(bmain, (PointCloud *)*r_newid, (PointCloud *)id, flag);
+        BLI_assert(0);
         break;
       case ID_VO:
-        BKE_volume_copy_data(bmain, (Volume *)*r_newid, (Volume *)id, flag);
+        BLI_assert(0);
         break;
       case ID_LI:
       case ID_SCR:
@@ -1461,13 +1455,13 @@ void BKE_libblock_init_empty(ID *id)
       BKE_cachefile_init((CacheFile *)id);
       break;
     case ID_HA:
-      BKE_hair_init((Hair *)id);
+      BLI_assert(0);
       break;
     case ID_PT:
-      BKE_pointcloud_init((PointCloud *)id);
+      BLI_assert(0);
       break;
     case ID_VO:
-      BKE_volume_init((Volume *)id);
+      BLI_assert(0);
       break;
     case ID_KE:
       /* Shapekeys are a complex topic too - they depend on their 'user' data type...
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
index 0f76fbb05b1..c2635e37987 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -253,13 +253,13 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
       BKE_workspace_free((WorkSpace *)id);
       break;
     case ID_HA:
-      BKE_hair_free((Hair *)id);
+      BLI_assert(0);
       break;
     case ID_PT:
-      BKE_pointcloud_free((PointCloud *)id);
+      BLI_assert(0);
       break;
     case ID_VO:
-      BKE_volume_free((Volume *)id);
+      BLI_assert(0);
       break;
   }
 }
diff --git a/source/blender/blenkernel/intern/pointcloud.c b/source/blender/blenkernel/intern/pointcloud.c
index cc60c0b2cc7..a2fcb113854 100644
--- a/source/blender/blenkernel/intern/pointcloud.c
+++ b/source/blender/blenkernel/intern/pointcloud.c
@@ -36,6 +36,7 @@
 
 #include "BKE_animsys.h"
 #include "BKE_customdata.h"
+#include "BKE_idtype.h"
 #include "BKE_global.h"
 #include "BKE_lib_id.h"
 #include "BKE_lib_query.h"
@@ -45,6 +46,8 @@
 #include "BKE_object.h"
 #include "BKE_pointcloud.h"
 
+#include "BLT_translation.h"


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list