[Bf-blender-cvs] [0de48f8550a] master: Refactor: move animdata code from blenloader to blenkernel

Jacques Lucke noreply at git.blender.org
Fri Aug 21 15:58:45 CEST 2020


Commit: 0de48f8550ad599f43bcc2773cc60a32bebbf5d5
Author: Jacques Lucke
Date:   Fri Aug 21 15:58:28 2020 +0200
Branches: master
https://developer.blender.org/rB0de48f8550ad599f43bcc2773cc60a32bebbf5d5

Refactor: move animdata code from blenloader to blenkernel

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

M	source/blender/blenkernel/BKE_anim_data.h
M	source/blender/blenkernel/intern/anim_data.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenkernel/BKE_anim_data.h b/source/blender/blenkernel/BKE_anim_data.h
index 189e45f4fe5..587262306fe 100644
--- a/source/blender/blenkernel/BKE_anim_data.h
+++ b/source/blender/blenkernel/BKE_anim_data.h
@@ -35,6 +35,10 @@ struct LibraryForeachIDData;
 struct Main;
 struct ReportList;
 struct bAction;
+struct BlendWriter;
+struct BlendDataReader;
+struct BlendLibReader;
+struct BlendExpander;
 
 /* ************************************* */
 /* AnimData API */
@@ -94,6 +98,13 @@ void BKE_animdata_merge_copy(struct Main *bmain,
                              eAnimData_MergeCopy_Modes action_mode,
                              bool fix_drivers);
 
+void BKE_animdata_blend_write(struct BlendWriter *writer, struct AnimData *adt);
+void BKE_animdata_blend_data_read(struct BlendDataReader *reader, struct AnimData *adt);
+void BKE_animdata_blend_lib_read(struct BlendLibReader *reader,
+                                 struct ID *id,
+                                 struct AnimData *adt);
+void BKE_animdata_blend_expand(struct BlendExpander *expander, struct AnimData *adt);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/anim_data.c b/source/blender/blenkernel/intern/anim_data.c
index 038a0d14ddb..875c97e2895 100644
--- a/source/blender/blenkernel/intern/anim_data.c
+++ b/source/blender/blenkernel/intern/anim_data.c
@@ -54,6 +54,8 @@
 
 #include "DEG_depsgraph.h"
 
+#include "BLO_read_write.h"
+
 #include "RNA_access.h"
 
 #include "CLG_log.h"
@@ -1497,3 +1499,85 @@ void BKE_animdata_fix_paths_rename_all(ID *ref_id,
   /* scenes */
   RENAMEFIX_ANIM_NODETREE_IDS(bmain->scenes.first, Scene);
 }
