Refactor: move CacheFile .blend I/O to IDTypeInfo callbacks
This commit is contained in:
parent
f8ef7f045c
commit
c27d00cde0
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include "BLT_translation.h"
|
||||
|
||||
#include "BKE_anim_data.h"
|
||||
#include "BKE_cachefile.h"
|
||||
#include "BKE_idtype.h"
|
||||
#include "BKE_lib_id.h"
|
||||
|
@ -48,6 +49,8 @@
|
|||
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
#include "BLO_read_write.h"
|
||||
|
||||
#ifdef WITH_ALEMBIC
|
||||
# include "ABC_alembic.h"
|
||||
#endif
|
||||
|
@ -85,6 +88,37 @@ static void cache_file_free_data(ID *id)
|
|||
BLI_freelistN(&cache_file->object_paths);
|
||||
}
|
||||
|
||||
static void cache_file_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
||||
{
|
||||
CacheFile *cache_file = (CacheFile *)id;
|
||||
if (cache_file->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
||||
BLI_listbase_clear(&cache_file->object_paths);
|
||||
cache_file->handle = NULL;
|
||||
memset(cache_file->handle_filepath, 0, sizeof(cache_file->handle_filepath));
|
||||
cache_file->handle_readers = NULL;
|
||||
|
||||
BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id);
|
||||
|
||||
if (cache_file->adt) {
|
||||
BKE_animdata_blend_write(writer, cache_file->adt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void cache_file_blend_read_data(BlendDataReader *reader, ID *id)
|
||||
{
|
||||
CacheFile *cache_file = (CacheFile *)id;
|
||||
BLI_listbase_clear(&cache_file->object_paths);
|
||||
cache_file->handle = NULL;
|
||||
cache_file->handle_filepath[0] = '\0';
|
||||
cache_file->handle_readers = NULL;
|
||||
|
||||
/* relink animdata */
|
||||
BLO_read_data_address(reader, &cache_file->adt);
|
||||
BKE_animdata_blend_read_data(reader, cache_file->adt);
|
||||
}
|
||||
|
||||
IDTypeInfo IDType_ID_CF = {
|
||||
.id_code = ID_CF,
|
||||
.id_filter = FILTER_ID_CF,
|
||||
|
@ -102,8 +136,8 @@ IDTypeInfo IDType_ID_CF = {
|
|||
.foreach_id = NULL,
|
||||
.foreach_cache = NULL,
|
||||
|
||||
.blend_write = NULL,
|
||||
.blend_read_data = NULL,
|
||||
.blend_write = cache_file_blend_write,
|
||||
.blend_read_data = cache_file_blend_read_data,
|
||||
.blend_read_lib = NULL,
|
||||
.blend_read_expand = NULL,
|
||||
};
|
||||
|
|
|
@ -2537,28 +2537,6 @@ static void lib_link_constraint_channels(BlendLibReader *reader, ID *id, ListBas
|
|||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Read ID: CacheFiles
|
||||
* \{ */
|
||||
|
||||
static void lib_link_cachefiles(BlendLibReader *UNUSED(reader), CacheFile *UNUSED(cache_file))
|
||||
{
|
||||
}
|
||||
|
||||
static void direct_link_cachefile(BlendDataReader *reader, CacheFile *cache_file)
|
||||
{
|
||||
BLI_listbase_clear(&cache_file->object_paths);
|
||||
cache_file->handle = NULL;
|
||||
cache_file->handle_filepath[0] = '\0';
|
||||
cache_file->handle_readers = NULL;
|
||||
|
||||
/* relink animdata */
|
||||
BLO_read_data_address(reader, &cache_file->adt);
|
||||
BKE_animdata_blend_read_data(reader, cache_file->adt);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Read ID: WorkSpace
|
||||
* \{ */
|
||||
|
@ -6371,9 +6349,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
|
|||
case ID_PA:
|
||||
direct_link_particlesettings(&reader, (ParticleSettings *)id);
|
||||
break;
|
||||
case ID_CF:
|
||||
direct_link_cachefile(&reader, (CacheFile *)id);
|
||||
break;
|
||||
case ID_WS:
|
||||
direct_link_workspace(&reader, (WorkSpace *)id, main);
|
||||
break;
|
||||
|
@ -6407,6 +6382,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
|
|||
case ID_VO:
|
||||
case ID_SIM:
|
||||
case ID_SO:
|
||||
case ID_CF:
|
||||
/* Do nothing. Handled by IDTypeInfo callback. */
|
||||
break;
|
||||
}
|
||||
|
@ -7036,9 +7012,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
|
|||
case ID_GR:
|
||||
lib_link_collection(&reader, (Collection *)id);
|
||||
break;
|
||||
case ID_CF:
|
||||
lib_link_cachefiles(&reader, (CacheFile *)id);
|
||||
break;
|
||||
case ID_IP:
|
||||
/* XXX deprecated... still needs to be maintained for version patches still. */
|
||||
lib_link_ipo(&reader, (Ipo *)id);
|
||||
|
@ -7076,6 +7049,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
|
|||
case ID_VO:
|
||||
case ID_SIM:
|
||||
case ID_SO:
|
||||
case ID_CF:
|
||||
/* Do nothing. Handled by IDTypeInfo callback. */
|
||||
break;
|
||||
}
|
||||
|
@ -8003,10 +7977,6 @@ static void expand_scene(BlendExpander *expander, Scene *sce)
|
|||
}
|
||||
}
|
||||
|
||||
static void expand_cachefile(BlendExpander *UNUSED(expander), CacheFile *UNUSED(cache_file))
|
||||
{
|
||||
}
|
||||
|
||||
static void expand_workspace(BlendExpander *expander, WorkSpace *workspace)
|
||||
{
|
||||
LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) {
|
||||
|
@ -8072,9 +8042,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
|
|||
case ID_PA:
|
||||
expand_particlesettings(&expander, (ParticleSettings *)id);
|
||||
break;
|
||||
case ID_CF:
|
||||
expand_cachefile(&expander, (CacheFile *)id);
|
||||
break;
|
||||
case ID_WS:
|
||||
expand_workspace(&expander, (WorkSpace *)id);
|
||||
break;
|
||||
|
|
|
@ -2055,23 +2055,6 @@ static void write_screen(BlendWriter *writer, bScreen *screen, const void *id_ad
|
|||
}
|
||||
}
|
||||
|
||||
static void write_cachefile(BlendWriter *writer, CacheFile *cache_file, const void *id_address)
|
||||
{
|
||||
if (cache_file->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
||||
BLI_listbase_clear(&cache_file->object_paths);
|
||||
cache_file->handle = NULL;
|
||||
memset(cache_file->handle_filepath, 0, sizeof(cache_file->handle_filepath));
|
||||
cache_file->handle_readers = NULL;
|
||||
|
||||
BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id);
|
||||
|
||||
if (cache_file->adt) {
|
||||
BKE_animdata_blend_write(writer, cache_file->adt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const void *id_address)
|
||||
{
|
||||
BLO_write_id_struct(writer, WorkSpace, id_address, &workspace->id);
|
||||
|
@ -2366,9 +2349,6 @@ static bool write_file_handle(Main *mainvar,
|
|||
case ID_PA:
|
||||
write_particlesettings(&writer, (ParticleSettings *)id_buffer, id);
|
||||
break;
|
||||
case ID_CF:
|
||||
write_cachefile(&writer, (CacheFile *)id_buffer, id);
|
||||
break;
|
||||
case ID_ME:
|
||||
case ID_LT:
|
||||
case ID_AC:
|
||||
|
@ -2399,6 +2379,7 @@ static bool write_file_handle(Main *mainvar,
|
|||
case ID_VO:
|
||||
case ID_SIM:
|
||||
case ID_SO:
|
||||
case ID_CF:
|
||||
/* Do nothing, handled in IDTypeInfo callback. */
|
||||
break;
|
||||
case ID_LI:
|
||||
|
|
Loading…
Reference in New Issue