Move volume to new cache management system for undo.

This commit is contained in:
Bastien Montagne 2020-07-03 15:27:12 +02:00
parent 1e255ce031
commit c9975088a9
3 changed files with 24 additions and 13 deletions

View File

@ -483,6 +483,20 @@ static void volume_foreach_id(ID *id, LibraryForeachIDData *data)
}
}
static void volume_foreach_cache(ID *id,
IDTypeForeachCacheFunctionCallback function_callback,
void *user_data)
{
Volume *volume = (Volume *)id;
IDCacheKey key = {
/* id_session_uuid */ id->session_uuid,
/*offset_in_ID*/ offsetof(Volume, runtime.grids),
/* cache_v */ volume->runtime.grids,
};
function_callback(id, &key, (void **)&volume->runtime.grids, user_data);
}
IDTypeInfo IDType_ID_VO = {
/* id_code */ ID_VO,
/* id_filter */ FILTER_ID_VO,
@ -498,6 +512,7 @@ IDTypeInfo IDType_ID_VO = {
/* free_data */ volume_free_data,
/* make_local */ nullptr,
/* foreach_id */ volume_foreach_id,
/* foreach_cache */ volume_foreach_cache,
};
void BKE_volume_init_grids(Volume *volume)

View File

@ -399,9 +399,6 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain,
/* makes lookup of existing video clips in old main */
blo_make_movieclip_pointer_map(fd, oldmain);
/* make lookups of existing volume data in old main */
blo_make_volume_pointer_map(fd, oldmain);
/* removed packed data from this trick - it's internal data that needs saves */
blo_cache_storage_init(fd, oldmain);
@ -419,9 +416,6 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain,
/* ensures relinked movie clips are not freed */
blo_end_movieclip_pointer_map(fd, oldmain);
/* ensures relinked volumes are not freed */
blo_end_volume_pointer_map(fd, oldmain);
/* Still in-use libraries have already been moved from oldmain to new mainlist,
* but oldmain itself shall *never* be 'transferred' to new mainlist! */
BLI_assert(old_mainlist.first == oldmain);

View File

@ -4360,9 +4360,10 @@ static void direct_link_text(BlendDataReader *reader, Text *text)
static void lib_link_image(BlendLibReader *UNUSED(reader), Image *ima)
{
/* Images have some kind of 'main' cache, when NULL we should also clear all others.
* XXX It is not ideal to do that from here, but for now it will do. We have to do it after all
* cache pointers have been potentially remapped (in undo case) or NULL-ified. */
/* Images have some kind of 'main' cache, when NULL we should also clear all others. */
/* Needs to be done *after* cache pointers are restored (call to
* `foreach_cache`/`blo_cache_storage_entry_restore_in_new`), easier for now to do it in
* lib_link... */
if (ima->cache == NULL) {
BKE_image_free_buffers(ima);
}
@ -8946,6 +8947,11 @@ static void direct_link_pointcloud(BlendDataReader *reader, PointCloud *pointclo
static void lib_link_volume(BlendLibReader *reader, Volume *volume)
{
/* Needs to be done *after* cache pointers are restored (call to
* `foreach_cache`/`blo_cache_storage_entry_restore_in_new`), easier for now to do it in
* lib_link... */
BKE_volume_init_grids(volume);
for (int a = 0; a < volume->totcol; a++) {
BLO_read_id_address(reader, volume->id.lib, &volume->mat[a]);
}
@ -8957,11 +8963,7 @@ static void direct_link_volume(BlendDataReader *reader, Volume *volume)
direct_link_animdata(reader, volume->adt);
volume->packedfile = direct_link_packedfile(reader, volume->packedfile);
volume->runtime.grids = (reader->fd->volumemap) ?
newvolumeadr(reader->fd, volume->runtime.grids) :
NULL;
volume->runtime.frame = 0;
BKE_volume_init_grids(volume);
/* materials */
BLO_read_pointer_array(reader, (void **)&volume->mat);