[Bf-blender-cvs] [15c834ebbfa] master: Cleanup: ShapeKey: Move to IDTypeInfo and remove unused BKE API.

Bastien Montagne noreply at git.blender.org
Fri Mar 6 12:54:13 CET 2020


Commit: 15c834ebbfa050aff2d955a6b9f5aaebee67ae7e
Author: Bastien Montagne
Date:   Fri Mar 6 12:16:56 2020 +0100
Branches: master
https://developer.blender.org/rB15c834ebbfa050aff2d955a6b9f5aaebee67ae7e

Cleanup: ShapeKey: Move to IDTypeInfo and remove unused BKE API.

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

M	source/blender/blenkernel/BKE_idtype.h
M	source/blender/blenkernel/BKE_key.h
M	source/blender/blenkernel/intern/idtype.c
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/blenkernel/intern/lib_id_delete.c

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

diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index ec7c5cafbcf..a8ed78241d8 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -137,7 +137,7 @@ extern IDTypeInfo IDType_ID_OB;
 extern IDTypeInfo IDType_ID_LA;
 extern IDTypeInfo IDType_ID_CA;
 // extern IDTypeInfo IDType_ID_IP;
-// extern IDTypeInfo IDType_ID_KE;
+extern IDTypeInfo IDType_ID_KE;
 extern IDTypeInfo IDType_ID_WO;
 // extern IDTypeInfo IDType_ID_SCR;
 // extern IDTypeInfo IDType_ID_VF;
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index 477a22b07bb..6581891062c 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -40,10 +40,6 @@ extern "C" {
 void BKE_key_free(struct Key *sc);
 void BKE_key_free_nolib(struct Key *key);
 struct Key *BKE_key_add(struct Main *bmain, struct ID *id);
-void BKE_key_copy_data(struct Main *bmain,
-                       struct Key *key_dst,
-                       const struct Key *key_src,
-                       const int flag);
 struct Key *BKE_key_copy(struct Main *bmain, const struct Key *key);
 struct Key *BKE_key_copy_nolib(struct Key *key);
 void BKE_key_sort(struct Key *key);
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index 2193ff2165c..e4013c0d327 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -64,7 +64,7 @@ static void id_type_init(void)
   INIT_TYPE(ID_LA);
   INIT_TYPE(ID_CA);
   // INIT_TYPE(ID_IP);
-  // INIT_TYPE(ID_KE);
+  INIT_TYPE(ID_KE);
   INIT_TYPE(ID_WO);
   // INIT_TYPE(ID_SCR);
   // INIT_TYPE(ID_VF);
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index c5ee20d00dd..77e3a3dc005 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -35,6 +35,7 @@
 #include "BLT_translation.h"
 
 #include "DNA_anim_types.h"
+#include "DNA_ID.h"
 #include "DNA_key_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_mesh_types.h"
@@ -46,6 +47,7 @@
 #include "BKE_curve.h"
 #include "BKE_customdata.h"
 #include "BKE_deform.h"
+#include "BKE_idtype.h"
 #include "BKE_key.h"
 #include "BKE_lattice.h"
 #include "BKE_lib_id.h"
@@ -56,6 +58,58 @@
 
 #include "RNA_access.h"
 
+static void shapekey_copy_data(Main *UNUSED(bmain),
+                               ID *id_dst,
+                               const ID *id_src,
+                               const int UNUSED(flag))
+{
+  Key *key_dst = (Key *)id_dst;
+  const Key *key_src = (const Key *)id_src;
+  BLI_duplicatelist(&key_dst->block, &key_src->block);
+
+  KeyBlock *kb_dst, *kb_src;
+  for (kb_src = key_src->block.first, kb_dst = key_dst->block.first; kb_dst;
+       kb_src = kb_src->next, kb_dst = kb_dst->next) {
+    if (kb_dst->data) {
+      kb_dst->data = MEM_dupallocN(kb_dst->data);
+    }
+    if (kb_src == key_src->refkey) {
+      key_dst->refkey = kb_dst;
+    }
+  }
+}
+
+static void shapekey_free_data(ID *id)
+{
+  Key *key = (Key *)id;
+  KeyBlock *kb;
+
+  BKE_animdata_free((ID *)key, false);
+
+  while ((kb = BLI_pophead(&key->block))) {
+    if (kb->data) {
+      MEM_freeN(kb->data);
+    }
+    MEM_freeN(kb);
+  }
+}
+
+IDTypeInfo IDType_ID_KE = {
+    .id_code = ID_KE,
+    .id_filter = 0,
+    .main_listbase_index = INDEX_ID_KE,
+    .struct_size = sizeof(Key),
+    .name = "Key",
+    .name_plural = "shape_keys",
+    .translation_context = BLT_I18NCONTEXT_ID_SHAPEKEY,
+    .flags = IDTYPE_FLAGS_NO_LIBLINKING | IDTYPE_FLAGS_NO_MAKELOCAL,
+
+    .init_data = NULL,
+    .copy_data = shapekey_copy_data,
+    .free_data = shapekey_free_data,
+    .make_local = NULL,
+};
+
 #define KEY_MODE_DUMMY 0 /* use where mode isn't checked for */
 #define KEY_MODE_BPOINT 1
 #define KEY_MODE_BEZTRIPLE 2
@@ -74,16 +128,7 @@ typedef struct WeightsArrayCache {
 /** Free (or release) any data used by this shapekey (does not free the key itself). */
 void BKE_key_free(Key *key)
 {
-  KeyBlock *kb;
-
-  BKE_animdata_free((ID *)key, false);
-
-  while ((kb = BLI_pophead(&key->block))) {
-    if (kb->data) {
-      MEM_freeN(kb->data);
-    }
-    MEM_freeN(kb);
-  }
+  shapekey_free_data(&key->id);
 }
 
 void BKE_key_free_nolib(Key *key)
@@ -150,35 +195,6 @@ Key *BKE_key_add(Main *bmain, ID *id) /* common function */
   return key;
 }
 
-/**
- * Only copy internal data of ShapeKey ID from source
- * to already allocated/initialized destination.
- * You probably never want to use that directly,
- * use #BKE_id_copy or #BKE_id_copy_ex for typical needs.
- *
- * WARNING! This function will not handle ID user count!
- *
- * \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more).
- */
-void BKE_key_copy_data(Main *UNUSED(bmain),
-                       Key *key_dst,
-                       const Key *key_src,
-                       const int UNUSED(flag))
-{
-  BLI_duplicatelist(&key_dst->block, &key_src->block);
-
-  KeyBlock *kb_dst, *kb_src;
-  for (kb_src = key_src->block.first, kb_dst = key_dst->block.first; kb_dst;
-       kb_src = kb_src->next, kb_dst = kb_dst->next) {
-    if (kb_dst->data) {
-      kb_dst->data = MEM_dupallocN(kb_dst->data);
-    }
-    if (kb_src == key_src->refkey) {
-      key_dst->refkey = kb_dst;
-    }
-  }
-}
-
 Key *BKE_key_copy(Main *bmain, const Key *key)
 {
   Key *key_copy;
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 01d6bb1077d..8ffd9ece659 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -757,7 +757,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
         BLI_assert(0);
         break;
       case ID_KE:
-        BKE_key_copy_data(bmain, (Key *)*r_newid, (Key *)id, flag);
+        BLI_assert(0);
         break;
       case ID_WO:
         BLI_assert(0);
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
index 7d5f5c55ead..8d9d359746f 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -176,7 +176,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
       BKE_ipo_free((Ipo *)id);
       break;
     case ID_KE:
-      BKE_key_free((Key *)id);
+      BLI_assert(0);
       break;
     case ID_WO:
       BLI_assert(0);



More information about the Bf-blender-cvs mailing list