+
+/* .blend file API -------------------------------------------- */
+
+void BKE_animdata_blend_write(BlendWriter *writer, struct AnimData *adt)
+{
+  /* firstly, just write the AnimData block */
+  BLO_write_struct(writer, AnimData, adt);
+
+  /* write drivers */
+  BKE_fcurve_blend_write(writer, &adt->drivers);
+
+  /* write overrides */
+  // FIXME: are these needed?
+  LISTBASE_FOREACH (AnimOverride *, aor, &adt->overrides) {
+    /* overrides consist of base data + rna_path */
+    BLO_write_struct(writer, AnimOverride, aor);
+    BLO_write_string(writer, aor->rna_path);
+  }
+
+  // TODO write the remaps (if they are needed)
+
+  /* write NLA data */
+  BKE_nla_blend_write(writer, &adt->nla_tracks);
+}
+
+void BKE_animdata_blend_data_read(BlendDataReader *reader, AnimData *adt)
+{
+  /* NOTE: must have called BLO_read_data_address already before doing this... */
+  if (adt == NULL) {
+    return;
+  }
+
+  /* link drivers */
+  BLO_read_list(reader, &adt->drivers);
+  BKE_fcurve_blend_data_read(reader, &adt->drivers);
+  adt->driver_array = NULL;
+
+  /* link overrides */
+  // TODO...
+
+  /* link NLA-data */
+  BLO_read_list(reader, &adt->nla_tracks);
+  BKE_nla_blend_data_read(reader, &adt->nla_tracks);
+
+  /* relink active track/strip - even though strictly speaking this should only be used
+   * if we're in 'tweaking mode', we need to be able to have this loaded back for
+   * undo, but also since users may not exit tweakmode before saving (#24535)
+   */
+  // TODO: it's not really nice that anyone should be able to save the file in this
+  //      state, but it's going to be too hard to enforce this single case...
+  BLO_read_data_address(reader, &adt->act_track);
+  BLO_read_data_address(reader, &adt->actstrip);
+}
+
+void BKE_animdata_blend_lib_read(BlendLibReader *reader, ID *id, AnimData *adt)
+{
+  if (adt == NULL) {
+    return;
+  }
+
+  /* link action data */
+  BLO_read_id_address(reader, id->lib, &adt->action);
+  BLO_read_id_address(reader, id->lib, &adt->tmpact);
+
+  /* link drivers */
+  BKE_fcurve_blend_lib_read(reader, id, &adt->drivers);
+
+  /* overrides don't have lib-link for now, so no need to do anything */
+
+  /* link NLA-data */
+  BKE_nla_blend_lib_read(reader, id, &adt->nla_tracks);
+}
+
+void BKE_animdata_blend_expand(struct BlendExpander *expander, AnimData *adt)
+{
+  /* own action */
+  BLO_expand(expander, adt->action);
+  BLO_expand(expander, adt->tmpact);
+
+  /* drivers - assume that these F-Curves have driver data to be in this list... */
+  BKE_fcurve_blend_expand(expander, &adt->drivers);
+}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index a99f847d96e..efe5d5ef0db 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -265,8 +265,6 @@ static BHead *find_bhead_from_idname(FileData *fd, const char *idname);
 #ifdef USE_COLLECTION_COMPAT_28
 static void expand_scene_collection(BlendExpander *expander, SceneCollection *sc);
 #endif
-static void direct_link_animdata(BlendDataReader *reader, AnimData *adt);
-static void lib_link_animdata(BlendLibReader *reader, ID *id, AnimData *adt);
 
 typedef struct BHeadN {
   struct BHeadN *next, *prev;
@@ -2307,7 +2305,7 @@ static void lib_link_id(BlendLibReader *reader, ID *id)
 
   AnimData *adt = BKE_animdata_from_id(id);
   if (adt != NULL) {
-    lib_link_animdata(reader, id, adt);
+    BKE_animdata_blend_lib_read(reader, id, adt);
   }
 
   if (id->override_library) {
@@ -2785,56 +2783,6 @@ static void direct_link_keyingsets(BlendDataReader *reader, ListBase *list)
   }
 }
 
-/* ------- */
-
-static void lib_link_animdata(BlendLibReader *reader, ID *id, AnimData *adt)
-{
-  if (adt == NULL) {
-    return;
-  }
-
-  /* link action data */
-  BLO_read_id_address(reader, id->lib, &adt->action);
-  BLO_read_id_address(reader, id->lib, &adt->tmpact);
-
-  /* link drivers */
-  BKE_fcurve_blend_lib_read(reader, id, &adt->drivers);
-
-  /* overrides don't have lib-link for now, so no need to do anything */
-
-  /* link NLA-data */
-  BKE_nla_blend_lib_read(reader, id, &adt->nla_tracks);
-}
-
-static void direct_link_animdata(BlendDataReader *reader, AnimData *adt)
-{
-  /* NOTE: must have called newdataadr already before doing this... */
-  if (adt == NULL) {
-    return;
-  }
-
-  /* link drivers */
-  BLO_read_list(reader, &adt->drivers);
-  BKE_fcurve_blend_data_read(reader, &adt->drivers);
-  adt->driver_array = NULL;
-
-  /* link overrides */
-  // TODO...
-
-  /* link NLA-data */
-  BLO_read_list(reader, &adt->nla_tracks);
-  BKE_nla_blend_data_read(reader, &adt->nla_tracks);
-
-  /* relink active track/strip - even though strictly speaking this should only be used
-   * if we're in 'tweaking mode', we need to be able to have this loaded back for
-   * undo, but also since users may not exit tweakmode before saving (#24535)
-   */
-  // TODO: it's not really nice that anyone should be able to save the file in this
-  //      state, but it's going to be too hard to enforce this single case...
-  BLO_read_data_address(reader, &adt->act_track);
-  BLO_read_data_address(reader, &adt->actstrip);
-}
-
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -2854,7 +2802,7 @@ static void direct_link_cachefile(BlendDataReader *reader, CacheFile *cache_file
 
   /* relink animdata */
   BLO_read_data_address(reader, &cache_file->adt);
-  direct_link_animdata(reader, cache_file->adt);
+  BKE_animdata_blend_data_read(reader, cache_file->adt);
 }
 
 /** \} */
