diff options
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 302 |
1 files changed, 19 insertions, 283 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 836260c46e5..44a1a6ec44a 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1613,21 +1613,6 @@ void blo_filedata_free(FileData *fd) if (fd->globmap) { oldnewmap_free(fd->globmap); } - if (fd->imamap) { - oldnewmap_free(fd->imamap); - } - if (fd->movieclipmap) { - oldnewmap_free(fd->movieclipmap); - } - if (fd->scenemap) { - oldnewmap_free(fd->scenemap); - } - if (fd->soundmap) { - oldnewmap_free(fd->soundmap); - } - if (fd->volumemap) { - oldnewmap_free(fd->volumemap); - } if (fd->packedmap) { oldnewmap_free(fd->packedmap); } @@ -1804,51 +1789,6 @@ static void *newglobadr(FileData *fd, const void *adr) return oldnewmap_lookup_and_inc(fd->globmap, adr, true); } -/* used to restore image data after undo */ -static void *newimaadr(FileData *fd, const void *adr) -{ - if (fd->imamap && adr) { - return oldnewmap_lookup_and_inc(fd->imamap, adr, true); - } - return NULL; -} - -/* used to restore scene data after undo */ -static void *newsceadr(FileData *fd, const void *adr) -{ - if (fd->scenemap && adr) { - return oldnewmap_lookup_and_inc(fd->scenemap, adr, true); - } - return NULL; -} - -/* used to restore movie clip data after undo */ -static void *newmclipadr(FileData *fd, const void *adr) -{ - if (fd->movieclipmap && adr) { - return oldnewmap_lookup_and_inc(fd->movieclipmap, adr, true); - } - return NULL; -} - -/* used to restore sound data after undo */ -static void *newsoundadr(FileData *fd, const void *adr) -{ - if (fd->soundmap && adr) { - return oldnewmap_lookup_and_inc(fd->soundmap, adr, true); - } - return NULL; -} - -/* used to restore volume data after undo */ -static void *newvolumeadr(FileData *fd, const void *adr) -{ - if (fd->volumemap && adr) { - return oldnewmap_lookup_and_inc(fd->volumemap, adr, true); - } - return NULL; -} - /* used to restore packed data after undo */ static void *newpackedadr(FileData *fd, const void *adr) { @@ -1926,201 +1866,6 @@ void blo_clear_proxy_pointers_from_lib(Main *oldmain) } } -void blo_make_scene_pointer_map(FileData *fd, Main *oldmain) -{ - Scene *sce = oldmain->scenes.first; - - fd->scenemap = oldnewmap_new(); - - for (; sce; sce = sce->id.next) { - if (sce->eevee.light_cache_data) { - struct LightCache *light_cache = sce->eevee.light_cache_data; - oldnewmap_insert(fd->scenemap, light_cache, light_cache, 0); - } - } -} - -void blo_end_scene_pointer_map(FileData *fd, Main *oldmain) -{ - OldNew *entry = fd->scenemap->entries; - Scene *sce = oldmain->scenes.first; - int i; - - /* used entries were restored, so we put them to zero */ - for (i = 0; i < fd->scenemap->nentries; i++, entry++) { - if (entry->nr > 0) { - entry->newp = NULL; - } - } - - for (; sce; sce = sce->id.next) { - sce->eevee.light_cache_data = newsceadr(fd, sce->eevee.light_cache_data); - } -} - -void blo_make_image_pointer_map(FileData *fd, Main *oldmain) -{ - Scene *sce = oldmain->scenes.first; - fd->imamap = oldnewmap_new(); - - for (; sce; sce = sce->id.next) { - if (sce->nodetree && sce->nodetree->previews) { - bNodeInstanceHashIterator iter; - NODE_INSTANCE_HASH_ITER (iter, sce->nodetree->previews) { - bNodePreview *preview = BKE_node_instance_hash_iterator_get_value(&iter); - oldnewmap_insert(fd->imamap, preview, preview, 0); - } - } - } -} - -/* set old main image ibufs to zero if it has been restored */ -/* this works because freeing old main only happens after this call */ -void blo_end_image_pointer_map(FileData *fd, Main *oldmain) -{ - OldNew *entry = fd->imamap->entries; - Scene *sce = oldmain->scenes.first; - int i; - - /* used entries were restored, so we put them to zero */ - for (i = 0; i < fd->imamap->nentries; i++, entry++) { - if (entry->nr > 0) { - entry->newp = NULL; - } - } - - for (; sce; sce = sce->id.next) { - if (sce->nodetree && sce->nodetree->previews) { - bNodeInstanceHash *new_previews = BKE_node_instance_hash_new("node previews"); - bNodeInstanceHashIterator iter; - - /* reconstruct the preview hash, only using remaining pointers */ - NODE_INSTANCE_HASH_ITER (iter, sce->nodetree->previews) { - bNodePreview *preview = BKE_node_instance_hash_iterator_get_value(&iter); - if (preview) { - bNodePreview *new_preview = newimaadr(fd, preview); - if (new_preview) { - bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter); - BKE_node_instance_hash_insert(new_previews, key, new_preview); - } - } - } - BKE_node_instance_hash_free(sce->nodetree->previews, NULL); - sce->nodetree->previews = new_previews; - } - } -} - -void blo_make_movieclip_pointer_map(FileData *fd, Main *oldmain) -{ - Scene *sce = oldmain->scenes.first; - - fd->movieclipmap = oldnewmap_new(); - - for (; sce; sce = sce->id.next) { - if (sce->nodetree) { - bNode *node; - for (node = sce->nodetree->nodes.first; node; node = node->next) { - if (node->type == CMP_NODE_MOVIEDISTORTION) { - oldnewmap_insert(fd->movieclipmap, node->storage, node->storage, 0); - } - } - } - } -} - -/* set old main movie clips caches to zero if it has been restored */ -/* this works because freeing old main only happens after this call */ -void blo_end_movieclip_pointer_map(FileData *fd, Main *oldmain) -{ - OldNew *entry = fd->movieclipmap->entries; - Scene *sce = oldmain->scenes.first; - int i; - - /* used entries were restored, so we put them to zero */ - for (i = 0; i < fd->movieclipmap->nentries; i++, entry++) { - if (entry->nr > 0) { - entry->newp = NULL; - } - } - - for (; sce; sce = sce->id.next) { - if (sce->nodetree) { - bNode *node; - for (node = sce->nodetree->nodes.first; node; node = node->next) { - if (node->type == CMP_NODE_MOVIEDISTORTION) { - node->storage = newmclipadr(fd, node->storage); - } - } - } - } -} - -void blo_make_sound_pointer_map(FileData *fd, Main *oldmain) -{ - bSound *sound = oldmain->sounds.first; - - fd->soundmap = oldnewmap_new(); - - for (; sound; sound = sound->id.next) { - if (sound->waveform) { - oldnewmap_insert(fd->soundmap, sound->waveform, sound->waveform, 0); - } - } -} - -/* set old main sound caches to zero if it has been restored */ -/* this works because freeing old main only happens after this call */ -void blo_end_sound_pointer_map(FileData *fd, Main *oldmain) -{ - OldNew *entry = fd->soundmap->entries; - bSound *sound = oldmain->sounds.first; - int i; - - /* used entries were restored, so we put them to zero */ - for (i = 0; i < fd->soundmap->nentries; i++, entry++) { - if (entry->nr > 0) { - entry->newp = NULL; - } - } - - for (; sound; sound = sound->id.next) { - sound->waveform = newsoundadr(fd, sound->waveform); - } -} - -void blo_make_volume_pointer_map(FileData *fd, Main *oldmain) -{ - fd->volumemap = oldnewmap_new(); - - Volume *volume = oldmain->volumes.first; - for (; volume; volume = volume->id.next) { - if (volume->runtime.grids) { - oldnewmap_insert(fd->volumemap, volume->runtime.grids, volume->runtime.grids, 0); - } - } -} - -/* set old main volume caches to zero if it has been restored */ -/* this works because freeing old main only happens after this call */ -void blo_end_volume_pointer_map(FileData *fd, Main *oldmain) -{ - OldNew *entry = fd->volumemap->entries; - Volume *volume = oldmain->volumes.first; - int i; - - /* used entries were restored, so we put them to zero */ - for (i = 0; i < fd->volumemap->nentries; i++, entry++) { - if (entry->nr > 0) { - entry->newp = NULL; - } - } - - for (; volume; volume = volume->id.next) { - volume->runtime.grids = newvolumeadr(fd, volume->runtime.grids); - } -} - /* XXX disabled this feature - packed files also belong in temp saves and quit.blend, * to make restore work. */ @@ -2263,6 +2008,7 @@ typedef struct BLOCacheStorage { static void blo_cache_storage_entry_register(ID *id, const IDCacheKey *key, void **UNUSED(cache_p), + eIDTypeInfoCacheCallbackFlags UNUSED(flags), void *cache_storage_v) { BLI_assert(key->id_session_uuid == id->session_uuid); @@ -2280,12 +2026,18 @@ static void blo_cache_storage_entry_register(ID *id, static void blo_cache_storage_entry_restore_in_new(ID *UNUSED(id), const IDCacheKey *key, void **cache_p, + eIDTypeInfoCacheCallbackFlags flags, void *cache_storage_v) { BLOCacheStorage *cache_storage = cache_storage_v; if (cache_storage == NULL) { - *cache_p = NULL; + /* In non-undo case, only clear the pointer if it is a purely runtime one. + * If it may be stored in a persistent way in the .blend file, direct_link code is responsible + * to properly deal with it. */ + if ((flags & IDTYPE_CACHE_CB_FLAGS_PERSISTENT) == 0) { + *cache_p = NULL; + } return; } @@ -2302,6 +2054,7 @@ static void blo_cache_storage_entry_restore_in_new(ID *UNUSED(id), static void blo_cache_storage_entry_clear_in_old(ID *UNUSED(id), const IDCacheKey *key, void **cache_p, + eIDTypeInfoCacheCallbackFlags UNUSED(flags), void *cache_storage_v) { BLOCacheStorage *cache_storage = cache_storage_v; @@ -2341,7 +2094,7 @@ void blo_cache_storage_init(FileData *fd, Main *bmain) if (ID_IS_LINKED(id)) { continue; } - type_info->foreach_cache(id, blo_cache_storage_entry_register, fd->cache_storage); + BKE_idtype_id_foreach_cache(id, blo_cache_storage_entry_register, fd->cache_storage); } FOREACH_MAIN_LISTBASE_ID_END; } @@ -2371,7 +2124,7 @@ void blo_cache_storage_old_bmain_clear(FileData *fd, Main *bmain_old) if (ID_IS_LINKED(id)) { continue; } - type_info->foreach_cache(id, blo_cache_storage_entry_clear_in_old, fd->cache_storage); + BKE_idtype_id_foreach_cache(id, blo_cache_storage_entry_clear_in_old, fd->cache_storage); } FOREACH_MAIN_LISTBASE_ID_END; } @@ -3744,7 +3497,8 @@ static void direct_link_nodetree(BlendDataReader *reader, bNodeTree *ntree) } if (node->type == CMP_NODE_MOVIEDISTORTION) { - node->storage = newmclipadr(reader->fd, node->storage); + /* Do nothing, this is runtime cache and hence handled by generic code using + * `IDTypeInfo.foreach_cache` callback. */ } else { BLO_read_data_address(reader, &node->storage); @@ -3843,28 +3597,8 @@ static void direct_link_nodetree(BlendDataReader *reader, bNodeTree *ntree) BLO_read_data_address(reader, &link->tosock); } -#if 0 - if (ntree->previews) { - bNodeInstanceHash* new_previews = BKE_node_instance_hash_new("node previews"); - bNodeInstanceHashIterator iter; - - NODE_INSTANCE_HASH_ITER(iter, ntree->previews) { - bNodePreview* preview = BKE_node_instance_hash_iterator_get_value(&iter); - if (preview) { - bNodePreview* new_preview = newimaadr(fd, preview); - if (new_preview) { - bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter); - BKE_node_instance_hash_insert(new_previews, key, new_preview); - } - } - } - BKE_node_instance_hash_free(ntree->previews, NULL); - ntree->previews = new_previews; - } -#else - /* XXX TODO */ + /* TODO, should be dealt by new generic cache handling of IDs... */ ntree->previews = NULL; -#endif /* type verification is in lib-link */ } @@ -8952,6 +8686,7 @@ static void direct_link_simulation(BlendDataReader *reader, Simulation *simulati BLO_read_list(reader, &simulation->states); LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { + BLO_read_data_address(reader, &state->name); switch ((eSimulationStateType)state->type) { case SIM_STATE_TYPE_PARTICLES: { ParticleSimulationState *particle_state = (ParticleSimulationState *)state; @@ -9234,7 +8969,8 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * /* try to restore (when undoing) or clear ID's cache pointers. */ if (id_type->foreach_cache != NULL) { - id_type->foreach_cache(id, blo_cache_storage_entry_restore_in_new, reader.fd->cache_storage); + BKE_idtype_id_foreach_cache( + id, blo_cache_storage_entry_restore_in_new, reader.fd->cache_storage); } return success; @@ -9249,8 +8985,8 @@ static BHead *read_data_into_datamap(FileData *fd, BHead *bhead, const char *all void *data; #if 0 /* XXX DUMB DEBUGGING OPTION TO GIVE NAMES for guarded malloc errors */ - short* sp = fd->filesdna->structs[bhead->SDNAnr]; - char* tmp = malloc(100); + short *sp = fd->filesdna->structs[bhead->SDNAnr]; + char *tmp = malloc(100); allocname = fd->filesdna->types[sp[0]]; strcpy(tmp, allocname); data = read_struct(fd, bhead, tmp); |