Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-09-10 19:00:44 +0300
committerJacques Lucke <jacques@blender.org>2020-09-10 19:01:55 +0300
commit11df9cb9fb7391825220eaa7e4975a298f339674 (patch)
tree25f179032c9312823eb696de6b7f871ce99eca8b /source/blender
parentb0741e1dcbc5e4549e95745b1f1b501f8cd33add (diff)
Refactor: move Key .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/intern/key.c108
-rw-r--r--source/blender/blenloader/intern/readfile.c69
-rw-r--r--source/blender/blenloader/intern/writefile.c25
3 files changed, 102 insertions, 100 deletions
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index 9cdbb30b90a..1b63aa1a8af 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -28,12 +28,16 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
+#include "BLI_endian_switch.h"
#include "BLI_math_vector.h"
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
+/* Allow using deprecated functionality for .blend file I/O. */
+#define DNA_DEPRECATED_ALLOW
+
#include "DNA_ID.h"
#include "DNA_anim_types.h"
#include "DNA_key_types.h"
@@ -43,6 +47,7 @@
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "BKE_anim_data.h"
#include "BKE_curve.h"
#include "BKE_customdata.h"
#include "BKE_deform.h"
@@ -58,6 +63,8 @@
#include "RNA_access.h"
+#include "BLO_read_write.h"
+
static void shapekey_copy_data(Main *UNUSED(bmain),
ID *id_dst,
const ID *id_src,
@@ -98,6 +105,94 @@ static void shapekey_foreach_id(ID *id, LibraryForeachIDData *data)
BKE_LIB_FOREACHID_PROCESS_ID(data, key->from, IDWALK_CB_LOOPBACK);
}
+static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_address)
+{
+ Key *key = (Key *)id;
+ if (key->id.us > 0 || BLO_write_is_undo(writer)) {
+ /* write LibData */
+ BLO_write_id_struct(writer, Key, id_address, &key->id);
+ BKE_id_blend_write(writer, &key->id);
+
+ if (key->adt) {
+ BKE_animdata_blend_write(writer, key->adt);
+ }
+
+ /* direct data */
+ LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
+ BLO_write_struct(writer, KeyBlock, kb);
+ if (kb->data) {
+ BLO_write_raw(writer, kb->totelem * key->elemsize, kb->data);
+ }
+ }
+ }
+}
+
+/* old defines from DNA_ipo_types.h for data-type, stored in DNA - don't modify! */
+#define IPO_FLOAT 4
+#define IPO_BEZTRIPLE 100
+#define IPO_BPOINT 101
+
+static void switch_endian_keyblock(Key *key, KeyBlock *kb)
+{
+ int elemsize = key->elemsize;
+ char *data = kb->data;
+
+ for (int a = 0; a < kb->totelem; a++) {
+ const char *cp = key->elemstr;
+ char *poin = data;
+
+ while (cp[0]) { /* cp[0] == amount */
+ switch (cp[1]) { /* cp[1] = type */
+ case IPO_FLOAT:
+ case IPO_BPOINT:
+ case IPO_BEZTRIPLE: {
+ int b = cp[0];
+ BLI_endian_switch_float_array((float *)poin, b);
+ poin += sizeof(float) * b;
+ break;
+ }
+ }
+
+ cp += 2;
+ }
+ data += elemsize;
+ }
+}
+
+static void shapekey_blend_read_data(BlendDataReader *reader, ID *id)
+{
+ Key *key = (Key *)id;
+ BLO_read_list(reader, &(key->block));
+
+ BLO_read_data_address(reader, &key->adt);
+ BKE_animdata_blend_read_data(reader, key->adt);
+
+ BLO_read_data_address(reader, &key->refkey);
+
+ LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
+ BLO_read_data_address(reader, &kb->data);
+
+ if (BLO_read_requires_endian_switch(reader)) {
+ switch_endian_keyblock(key, kb);
+ }
+ }
+}
+
+static void shapekey_blend_read_lib(BlendLibReader *reader, ID *id)
+{
+ Key *key = (Key *)id;
+ BLI_assert((key->id.tag & LIB_TAG_EXTERN) == 0);
+
+ BLO_read_id_address(reader, key->id.lib, &key->ipo); // XXX deprecated - old animation system
+ BLO_read_id_address(reader, key->id.lib, &key->from);
+}
+
+static void shapekey_blend_read_expand(BlendExpander *expander, ID *id)
+{
+ Key *key = (Key *)id;
+ BLO_expand(expander, key->ipo); // XXX deprecated - old animation system
+}
+
IDTypeInfo IDType_ID_KE = {
.id_code = ID_KE,
.id_filter = 0,
@@ -115,21 +210,16 @@ IDTypeInfo IDType_ID_KE = {
.foreach_id = shapekey_foreach_id,
.foreach_cache = NULL,
- .blend_write = NULL,
- .blend_read_data = NULL,
- .blend_read_lib = NULL,
- .blend_read_expand = NULL,
+ .blend_write = shapekey_blend_write,
+ .blend_read_data = shapekey_blend_read_data,
+ .blend_read_lib = shapekey_blend_read_lib,
+ .blend_read_expand = shapekey_blend_read_expand,
};
#define KEY_MODE_DUMMY 0 /* use where mode isn't checked for */
#define KEY_MODE_BPOINT 1
#define KEY_MODE_BEZTRIPLE 2
-/* old defines from DNA_ipo_types.h for data-type, stored in DNA - don't modify! */
-#define IPO_FLOAT 4
-#define IPO_BEZTRIPLE 100
-#define IPO_BPOINT 101
-
/* Internal use only. */
typedef struct WeightsArrayCache {
int num_defgroup_weights;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 9b8564cf817..3d42330dd4f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2801,59 +2801,6 @@ void blo_do_versions_key_uidgen(Key *key)
}
}
-static void lib_link_key(BlendLibReader *reader, Key *key)
-{
- BLI_assert((key->id.tag & LIB_TAG_EXTERN) == 0);
-
- BLO_read_id_address(reader, key->id.lib, &key->ipo); // XXX deprecated - old animation system
- BLO_read_id_address(reader, key->id.lib, &key->from);
-}
-
-static void switch_endian_keyblock(Key *key, KeyBlock *kb)
-{
- int elemsize = key->elemsize;
- char *data = kb->data;
-
- for (int a = 0; a < kb->totelem; a++) {
- const char *cp = key->elemstr;
- char *poin = data;
-
- while (cp[0]) { /* cp[0] == amount */
- switch (cp[1]) { /* cp[1] = type */
- case IPO_FLOAT:
- case IPO_BPOINT:
- case IPO_BEZTRIPLE: {
- int b = cp[0];
- BLI_endian_switch_float_array((float *)poin, b);
- poin += sizeof(float) * b;
- break;
- }
- }
-
- cp += 2;
- }
- data += elemsize;
- }
-}
-
-static void direct_link_key(BlendDataReader *reader, Key *key)
-{
- BLO_read_list(reader, &(key->block));
-
- BLO_read_data_address(reader, &key->adt);
- BKE_animdata_blend_read_data(reader, key->adt);
-
- BLO_read_data_address(reader, &key->refkey);
-
- LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
- BLO_read_data_address(reader, &kb->data);
-
- if (BLO_read_requires_endian_switch(reader)) {
- switch_endian_keyblock(key, kb);
- }
- }
-}
-
/** \} */
/* -------------------------------------------------------------------- */
@@ -6689,9 +6636,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_IP:
direct_link_ipo(&reader, (Ipo *)id);
break;
- case ID_KE:
- direct_link_key(&reader, (Key *)id);
- break;
case ID_LI:
direct_link_library(fd, (Library *)id, main);
break;
@@ -6747,6 +6691,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_SPK:
case ID_AR:
case ID_LP:
+ case ID_KE:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -7397,9 +7342,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_GD:
lib_link_gpencil(&reader, (bGPdata *)id);
break;
- case ID_KE:
- lib_link_key(&reader, (Key *)id);
- break;
case ID_SIM:
lib_link_simulation(&reader, (Simulation *)id);
break;
@@ -7432,6 +7374,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_SPK:
case ID_AR:
case ID_LP:
+ case ID_KE:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -8117,11 +8060,6 @@ static void expand_collection(BlendExpander *expander, Collection *collection)
#endif
}
-static void expand_key(BlendExpander *expander, Key *key)
-{
- BLO_expand(expander, key->ipo); // XXX deprecated - old animation system
-}
-
static void expand_texture(BlendExpander *expander, Tex *tex)
{
BLO_expand(expander, tex->ima);
@@ -8477,9 +8415,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
case ID_TE:
expand_texture(&expander, (Tex *)id);
break;
- case ID_KE:
- expand_key(&expander, (Key *)id);
- break;
case ID_SO:
expand_sound(&expander, (bSound *)id);
break;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index cae6990fbb0..d4e3f4646d6 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1393,27 +1393,6 @@ static void write_object(BlendWriter *writer, Object *ob, const void *id_address
}
}
-static void write_key(BlendWriter *writer, Key *key, const void *id_address)
-{
- if (key->id.us > 0 || BLO_write_is_undo(writer)) {
- /* write LibData */
- BLO_write_id_struct(writer, Key, id_address, &key->id);
- BKE_id_blend_write(writer, &key->id);
-
- if (key->adt) {
- BKE_animdata_blend_write(writer, key->adt);
- }
-
- /* direct data */
- LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
- BLO_write_struct(writer, KeyBlock, kb);
- if (kb->data) {
- BLO_write_raw(writer, kb->totelem * key->elemsize, kb->data);
- }
- }
- }
-}
-
static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address)
{
if (tex->id.us > 0 || BLO_write_is_undo(writer)) {
@@ -2592,9 +2571,6 @@ static bool write_file_handle(Main *mainvar,
case ID_SCE:
write_scene(&writer, (Scene *)id_buffer, id);
break;
- case ID_KE:
- write_key(&writer, (Key *)id_buffer, id);
- break;
case ID_SO:
write_sound(&writer, (bSound *)id_buffer, id);
break;
@@ -2650,6 +2626,7 @@ static bool write_file_handle(Main *mainvar,
case ID_SPK:
case ID_AR:
case ID_LP:
+ case ID_KE:
/* Do nothing, handled in IDTypeInfo callback. */
break;
case ID_LI: