From b443f9b54c38570ca6b7cdc25a8eb1f3c97b735e Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 10 Sep 2020 11:17:35 +0200 Subject: Refactor: move keyingset .blend I/O to blenkernel Ref T76372 --- source/blender/blenkernel/BKE_animsys.h | 11 ++++++ source/blender/blenkernel/intern/anim_sys.c | 51 ++++++++++++++++++++++++++++ source/blender/blenloader/intern/readfile.c | 48 +++----------------------- source/blender/blenloader/intern/writefile.c | 21 ++---------- 4 files changed, 68 insertions(+), 63 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h index ef74bb61a7e..fa3c59c781d 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -46,6 +46,10 @@ struct Scene; struct bAction; struct bActionGroup; struct bContext; +struct BlendWriter; +struct BlendDataReader; +struct BlendLibReader; +struct BlendExpander; /* Container for data required to do FCurve and Driver evaluation. */ typedef struct AnimationEvalContext { @@ -101,6 +105,13 @@ void BKE_keyingset_free(struct KeyingSet *ks); /* Free all the KeyingSets in the given list */ void BKE_keyingsets_free(struct ListBase *list); +void BKE_keyingsets_blend_write(struct BlendWriter *writer, struct ListBase *list); +void BKE_keyingsets_blend_read_data(struct BlendDataReader *reader, struct ListBase *list); +void BKE_keyingsets_blend_read_lib(struct BlendLibReader *reader, + struct ID *id, + struct ListBase *list); +void BKE_keyingsets_blend_read_expand(struct BlendExpander *expander, struct ListBase *list); + /* ************************************* */ /* Path Fixing API */ diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 69e70cffdb2..98c01351f32 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -69,6 +69,8 @@ #include "RNA_access.h" +#include "BLO_read_write.h" + #include "nla_private.h" #include "atomic_ops.h" @@ -308,6 +310,55 @@ void BKE_keyingsets_free(ListBase *list) } } +void BKE_keyingsets_blend_write(BlendWriter *writer, ListBase *list) +{ + LISTBASE_FOREACH (KeyingSet *, ks, list) { + /* KeyingSet */ + BLO_write_struct(writer, KeyingSet, ks); + + /* Paths */ + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { + /* Path */ + BLO_write_struct(writer, KS_Path, ksp); + + if (ksp->rna_path) { + BLO_write_string(writer, ksp->rna_path); + } + } + } +} + +void BKE_keyingsets_blend_read_data(BlendDataReader *reader, ListBase *list) +{ + LISTBASE_FOREACH (KeyingSet *, ks, list) { + /* paths */ + BLO_read_list(reader, &ks->paths); + + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { + /* rna path */ + BLO_read_data_address(reader, &ksp->rna_path); + } + } +} + +void BKE_keyingsets_blend_read_lib(BlendLibReader *reader, ID *id, ListBase *list) +{ + LISTBASE_FOREACH (KeyingSet *, ks, list) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { + BLO_read_id_address(reader, id->lib, &ksp->id); + } + } +} + +void BKE_keyingsets_blend_read_expand(BlendExpander *expander, ListBase *list) +{ + LISTBASE_FOREACH (KeyingSet *, ks, list) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { + BLO_expand(expander, ksp->id); + } + } +} + /* ***************************************** */ /* Evaluation Data-Setting Backend */ diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 462849a5c29..59287cc4d6a 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -113,6 +113,7 @@ #include "BKE_action.h" #include "BKE_anim_data.h" +#include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_brush.h" #include "BKE_collection.h" @@ -2687,37 +2688,6 @@ static void lib_link_constraint_channels(BlendLibReader *reader, ID *id, ListBas /** \} */ -/* -------------------------------------------------------------------- */ -/** \name Read: Keyingsets - * \{ */ - -static void lib_link_keyingsets(BlendLibReader *reader, ID *id, ListBase *list) -{ - /* here, we're only interested in the ID pointer stored in some of the paths */ - LISTBASE_FOREACH (KeyingSet *, ks, list) { - LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { - BLO_read_id_address(reader, id->lib, &ksp->id); - } - } -} - -/* NOTE: this assumes that BLO_read_list has already been called on the list */ -static void direct_link_keyingsets(BlendDataReader *reader, ListBase *list) -{ - /* link KeyingSet data to KeyingSet again (non ID-libs) */ - LISTBASE_FOREACH (KeyingSet *, ks, list) { - /* paths */ - BLO_read_list(reader, &ks->paths); - - LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { - /* rna path */ - BLO_read_data_address(reader, &ksp->rna_path); - } - } -} - -/** \} */ - /* -------------------------------------------------------------------- */ /** \name Read ID: CacheFiles * \{ */ @@ -5257,7 +5227,7 @@ static bool scene_validate_setscene__liblink(Scene *sce, const int totscene) static void lib_link_scene(BlendLibReader *reader, Scene *sce) { - lib_link_keyingsets(reader, &sce->id, &sce->keyingsets); + BKE_keyingsets_blend_read_lib(reader, &sce->id, &sce->keyingsets); BLO_read_id_address(reader, sce->id.lib, &sce->camera); BLO_read_id_address(reader, sce->id.lib, &sce->world); @@ -5536,7 +5506,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) BKE_animdata_blend_read_data(reader, sce->adt); BLO_read_list(reader, &sce->keyingsets); - direct_link_keyingsets(reader, &sce->keyingsets); + BKE_keyingsets_blend_read_data(reader, &sce->keyingsets); BLO_read_data_address(reader, &sce->basact); @@ -9416,16 +9386,6 @@ static void expand_id(BlendExpander *expander, ID *id) expand_id_embedded_id(expander, id); } -static void expand_keyingsets(BlendExpander *expander, ListBase *list) -{ - /* expand the ID-pointers in KeyingSets's paths */ - LISTBASE_FOREACH (KeyingSet *, ks, list) { - LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { - BLO_expand(expander, ksp->id); - } - } -} - static void expand_particlesettings(BlendExpander *expander, ParticleSettings *part) { BLO_expand(expander, part->instance_object); @@ -9783,7 +9743,7 @@ static void expand_scene(BlendExpander *expander, Scene *sce) BLO_expand(expander, sce->camera); BLO_expand(expander, sce->world); - expand_keyingsets(expander, &sce->keyingsets); + BKE_keyingsets_blend_read_expand(expander, &sce->keyingsets); if (sce->set) { BLO_expand(expander, sce->set); diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 429045222f0..daad7f0e05e 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -153,6 +153,7 @@ #include "BKE_action.h" #include "BKE_anim_data.h" +#include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_blender_version.h" #include "BKE_bpath.h" @@ -660,24 +661,6 @@ static void writelist_id(WriteData *wd, int filecode, const char *structname, co * These functions are used by blender's .blend system for file saving/loading. * \{ */ -static void write_keyingsets(BlendWriter *writer, ListBase *list) -{ - LISTBASE_FOREACH (KeyingSet *, ks, list) { - /* KeyingSet */ - BLO_write_struct(writer, KeyingSet, ks); - - /* Paths */ - LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { - /* Path */ - BLO_write_struct(writer, KS_Path, ksp); - - if (ksp->rna_path) { - BLO_write_string(writer, ksp->rna_path); - } - } - } -} - static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *sock) { if (sock->default_value == NULL) { @@ -2018,7 +2001,7 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address) if (sce->adt) { BKE_animdata_blend_write(writer, sce->adt); } - write_keyingsets(writer, &sce->keyingsets); + BKE_keyingsets_blend_write(writer, &sce->keyingsets); /* direct data */ ToolSettings *tos = sce->toolsettings; -- cgit v1.2.3