diff options
author | Bastien Montagne <mont29> | 2021-11-29 16:20:58 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-11-29 16:22:38 +0300 |
commit | e5e8db73df86ee04260c5f2bd2c61dfa8eb7943f (patch) | |
tree | 46a5840efb51a363f17e64b93d5132679a5dbec4 /source/blender/blenkernel/intern/scene.c | |
parent | 6ae34bb0714859d9ef0b7fa2aceb16b4531df48f (diff) |
Refactor BKE_bpath module.
The main goal of this refactor is to make BPath module use `IDTypeInfo`,
and move each ID-specific part of the `foreach_path` looper into their
own IDTypeInfo struct, using a new `foreach_path` callback.
Additionally, following improvements/cleanups are included:
* Attempt to get better, more consistent namings.
** In particular, move from `path_visitor` to more standard `foreach_path`.
* Update and extend documentation.
** API doc was moved to header, according to recent discussions on this
topic.
* Remove `BKE_bpath_relocate_visitor` from API, this is specific
callback that belongs in `lib_id.c` user code.
NOTE: This commit is expected to be 100% non-behavioral-change. This
implies that several potential further changes were only noted as
comments (like using a more generic solution for
`lib_id_library_local_paths`, addressing inconsistencies like path of
packed libraries always being skipped, regardless of the
`BKE_BPATH_FOREACH_PATH_SKIP_PACKED` `eBPathForeachFlag` flag value,
etc.).
NOTE: basic unittests were added to master already in
rBdcc500e5a265093bc9cc.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D13381
Diffstat (limited to 'source/blender/blenkernel/intern/scene.c')
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index a5937326e3b..31e1ca464fc 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -71,6 +71,7 @@ #include "BKE_anim_data.h" #include "BKE_animsys.h" #include "BKE_armature.h" +#include "BKE_bpath.h" #include "BKE_cachefile.h" #include "BKE_collection.h" #include "BKE_colortools.h" @@ -891,6 +892,45 @@ static void scene_foreach_cache(ID *id, user_data); } +static bool seq_foreach_path_callback(Sequence *seq, void *user_data) +{ + if (SEQ_HAS_PATH(seq)) { + StripElem *se = seq->strip->stripdata; + BPathForeachPathData *bpath_data = (BPathForeachPathData *)user_data; + + if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM) && se) { + BKE_bpath_foreach_path_dirfile_fixed_process(bpath_data, seq->strip->dir, se->name); + } + else if ((seq->type == SEQ_TYPE_IMAGE) && se) { + /* NOTE: An option not to loop over all strips could be usefull? */ + unsigned int len = (unsigned int)MEM_allocN_len(se) / (unsigned int)sizeof(*se); + unsigned int i; + + if (bpath_data->flag & BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE) { + /* only operate on one path */ + len = MIN2(1u, len); + } + + for (i = 0; i < len; i++, se++) { + BKE_bpath_foreach_path_dirfile_fixed_process(bpath_data, seq->strip->dir, se->name); + } + } + else { + /* simple case */ + BKE_bpath_foreach_path_fixed_process(bpath_data, seq->strip->dir); + } + } + return true; +} + +static void scene_foreach_path(ID *id, BPathForeachPathData *bpath_data) +{ + Scene *scene = (Scene *)id; + if (scene->ed != NULL) { + SEQ_for_each_callback(&scene->ed->seqbase, seq_foreach_path_callback, bpath_data); + } +} + static void scene_blend_write(BlendWriter *writer, ID *id, const void *id_address) { Scene *sce = (Scene *)id; @@ -1610,6 +1650,7 @@ IDTypeInfo IDType_ID_SCE = { .make_local = NULL, .foreach_id = scene_foreach_id, .foreach_cache = scene_foreach_cache, + .foreach_path = scene_foreach_path, .owner_get = NULL, .blend_write = scene_blend_write, |