@@ -3041,7 +2989,7 @@ static void direct_link_nodetree(BlendDataReader *reader, bNodeTree *ntree)
   ntree->execdata = NULL;
 
   BLO_read_data_address(reader, &ntree->adt);
-  direct_link_animdata(reader, ntree->adt);
+  BKE_animdata_blend_data_read(reader, ntree->adt);
 
   BLO_read_list(reader, &ntree->nodes);
   LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
@@ -3371,7 +3319,7 @@ static void direct_link_armature(BlendDataReader *reader, bArmature *arm)
   arm->needs_flush_to_id = 0;
 
   BLO_read_data_address(reader, &arm->adt);
-  direct_link_animdata(reader, arm->adt);
+  BKE_animdata_blend_data_read(reader, arm->adt);
 
   LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) {
     direct_link_bones(reader, bone);
@@ -3405,7 +3353,7 @@ static void lib_link_camera(BlendLibReader *reader, Camera *ca)
 static void direct_link_camera(BlendDataReader *reader, Camera *ca)
 {
   BLO_read_data_address(reader, &ca->adt);
-  direct_link_animdata(reader, ca->adt);
+  BKE_animdata_blend_data_read(reader, ca->adt);
 
   BLO_read_list(reader, &ca->bg_images);
 
@@ -3429,7 +3377,7 @@ static void lib_link_light(BlendLibReader *reader, Light *la)
 static void direct_link_light(BlendDataReader *reader, Light *la)
 {
   BLO_read_data_address(reader, &la->adt);
-  direct_link_animdata(reader, la->adt);
+  BKE_animdata_blend_data_read(reader, la->adt);
 
   BLO_read_data_address(reader, &la->curfalloff);
   if (la->curfalloff) {
@@ -3493,7 +3441,7 @@ static void direct_link_key(BlendDataReader *reader, Key *key)
   BLO_read_list(reader, &(key->block));
 
   BLO_read_data_address(reader, &key->adt);
-  direct_link_animdata(reader, key->adt);
+  BKE_animdata_blend_data_read(reader, key->adt);
 
   BLO_read_data_address(reader, &key->refkey);
 
@@ -3524,7 +3472,7 @@ static void lib_link_mball(BlendLibReader *reader, MetaBall *mb)
 static void direct_link_mball(BlendDataReader *reader, MetaBall *mb)
 {
   BLO_read_data_address(reader, &mb->adt);
-  direct_link_animdata(reader, mb->adt);
+  BKE_animdata_blend_data_read(reader, mb->adt);
 
   BLO_read_pointer_array(reader, (void **)&mb->mat);
 
@@ -3553,7 +3501,7 @@ static void lib_link_world(BlendLibReader *reader, World *wrld)
 static void direct_link_world(BlendDataReader *reader, World *wrld)
 {
   BLO_read_data_address(reader, &wrld->adt);
-  direct_link_animdata(reader, wrld->adt);
+  BKE_animdata_blend_data_read(reader, wrld->adt);
 
   wrld->preview = direct_link_preview_image(reader, wrld->preview);
   BLI_listbase_clear(&wrld->gpumaterial);
@@ -3704,7 +3652,7 @@ static void switch_endian_knots(Nurb *nu)
 static void direct_link_curve(BlendDataReader *reader, Curve *cu)
 {
   BLO_read_data_address(reader, &cu->adt);
-  direct_link_animdata(reader, cu->adt);
+  BKE_animdata_blend_data_read(reader, cu->adt);
 
   /* Protect against integer overflow vulnerability. */
   CLAMP(cu->len_char32, 0, INT_MAX - 4);
@@ -3773,7 +3721,7 @@ static void lib_link_texture(BlendLibReader *reader, Tex *tex

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list