diff options
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 1625 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_250.c | 16 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_260.c | 12 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_270.c | 19 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_280.c | 12 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_290.c | 107 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_defaults.c | 2 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_legacy.c | 12 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_userdef.c | 36 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 791 |
10 files changed, 580 insertions, 2052 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 42b97550db1..84cb898a426 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -120,7 +120,9 @@ #include "BKE_constraint.h" #include "BKE_curve.h" #include "BKE_curveprofile.h" +#include "BKE_deform.h" #include "BKE_effect.h" +#include "BKE_fcurve.h" #include "BKE_fcurve_driver.h" #include "BKE_fluid.h" #include "BKE_global.h" // for G @@ -140,6 +142,7 @@ #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" #include "BKE_multires.h" +#include "BKE_nla.h" #include "BKE_node.h" // for tree type defines #include "BKE_object.h" #include "BKE_paint.h" @@ -263,8 +266,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; @@ -1826,9 +1827,7 @@ static void change_link_placeholder_to_real_ID_pointer(ListBase *mainlist, void *old, void *new) { - Main *mainptr; - - for (mainptr = mainlist->first; mainptr; mainptr = mainptr->next) { + LISTBASE_FOREACH (Main *, mainptr, mainlist) { FileData *fd; if (mainptr->curlib) { @@ -1852,9 +1851,7 @@ static void change_link_placeholder_to_real_ID_pointer(ListBase *mainlist, */ void blo_clear_proxy_pointers_from_lib(Main *oldmain) { - Object *ob = oldmain->objects.first; - - for (; ob; ob = ob->id.next) { + LISTBASE_FOREACH (Object *, ob, &oldmain->objects) { if (ob->id.lib != NULL && ob->proxy_from != NULL && ob->proxy_from->id.lib == NULL) { ob->proxy_from = NULL; } @@ -1872,47 +1869,39 @@ static void insert_packedmap(FileData *fd, PackedFile *pf) void blo_make_packed_pointer_map(FileData *fd, Main *oldmain) { - Image *ima; - VFont *vfont; - bSound *sound; - Volume *volume; - Library *lib; - fd->packedmap = oldnewmap_new(); - for (ima = oldmain->images.first; ima; ima = ima->id.next) { - ImagePackedFile *imapf; - + LISTBASE_FOREACH (Image *, ima, &oldmain->images) { if (ima->packedfile) { insert_packedmap(fd, ima->packedfile); } - for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { + LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) { if (imapf->packedfile) { insert_packedmap(fd, imapf->packedfile); } } } - for (vfont = oldmain->fonts.first; vfont; vfont = vfont->id.next) { + LISTBASE_FOREACH (VFont *, vfont, &oldmain->fonts) { if (vfont->packedfile) { insert_packedmap(fd, vfont->packedfile); } } - for (sound = oldmain->sounds.first; sound; sound = sound->id.next) { + LISTBASE_FOREACH (bSound *, sound, &oldmain->sounds) { if (sound->packedfile) { insert_packedmap(fd, sound->packedfile); } } - for (volume = oldmain->volumes.first; volume; volume = volume->id.next) { + LISTBASE_FOREACH (Volume *, volume, &oldmain->volumes) { if (volume->packedfile) { insert_packedmap(fd, volume->packedfile); } } - for (lib = oldmain->libraries.first; lib; lib = lib->id.next) { + LISTBASE_FOREACH (Library *, lib, &oldmain->libraries) { if (lib->packedfile) { insert_packedmap(fd, lib->packedfile); } @@ -1923,44 +1912,36 @@ void blo_make_packed_pointer_map(FileData *fd, Main *oldmain) /* this works because freeing old main only happens after this call */ void blo_end_packed_pointer_map(FileData *fd, Main *oldmain) { - Image *ima; - VFont *vfont; - bSound *sound; - Volume *volume; - Library *lib; OldNew *entry = fd->packedmap->entries; - int i; /* used entries were restored, so we put them to zero */ - for (i = 0; i < fd->packedmap->nentries; i++, entry++) { + for (int i = 0; i < fd->packedmap->nentries; i++, entry++) { if (entry->nr > 0) { entry->newp = NULL; } } - for (ima = oldmain->images.first; ima; ima = ima->id.next) { - ImagePackedFile *imapf; - + LISTBASE_FOREACH (Image *, ima, &oldmain->images) { ima->packedfile = newpackedadr(fd, ima->packedfile); - for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { + LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) { imapf->packedfile = newpackedadr(fd, imapf->packedfile); } } - for (vfont = oldmain->fonts.first; vfont; vfont = vfont->id.next) { + LISTBASE_FOREACH (VFont *, vfont, &oldmain->fonts) { vfont->packedfile = newpackedadr(fd, vfont->packedfile); } - for (sound = oldmain->sounds.first; sound; sound = sound->id.next) { + LISTBASE_FOREACH (bSound *, sound, &oldmain->sounds) { sound->packedfile = newpackedadr(fd, sound->packedfile); } - for (lib = oldmain->libraries.first; lib; lib = lib->id.next) { + LISTBASE_FOREACH (Library *, lib, &oldmain->libraries) { lib->packedfile = newpackedadr(fd, lib->packedfile); } - for (volume = oldmain->volumes.first; volume; volume = volume->id.next) { + LISTBASE_FOREACH (Volume *, volume, &oldmain->volumes) { volume->packedfile = newpackedadr(fd, volume->packedfile); } } @@ -1968,14 +1949,12 @@ void blo_end_packed_pointer_map(FileData *fd, Main *oldmain) /* undo file support: add all library pointers in lookup */ void blo_add_library_pointer_map(ListBase *old_mainlist, FileData *fd) { - Main *ptr = old_mainlist->first; ListBase *lbarray[MAX_LIBARRAY]; - for (ptr = ptr->next; ptr; ptr = ptr->next) { + LISTBASE_FOREACH (Main *, ptr, old_mainlist) { int i = set_listbasepointers(ptr, lbarray); while (i--) { - ID *id; - for (id = lbarray[i]->first; id; id = id->next) { + LISTBASE_FOREACH (ID *, id, lbarray[i]) { oldnewmap_insert(fd->libmap, id, id, GS(id->name)); } } @@ -2003,7 +1982,7 @@ typedef struct BLOCacheStorage { static void blo_cache_storage_entry_register(ID *id, const IDCacheKey *key, void **UNUSED(cache_p), - eIDTypeInfoCacheCallbackFlags UNUSED(flags), + uint UNUSED(flags), void *cache_storage_v) { BLI_assert(key->id_session_uuid == id->session_uuid); @@ -2018,11 +1997,8 @@ static void blo_cache_storage_entry_register(ID *id, } /** Restore a cache data entry from old ID into new one, when reading some undo memfile. */ -static void blo_cache_storage_entry_restore_in_new(ID *UNUSED(id), - const IDCacheKey *key, - void **cache_p, - eIDTypeInfoCacheCallbackFlags flags, - void *cache_storage_v) +static void blo_cache_storage_entry_restore_in_new( + ID *UNUSED(id), const IDCacheKey *key, void **cache_p, uint flags, void *cache_storage_v) { BLOCacheStorage *cache_storage = cache_storage_v; @@ -2049,7 +2025,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), + uint UNUSED(flags), void *cache_storage_v) { BLOCacheStorage *cache_storage = cache_storage_v; @@ -2269,185 +2245,6 @@ static void link_glob_list(FileData *fd, ListBase *lb) /* for glob data */ /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID Properties - * \{ */ - -static void IDP_DirectLinkProperty(IDProperty *prop, BlendDataReader *reader); -static void IDP_LibLinkProperty(IDProperty *prop, BlendLibReader *reader); - -static void IDP_DirectLinkIDPArray(IDProperty *prop, BlendDataReader *reader) -{ - IDProperty *array; - int i; - - /* since we didn't save the extra buffer, set totallen to len */ - prop->totallen = prop->len; - BLO_read_data_address(reader, &prop->data.pointer); - - array = (IDProperty *)prop->data.pointer; - - /* note!, idp-arrays didn't exist in 2.4x, so the pointer will be cleared - * there's not really anything we can do to correct this, at least don't crash */ - if (array == NULL) { - prop->len = 0; - prop->totallen = 0; - } - - for (i = 0; i < prop->len; i++) { - IDP_DirectLinkProperty(&array[i], reader); - } -} - -static void IDP_DirectLinkArray(IDProperty *prop, BlendDataReader *reader) -{ - IDProperty **array; - int i; - - /* since we didn't save the extra buffer, set totallen to len */ - prop->totallen = prop->len; - - if (prop->subtype == IDP_GROUP) { - BLO_read_pointer_array(reader, &prop->data.pointer); - array = prop->data.pointer; - - for (i = 0; i < prop->len; i++) { - IDP_DirectLinkProperty(array[i], reader); - } - } - else if (prop->subtype == IDP_DOUBLE) { - BLO_read_double_array(reader, prop->len, (double **)&prop->data.pointer); - } - else { - /* also used for floats */ - BLO_read_int32_array(reader, prop->len, (int **)&prop->data.pointer); - } -} - -static void IDP_DirectLinkString(IDProperty *prop, BlendDataReader *reader) -{ - /*since we didn't save the extra string buffer, set totallen to len.*/ - prop->totallen = prop->len; - BLO_read_data_address(reader, &prop->data.pointer); -} - -static void IDP_DirectLinkGroup(IDProperty *prop, BlendDataReader *reader) -{ - ListBase *lb = &prop->data.group; - IDProperty *loop; - - BLO_read_list(reader, lb); - - /*Link child id properties now*/ - for (loop = prop->data.group.first; loop; loop = loop->next) { - IDP_DirectLinkProperty(loop, reader); - } -} - -static void IDP_DirectLinkProperty(IDProperty *prop, BlendDataReader *reader) -{ - switch (prop->type) { - case IDP_GROUP: - IDP_DirectLinkGroup(prop, reader); - break; - case IDP_STRING: - IDP_DirectLinkString(prop, reader); - break; - case IDP_ARRAY: - IDP_DirectLinkArray(prop, reader); - break; - case IDP_IDPARRAY: - IDP_DirectLinkIDPArray(prop, reader); - break; - case IDP_DOUBLE: - /* Workaround for doubles. - * They are stored in the same field as `int val, val2` in the IDPropertyData struct, - * they have to deal with endianness specifically. - * - * In theory, val and val2 would've already been swapped - * if switch_endian is true, so we have to first unswap - * them then re-swap them as a single 64-bit entity. */ - if (BLO_read_requires_endian_switch(reader)) { - BLI_endian_switch_int32(&prop->data.val); - BLI_endian_switch_int32(&prop->data.val2); - BLI_endian_switch_int64((int64_t *)&prop->data.val); - } - break; - case IDP_INT: - case IDP_FLOAT: - case IDP_ID: - break; /* Nothing special to do here. */ - default: - /* Unknown IDP type, nuke it (we cannot handle unknown types everywhere in code, - * IDP are way too polymorphic to do it safely. */ - printf( - "%s: found unknown IDProperty type %d, reset to Integer one !\n", __func__, prop->type); - /* Note: we do not attempt to free unknown prop, we have no way to know how to do that! */ - prop->type = IDP_INT; - prop->subtype = 0; - IDP_Int(prop) = 0; - } -} - -#define IDP_DirectLinkGroup_OrFree(prop, reader) \ - _IDP_DirectLinkGroup_OrFree(prop, reader, __func__) - -static void _IDP_DirectLinkGroup_OrFree(IDProperty **prop, - BlendDataReader *reader, - const char *caller_func_id) -{ - if (*prop) { - if ((*prop)->type == IDP_GROUP) { - IDP_DirectLinkGroup(*prop, reader); - } - else { - /* corrupt file! */ - printf("%s: found non group data, freeing type %d!\n", caller_func_id, (*prop)->type); - /* don't risk id, data's likely corrupt. */ - // IDP_FreePropertyContent(*prop); - *prop = NULL; - } - } -} - -static void IDP_LibLinkProperty(IDProperty *prop, BlendLibReader *reader) -{ - if (!prop) { - return; - } - - switch (prop->type) { - case IDP_ID: /* PointerProperty */ - { - void *newaddr = BLO_read_get_new_id_address(reader, NULL, IDP_Id(prop)); - if (IDP_Id(prop) && !newaddr && G.debug) { - printf("Error while loading \"%s\". Data not found in file!\n", prop->name); - } - prop->data.pointer = newaddr; - break; - } - case IDP_IDPARRAY: /* CollectionProperty */ - { - IDProperty *idp_array = IDP_IDPArray(prop); - for (int i = 0; i < prop->len; i++) { - IDP_LibLinkProperty(&(idp_array[i]), reader); - } - break; - } - case IDP_GROUP: /* PointerProperty */ - { - LISTBASE_FOREACH (IDProperty *, loop, &prop->data.group) { - IDP_LibLinkProperty(loop, reader); - } - break; - } - default: - break; /* Nothing to do for other IDProps. */ - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read Image Preview * \{ */ @@ -2456,8 +2253,7 @@ static PreviewImage *direct_link_preview_image(BlendDataReader *reader, PreviewI PreviewImage *prv = BLO_read_get_new_data_address(reader, old_prv); if (prv) { - int i; - for (i = 0; i < NUM_ICON_SIZES; i++) { + for (int i = 0; i < NUM_ICON_SIZES; i++) { if (prv->rect[i]) { BLO_read_data_address(reader, &prv->rect[i]); } @@ -2503,11 +2299,11 @@ static void lib_link_id(BlendLibReader *reader, ID *id) { /* Note: WM IDProperties are never written to file, hence they should always be NULL here. */ BLI_assert((GS(id->name) != ID_WM) || id->properties == NULL); - IDP_LibLinkProperty(id->properties, reader); + IDP_BlendReadLib(reader, id->properties); AnimData *adt = BKE_animdata_from_id(id); if (adt != NULL) { - lib_link_animdata(reader, id, adt); + BKE_animdata_blend_read_lib(reader, id, adt); } if (id->override_library) { @@ -2634,7 +2430,7 @@ static int direct_link_id_restore_recalc(const FileData *fd, static void direct_link_id_common( BlendDataReader *reader, Library *current_library, ID *id, ID *id_old, const int tag) { - if (reader->fd->memfile == NULL) { + if (!BLO_read_data_is_undo(reader)) { /* When actually reading a file , we do want to reset/re-generate session uuids. * In undo case, we want to re-use existing ones. */ id->session_uuid = MAIN_ID_SESSION_UUID_UNSET; @@ -2662,7 +2458,7 @@ static void direct_link_id_common( if (id->properties) { BLO_read_data_address(reader, &id->properties); /* this case means the data was written incorrectly, it should not happen */ - IDP_DirectLinkGroup_OrFree(&id->properties, reader); + IDP_BlendDataRead(reader, &id->properties); } id->flag &= ~LIB_INDIRECT_WEAK_LINK; @@ -2675,7 +2471,7 @@ static void direct_link_id_common( * * But for regular file load we clear the flag, since the flags might have been changed since * the version the file has been saved with. */ - if (reader->fd->memfile == NULL) { + if (!BLO_read_data_is_undo(reader)) { id->recalc = 0; id->recalc_after_undo_push = 0; } @@ -2835,12 +2631,12 @@ static void direct_link_paint_curve(BlendDataReader *reader, PaintCurve *pc) /** \name Read PackedFile * \{ */ -static PackedFile *direct_link_packedfile(BlendDataReader *reader, PackedFile *oldpf) +static PackedFile *direct_link_packedfile(BlendDataReader *reader, PackedFile *pf) { - PackedFile *pf = newpackedadr(reader->fd, oldpf); + BLO_read_packed_address(reader, &pf); if (pf) { - pf->data = newpackedadr(reader->fd, pf->data); + BLO_read_packed_address(reader, &pf->data); if (pf->data == NULL) { /* We cannot allow a PackedFile with a NULL data field, * the whole code assumes this is not possible. See T70315. */ @@ -2871,11 +2667,9 @@ static void lib_link_ipo(BlendLibReader *reader, Ipo *ipo) // XXX deprecated - old animation system static void direct_link_ipo(BlendDataReader *reader, Ipo *ipo) { - IpoCurve *icu; - BLO_read_list(reader, &(ipo->curve)); - for (icu = ipo->curve.first; icu; icu = icu->next) { + LISTBASE_FOREACH (IpoCurve *, icu, &ipo->curve) { BLO_read_data_address(reader, &icu->bezt); BLO_read_data_address(reader, &icu->bp); BLO_read_data_address(reader, &icu->driver); @@ -2885,14 +2679,11 @@ static void direct_link_ipo(BlendDataReader *reader, Ipo *ipo) // XXX deprecated - old animation system static void lib_link_nlastrips(BlendLibReader *reader, ID *id, ListBase *striplist) { - bActionStrip *strip; - bActionModifier *amod; - - for (strip = striplist->first; strip; strip = strip->next) { + LISTBASE_FOREACH (bActionStrip *, strip, striplist) { BLO_read_id_address(reader, id->lib, &strip->object); BLO_read_id_address(reader, id->lib, &strip->act); BLO_read_id_address(reader, id->lib, &strip->ipo); - for (amod = strip->modifiers.first; amod; amod = amod->next) { + LISTBASE_FOREACH (bActionModifier *, amod, &strip->modifiers) { BLO_read_id_address(reader, id->lib, &amod->ob); } } @@ -2901,11 +2692,9 @@ static void lib_link_nlastrips(BlendLibReader *reader, ID *id, ListBase *stripli // XXX deprecated - old animation system static void direct_link_nlastrips(BlendDataReader *reader, ListBase *strips) { - bActionStrip *strip; - BLO_read_list(reader, strips); - for (strip = strips->first; strip; strip = strip->next) { + LISTBASE_FOREACH (bActionStrip *, strip, strips) { BLO_read_list(reader, &strip->modifiers); } } @@ -2913,9 +2702,7 @@ static void direct_link_nlastrips(BlendDataReader *reader, ListBase *strips) // XXX deprecated - old animation system static void lib_link_constraint_channels(BlendLibReader *reader, ID *id, ListBase *chanbase) { - bConstraintChannel *chan; - - for (chan = chanbase->first; chan; chan = chan->next) { + LISTBASE_FOREACH (bConstraintChannel *, chan, chanbase) { BLO_read_id_address(reader, id->lib, &chan->ipo); } } @@ -2926,153 +2713,6 @@ static void lib_link_constraint_channels(BlendLibReader *reader, ID *id, ListBas /** \name Read ID: Action * \{ */ -static void lib_link_fmodifiers(BlendLibReader *reader, ID *id, ListBase *list) -{ - FModifier *fcm; - - for (fcm = list->first; fcm; fcm = fcm->next) { - /* data for specific modifiers */ - switch (fcm->type) { - case FMODIFIER_TYPE_PYTHON: { - FMod_Python *data = (FMod_Python *)fcm->data; - BLO_read_id_address(reader, id->lib, &data->script); - - break; - } - } - } -} - -static void lib_link_fcurves(BlendLibReader *reader, ID *id, ListBase *list) -{ - FCurve *fcu; - - if (list == NULL) { - return; - } - - /* relink ID-block references... */ - for (fcu = list->first; fcu; fcu = fcu->next) { - /* driver data */ - if (fcu->driver) { - ChannelDriver *driver = fcu->driver; - DriverVar *dvar; - - for (dvar = driver->variables.first; dvar; dvar = dvar->next) { - DRIVER_TARGETS_LOOPER_BEGIN (dvar) { - /* only relink if still used */ - if (tarIndex < dvar->num_targets) { - BLO_read_id_address(reader, id->lib, &dtar->id); - } - else { - dtar->id = NULL; - } - } - DRIVER_TARGETS_LOOPER_END; - } - } - - /* modifiers */ - lib_link_fmodifiers(reader, id, &fcu->modifiers); - } -} - -/* NOTE: this assumes that link_list has already been called on the list */ -static void direct_link_fmodifiers(BlendDataReader *reader, ListBase *list, FCurve *curve) -{ - FModifier *fcm; - - for (fcm = list->first; fcm; fcm = fcm->next) { - /* relink general data */ - BLO_read_data_address(reader, &fcm->data); - fcm->curve = curve; - - /* do relinking of data for specific types */ - switch (fcm->type) { - case FMODIFIER_TYPE_GENERATOR: { - FMod_Generator *data = (FMod_Generator *)fcm->data; - BLO_read_float_array(reader, data->arraysize, &data->coefficients); - break; - } - case FMODIFIER_TYPE_ENVELOPE: { - FMod_Envelope *data = (FMod_Envelope *)fcm->data; - - BLO_read_data_address(reader, &data->data); - - break; - } - case FMODIFIER_TYPE_PYTHON: { - FMod_Python *data = (FMod_Python *)fcm->data; - - BLO_read_data_address(reader, &data->prop); - IDP_DirectLinkGroup_OrFree(&data->prop, reader); - - break; - } - } - } -} - -/* NOTE: this assumes that link_list has already been called on the list */ -static void direct_link_fcurves(BlendDataReader *reader, ListBase *list) -{ - FCurve *fcu; - - /* link F-Curve data to F-Curve again (non ID-libs) */ - for (fcu = list->first; fcu; fcu = fcu->next) { - /* curve data */ - BLO_read_data_address(reader, &fcu->bezt); - BLO_read_data_address(reader, &fcu->fpt); - - /* rna path */ - BLO_read_data_address(reader, &fcu->rna_path); - - /* group */ - BLO_read_data_address(reader, &fcu->grp); - - /* clear disabled flag - allows disabled drivers to be tried again ([#32155]), - * but also means that another method for "reviving disabled F-Curves" exists - */ - fcu->flag &= ~FCURVE_DISABLED; - - /* driver */ - BLO_read_data_address(reader, &fcu->driver); - if (fcu->driver) { - ChannelDriver *driver = fcu->driver; - DriverVar *dvar; - - /* Compiled expression data will need to be regenerated - * (old pointer may still be set here). */ - driver->expr_comp = NULL; - driver->expr_simple = NULL; - - /* give the driver a fresh chance - the operating environment may be different now - * (addons, etc. may be different) so the driver namespace may be sane now [#32155] - */ - driver->flag &= ~DRIVER_FLAG_INVALID; - - /* relink variables, targets and their paths */ - BLO_read_list(reader, &driver->variables); - for (dvar = driver->variables.first; dvar; dvar = dvar->next) { - DRIVER_TARGETS_LOOPER_BEGIN (dvar) { - /* only relink the targets being used */ - if (tarIndex < dvar->num_targets) { - BLO_read_data_address(reader, &dtar->rna_path); - } - else { - dtar->rna_path = NULL; - } - } - DRIVER_TARGETS_LOOPER_END; - } - } - - /* modifiers */ - BLO_read_list(reader, &fcu->modifiers); - direct_link_fmodifiers(reader, &fcu->modifiers, fcu); - } -} - static void lib_link_action(BlendLibReader *reader, bAction *act) { // XXX deprecated - old animation system <<< @@ -3082,7 +2722,7 @@ static void lib_link_action(BlendLibReader *reader, bAction *act) } // >>> XXX deprecated - old animation system - lib_link_fcurves(reader, &act->id, &act->curves); + BKE_fcurve_blend_read_lib(reader, &act->id, &act->curves); LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { if (marker->camera) { @@ -3093,102 +2733,34 @@ static void lib_link_action(BlendLibReader *reader, bAction *act) static void direct_link_action(BlendDataReader *reader, bAction *act) { - bActionChannel *achan; // XXX deprecated - old animation system - bActionGroup *agrp; - BLO_read_list(reader, &act->curves); BLO_read_list(reader, &act->chanbase); // XXX deprecated - old animation system BLO_read_list(reader, &act->groups); BLO_read_list(reader, &act->markers); // XXX deprecated - old animation system <<< - for (achan = act->chanbase.first; achan; achan = achan->next) { + LISTBASE_FOREACH (bActionChannel *, achan, &act->chanbase) { BLO_read_data_address(reader, &achan->grp); BLO_read_list(reader, &achan->constraintChannels); } // >>> XXX deprecated - old animation system - direct_link_fcurves(reader, &act->curves); + BKE_fcurve_blend_read_data(reader, &act->curves); - for (agrp = act->groups.first; agrp; agrp = agrp->next) { + LISTBASE_FOREACH (bActionGroup *, agrp, &act->groups) { BLO_read_data_address(reader, &agrp->channels.first); BLO_read_data_address(reader, &agrp->channels.last); } } -static void lib_link_nladata_strips(BlendLibReader *reader, ID *id, ListBase *list) -{ - NlaStrip *strip; - - for (strip = list->first; strip; strip = strip->next) { - /* check strip's children */ - lib_link_nladata_strips(reader, id, &strip->strips); - - /* check strip's F-Curves */ - lib_link_fcurves(reader, id, &strip->fcurves); - - /* reassign the counted-reference to action */ - BLO_read_id_address(reader, id->lib, &strip->act); - } -} - -static void lib_link_nladata(BlendLibReader *reader, ID *id, ListBase *list) -{ - NlaTrack *nlt; - - /* we only care about the NLA strips inside the tracks */ - for (nlt = list->first; nlt; nlt = nlt->next) { - lib_link_nladata_strips(reader, id, &nlt->strips); - } -} - -/* This handles Animato NLA-Strips linking - * NOTE: this assumes that link_list has already been called on the list - */ -static void direct_link_nladata_strips(BlendDataReader *reader, ListBase *list) -{ - NlaStrip *strip; - - for (strip = list->first; strip; strip = strip->next) { - /* strip's child strips */ - BLO_read_list(reader, &strip->strips); - direct_link_nladata_strips(reader, &strip->strips); - - /* strip's F-Curves */ - BLO_read_list(reader, &strip->fcurves); - direct_link_fcurves(reader, &strip->fcurves); - - /* strip's F-Modifiers */ - BLO_read_list(reader, &strip->modifiers); - direct_link_fmodifiers(reader, &strip->modifiers, NULL); - } -} - -/* NOTE: this assumes that BLO_read_list has already been called on the list */ -static void direct_link_nladata(BlendDataReader *reader, ListBase *list) -{ - NlaTrack *nlt; - - for (nlt = list->first; nlt; nlt = nlt->next) { - /* relink list of strips */ - BLO_read_list(reader, &nlt->strips); - - /* relink strip data */ - direct_link_nladata_strips(reader, &nlt->strips); - } -} - /* ------- */ static void lib_link_keyingsets(BlendLibReader *reader, ID *id, ListBase *list) { - KeyingSet *ks; - KS_Path *ksp; - /* here, we're only interested in the ID pointer stored in some of the paths */ - for (ks = list->first; ks; ks = ks->next) { - for (ksp = ks->paths.first; ksp; ksp = ksp->next) { + LISTBASE_FOREACH (KeyingSet *, ks, list) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { BLO_read_id_address(reader, id->lib, &ksp->id); } } @@ -3197,71 +2769,18 @@ static void lib_link_keyingsets(BlendLibReader *reader, ID *id, ListBase *list) /* NOTE: this assumes that BLO_read_list has already been called on the list */ static void direct_link_keyingsets(BlendDataReader *reader, ListBase *list) { - KeyingSet *ks; - KS_Path *ksp; - /* link KeyingSet data to KeyingSet again (non ID-libs) */ - for (ks = list->first; ks; ks = ks->next) { + LISTBASE_FOREACH (KeyingSet *, ks, list) { /* paths */ BLO_read_list(reader, &ks->paths); - for (ksp = ks->paths.first; ksp; ksp = ksp->next) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { /* rna path */ BLO_read_data_address(reader, &ksp->rna_path); } } } -/* ------- */ - -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 */ - lib_link_fcurves(reader, id, &adt->drivers); - - /* overrides don't have lib-link for now, so no need to do anything */ - - /* link NLA-data */ - lib_link_nladata(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); - direct_link_fcurves(reader, &adt->drivers); - adt->driver_array = NULL; - - /* link overrides */ - // TODO... - - /* link NLA-data */ - BLO_read_list(reader, &adt->nla_tracks); - direct_link_nladata(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); -} - /** \} */ /* -------------------------------------------------------------------- */ @@ -3281,7 +2800,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_read_data(reader, cache_file->adt); } /** \} */ @@ -3329,7 +2848,7 @@ static void direct_link_workspace(BlendDataReader *reader, WorkSpace *workspace, /* Same issue/fix as in direct_link_workspace_link_scene_data: Can't read workspace data * when reading windows, so have to update windows after/when reading workspaces. */ - for (wmWindowManager *wm = main->wm.first; wm; wm = wm->id.next) { + LISTBASE_FOREACH (wmWindowManager *, wm, &main->wm) { LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { BLO_read_data_address(reader, &win->workspace_hook->act_layout); } @@ -3338,7 +2857,7 @@ static void direct_link_workspace(BlendDataReader *reader, WorkSpace *workspace, LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { tref->runtime = NULL; BLO_read_data_address(reader, &tref->properties); - IDP_DirectLinkGroup_OrFree(&tref->properties, reader); + IDP_BlendDataRead(reader, &tref->properties); } workspace->status_text = NULL; @@ -3363,7 +2882,7 @@ static void lib_link_workspace_instance_hook(BlendLibReader *reader, static void lib_link_node_socket(BlendLibReader *reader, Library *lib, bNodeSocket *sock) { - IDP_LibLinkProperty(sock->prop, reader); + IDP_BlendReadLib(reader, sock->prop); switch ((eNodeSocketDatatype)sock->type) { case SOCK_OBJECT: { @@ -3410,7 +2929,7 @@ static void lib_link_ntree(BlendLibReader *reader, Library *lib, bNodeTree *ntre LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { /* Link ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ - IDP_LibLinkProperty(node->prop, reader); + IDP_BlendReadLib(reader, node->prop); BLO_read_id_address(reader, lib, &node->id); @@ -3429,7 +2948,7 @@ static void lib_link_ntree(BlendLibReader *reader, Library *lib, bNodeTree *ntre /* For nodes with static socket layout, add/remove sockets as needed * to match the static layout. */ - if (reader->fd->memfile == NULL) { + if (!BLO_read_lib_is_undo(reader)) { LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { node_verify_socket_templates(ntree, node); } @@ -3445,7 +2964,7 @@ static void lib_link_nodetree(BlendLibReader *reader, bNodeTree *ntree) static void direct_link_node_socket(BlendDataReader *reader, bNodeSocket *sock) { BLO_read_data_address(reader, &sock->prop); - IDP_DirectLinkGroup_OrFree(&sock->prop, reader); + IDP_BlendDataRead(reader, &sock->prop); BLO_read_data_address(reader, &sock->link); sock->typeinfo = NULL; @@ -3458,9 +2977,6 @@ static void direct_link_node_socket(BlendDataReader *reader, bNodeSocket *sock) static void direct_link_nodetree(BlendDataReader *reader, bNodeTree *ntree) { /* note: writing and reading goes in sync, for speed */ - bNode *node; - bNodeSocket *sock; - bNodeLink *link; ntree->init = 0; /* to set callbacks and force setting types */ ntree->is_updating = false; @@ -3471,20 +2987,20 @@ 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_read_data(reader, ntree->adt); BLO_read_list(reader, &ntree->nodes); - for (node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { node->typeinfo = NULL; BLO_read_list(reader, &node->inputs); BLO_read_list(reader, &node->outputs); BLO_read_data_address(reader, &node->prop); - IDP_DirectLinkGroup_OrFree(&node->prop, reader); + IDP_BlendDataRead(reader, &node->prop); BLO_read_list(reader, &node->internal_links); - for (link = node->internal_links.first; link; link = link->next) { + LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) { BLO_read_data_address(reader, &link->fromnode); BLO_read_data_address(reader, &link->fromsock); BLO_read_data_address(reader, &link->tonode); @@ -3563,14 +3079,14 @@ static void direct_link_nodetree(BlendDataReader *reader, bNodeTree *ntree) BLO_read_list(reader, &ntree->links); /* and we connect the rest */ - for (node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { BLO_read_data_address(reader, &node->parent); node->lasty = 0; - for (sock = node->inputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { direct_link_node_socket(reader, sock); } - for (sock = node->outputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { direct_link_node_socket(reader, sock); } } @@ -3578,14 +3094,14 @@ static void direct_link_nodetree(BlendDataReader *reader, bNodeTree *ntree) /* interface socket lists */ BLO_read_list(reader, &ntree->inputs); BLO_read_list(reader, &ntree->outputs); - for (sock = ntree->inputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) { direct_link_node_socket(reader, sock); } - for (sock = ntree->outputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) { direct_link_node_socket(reader, sock); } - for (link = ntree->links.first; link; link = link->next) { + LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { BLO_read_data_address(reader, &link->fromnode); BLO_read_data_address(reader, &link->tonode); BLO_read_data_address(reader, &link->fromsock); @@ -3622,10 +3138,9 @@ static void lib_link_constraint_cb(bConstraint *UNUSED(con), static void lib_link_constraints(BlendLibReader *reader, ID *id, ListBase *conlist) { tConstraintLinkData cld; - bConstraint *con; /* legacy fixes */ - for (con = conlist->first; con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, conlist) { /* patch for error introduced by changing constraints (dunno how) */ /* if con->data type changes, dna cannot resolve the pointer! (ton) */ if (con->data == NULL) { @@ -3649,10 +3164,8 @@ static void lib_link_constraints(BlendLibReader *reader, ID *id, ListBase *conli static void direct_link_constraints(BlendDataReader *reader, ListBase *lb) { - bConstraint *con; - BLO_read_list(reader, lb); - for (con = lb->first; con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, lb) { BLO_read_data_address(reader, &con->data); switch (con->type) { @@ -3662,7 +3175,7 @@ static void direct_link_constraints(BlendDataReader *reader, ListBase *lb) BLO_read_list(reader, &data->targets); BLO_read_data_address(reader, &data->prop); - IDP_DirectLinkGroup_OrFree(&data->prop, reader); + IDP_BlendDataRead(reader, &data->prop); break; } case CONSTRAINT_TYPE_ARMATURE: { @@ -3715,7 +3228,7 @@ static void lib_link_pose(BlendLibReader *reader, Object *ob, bPose *pose) /* always rebuild to match proxy or lib changes, but on Undo */ bool rebuild = false; - if (reader->fd->memfile == NULL) { + if (!BLO_read_lib_is_undo(reader)) { if (ob->proxy || ob->id.lib != arm->id.lib) { rebuild = true; } @@ -3741,7 +3254,7 @@ static void lib_link_pose(BlendLibReader *reader, Object *ob, bPose *pose) pchan->bone = BKE_armature_find_bone_name(arm, pchan->name); - IDP_LibLinkProperty(pchan->prop, reader); + IDP_BlendReadLib(reader, pchan->prop); BLO_read_id_address(reader, arm->id.lib, &pchan->custom); if (UNLIKELY(pchan->bone == NULL)) { @@ -3763,7 +3276,7 @@ static void lib_link_pose(BlendLibReader *reader, Object *ob, bPose *pose) static void lib_link_bones(BlendLibReader *reader, Bone *bone) { - IDP_LibLinkProperty(bone->prop, reader); + IDP_BlendReadLib(reader, bone->prop); LISTBASE_FOREACH (Bone *, curbone, &bone->childbase) { lib_link_bones(reader, curbone); @@ -3779,11 +3292,9 @@ static void lib_link_armature(BlendLibReader *reader, bArmature *arm) static void direct_link_bones(BlendDataReader *reader, Bone *bone) { - Bone *child; - BLO_read_data_address(reader, &bone->parent); BLO_read_data_address(reader, &bone->prop); - IDP_DirectLinkGroup_OrFree(&bone->prop, reader); + IDP_BlendDataRead(reader, &bone->prop); BLO_read_data_address(reader, &bone->bbone_next); BLO_read_data_address(reader, &bone->bbone_prev); @@ -3792,15 +3303,13 @@ static void direct_link_bones(BlendDataReader *reader, Bone *bone) BLO_read_list(reader, &bone->childbase); - for (child = bone->childbase.first; child; child = child->next) { + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { direct_link_bones(reader, child); } } static void direct_link_armature(BlendDataReader *reader, bArmature *arm) { - Bone *bone; - BLO_read_list(reader, &arm->bonebase); arm->bonehash = NULL; arm->edbo = NULL; @@ -3808,9 +3317,9 @@ 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_read_data(reader, arm->adt); - for (bone = arm->bonebase.first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { direct_link_bones(reader, bone); } @@ -3842,7 +3351,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_read_data(reader, ca->adt); BLO_read_list(reader, &ca->bg_images); @@ -3866,7 +3375,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_read_data(reader, la->adt); BLO_read_data_address(reader, &la->curfalloff); if (la->curfalloff) { @@ -3884,10 +3393,8 @@ static void direct_link_light(BlendDataReader *reader, Light *la) void blo_do_versions_key_uidgen(Key *key) { - KeyBlock *block; - key->uidgen = 1; - for (block = key->block.first; block; block = block->next) { + LISTBASE_FOREACH (KeyBlock *, block, &key->block) { block->uid = key->uidgen++; } } @@ -3902,13 +3409,10 @@ static void lib_link_key(BlendLibReader *reader, Key *key) static void switch_endian_keyblock(Key *key, KeyBlock *kb) { - int elemsize, a, b; - char *data; - - elemsize = key->elemsize; - data = kb->data; + int elemsize = key->elemsize; + char *data = kb->data; - for (a = 0; a < kb->totelem; a++) { + for (int a = 0; a < kb->totelem; a++) { const char *cp = key->elemstr; char *poin = data; @@ -3916,11 +3420,12 @@ static void switch_endian_keyblock(Key *key, KeyBlock *kb) switch (cp[1]) { /* cp[1] = type */ case IPO_FLOAT: case IPO_BPOINT: - case IPO_BEZTRIPLE: - b = cp[0]; + case IPO_BEZTRIPLE: { + int b = cp[0]; BLI_endian_switch_float_array((float *)poin, b); poin += sizeof(float) * b; break; + } } cp += 2; @@ -3931,16 +3436,14 @@ static void switch_endian_keyblock(Key *key, KeyBlock *kb) static void direct_link_key(BlendDataReader *reader, Key *key) { - KeyBlock *kb; - BLO_read_list(reader, &(key->block)); BLO_read_data_address(reader, &key->adt); - direct_link_animdata(reader, key->adt); + BKE_animdata_blend_read_data(reader, key->adt); BLO_read_data_address(reader, &key->refkey); - for (kb = key->block.first; kb; kb = kb->next) { + LISTBASE_FOREACH (KeyBlock *, kb, &key->block) { BLO_read_data_address(reader, &kb->data); if (BLO_read_requires_endian_switch(reader)) { @@ -3967,7 +3470,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_read_data(reader, mb->adt); BLO_read_pointer_array(reader, (void **)&mb->mat); @@ -3996,7 +3499,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_read_data(reader, wrld->adt); wrld->preview = direct_link_preview_image(reader, wrld->preview); BLI_listbase_clear(&wrld->gpumaterial); @@ -4031,8 +3534,6 @@ static void lib_link_text(BlendLibReader *UNUSED(reader), Text *UNUSED(text)) static void direct_link_text(BlendDataReader *reader, Text *text) { - TextLine *ln; - BLO_read_data_address(reader, &text->filepath); text->compiled = NULL; @@ -4049,7 +3550,7 @@ static void direct_link_text(BlendDataReader *reader, Text *text) BLO_read_data_address(reader, &text->curl); BLO_read_data_address(reader, &text->sell); - for (ln = text->lines.first; ln; ln = ln->next) { + LISTBASE_FOREACH (TextLine *, ln, &text->lines) { BLO_read_data_address(reader, &ln->line); ln->format = NULL; @@ -4083,12 +3584,10 @@ static void lib_link_image(BlendLibReader *UNUSED(reader), Image *ima) static void direct_link_image(BlendDataReader *reader, Image *ima) { - ImagePackedFile *imapf; - BLO_read_list(reader, &ima->tiles); BLO_read_list(reader, &(ima->renderslots)); - if (reader->fd->memfile == NULL) { + if (!BLO_read_data_is_undo(reader)) { /* We reset this last render slot index only when actually reading a file, not for undo. */ ima->last_render_slot = ima->render_slot; } @@ -4097,7 +3596,7 @@ static void direct_link_image(BlendDataReader *reader, Image *ima) BLO_read_list(reader, &(ima->packedfiles)); if (ima->packedfiles.first) { - for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { + LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) { imapf->packedfile = direct_link_packedfile(reader, imapf->packedfile); } ima->packedfile = NULL; @@ -4150,11 +3649,8 @@ static void switch_endian_knots(Nurb *nu) static void direct_link_curve(BlendDataReader *reader, Curve *cu) { - Nurb *nu; - TextBox *tb; - BLO_read_data_address(reader, &cu->adt); - direct_link_animdata(reader, cu->adt); + BKE_animdata_blend_read_data(reader, cu->adt); /* Protect against integer overflow vulnerability. */ CLAMP(cu->len_char32, 0, INT_MAX - 4); @@ -4171,7 +3667,7 @@ static void direct_link_curve(BlendDataReader *reader, Curve *cu) else { cu->nurb.first = cu->nurb.last = NULL; - tb = MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "TextBoxread"); + TextBox *tb = MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "TextBoxread"); if (cu->tb) { memcpy(tb, cu->tb, cu->totbox * sizeof(TextBox)); MEM_freeN(cu->tb); @@ -4192,7 +3688,7 @@ static void direct_link_curve(BlendDataReader *reader, Curve *cu) cu->editfont = NULL; cu->batch_cache = NULL; - for (nu = cu->nurb.first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { BLO_read_data_address(reader, &nu->bezt); BLO_read_data_address(reader, &nu->bp); BLO_read_data_address(reader, &nu->knotsu); @@ -4223,7 +3719,7 @@ static void lib_link_texture(BlendLibReader *reader, Tex *tex) static void direct_link_texture(BlendDataReader *reader, Tex *tex) { BLO_read_data_address(reader, &tex->adt); - direct_link_animdata(reader, tex->adt); + BKE_animdata_blend_read_data(reader, tex->adt); BLO_read_data_address(reader, &tex->coba); @@ -4258,7 +3754,7 @@ static void lib_link_material(BlendLibReader *reader, Material *ma) static void direct_link_material(BlendDataReader *reader, Material *ma) { BLO_read_data_address(reader, &ma->adt); - direct_link_animdata(reader, ma->adt); + BKE_animdata_blend_read_data(reader, ma->adt); ma->texpaintslot = NULL; @@ -4289,9 +3785,7 @@ static const char *ptcache_data_struct[] = { static void direct_link_pointcache_cb(BlendDataReader *reader, void *data) { PTCacheMem *pm = data; - PTCacheExtra *extra; - int i; - for (i = 0; i < BPHYS_TOT_DATA; i++) { + for (int i = 0; i < BPHYS_TOT_DATA; i++) { BLO_read_data_address(reader, &pm->data[i]); /* the cache saves non-struct data without DNA */ @@ -4308,7 +3802,7 @@ static void direct_link_pointcache_cb(BlendDataReader *reader, void *data) BLO_read_list(reader, &pm->extradata); - for (extra = pm->extradata.first; extra; extra = extra->next) { + LISTBASE_FOREACH (PTCacheExtra *, extra, &pm->extradata) { BLO_read_data_address(reader, &extra->data); } } @@ -4336,9 +3830,8 @@ static void direct_link_pointcache_list(BlendDataReader *reader, int force_disk) { if (ptcaches->first) { - PointCache *cache = NULL; BLO_read_list(reader, ptcaches); - for (cache = ptcaches->first; cache; cache = cache->next) { + LISTBASE_FOREACH (PointCache *, cache, ptcaches) { direct_link_pointcache(reader, cache); if (force_disk) { cache->flag |= PTCACHE_DISK_CACHE; @@ -4401,11 +3894,8 @@ static void lib_link_particlesettings(BlendLibReader *reader, ParticleSettings * } if (part->boids) { - BoidState *state = part->boids->states.first; - BoidRule *rule; - for (; state; state = state->next) { - rule = state->rules.first; - for (; rule; rule = rule->next) { + LISTBASE_FOREACH (BoidState *, state, &part->boids->states) { + LISTBASE_FOREACH (BoidRule *, rule, &state->rules) { switch (rule->type) { case eBoidRuleType_Goal: case eBoidRuleType_Avoid: { @@ -4441,13 +3931,11 @@ static void direct_link_partdeflect(PartDeflect *pd) static void direct_link_particlesettings(BlendDataReader *reader, ParticleSettings *part) { - int a; - BLO_read_data_address(reader, &part->adt); BLO_read_data_address(reader, &part->pd); BLO_read_data_address(reader, &part->pd2); - direct_link_animdata(reader, part->adt); + BKE_animdata_blend_read_data(reader, part->adt); direct_link_partdeflect(part->pd); direct_link_partdeflect(part->pd2); @@ -4475,16 +3963,15 @@ static void direct_link_particlesettings(BlendDataReader *reader, ParticleSettin BLO_read_data_address(reader, &part->fluid); if (part->boids) { - BoidState *state; BLO_read_list(reader, &part->boids->states); - for (state = part->boids->states.first; state; state = state->next) { + LISTBASE_FOREACH (BoidState *, state, &part->boids->states) { BLO_read_list(reader, &state->rules); BLO_read_list(reader, &state->conditions); BLO_read_list(reader, &state->actions); } } - for (a = 0; a < MAX_MTEX; a++) { + for (int a = 0; a < MAX_MTEX; a++) { BLO_read_data_address(reader, &part->mtex[a]); } @@ -4497,16 +3984,11 @@ static void lib_link_particlesystems(BlendLibReader *reader, ID *id, ListBase *particles) { - ParticleSystem *psys, *psysnext; - - for (psys = particles->first; psys; psys = psysnext) { - psysnext = psys->next; + LISTBASE_FOREACH_MUTABLE (ParticleSystem *, psys, particles) { BLO_read_id_address(reader, id->lib, &psys->part); if (psys->part) { - ParticleTarget *pt = psys->targets.first; - - for (; pt; pt = pt->next) { + LISTBASE_FOREACH (ParticleTarget *, pt, &psys->targets) { BLO_read_id_address(reader, id->lib, &pt->ob); } @@ -4535,11 +4017,10 @@ static void lib_link_particlesystems(BlendLibReader *reader, } static void direct_link_particlesystems(BlendDataReader *reader, ListBase *particles) { - ParticleSystem *psys; ParticleData *pa; int a; - for (psys = particles->first; psys; psys = psys->next) { + LISTBASE_FOREACH (ParticleSystem *, psys, particles) { BLO_read_data_address(reader, &psys->particles); if (psys->particles && psys->particles->hair) { @@ -4628,255 +4109,6 @@ static void direct_link_particlesystems(BlendDataReader *reader, ListBase *parti /** \name Read ID: Mesh * \{ */ -static void lib_link_mesh(BlendLibReader *reader, Mesh *me) -{ - /* this check added for python created meshes */ - if (me->mat) { - for (int i = 0; i < me->totcol; i++) { - BLO_read_id_address(reader, me->id.lib, &me->mat[i]); - } - } - else { - me->totcol = 0; - } - - BLO_read_id_address(reader, me->id.lib, &me->ipo); // XXX: deprecated: old anim sys - BLO_read_id_address(reader, me->id.lib, &me->key); - BLO_read_id_address(reader, me->id.lib, &me->texcomesh); -} - -static void direct_link_dverts(BlendDataReader *reader, int count, MDeformVert *mdverts) -{ - int i; - - if (mdverts == NULL) { - return; - } - - for (i = count; i > 0; i--, mdverts++) { - /*convert to vgroup allocation system*/ - MDeformWeight *dw; - if (mdverts->dw && (dw = BLO_read_get_new_data_address(reader, mdverts->dw))) { - const ssize_t dw_len = mdverts->totweight * sizeof(MDeformWeight); - void *dw_tmp = MEM_mallocN(dw_len, "direct_link_dverts"); - memcpy(dw_tmp, dw, dw_len); - mdverts->dw = dw_tmp; - MEM_freeN(dw); - } - else { - mdverts->dw = NULL; - mdverts->totweight = 0; - } - } -} - -static void direct_link_mdisps(BlendDataReader *reader, int count, MDisps *mdisps, int external) -{ - if (mdisps) { - int i; - - for (i = 0; i < count; i++) { - BLO_read_data_address(reader, &mdisps[i].disps); - BLO_read_data_address(reader, &mdisps[i].hidden); - - if (mdisps[i].totdisp && !mdisps[i].level) { - /* this calculation is only correct for loop mdisps; - * if loading pre-BMesh face mdisps this will be - * overwritten with the correct value in - * bm_corners_to_loops() */ - float gridsize = sqrtf(mdisps[i].totdisp); - mdisps[i].level = (int)(logf(gridsize - 1.0f) / (float)M_LN2) + 1; - } - - if (BLO_read_requires_endian_switch(reader) && (mdisps[i].disps)) { - /* DNA_struct_switch_endian doesn't do endian swap for (*disps)[] */ - /* this does swap for data written at write_mdisps() - readfile.c */ - BLI_endian_switch_float_array(*mdisps[i].disps, mdisps[i].totdisp * 3); - } - if (!external && !mdisps[i].disps) { - mdisps[i].totdisp = 0; - } - } - } -} - -static void direct_link_grid_paint_mask(BlendDataReader *reader, - int count, - GridPaintMask *grid_paint_mask) -{ - if (grid_paint_mask) { - int i; - - for (i = 0; i < count; i++) { - GridPaintMask *gpm = &grid_paint_mask[i]; - if (gpm->data) { - BLO_read_data_address(reader, &gpm->data); - } - } - } -} - -/*this isn't really a public api function, so prototyped here*/ -static void direct_link_customdata(BlendDataReader *reader, CustomData *data, int count) -{ - int i = 0; - - BLO_read_data_address(reader, &data->layers); - - /* annoying workaround for bug [#31079] loading legacy files with - * no polygons _but_ have stale customdata */ - if (UNLIKELY(count == 0 && data->layers == NULL && data->totlayer != 0)) { - CustomData_reset(data); - return; - } - - BLO_read_data_address(reader, &data->external); - - while (i < data->totlayer) { - CustomDataLayer *layer = &data->layers[i]; - - if (layer->flag & CD_FLAG_EXTERNAL) { - layer->flag &= ~CD_FLAG_IN_MEMORY; - } - - layer->flag &= ~CD_FLAG_NOFREE; - - if (CustomData_verify_versions(data, i)) { - BLO_read_data_address(reader, &layer->data); - if (layer->type == CD_MDISPS) { - direct_link_mdisps(reader, count, layer->data, layer->flag & CD_FLAG_EXTERNAL); - } - else if (layer->type == CD_GRID_PAINT_MASK) { - direct_link_grid_paint_mask(reader, count, layer->data); - } - i++; - } - } - - CustomData_update_typemap(data); -} - -static void direct_link_mesh(BlendDataReader *reader, Mesh *mesh) -{ - BLO_read_pointer_array(reader, (void **)&mesh->mat); - - BLO_read_data_address(reader, &mesh->mvert); - BLO_read_data_address(reader, &mesh->medge); - BLO_read_data_address(reader, &mesh->mface); - BLO_read_data_address(reader, &mesh->mloop); - BLO_read_data_address(reader, &mesh->mpoly); - BLO_read_data_address(reader, &mesh->tface); - BLO_read_data_address(reader, &mesh->mtface); - BLO_read_data_address(reader, &mesh->mcol); - BLO_read_data_address(reader, &mesh->dvert); - BLO_read_data_address(reader, &mesh->mloopcol); - BLO_read_data_address(reader, &mesh->mloopuv); - BLO_read_data_address(reader, &mesh->mselect); - - /* animdata */ - BLO_read_data_address(reader, &mesh->adt); - direct_link_animdata(reader, mesh->adt); - - /* Normally direct_link_dverts should be called in direct_link_customdata, - * but for backwards compatibility in do_versions to work we do it here. */ - direct_link_dverts(reader, mesh->totvert, mesh->dvert); - - direct_link_customdata(reader, &mesh->vdata, mesh->totvert); - direct_link_customdata(reader, &mesh->edata, mesh->totedge); - direct_link_customdata(reader, &mesh->fdata, mesh->totface); - direct_link_customdata(reader, &mesh->ldata, mesh->totloop); - direct_link_customdata(reader, &mesh->pdata, mesh->totpoly); - - mesh->texflag &= ~ME_AUTOSPACE_EVALUATED; - mesh->edit_mesh = NULL; - BKE_mesh_runtime_reset(mesh); - - /* happens with old files */ - if (mesh->mselect == NULL) { - mesh->totselect = 0; - } - - /* Multires data */ - BLO_read_data_address(reader, &mesh->mr); - if (mesh->mr) { - MultiresLevel *lvl; - - BLO_read_list(reader, &mesh->mr->levels); - lvl = mesh->mr->levels.first; - - direct_link_customdata(reader, &mesh->mr->vdata, lvl->totvert); - direct_link_dverts(reader, lvl->totvert, CustomData_get(&mesh->mr->vdata, 0, CD_MDEFORMVERT)); - direct_link_customdata(reader, &mesh->mr->fdata, lvl->totface); - - BLO_read_data_address(reader, &mesh->mr->edge_flags); - BLO_read_data_address(reader, &mesh->mr->edge_creases); - - BLO_read_data_address(reader, &mesh->mr->verts); - - /* If mesh has the same number of vertices as the - * highest multires level, load the current mesh verts - * into multires and discard the old data. Needed - * because some saved files either do not have a verts - * array, or the verts array contains out-of-date - * data. */ - if (mesh->totvert == ((MultiresLevel *)mesh->mr->levels.last)->totvert) { - if (mesh->mr->verts) { - MEM_freeN(mesh->mr->verts); - } - mesh->mr->verts = MEM_dupallocN(mesh->mvert); - } - - for (; lvl; lvl = lvl->next) { - BLO_read_data_address(reader, &lvl->verts); - BLO_read_data_address(reader, &lvl->faces); - BLO_read_data_address(reader, &lvl->edges); - BLO_read_data_address(reader, &lvl->colfaces); - } - } - - /* if multires is present but has no valid vertex data, - * there's no way to recover it; silently remove multires */ - if (mesh->mr && !mesh->mr->verts) { - multires_free(mesh->mr); - mesh->mr = NULL; - } - - if ((BLO_read_requires_endian_switch(reader)) && mesh->tface) { - TFace *tf = mesh->tface; - int i; - - for (i = 0; i < mesh->totface; i++, tf++) { - BLI_endian_switch_uint32_array(tf->col, 4); - } - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Lattice - * \{ */ - -static void lib_link_latt(BlendLibReader *reader, Lattice *lt) -{ - BLO_read_id_address(reader, lt->id.lib, <->ipo); // XXX deprecated - old animation system - BLO_read_id_address(reader, lt->id.lib, <->key); -} - -static void direct_link_latt(BlendDataReader *reader, Lattice *lt) -{ - BLO_read_data_address(reader, <->def); - - BLO_read_data_address(reader, <->dvert); - direct_link_dverts(reader, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert); - - lt->editlatt = NULL; - lt->batch_cache = NULL; - - BLO_read_data_address(reader, <->adt); - direct_link_animdata(reader, lt->adt); -} - /** \} */ /* -------------------------------------------------------------------- */ @@ -4899,7 +4131,7 @@ static void lib_link_modifiers(BlendLibReader *reader, Object *ob) /* If linking from a library, clear 'local' library override flag. */ if (ob->id.lib != NULL) { - for (ModifierData *mod = ob->modifiers.first; mod != NULL; mod = mod->next) { + LISTBASE_FOREACH (ModifierData *, mod, &ob->modifiers) { mod->flag &= ~eModifierFlag_OverrideLibrary_Local; } } @@ -4911,8 +4143,7 @@ static void lib_link_gpencil_modifiers(BlendLibReader *reader, Object *ob) /* If linking from a library, clear 'local' library override flag. */ if (ob->id.lib != NULL) { - for (GpencilModifierData *mod = ob->greasepencil_modifiers.first; mod != NULL; - mod = mod->next) { + LISTBASE_FOREACH (GpencilModifierData *, mod, &ob->greasepencil_modifiers) { mod->flag &= ~eGpencilModifierFlag_OverrideLibrary_Local; } } @@ -4924,7 +4155,7 @@ static void lib_link_shaderfxs(BlendLibReader *reader, Object *ob) /* If linking from a library, clear 'local' library override flag. */ if (ob->id.lib != NULL) { - for (ShaderFxData *fx = ob->shader_fx.first; fx != NULL; fx = fx->next) { + LISTBASE_FOREACH (ShaderFxData *, fx, &ob->shader_fx) { fx->flag &= ~eShaderFxFlag_OverrideLibrary_Local; } } @@ -4933,7 +4164,6 @@ static void lib_link_shaderfxs(BlendLibReader *reader, Object *ob) static void lib_link_object(BlendLibReader *reader, Object *ob) { bool warn = false; - int a; // XXX deprecated - old animation system <<< BLO_read_id_address(reader, ob->id.lib, &ob->ipo); @@ -5012,7 +4242,7 @@ static void lib_link_object(BlendLibReader *reader, Object *ob) ob->mode &= ~OB_MODE_POSE; } } - for (a = 0; a < ob->totcol; a++) { + for (int a = 0; a < ob->totcol; a++) { BLO_read_id_address(reader, ob->id.lib, &ob->mat[a]); } @@ -5093,17 +4323,6 @@ static void lib_link_object(BlendLibReader *reader, Object *ob) BLO_read_id_address(reader, ob->id.lib, &ob->rigidbody_constraint->ob2); } - { - LodLevel *level; - for (level = ob->lodlevels.first; level; level = level->next) { - BLO_read_id_address(reader, ob->id.lib, &level->source); - - if (!level->source && level == ob->lodlevels.first) { - level->source = ob; - } - } - } - if (warn) { BKE_report(reader->fd->reports, RPT_WARNING, "Warning in console"); } @@ -5127,8 +4346,6 @@ static void direct_link_motionpath(BlendDataReader *reader, bMotionPath *mpath) static void direct_link_pose(BlendDataReader *reader, bPose *pose) { - bPoseChannel *pchan; - if (!pose) { return; } @@ -5139,7 +4356,7 @@ static void direct_link_pose(BlendDataReader *reader, bPose *pose) pose->chanhash = NULL; pose->chan_array = NULL; - for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { BKE_pose_channel_runtime_reset(&pchan->runtime); BKE_pose_channel_session_uuid_generate(pchan); @@ -5154,7 +4371,7 @@ static void direct_link_pose(BlendDataReader *reader, bPose *pose) direct_link_constraints(reader, &pchan->constraints); BLO_read_data_address(reader, &pchan->prop); - IDP_DirectLinkGroup_OrFree(&pchan->prop, reader); + IDP_BlendDataRead(reader, &pchan->prop); BLO_read_data_address(reader, &pchan->mpath); if (pchan->mpath) { @@ -5291,11 +4508,9 @@ static ModifierData *modifier_replace_with_fluid(FileData *fd, static void direct_link_modifiers(BlendDataReader *reader, ListBase *lb, Object *ob) { - ModifierData *md; - BLO_read_list(reader, lb); - for (md = lb->first; md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, lb) { BKE_modifier_session_uuid_generate(md); md->error = NULL; @@ -5452,10 +4667,9 @@ static void direct_link_modifiers(BlendDataReader *reader, ListBase *lb, Object pmd->canvas->flags &= ~MOD_DPAINT_BAKING; /* just in case */ if (pmd->canvas->surfaces.first) { - DynamicPaintSurface *surface; BLO_read_list(reader, &pmd->canvas->surfaces); - for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { + LISTBASE_FOREACH (DynamicPaintSurface *, surface, &pmd->canvas->surfaces) { surface->canvas = pmd->canvas; surface->data = NULL; direct_link_pointcache_list(reader, &(surface->ptcaches), &(surface->pointcache), 1); @@ -5484,11 +4698,9 @@ static void direct_link_modifiers(BlendDataReader *reader, ListBase *lb, Object static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb) { - GpencilModifierData *md; - BLO_read_list(reader, lb); - for (md = lb->first; md; md = md->next) { + LISTBASE_FOREACH (GpencilModifierData *, md, lb) { md->error = NULL; /* if modifiers disappear, or for upward compatibility */ @@ -5565,11 +4777,9 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb) static void direct_link_shaderfxs(BlendDataReader *reader, ListBase *lb) { - ShaderFxData *fx; - BLO_read_list(reader, lb); - for (fx = lb->first; fx; fx = fx->next) { + LISTBASE_FOREACH (ShaderFxData *, fx, lb) { fx->error = NULL; /* if shader disappear, or for upward compatibility */ @@ -5593,15 +4803,16 @@ static void direct_link_object(BlendDataReader *reader, Object *ob) * Also when linking in a file don't allow edit and pose modes. * See [#34776, #42780] for more information. */ - if (reader->fd->memfile || (ob->id.tag & (LIB_TAG_EXTERN | LIB_TAG_INDIRECT))) { + const bool is_undo = BLO_read_data_is_undo(reader); + if (is_undo || (ob->id.tag & (LIB_TAG_EXTERN | LIB_TAG_INDIRECT))) { ob->mode &= ~(OB_MODE_EDIT | OB_MODE_PARTICLE_EDIT); - if (!reader->fd->memfile) { + if (!is_undo) { ob->mode &= ~OB_MODE_POSE; } } BLO_read_data_address(reader, &ob->adt); - direct_link_animdata(reader, ob->adt); + BKE_animdata_blend_read_data(reader, ob->adt); BLO_read_data_address(reader, &ob->pose); direct_link_pose(reader, ob->pose); @@ -5690,8 +4901,7 @@ static void direct_link_object(BlendDataReader *reader, Object *ob) /* still have to be loaded to be compatible with old files */ BLO_read_pointer_array(reader, (void **)&sb->keys); if (sb->keys) { - int a; - for (a = 0; a < sb->totkey; a++) { + for (int a = 0; a < sb->totkey; a++) { BLO_read_data_address(reader, &sb->keys[a]); } } @@ -5773,14 +4983,11 @@ static void direct_link_object(BlendDataReader *reader, Object *ob) if (ob->sculpt) { ob->sculpt = NULL; /* Only create data on undo, otherwise rely on editor mode switching. */ - if (reader->fd->memfile && (ob->mode & OB_MODE_ALL_SCULPT)) { + if (BLO_read_data_is_undo(reader) && (ob->mode & OB_MODE_ALL_SCULPT)) { BKE_object_sculpt_data_create(ob); } } - BLO_read_list(reader, &ob->lodlevels); - ob->currentlod = ob->lodlevels.first; - ob->preview = direct_link_preview_image(reader, ob->preview); } @@ -5827,7 +5034,7 @@ static void direct_link_view_layer(BlendDataReader *reader, ViewLayer *view_laye BLO_read_data_address(reader, &view_layer->active_collection); BLO_read_data_address(reader, &view_layer->id_properties); - IDP_DirectLinkGroup_OrFree(&view_layer->id_properties, reader); + IDP_BlendDataRead(reader, &view_layer->id_properties); BLO_read_list(reader, &(view_layer->freestyle_config.modules)); BLO_read_list(reader, &(view_layer->freestyle_config.linesets)); @@ -5847,9 +5054,8 @@ static void lib_link_layer_collection(BlendLibReader *reader, BLO_read_id_address(reader, lib, &layer_collection->collection); } - for (LayerCollection *layer_collection_nested = layer_collection->layer_collections.first; - layer_collection_nested != NULL; - layer_collection_nested = layer_collection_nested->next) { + LISTBASE_FOREACH ( + LayerCollection *, layer_collection_nested, &layer_collection->layer_collections) { lib_link_layer_collection(reader, lib, layer_collection_nested, false); } } @@ -5880,15 +5086,13 @@ static void lib_link_view_layer(BlendLibReader *reader, Library *lib, ViewLayer } } - for (LayerCollection *layer_collection = view_layer->layer_collections.first; - layer_collection != NULL; - layer_collection = layer_collection->next) { + LISTBASE_FOREACH (LayerCollection *, layer_collection, &view_layer->layer_collections) { lib_link_layer_collection(reader, lib, layer_collection, true); } BLO_read_id_address(reader, lib, &view_layer->mat_override); - IDP_LibLinkProperty(view_layer->id_properties, reader); + IDP_BlendReadLib(reader, view_layer->id_properties); } /** \} */ @@ -5949,8 +5153,7 @@ static void direct_link_collection(BlendDataReader *reader, Collection *collecti static void lib_link_collection_data(BlendLibReader *reader, Library *lib, Collection *collection) { - for (CollectionObject *cob = collection->gobject.first, *cob_next = NULL; cob; cob = cob_next) { - cob_next = cob->next; + LISTBASE_FOREACH_MUTABLE (CollectionObject *, cob, &collection->gobject) { BLO_read_id_address(reader, lib, &cob->ob); if (cob->ob == NULL) { @@ -5958,7 +5161,7 @@ static void lib_link_collection_data(BlendLibReader *reader, Library *lib, Colle } } - for (CollectionChild *child = collection->children.first; child != NULL; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { BLO_read_id_address(reader, lib, &child->collection); } } @@ -5987,9 +5190,8 @@ static void lib_link_collection(BlendLibReader *reader, Collection *collection) /* patch for missing scene IDs, can't be in do-versions */ static void composite_patch(bNodeTree *ntree, Scene *scene) { - bNode *node; - for (node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->id == NULL && node->type == CMP_NODE_R_LAYERS) { node->id = &scene->id; } @@ -6014,9 +5216,7 @@ static void link_paint(BlendLibReader *reader, Scene *sce, Paint *p) static void lib_link_sequence_modifiers(BlendLibReader *reader, Scene *scene, ListBase *lb) { - SequenceModifierData *smd; - - for (smd = lb->first; smd; smd = smd->next) { + LISTBASE_FOREACH (SequenceModifierData *, smd, lb) { if (smd->mask_id) { BLO_read_id_address(reader, scene->id.lib, &smd->mask_id); } @@ -6068,7 +5268,7 @@ static void direct_link_view3dshading(BlendDataReader *reader, View3DShading *sh { if (shading->prop) { BLO_read_data_address(reader, &shading->prop); - IDP_DirectLinkGroup_OrFree(&shading->prop, reader); + IDP_BlendDataRead(reader, &shading->prop); } } @@ -6167,10 +5367,7 @@ static void lib_link_scene(BlendLibReader *reader, Scene *sce) BLO_read_id_address(reader, sce->id.lib, &sce->toolsettings->gp_sculpt.guide.reference_object); - for (Base *base_legacy_next, *base_legacy = sce->base.first; base_legacy; - base_legacy = base_legacy_next) { - base_legacy_next = base_legacy->next; - + LISTBASE_FOREACH_MUTABLE (Base *, base_legacy, &sce->base) { BLO_read_id_address(reader, sce->id.lib, &base_legacy->object); if (base_legacy->object == NULL) { @@ -6187,8 +5384,8 @@ static void lib_link_scene(BlendLibReader *reader, Scene *sce) } Sequence *seq; - SEQ_BEGIN (sce->ed, seq) { - IDP_LibLinkProperty(seq->prop, reader); + SEQ_ALL_BEGIN (sce->ed, seq) { + IDP_BlendReadLib(reader, seq->prop); if (seq->ipo) { BLO_read_id_address( @@ -6229,7 +5426,7 @@ static void lib_link_scene(BlendLibReader *reader, Scene *sce) lib_link_sequence_modifiers(reader, sce, &seq->modifiers); } - SEQ_END; + SEQ_ALL_END; LISTBASE_FOREACH (TimeMarker *, marker, &sce->markers) { if (marker->camera) { @@ -6293,7 +5490,7 @@ static void lib_link_scenes_check_set(Main *bmain) { #ifdef USE_SETSCENE_CHECK const int totscene = BLI_listbase_count(&bmain->scenes); - for (Scene *sce = bmain->scenes.first; sce; sce = sce->id.next) { + LISTBASE_FOREACH (Scene *, sce, &bmain->scenes) { if (sce->flag & SCE_READFILE_LIBLINK_NEED_SETSCENE_CHECK) { sce->flag &= ~SCE_READFILE_LIBLINK_NEED_SETSCENE_CHECK; if (!scene_validate_setscene__liblink(sce, totscene)) { @@ -6310,11 +5507,9 @@ static void lib_link_scenes_check_set(Main *bmain) static void link_recurs_seq(BlendDataReader *reader, ListBase *lb) { - Sequence *seq; - BLO_read_list(reader, lb); - for (seq = lb->first; seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, lb) { if (seq->seqbase.first) { link_recurs_seq(reader, &seq->seqbase); } @@ -6359,11 +5554,9 @@ static void direct_link_paint_helper(BlendDataReader *reader, const Scene *scene static void direct_link_sequence_modifiers(BlendDataReader *reader, ListBase *lb) { - SequenceModifierData *smd; - BLO_read_list(reader, lb); - for (smd = lb->first; smd; smd = smd->next) { + LISTBASE_FOREACH (SequenceModifierData *, smd, lb) { if (smd->mask_sequence) { BLO_read_data_address(reader, &smd->mask_sequence); } @@ -6383,13 +5576,6 @@ static void direct_link_sequence_modifiers(BlendDataReader *reader, ListBase *lb static void direct_link_scene(BlendDataReader *reader, Scene *sce) { - Editing *ed; - Sequence *seq; - MetaStack *ms; - RigidBodyWorld *rbw; - ViewLayer *view_layer; - SceneRenderLayer *srl; - sce->depsgraph_hash = NULL; sce->fps_info = NULL; @@ -6404,7 +5590,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) BLO_read_list(reader, &(sce->base)); BLO_read_data_address(reader, &sce->adt); - direct_link_animdata(reader, sce->adt); + BKE_animdata_blend_read_data(reader, sce->adt); BLO_read_list(reader, &sce->keyingsets); direct_link_keyingsets(reader, &sce->keyingsets); @@ -6463,7 +5649,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) ListBase *old_seqbasep = &sce->ed->seqbase; BLO_read_data_address(reader, &sce->ed); - ed = sce->ed; + Editing *ed = sce->ed; BLO_read_data_address(reader, &ed->act_seq); ed->cache = NULL; @@ -6472,7 +5658,8 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) /* recursive link sequences, lb will be correctly initialized */ link_recurs_seq(reader, &ed->seqbase); - SEQ_BEGIN (ed, seq) { + Sequence *seq; + SEQ_ALL_BEGIN (ed, seq) { /* Do as early as possible, so that other parts of reading can rely on valid session UUID. */ BKE_sequence_session_uuid_generate(seq); @@ -6503,7 +5690,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) } BLO_read_data_address(reader, &seq->prop); - IDP_DirectLinkGroup_OrFree(&seq->prop, reader); + IDP_BlendDataRead(reader, &seq->prop); BLO_read_data_address(reader, &seq->strip); if (seq->strip && seq->strip->done == 0) { @@ -6535,7 +5722,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) direct_link_sequence_modifiers(reader, &seq->modifiers); } - SEQ_END; + SEQ_ALL_END; /* link metastack, slight abuse of structs here, * have to restore pointer to internal part in struct */ @@ -6565,7 +5752,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) /* stack */ BLO_read_list(reader, &(ed->metastack)); - for (ms = ed->metastack.first; ms; ms = ms->next) { + LISTBASE_FOREACH (MetaStack *, ms, &ed->metastack) { BLO_read_data_address(reader, &ms->parseq); if (ms->oldbasep == old_seqbasep) { @@ -6597,7 +5784,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) } if (sce->r.ffcodecdata.properties) { BLO_read_data_address(reader, &sce->r.ffcodecdata.properties); - IDP_DirectLinkGroup_OrFree(&sce->r.ffcodecdata.properties, reader); + IDP_BlendDataRead(reader, &sce->r.ffcodecdata.properties); } BLO_read_list(reader, &(sce->markers)); @@ -6605,9 +5792,9 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) BLO_read_list(reader, &(sce->r.layers)); BLO_read_list(reader, &(sce->r.views)); - for (srl = sce->r.layers.first; srl; srl = srl->next) { + LISTBASE_FOREACH (SceneRenderLayer *, srl, &sce->r.layers) { BLO_read_data_address(reader, &srl->prop); - IDP_DirectLinkGroup_OrFree(&srl->prop, reader); + IDP_BlendDataRead(reader, &srl->prop); BLO_read_list(reader, &(srl->freestyleConfig.modules)); BLO_read_list(reader, &(srl->freestyleConfig.linesets)); } @@ -6615,7 +5802,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) direct_link_view_settings(reader, &sce->view_settings); BLO_read_data_address(reader, &sce->rigidbody_world); - rbw = sce->rigidbody_world; + RigidBodyWorld *rbw = sce->rigidbody_world; if (rbw) { BLO_read_data_address(reader, &rbw->shared); @@ -6669,11 +5856,11 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) /* insert into global old-new map for reading without UI (link_global accesses it again) */ link_glob_list(reader->fd, &sce->view_layers); - for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &sce->view_layers) { direct_link_view_layer(reader, view_layer); } - if (reader->fd->memfile) { + if (BLO_read_data_is_undo(reader)) { /* If it's undo do nothing here, caches are handled by higher-level generic calling code. */ } else { @@ -6688,7 +5875,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) direct_link_view3dshading(reader, &sce->display.shading); BLO_read_data_address(reader, &sce->layer_properties); - IDP_DirectLinkGroup_OrFree(&sce->layer_properties, reader); + IDP_BlendDataRead(reader, &sce->layer_properties); } /** \} */ @@ -6716,8 +5903,6 @@ static void lib_link_gpencil(BlendLibReader *reader, bGPdata *gpd) /* relinks grease-pencil data - used for direct_link and old file linkage */ static void direct_link_gpencil(BlendDataReader *reader, bGPdata *gpd) { - bGPDpalette *palette; - /* we must firstly have some grease-pencil data to link! */ if (gpd == NULL) { return; @@ -6725,7 +5910,7 @@ static void direct_link_gpencil(BlendDataReader *reader, bGPdata *gpd) /* relink animdata */ BLO_read_data_address(reader, &gpd->adt); - direct_link_animdata(reader, gpd->adt); + BKE_animdata_blend_read_data(reader, gpd->adt); /* Ensure full objectmode for linked grease pencil. */ if (gpd->id.lib != NULL) { @@ -6745,7 +5930,7 @@ static void direct_link_gpencil(BlendDataReader *reader, bGPdata *gpd) /* relink palettes (old palettes deprecated, only to convert old files) */ BLO_read_list(reader, &gpd->palettes); if (gpd->palettes.first != NULL) { - for (palette = gpd->palettes.first; palette; palette = palette->next) { + LISTBASE_FOREACH (Palette *, palette, &gpd->palettes) { BLO_read_list(reader, &palette->colors); } } @@ -6780,7 +5965,7 @@ static void direct_link_gpencil(BlendDataReader *reader, bGPdata *gpd) /* relink weight data */ if (gps->dvert) { BLO_read_data_address(reader, &gps->dvert); - direct_link_dverts(reader, gps->totpoints, gps->dvert); + BKE_defvert_blend_read(reader, gps->totpoints, gps->dvert); } } } @@ -6808,19 +5993,17 @@ static void direct_link_panel_list(BlendDataReader *reader, ListBase *lb) static void direct_link_region(BlendDataReader *reader, ARegion *region, int spacetype) { - uiList *ui_list; - direct_link_panel_list(reader, ®ion->panels); BLO_read_list(reader, ®ion->panels_category_active); BLO_read_list(reader, ®ion->ui_lists); - for (ui_list = region->ui_lists.first; ui_list; ui_list = ui_list->next) { + LISTBASE_FOREACH (uiList *, ui_list, ®ion->ui_lists) { ui_list->type = NULL; ui_list->dyn_data = NULL; BLO_read_data_address(reader, &ui_list->properties); - IDP_DirectLinkGroup_OrFree(&ui_list->properties, reader); + IDP_BlendDataRead(reader, &ui_list->properties); } BLO_read_list(reader, ®ion->ui_previews); @@ -6873,9 +6056,6 @@ static void direct_link_region(BlendDataReader *reader, ARegion *region, int spa static void direct_link_area(BlendDataReader *reader, ScrArea *area) { - SpaceLink *sl; - ARegion *region; - BLO_read_list(reader, &(area->spacedata)); BLO_read_list(reader, &(area->regionbase)); @@ -6900,7 +6080,7 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area) area->spacetype = SPACE_EMPTY; } - for (region = area->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { direct_link_region(reader, region, area->spacetype); } @@ -6916,7 +6096,7 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area) blo_do_versions_view3d_split_250(area->spacedata.first, &area->regionbase); } - for (sl = area->spacedata.first; sl; sl = sl->next) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { BLO_read_list(reader, &(sl->regionbase)); /* if we do not have the spacetype registered we cannot @@ -6925,7 +6105,7 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area) sl->spacetype = SPACE_EMPTY; } - for (region = sl->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &sl->regionbase) { direct_link_region(reader, region, sl->spacetype); } @@ -6980,8 +6160,7 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area) space_outliner->treestore = BLI_mempool_create( sizeof(TreeStoreElem), ts->usedelem, 512, BLI_MEMPOOL_ALLOW_ITER); if (ts->usedelem && elems) { - int i; - for (i = 0; i < ts->usedelem; i++) { + for (int i = 0; i < ts->usedelem; i++) { TreeStoreElem *new_elem = BLI_mempool_alloc(space_outliner->treestore); *new_elem = elems[i]; } @@ -7063,7 +6242,6 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area) } else if (sl->spacetype == SPACE_CONSOLE) { SpaceConsole *sconsole = (SpaceConsole *)sl; - ConsoleLine *cl, *cl_next; BLO_read_list(reader, &sconsole->scrollback); BLO_read_list(reader, &sconsole->history); @@ -7074,8 +6252,7 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area) /* comma expressions, (e.g. expr1, expr2, expr3) evaluate each expression, * from left to right. the right-most expression sets the result of the comma * expression as a whole*/ - for (cl = sconsole->history.first; cl; cl = cl_next) { - cl_next = cl->next; + LISTBASE_FOREACH_MUTABLE (ConsoleLine *, cl, &sconsole->history) { BLO_read_data_address(reader, &cl->line); if (cl->line) { /* the allocted length is not written, so reset here */ @@ -7237,7 +6414,6 @@ static void lib_link_area(BlendLibReader *reader, ID *parent_id, ScrArea *area) } case SPACE_NODE: { SpaceNode *snode = (SpaceNode *)sl; - bNodeTreePath *path, *path_next; /* node tree can be stored locally in id too, link this first */ BLO_read_id_address(reader, parent_id->lib, &snode->id); @@ -7251,6 +6427,7 @@ static void lib_link_area(BlendLibReader *reader, ID *parent_id, ScrArea *area) BLO_read_id_address(reader, parent_id->lib, &snode->nodetree); } + bNodeTreePath *path; for (path = snode->treepath.first; path; path = path->next) { if (path == snode->treepath.first) { /* first nodetree in path is same as snode->nodetree */ @@ -7266,6 +6443,7 @@ static void lib_link_area(BlendLibReader *reader, ID *parent_id, ScrArea *area) } /* remaining path entries are invalid, remove */ + bNodeTreePath *path_next; for (; path; path = path_next) { path_next = path->next; @@ -7348,12 +6526,10 @@ static void lib_link_wm_xr_data(BlendLibReader *reader, ID *parent_id, wmXrData static void direct_link_windowmanager(BlendDataReader *reader, wmWindowManager *wm) { - wmWindow *win; - id_us_ensure_real(&wm->id); BLO_read_list(reader, &wm->windows); - for (win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { BLO_read_data_address(reader, &win->parent); WorkSpaceInstanceHook *hook = win->workspace_hook; @@ -7888,8 +7064,7 @@ void blo_lib_link_restore(Main *oldmain, struct IDNameLib_Map *id_map = BKE_main_idmap_create( newmain, true, oldmain, MAIN_IDMAP_TYPE_NAME); - for (WorkSpace *workspace = newmain->workspaces.first; workspace; - workspace = workspace->id.next) { + LISTBASE_FOREACH (WorkSpace *, workspace, &newmain->workspaces) { LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) { lib_link_workspace_layout_restore(id_map, newmain, layout); } @@ -7944,9 +7119,7 @@ void blo_lib_link_restore(Main *oldmain, /* and as patch for 2.48 and older */ void blo_do_versions_view3d_split_250(View3D *v3d, ListBase *regions) { - ARegion *region; - - for (region = regions->first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, regions) { if (region->regiontype == RGN_TYPE_WINDOW && region->regiondata == NULL) { RegionView3D *rv3d; @@ -8051,10 +7224,9 @@ static void lib_link_library(BlendLibReader *UNUSED(reader), Library *UNUSED(lib * in relation to the blend file. */ static void fix_relpaths_library(const char *basepath, Main *main) { - Library *lib; /* BLO_read_from_memory uses a blank filename */ if (basepath == NULL || basepath[0] == '\0') { - for (lib = main->libraries.first; lib; lib = lib->id.next) { + LISTBASE_FOREACH (Library *, lib, &main->libraries) { /* when loading a linked lib into a file which has not been saved, * there is nothing we can be relative to, so instead we need to make * it absolute. This can happen when appending an object with a relative @@ -8066,7 +7238,7 @@ static void fix_relpaths_library(const char *basepath, Main *main) } } else { - for (lib = main->libraries.first; lib; lib = lib->id.next) { + LISTBASE_FOREACH (Library *, lib, &main->libraries) { /* Libraries store both relative and abs paths, recreate relative paths, * relative to the blend file since indirectly linked libs will be * relative to their direct linked library. */ @@ -8092,7 +7264,7 @@ static void lib_link_lightprobe(BlendLibReader *reader, LightProbe *prb) static void direct_link_lightprobe(BlendDataReader *reader, LightProbe *prb) { BLO_read_data_address(reader, &prb->adt); - direct_link_animdata(reader, prb->adt); + BKE_animdata_blend_read_data(reader, prb->adt); } /** \} */ @@ -8109,7 +7281,7 @@ static void lib_link_speaker(BlendLibReader *reader, Speaker *spk) static void direct_link_speaker(BlendDataReader *reader, Speaker *spk) { BLO_read_data_address(reader, &spk->adt); - direct_link_animdata(reader, spk->adt); + BKE_animdata_blend_read_data(reader, spk->adt); #if 0 spk->sound = newdataadr(fd, spk->sound); @@ -8135,7 +7307,7 @@ static void direct_link_sound(BlendDataReader *reader, bSound *sound) sound->cache = NULL; } - if (reader->fd->memfile != NULL) { + if (BLO_read_data_is_undo(reader)) { sound->tags |= SOUND_TAGS_WAVEFORM_NO_RELOAD; } @@ -8169,26 +7341,20 @@ static void direct_link_movieReconstruction(BlendDataReader *reader, static void direct_link_movieTracks(BlendDataReader *reader, ListBase *tracksbase) { - MovieTrackingTrack *track; - BLO_read_list(reader, tracksbase); - for (track = tracksbase->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { BLO_read_data_address(reader, &track->markers); } } static void direct_link_moviePlaneTracks(BlendDataReader *reader, ListBase *plane_tracks_base) { - MovieTrackingPlaneTrack *plane_track; - BLO_read_list(reader, plane_tracks_base); - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { - int i; - + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { BLO_read_pointer_array(reader, (void **)&plane_track->point_tracks); - for (i = 0; i < plane_track->point_tracksnr; i++) { + for (int i = 0; i < plane_track->point_tracksnr; i++) { BLO_read_data_address(reader, &plane_track->point_tracks[i]); } @@ -8199,7 +7365,6 @@ static void direct_link_moviePlaneTracks(BlendDataReader *reader, ListBase *plan static void direct_link_movieclip(BlendDataReader *reader, MovieClip *clip) { MovieTracking *tracking = &clip->tracking; - MovieTrackingObject *object; BLO_read_data_address(reader, &clip->adt); @@ -8227,7 +7392,7 @@ static void direct_link_movieclip(BlendDataReader *reader, MovieClip *clip) BLO_read_list(reader, &tracking->objects); - for (object = tracking->objects.first; object; object = object->next) { + LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { direct_link_movieTracks(reader, &object->tracks); direct_link_moviePlaneTracks(reader, &object->plane_tracks); direct_link_movieReconstruction(reader, &object->reconstruction); @@ -8236,9 +7401,7 @@ static void direct_link_movieclip(BlendDataReader *reader, MovieClip *clip) static void lib_link_movieTracks(BlendLibReader *reader, MovieClip *clip, ListBase *tracksbase) { - MovieTrackingTrack *track; - - for (track = tracksbase->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { BLO_read_id_address(reader, clip->id.lib, &track->gpd); } } @@ -8247,9 +7410,7 @@ static void lib_link_moviePlaneTracks(BlendLibReader *reader, MovieClip *clip, ListBase *tracksbase) { - MovieTrackingPlaneTrack *plane_track; - - for (plane_track = tracksbase->first; plane_track; plane_track = plane_track->next) { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, tracksbase) { BLO_read_id_address(reader, clip->id.lib, &plane_track->image); } } @@ -8277,28 +7438,22 @@ static void lib_link_movieclip(BlendLibReader *reader, MovieClip *clip) static void direct_link_mask(BlendDataReader *reader, Mask *mask) { - MaskLayer *masklay; - BLO_read_data_address(reader, &mask->adt); BLO_read_list(reader, &mask->masklayers); - for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { - MaskSpline *spline; - MaskLayerShape *masklay_shape; - + LISTBASE_FOREACH (MaskLayer *, masklay, &mask->masklayers) { /* can't use newdataadr since it's a pointer within an array */ MaskSplinePoint *act_point_search = NULL; BLO_read_list(reader, &masklay->splines); - for (spline = masklay->splines.first; spline; spline = spline->next) { + LISTBASE_FOREACH (MaskSpline *, spline, &masklay->splines) { MaskSplinePoint *points_old = spline->points; - int i; BLO_read_data_address(reader, &spline->points); - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; if (point->tot_uw) { @@ -8315,8 +7470,7 @@ static void direct_link_mask(BlendDataReader *reader, Mask *mask) BLO_read_list(reader, &masklay->splines_shapes); - for (masklay_shape = masklay->splines_shapes.first; masklay_shape; - masklay_shape = masklay_shape->next) { + LISTBASE_FOREACH (MaskLayerShape *, masklay_shape, &masklay->splines_shapes) { BLO_read_data_address(reader, &masklay_shape->data); if (masklay_shape->tot_vert) { @@ -8345,9 +7499,7 @@ static void lib_link_mask(BlendLibReader *reader, Mask *mask) spline = masklay->splines.first; while (spline) { - int i; - - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; lib_link_mask_parent(reader, mask, &point->parent); @@ -8368,9 +7520,7 @@ static void lib_link_mask(BlendLibReader *reader, Mask *mask) static void lib_link_linestyle(BlendLibReader *reader, FreestyleLineStyle *linestyle) { - LineStyleModifier *m; - - for (m = linestyle->color_modifiers.first; m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) { switch (m->type) { case LS_MODIFIER_DISTANCE_FROM_OBJECT: { LineStyleColorModifier_DistanceFromObject *cm = @@ -8380,7 +7530,7 @@ static void lib_link_linestyle(BlendLibReader *reader, FreestyleLineStyle *lines } } } - for (m = linestyle->alpha_modifiers.first; m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->alpha_modifiers) { switch (m->type) { case LS_MODIFIER_DISTANCE_FROM_OBJECT: { LineStyleAlphaModifier_DistanceFromObject *am = @@ -8390,7 +7540,7 @@ static void lib_link_linestyle(BlendLibReader *reader, FreestyleLineStyle *lines } } } - for (m = linestyle->thickness_modifiers.first; m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->thickness_modifiers) { switch (m->type) { case LS_MODIFIER_DISTANCE_FROM_OBJECT: { LineStyleThicknessModifier_DistanceFromObject *tm = @@ -8576,28 +7726,25 @@ static void direct_link_linestyle_geometry_modifier(BlendDataReader *UNUSED(read static void direct_link_linestyle(BlendDataReader *reader, FreestyleLineStyle *linestyle) { - int a; - LineStyleModifier *modifier; - BLO_read_data_address(reader, &linestyle->adt); - direct_link_animdata(reader, linestyle->adt); + BKE_animdata_blend_read_data(reader, linestyle->adt); BLO_read_list(reader, &linestyle->color_modifiers); - for (modifier = linestyle->color_modifiers.first; modifier; modifier = modifier->next) { + LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->color_modifiers) { direct_link_linestyle_color_modifier(reader, modifier); } BLO_read_list(reader, &linestyle->alpha_modifiers); - for (modifier = linestyle->alpha_modifiers.first; modifier; modifier = modifier->next) { + LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->alpha_modifiers) { direct_link_linestyle_alpha_modifier(reader, modifier); } BLO_read_list(reader, &linestyle->thickness_modifiers); - for (modifier = linestyle->thickness_modifiers.first; modifier; modifier = modifier->next) { + LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->thickness_modifiers) { direct_link_linestyle_thickness_modifier(reader, modifier); } BLO_read_list(reader, &linestyle->geometry_modifiers); - for (modifier = linestyle->geometry_modifiers.first; modifier; modifier = modifier->next) { + LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->geometry_modifiers) { direct_link_linestyle_geometry_modifier(reader, modifier); } - for (a = 0; a < MAX_MTEX; a++) { + for (int a = 0; a < MAX_MTEX; a++) { BLO_read_data_address(reader, &linestyle->mtex[a]); } } @@ -8618,11 +7765,11 @@ static void lib_link_hair(BlendLibReader *reader, Hair *hair) static void direct_link_hair(BlendDataReader *reader, Hair *hair) { BLO_read_data_address(reader, &hair->adt); - direct_link_animdata(reader, hair->adt); + BKE_animdata_blend_read_data(reader, hair->adt); /* Geometry */ - direct_link_customdata(reader, &hair->pdata, hair->totpoint); - direct_link_customdata(reader, &hair->cdata, hair->totcurve); + CustomData_blend_read(reader, &hair->pdata, hair->totpoint); + CustomData_blend_read(reader, &hair->cdata, hair->totcurve); BKE_hair_update_customdata_pointers(hair); /* Materials */ @@ -8645,10 +7792,10 @@ static void lib_link_pointcloud(BlendLibReader *reader, PointCloud *pointcloud) static void direct_link_pointcloud(BlendDataReader *reader, PointCloud *pointcloud) { BLO_read_data_address(reader, &pointcloud->adt); - direct_link_animdata(reader, pointcloud->adt); + BKE_animdata_blend_read_data(reader, pointcloud->adt); /* Geometry */ - direct_link_customdata(reader, &pointcloud->pdata, pointcloud->totpoint); + CustomData_blend_read(reader, &pointcloud->pdata, pointcloud->totpoint); BKE_pointcloud_update_customdata_pointers(pointcloud); /* Materials */ @@ -8676,7 +7823,7 @@ static void lib_link_volume(BlendLibReader *reader, Volume *volume) static void direct_link_volume(BlendDataReader *reader, Volume *volume) { BLO_read_data_address(reader, &volume->adt); - direct_link_animdata(reader, volume->adt); + BKE_animdata_blend_read_data(reader, volume->adt); volume->packedfile = direct_link_packedfile(reader, volume->packedfile); volume->runtime.frame = 0; @@ -8701,7 +7848,7 @@ static void lib_link_simulation(BlendLibReader *reader, Simulation *simulation) static void direct_link_simulation(BlendDataReader *reader, Simulation *simulation) { BLO_read_data_address(reader, &simulation->adt); - direct_link_animdata(reader, simulation->adt); + BKE_animdata_blend_read_data(reader, simulation->adt); BLO_read_list(reader, &simulation->states); LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { @@ -8709,7 +7856,7 @@ static void direct_link_simulation(BlendDataReader *reader, Simulation *simulati BLO_read_data_address(reader, &state->type); if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_SIMULATION)) { ParticleSimulationState *particle_state = (ParticleSimulationState *)state; - direct_link_customdata(reader, &particle_state->attributes, particle_state->tot_particles); + CustomData_blend_read(reader, &particle_state->attributes, particle_state->tot_particles); } } @@ -8747,7 +7894,7 @@ static void placeholders_ensure_valid(Main *bmain) { /* Placeholder ObData IDs won't have any material, we have to update their objects for that, * otherwise the inconsistency between both will lead to crashes (especially in Eevee?). */ - for (Object *ob = bmain->objects.first; ob != NULL; ob = ob->id.next) { + LISTBASE_FOREACH (Object *, ob, &bmain->objects) { ID *obdata = ob->data; if (obdata != NULL && obdata->tag & LIB_TAG_MISSING) { BKE_object_materials_test(bmain, ob, obdata); @@ -8856,6 +8003,9 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * } const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id); + if (id_type->blend_read_data != NULL) { + id_type->blend_read_data(&reader, id); + } /* XXX Very weakly handled currently, see comment in read_libblock() before trying to * use it for anything new. */ @@ -8874,9 +8024,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_OB: direct_link_object(&reader, (Object *)id); break; - case ID_ME: - direct_link_mesh(&reader, (Mesh *)id); - break; case ID_CU: direct_link_curve(&reader, (Curve *)id); break; @@ -8907,9 +8054,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_KE: direct_link_key(&reader, (Key *)id); break; - case ID_LT: - direct_link_latt(&reader, (Lattice *)id); - break; case ID_WO: direct_link_world(&reader, (World *)id); break; @@ -8982,6 +8126,10 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_SIM: direct_link_simulation(&reader, (Simulation *)id); break; + case ID_ME: + case ID_LT: + /* Do nothing. Handled by IDTypeInfo callback. */ + break; } /* try to restore (when undoing) or clear ID's cache pointers. */ @@ -9458,11 +8606,9 @@ static void do_versions_userdef(FileData *fd, BlendFileData *bfd) } if (MAIN_VERSION_OLDER(bmain, 266, 4)) { - bTheme *btheme; - /* Themes for Node and Sequence editor were not using grid color, * but back. we copy this over then. */ - for (btheme = user->themes.first; btheme; btheme = btheme->next) { + LISTBASE_FOREACH (bTheme *, btheme, &user->themes) { copy_v4_v4_uchar(btheme->space_node.grid, btheme->space_node.back); copy_v4_v4_uchar(btheme->space_sequencer.grid, btheme->space_sequencer.back); } @@ -9577,6 +8723,11 @@ static void lib_link_all(FileData *fd, Main *bmain) lib_link_id(&reader, id); + const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id); + if (id_type->blend_read_lib != NULL) { + id_type->blend_read_lib(&reader, id); + } + /* Note: ID types are processed in reverse order as defined by INDEX_ID_XXX enums in DNA_ID.h. * This ensures handling of most dependencies in proper order, as elsewhere in code. * Please keep order of entries in that switch matching that order, it's easier to quickly see @@ -9642,18 +8793,12 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_LA: lib_link_light(&reader, (Light *)id); break; - case ID_LT: - lib_link_latt(&reader, (Lattice *)id); - break; case ID_MB: lib_link_mball(&reader, (MetaBall *)id); break; case ID_CU: lib_link_curve(&reader, (Curve *)id); break; - case ID_ME: - lib_link_mesh(&reader, (Mesh *)id); - break; case ID_CF: lib_link_cachefiles(&reader, (CacheFile *)id); break; @@ -9707,6 +8852,10 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_LI: lib_link_library(&reader, (Library *)id); /* Only init users. */ break; + case ID_ME: + case ID_LT: + /* Do nothing. Handled by IDTypeInfo callback. */ + break; } id->tag &= ~LIB_TAG_NEED_LINK; @@ -9743,7 +8892,7 @@ static void lib_link_all(FileData *fd, Main *bmain) static void direct_link_keymapitem(BlendDataReader *reader, wmKeyMapItem *kmi) { BLO_read_data_address(reader, &kmi->properties); - IDP_DirectLinkGroup_OrFree(&kmi->properties, reader); + IDP_BlendDataRead(reader, &kmi->properties); kmi->ptr = NULL; kmi->flag &= ~KMI_UPDATE; } @@ -9751,11 +8900,6 @@ static void direct_link_keymapitem(BlendDataReader *reader, wmKeyMapItem *kmi) static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead) { UserDef *user; - wmKeyMap *keymap; - wmKeyMapItem *kmi; - wmKeyMapDiffItem *kmdi; - bAddon *addon; - bfd->user = user = read_struct(fd, bhead, "user def"); /* User struct has separate do-version handling */ @@ -9775,7 +8919,7 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead) BLO_read_list(reader, &user->addons); BLO_read_list(reader, &user->autoexec_paths); - for (keymap = user->user_keymaps.first; keymap; keymap = keymap->next) { + LISTBASE_FOREACH (wmKeyMap *, keymap, &user->user_keymaps) { keymap->modal_items = NULL; keymap->poll = NULL; keymap->flag &= ~KEYMAP_UPDATE; @@ -9783,7 +8927,7 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead) BLO_read_list(reader, &keymap->diff_items); BLO_read_list(reader, &keymap->items); - for (kmdi = keymap->diff_items.first; kmdi; kmdi = kmdi->next) { + LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &keymap->diff_items) { BLO_read_data_address(reader, &kmdi->remove_item); BLO_read_data_address(reader, &kmdi->add_item); @@ -9795,14 +8939,14 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead) } } - for (kmi = keymap->items.first; kmi; kmi = kmi->next) { + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) { direct_link_keymapitem(reader, kmi); } } LISTBASE_FOREACH (wmKeyConfigPref *, kpt, &user->user_keyconfig_prefs) { BLO_read_data_address(reader, &kpt->prop); - IDP_DirectLinkGroup_OrFree(&kpt->prop, reader); + IDP_BlendDataRead(reader, &kpt->prop); } LISTBASE_FOREACH (bUserMenu *, um, &user->user_menus) { @@ -9811,14 +8955,14 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead) if (umi->type == USER_MENU_TYPE_OPERATOR) { bUserMenuItem_Op *umi_op = (bUserMenuItem_Op *)umi; BLO_read_data_address(reader, &umi_op->prop); - IDP_DirectLinkGroup_OrFree(&umi_op->prop, reader); + IDP_BlendDataRead(reader, &umi_op->prop); } } } - for (addon = user->addons.first; addon; addon = addon->next) { + LISTBASE_FOREACH (bAddon *, addon, &user->addons) { BLO_read_data_address(reader, &addon->prop); - IDP_DirectLinkGroup_OrFree(&addon->prop, reader); + IDP_BlendDataRead(reader, &addon->prop); } // XXX @@ -10277,8 +9421,7 @@ static BLOExpandDoitCallback expand_doit; // XXX deprecated - old animation system static void expand_ipo(BlendExpander *expander, Ipo *ipo) { - IpoCurve *icu; - for (icu = ipo->curve.first; icu; icu = icu->next) { + LISTBASE_FOREACH (IpoCurve *, icu, &ipo->curve) { if (icu->driver) { BLO_expand(expander, icu->driver->ob); } @@ -10288,115 +9431,11 @@ static void expand_ipo(BlendExpander *expander, Ipo *ipo) // XXX deprecated - old animation system static void expand_constraint_channels(BlendExpander *expander, ListBase *chanbase) { - bConstraintChannel *chan; - for (chan = chanbase->first; chan; chan = chan->next) { + LISTBASE_FOREACH (bConstraintChannel *, chan, chanbase) { BLO_expand(expander, chan->ipo); } } -static void expand_fmodifiers(BlendExpander *expander, ListBase *list) -{ - FModifier *fcm; - - for (fcm = list->first; fcm; fcm = fcm->next) { - /* library data for specific F-Modifier types */ - switch (fcm->type) { - case FMODIFIER_TYPE_PYTHON: { - FMod_Python *data = (FMod_Python *)fcm->data; - - BLO_expand(expander, data->script); - - break; - } - } - } -} - -static void expand_fcurves(BlendExpander *expander, ListBase *list) -{ - FCurve *fcu; - - for (fcu = list->first; fcu; fcu = fcu->next) { - /* Driver targets if there is a driver */ - if (fcu->driver) { - ChannelDriver *driver = fcu->driver; - DriverVar *dvar; - - for (dvar = driver->variables.first; dvar; dvar = dvar->next) { - DRIVER_TARGETS_LOOPER_BEGIN (dvar) { - // TODO: only expand those that are going to get used? - BLO_expand(expander, dtar->id); - } - DRIVER_TARGETS_LOOPER_END; - } - } - - /* F-Curve Modifiers */ - expand_fmodifiers(expander, &fcu->modifiers); - } -} - -static void expand_animdata_nlastrips(BlendExpander *expander, ListBase *list) -{ - NlaStrip *strip; - - for (strip = list->first; strip; strip = strip->next) { - /* check child strips */ - expand_animdata_nlastrips(expander, &strip->strips); - - /* check F-Curves */ - expand_fcurves(expander, &strip->fcurves); - - /* check F-Modifiers */ - expand_fmodifiers(expander, &strip->modifiers); - - /* relink referenced action */ - BLO_expand(expander, strip->act); - } -} - -static void expand_animdata(BlendExpander *expander, AnimData *adt) -{ - NlaTrack *nlt; - - /* 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... */ - expand_fcurves(expander, &adt->drivers); - - /* nla-data - referenced actions */ - for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { - expand_animdata_nlastrips(expander, &nlt->strips); - } -} - -static void expand_idprops(BlendExpander *expander, IDProperty *prop) -{ - if (!prop) { - return; - } - - switch (prop->type) { - case IDP_ID: - BLO_expand(expander, IDP_Id(prop)); - break; - case IDP_IDPARRAY: { - IDProperty *idp_array = IDP_IDPArray(prop); - for (int i = 0; i < prop->len; i++) { - expand_idprops(expander, &idp_array[i]); - } - break; - } - case IDP_GROUP: - LISTBASE_FOREACH (IDProperty *, loop, &prop->data.group) { - expand_idprops(expander, loop); - } - break; - } -} - static void expand_id(BlendExpander *expander, ID *id); static void expand_nodetree(BlendExpander *expander, bNodeTree *ntree); static void expand_collection(BlendExpander *expander, Collection *collection); @@ -10421,7 +9460,7 @@ static void expand_id_embedded_id(BlendExpander *expander, ID *id) static void expand_id(BlendExpander *expander, ID *id) { - expand_idprops(expander, id->properties); + IDP_BlendReadExpand(expander, id->properties); if (id->override_library) { BLO_expand(expander, id->override_library->reference); @@ -10430,7 +9469,7 @@ static void expand_id(BlendExpander *expander, ID *id) AnimData *adt = BKE_animdata_from_id(id); if (adt != NULL) { - expand_animdata(expander, adt); + BKE_animdata_blend_read_expand(expander, adt); } expand_id_embedded_id(expander, id); @@ -10438,17 +9477,15 @@ static void expand_id(BlendExpander *expander, ID *id) static void expand_action(BlendExpander *expander, bAction *act) { - bActionChannel *chan; - // XXX deprecated - old animation system -------------- - for (chan = act->chanbase.first; chan; chan = chan->next) { + LISTBASE_FOREACH (bActionChannel *, chan, &act->chanbase) { BLO_expand(expander, chan->ipo); expand_constraint_channels(expander, &chan->constraintChannels); } // --------------------------------------------------- /* F-Curves in Action */ - expand_fcurves(expander, &act->curves); + BKE_fcurve_blend_read_expand(expander, &act->curves); LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { if (marker->camera) { @@ -10459,12 +9496,9 @@ static void expand_action(BlendExpander *expander, bAction *act) static void expand_keyingsets(BlendExpander *expander, ListBase *list) { - KeyingSet *ks; - KS_Path *ksp; - /* expand the ID-pointers in KeyingSets's paths */ - for (ks = list->first; ks; ks = ks->next) { - for (ksp = ks->paths.first; ksp; ksp = ksp->next) { + LISTBASE_FOREACH (KeyingSet *, ks, list) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { BLO_expand(expander, ksp->id); } } @@ -10472,15 +9506,13 @@ static void expand_keyingsets(BlendExpander *expander, ListBase *list) static void expand_particlesettings(BlendExpander *expander, ParticleSettings *part) { - int a; - BLO_expand(expander, part->instance_object); BLO_expand(expander, part->instance_collection); BLO_expand(expander, part->force_group); BLO_expand(expander, part->bb_ob); BLO_expand(expander, part->collision_group); - for (a = 0; a < MAX_MTEX; a++) { + for (int a = 0; a < MAX_MTEX; a++) { if (part->mtex[a]) { BLO_expand(expander, part->mtex[a]->tex); BLO_expand(expander, part->mtex[a]->object); @@ -10501,11 +9533,8 @@ static void expand_particlesettings(BlendExpander *expander, ParticleSettings *p } if (part->boids) { - BoidState *state; - BoidRule *rule; - - for (state = part->boids->states.first; state; state = state->next) { - for (rule = state->rules.first; rule; rule = rule->next) { + LISTBASE_FOREACH (BoidState *, state, &part->boids->states) { + LISTBASE_FOREACH (BoidRule *, rule, &state->rules) { if (rule->type == eBoidRuleType_Avoid) { BoidRuleGoalAvoid *gabr = (BoidRuleGoalAvoid *)rule; BLO_expand(expander, gabr->ob); @@ -10547,7 +9576,7 @@ static void expand_key(BlendExpander *expander, Key *key) static void expand_node_socket(BlendExpander *expander, bNodeSocket *sock) { - expand_idprops(expander, sock->prop); + IDP_BlendReadExpand(expander, sock->prop); if (sock->default_value != NULL) { @@ -10589,18 +9618,16 @@ static void expand_node_sockets(BlendExpander *expander, ListBase *sockets) static void expand_nodetree(BlendExpander *expander, bNodeTree *ntree) { - bNode *node; - if (ntree->gpd) { BLO_expand(expander, ntree->gpd); } - for (node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->id && node->type != CMP_NODE_R_LAYERS) { BLO_expand(expander, node->id); } - expand_idprops(expander, node->prop); + IDP_BlendReadExpand(expander, node->prop); expand_node_sockets(expander, &node->inputs); expand_node_sockets(expander, &node->outputs); @@ -10643,12 +9670,6 @@ static void expand_light(BlendExpander *expander, Light *la) BLO_expand(expander, la->ipo); // XXX deprecated - old animation system } -static void expand_lattice(BlendExpander *expander, Lattice *lt) -{ - BLO_expand(expander, lt->ipo); // XXX deprecated - old animation system - BLO_expand(expander, lt->key); -} - static void expand_world(BlendExpander *expander, World *wrld) { BLO_expand(expander, wrld->ipo); // XXX deprecated - old animation system @@ -10656,18 +9677,14 @@ static void expand_world(BlendExpander *expander, World *wrld) static void expand_mball(BlendExpander *expander, MetaBall *mb) { - int a; - - for (a = 0; a < mb->totcol; a++) { + for (int a = 0; a < mb->totcol; a++) { BLO_expand(expander, mb->mat[a]); } } static void expand_curve(BlendExpander *expander, Curve *cu) { - int a; - - for (a = 0; a < cu->totcol; a++) { + for (int a = 0; a < cu->totcol; a++) { BLO_expand(expander, cu->mat[a]); } @@ -10682,18 +9699,6 @@ static void expand_curve(BlendExpander *expander, Curve *cu) BLO_expand(expander, cu->textoncurve); } -static void expand_mesh(BlendExpander *expander, Mesh *me) -{ - int a; - - for (a = 0; a < me->totcol; a++) { - BLO_expand(expander, me->mat[a]); - } - - BLO_expand(expander, me->key); - BLO_expand(expander, me->texcomesh); -} - /* callback function used to expand constraint ID-links */ static void expand_constraint_cb(bConstraint *UNUSED(con), ID **idpoin, @@ -10706,12 +9711,10 @@ static void expand_constraint_cb(bConstraint *UNUSED(con), static void expand_constraints(BlendExpander *expander, ListBase *lb) { - bConstraint *curcon; - BKE_constraints_id_loop(lb, expand_constraint_cb, expander); /* deprecated manual expansion stuff */ - for (curcon = lb->first; curcon; curcon = curcon->next) { + LISTBASE_FOREACH (bConstraint *, curcon, lb) { if (curcon->ipo) { BLO_expand(expander, curcon->ipo); // XXX deprecated - old animation system } @@ -10720,22 +9723,20 @@ static void expand_constraints(BlendExpander *expander, ListBase *lb) static void expand_pose(BlendExpander *expander, bPose *pose) { - bPoseChannel *chan; - if (!pose) { return; } - for (chan = pose->chanbase.first; chan; chan = chan->next) { + LISTBASE_FOREACH (bPoseChannel *, chan, &pose->chanbase) { expand_constraints(expander, &chan->constraints); - expand_idprops(expander, chan->prop); + IDP_BlendReadExpand(expander, chan->prop); BLO_expand(expander, chan->custom); } } static void expand_bones(BlendExpander *expander, Bone *bone) { - expand_idprops(expander, bone->prop); + IDP_BlendReadExpand(expander, bone->prop); LISTBASE_FOREACH (Bone *, curBone, &bone->childbase) { expand_bones(expander, curBone); @@ -10760,11 +9761,6 @@ static void expand_object_expandModifiers(void *userData, static void expand_object(BlendExpander *expander, Object *ob) { - ParticleSystem *psys; - bActionStrip *strip; - PartEff *paf; - int a; - BLO_expand(expander, ob->data); /* expand_object_expandModifier() */ @@ -10794,18 +9790,18 @@ static void expand_object(BlendExpander *expander, Object *ob) expand_constraint_channels(expander, &ob->constraintChannels); - for (strip = ob->nlastrips.first; strip; strip = strip->next) { + LISTBASE_FOREACH (bActionStrip *, strip, &ob->nlastrips) { BLO_expand(expander, strip->object); BLO_expand(expander, strip->act); BLO_expand(expander, strip->ipo); } // XXX deprecated - old animation system (for version patching only) - for (a = 0; a < ob->totcol; a++) { + for (int a = 0; a < ob->totcol; a++) { BLO_expand(expander, ob->mat[a]); } - paf = blo_do_version_give_parteff_245(ob); + PartEff *paf = blo_do_version_give_parteff_245(ob); if (paf && paf->group) { BLO_expand(expander, paf->group); } @@ -10821,7 +9817,7 @@ static void expand_object(BlendExpander *expander, Object *ob) BLO_expand(expander, ob->proxy_group); } - for (psys = ob->particlesystem.first; psys; psys = psys->next) { + LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { BLO_expand(expander, psys->part); } @@ -10842,13 +9838,6 @@ static void expand_object(BlendExpander *expander, Object *ob) BLO_expand(expander, ob->rigidbody_constraint->ob1); BLO_expand(expander, ob->rigidbody_constraint->ob2); } - - if (ob->currentlod) { - LodLevel *level; - for (level = ob->lodlevels.first; level; level = level->next) { - BLO_expand(expander, level->source); - } - } } #ifdef USE_COLLECTION_COMPAT_28 @@ -10866,10 +9855,6 @@ static void expand_scene_collection(BlendExpander *expander, SceneCollection *sc static void expand_scene(BlendExpander *expander, Scene *sce) { - SceneRenderLayer *srl; - FreestyleModuleConfig *module; - FreestyleLineSet *lineset; - LISTBASE_FOREACH (Base *, base_legacy, &sce->base) { BLO_expand(expander, base_legacy->object); } @@ -10882,14 +9867,14 @@ static void expand_scene(BlendExpander *expander, Scene *sce) BLO_expand(expander, sce->set); } - for (srl = sce->r.layers.first; srl; srl = srl->next) { + LISTBASE_FOREACH (SceneRenderLayer *, srl, &sce->r.layers) { BLO_expand(expander, srl->mat_override); - for (module = srl->freestyleConfig.modules.first; module; module = module->next) { + LISTBASE_FOREACH (FreestyleModuleConfig *, module, &srl->freestyleConfig.modules) { if (module->script) { BLO_expand(expander, module->script); } } - for (lineset = srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) { + LISTBASE_FOREACH (FreestyleLineSet *, lineset, &srl->freestyleConfig.linesets) { if (lineset->group) { BLO_expand(expander, lineset->group); } @@ -10898,15 +9883,15 @@ static void expand_scene(BlendExpander *expander, Scene *sce) } LISTBASE_FOREACH (ViewLayer *, view_layer, &sce->view_layers) { - expand_idprops(expander, view_layer->id_properties); + IDP_BlendReadExpand(expander, view_layer->id_properties); - for (module = view_layer->freestyle_config.modules.first; module; module = module->next) { + LISTBASE_FOREACH (FreestyleModuleConfig *, module, &view_layer->freestyle_config.modules) { if (module->script) { BLO_expand(expander, module->script); } } - for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) { + LISTBASE_FOREACH (FreestyleLineSet *, lineset, &view_layer->freestyle_config.linesets) { if (lineset->group) { BLO_expand(expander, lineset->group); } @@ -10921,8 +9906,8 @@ static void expand_scene(BlendExpander *expander, Scene *sce) if (sce->ed) { Sequence *seq; - SEQ_BEGIN (sce->ed, seq) { - expand_idprops(expander, seq->prop); + SEQ_ALL_BEGIN (sce->ed, seq) { + IDP_BlendReadExpand(expander, seq->prop); if (seq->scene) { BLO_expand(expander, seq->scene); @@ -10945,7 +9930,7 @@ static void expand_scene(BlendExpander *expander, Scene *sce) BLO_expand(expander, data->text_font); } } - SEQ_END; + SEQ_ALL_END; } if (sce->rigidbody_world) { @@ -11017,17 +10002,10 @@ static void expand_mask_parent(BlendExpander *expander, MaskParent *parent) static void expand_mask(BlendExpander *expander, Mask *mask) { - MaskLayer *mask_layer; - - for (mask_layer = mask->masklayers.first; mask_layer; mask_layer = mask_layer->next) { - MaskSpline *spline; - - for (spline = mask_layer->splines.first; spline; spline = spline->next) { - int i; - - for (i = 0; i < spline->tot_point; i++) { + LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) { + LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; - expand_mask_parent(expander, &point->parent); } @@ -11038,27 +10016,24 @@ static void expand_mask(BlendExpander *expander, Mask *mask) static void expand_linestyle(BlendExpander *expander, FreestyleLineStyle *linestyle) { - int a; - LineStyleModifier *m; - - for (a = 0; a < MAX_MTEX; a++) { + for (int a = 0; a < MAX_MTEX; a++) { if (linestyle->mtex[a]) { BLO_expand(expander, linestyle->mtex[a]->tex); BLO_expand(expander, linestyle->mtex[a]->object); } } - for (m = linestyle->color_modifiers.first; m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) { if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { BLO_expand(expander, ((LineStyleColorModifier_DistanceFromObject *)m)->target); } } - for (m = linestyle->alpha_modifiers.first; m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->alpha_modifiers) { if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { BLO_expand(expander, ((LineStyleAlphaModifier_DistanceFromObject *)m)->target); } } - for (m = linestyle->thickness_modifiers.first; m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->thickness_modifiers) { if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { BLO_expand(expander, ((LineStyleThicknessModifier_DistanceFromObject *)m)->target); } @@ -11088,10 +10063,6 @@ static void expand_hair(BlendExpander *expander, Hair *hair) for (int a = 0; a < hair->totcol; a++) { BLO_expand(expander, hair->mat[a]); } - - if (hair->adt) { - expand_animdata(expander, hair->adt); - } } static void expand_pointcloud(BlendExpander *expander, PointCloud *pointcloud) @@ -11099,10 +10070,6 @@ static void expand_pointcloud(BlendExpander *expander, PointCloud *pointcloud) for (int a = 0; a < pointcloud->totcol; a++) { BLO_expand(expander, pointcloud->mat[a]); } - - if (pointcloud->adt) { - expand_animdata(expander, pointcloud->adt); - } } static void expand_volume(BlendExpander *expander, Volume *volume) @@ -11110,17 +10077,10 @@ static void expand_volume(BlendExpander *expander, Volume *volume) for (int a = 0; a < volume->totcol; a++) { BLO_expand(expander, volume->mat[a]); } - - if (volume->adt) { - expand_animdata(expander, volume->adt); - } } static void expand_simulation(BlendExpander *expander, Simulation *simulation) { - if (simulation->adt) { - expand_animdata(expander, simulation->adt); - } LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) { BLO_expand(expander, dependency->id); } @@ -11163,13 +10123,15 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) if (id->tag & LIB_TAG_NEED_EXPAND) { expand_id(&expander, id); + const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id); + if (id_type->blend_read_expand != NULL) { + id_type->blend_read_expand(&expander, id); + } + switch (GS(id->name)) { case ID_OB: expand_object(&expander, (Object *)id); break; - case ID_ME: - expand_mesh(&expander, (Mesh *)id); - break; case ID_CU: expand_curve(&expander, (Curve *)id); break; @@ -11188,9 +10150,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) case ID_WO: expand_world(&expander, (World *)id); break; - case ID_LT: - expand_lattice(&expander, (Lattice *)id); - break; case ID_LA: expand_light(&expander, (Light *)id); break; @@ -11281,9 +10240,7 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) static bool object_in_any_scene(Main *bmain, Object *ob) { - Scene *sce; - - for (sce = bmain->scenes.first; sce; sce = sce->id.next) { + LISTBASE_FOREACH (Scene *, sce, &bmain->scenes) { if (BKE_scene_object_find(sce, ob)) { return true; } @@ -11294,9 +10251,7 @@ static bool object_in_any_scene(Main *bmain, Object *ob) static bool object_in_any_collection(Main *bmain, Object *ob) { - Collection *collection; - - for (collection = bmain->collections.first; collection; collection = collection->id.next) { + LISTBASE_FOREACH (Collection *, collection, &bmain->collections) { if (BKE_collection_has_object(collection, ob)) { return true; } @@ -11320,7 +10275,7 @@ static void add_loose_objects_to_scene(Main *mainvar, /* Give all objects which are LIB_TAG_INDIRECT a base, * or for a collection when *lib has been set. */ - for (Object *ob = mainvar->objects.first; ob; ob = ob->id.next) { + LISTBASE_FOREACH (Object *, ob, &mainvar->objects) { bool do_it = (ob->id.tag & LIB_TAG_DOIT) != 0; if (do_it || ((ob->id.tag & LIB_TAG_INDIRECT) && (ob->id.tag & LIB_TAG_PRE_EXISTING) == 0)) { if (do_append) { @@ -11387,8 +10342,7 @@ static void add_collections_to_scene(Main *mainvar, } /* Give all objects which are tagged a base. */ - for (Collection *collection = mainvar->collections.first; collection; - collection = collection->id.next) { + LISTBASE_FOREACH (Collection *, collection, &mainvar->collections) { if ((flag & FILE_GROUP_INSTANCE) && (collection->id.tag & LIB_TAG_DOIT)) { /* Any indirect collection should not have been tagged. */ BLI_assert((collection->id.tag & LIB_TAG_INDIRECT) == 0); @@ -11431,8 +10385,7 @@ static void add_collections_to_scene(Main *mainvar, * Note that we only check object directly into that collection, * not recursively into its children. */ - for (CollectionObject *coll_ob = collection->gobject.first; coll_ob != NULL; - coll_ob = coll_ob->next) { + LISTBASE_FOREACH (CollectionObject *, coll_ob, &collection->gobject) { Object *ob = coll_ob->ob; if ((ob->id.tag & (LIB_TAG_PRE_EXISTING | LIB_TAG_DOIT | LIB_TAG_INDIRECT)) == 0 && (ob->id.lib == lib) && (object_in_any_scene(bmain, ob) == 0)) { @@ -11446,8 +10399,7 @@ static void add_collections_to_scene(Main *mainvar, BKE_collection_child_add(bmain, active_collection, collection); if (flag & FILE_AUTOSELECT) { - for (CollectionObject *coll_ob = collection->gobject.first; coll_ob != NULL; - coll_ob = coll_ob->next) { + LISTBASE_FOREACH (CollectionObject *, coll_ob, &collection->gobject) { Object *ob = coll_ob->ob; Base *base = BKE_view_layer_base_find(view_layer, ob); if (base) { @@ -11673,9 +10625,7 @@ static void split_main_newid(Main *mainptr, Main *main_newid) while (i--) { BLI_listbase_clear(lbarray_newid[i]); - for (ID *id = lbarray[i]->first, *idnext; id; id = idnext) { - idnext = id->next; - + LISTBASE_FOREACH_MUTABLE (ID *, id, lbarray[i]) { if (id->tag & LIB_TAG_NEW) { BLI_remlink(lbarray[i], id); BLI_addtail(lbarray_newid[i], id); @@ -12121,8 +11071,8 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) } /* Note: No need to call #do_versions_after_linking() or #BKE_main_id_refcount_recompute() - * here, as this function is only called for library 'subset' data handling, as part of either - * full blendfile reading (#blo_read_file_internal()), or library-data linking + * here, as this function is only called for library 'subset' data handling, as part of + * either full blendfile reading (#blo_read_file_internal()), or library-data linking * (#library_link_end()). */ /* Free file data we no longer need. */ @@ -12139,6 +11089,11 @@ void *BLO_read_get_new_data_address(BlendDataReader *reader, const void *old_add return newdataadr(reader->fd, old_address); } +void *BLO_read_get_new_packed_address(BlendDataReader *reader, const void *old_address) +{ + return newpackedadr(reader->fd, old_address); +} + ID *BLO_read_get_new_id_address(BlendLibReader *reader, Library *lib, ID *id) { return newlibadr(reader->fd, lib, id); @@ -12294,6 +11249,16 @@ void BLO_read_pointer_array(BlendDataReader *reader, void **ptr_p) *ptr_p = final_array; } +bool BLO_read_data_is_undo(BlendDataReader *reader) +{ + return reader->fd->memfile != NULL; +} + +bool BLO_read_lib_is_undo(BlendLibReader *reader) +{ + return reader->fd->memfile != NULL; +} + void BLO_expand_id(BlendExpander *expander, ID *id) { expand_doit(expander->fd, expander->main, id); diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 0e753c84476..dad86f80813 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -666,7 +666,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) for (scene = bmain->scenes.first; scene; scene = scene->id.next) { if (scene->ed && scene->ed->seqbasep) { - SEQ_BEGIN (scene->ed, seq) { + SEQ_ALL_BEGIN (scene->ed, seq) { if (seq->type == SEQ_TYPE_SOUND_HD) { char str[FILE_MAX]; BLI_join_dirfile(str, sizeof(str), seq->strip->dir, seq->strip->stripdata->name); @@ -682,7 +682,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) #undef SEQ_USE_PROXY_CUSTOM_DIR #undef SEQ_USE_PROXY_CUSTOM_FILE } - SEQ_END; + SEQ_ALL_END; } } @@ -1409,10 +1409,10 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) sce->r.ffcodecdata.audio_codec = 0x0; // CODEC_ID_NONE } - SEQ_BEGIN (sce->ed, seq) { + SEQ_ALL_BEGIN (sce->ed, seq) { seq->volume = 1.0f; } - SEQ_END; + SEQ_ALL_END; } /* particle brush strength factor was changed from int to float */ @@ -1681,12 +1681,12 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) for (scene = bmain->scenes.first; scene; scene = scene->id.next) { Sequence *seq; - SEQ_BEGIN (scene->ed, seq) { + SEQ_ALL_BEGIN (scene->ed, seq) { if (seq->sat == 0.0f) { seq->sat = 1.0f; } } - SEQ_END; + SEQ_ALL_END; } /* GSOC 2010 Sculpt - New settings for Brush */ @@ -2166,10 +2166,10 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) for (scene = bmain->scenes.first; scene; scene = scene->id.next) { scene->r.ffcodecdata.audio_channels = 2; scene->audio.volume = 1.0f; - SEQ_BEGIN (scene->ed, seq) { + SEQ_ALL_BEGIN (scene->ed, seq) { seq->pitch = 1.0f; } - SEQ_END; + SEQ_ALL_END; } } diff --git a/source/blender/blenloader/intern/versioning_260.c b/source/blender/blenloader/intern/versioning_260.c index 1ac90398c0a..dec5c8d495a 100644 --- a/source/blender/blenloader/intern/versioning_260.c +++ b/source/blender/blenloader/intern/versioning_260.c @@ -1489,7 +1489,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) if (scene->ed) { Sequence *seq; - SEQ_BEGIN (scene->ed, seq) { + SEQ_ALL_BEGIN (scene->ed, seq) { Strip *strip = seq->strip; if (strip && strip->color_balance) { @@ -1512,7 +1512,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) strip->color_balance = NULL; } } - SEQ_END; + SEQ_ALL_END; } } } @@ -1804,7 +1804,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) for (scene = bmain->scenes.first; scene; scene = scene->id.next) { Sequence *seq; - SEQ_BEGIN (scene->ed, seq) { + SEQ_ALL_BEGIN (scene->ed, seq) { enum { SEQ_MAKE_PREMUL = (1 << 6) }; if (seq->flag & SEQ_MAKE_PREMUL) { seq->alpha_mode = SEQ_ALPHA_STRAIGHT; @@ -1813,7 +1813,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) BKE_sequence_alpha_mode_from_extension(seq); } } - SEQ_END; + SEQ_ALL_END; if (scene->r.bake_samples == 0) { scene->r.bake_samples = 256; @@ -2447,13 +2447,13 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) for (scene = bmain->scenes.first; scene; scene = scene->id.next) { Sequence *seq; - SEQ_BEGIN (scene->ed, seq) { + SEQ_ALL_BEGIN (scene->ed, seq) { if (seq->type == SEQ_TYPE_WIPE) { WipeVars *wv = seq->effectdata; wv->angle = DEG2RADF(wv->angle); } } - SEQ_END; + SEQ_ALL_END; } FOREACH_NODETREE_BEGIN (bmain, ntree, id) { diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index b19c6221391..2452ac43bd4 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -891,17 +891,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) } } } - - /* hysteresis set to 10% but not activated */ - if (!DNA_struct_elem_find(fd->filesdna, "LodLevel", "int", "obhysteresis")) { - Object *ob; - for (ob = bmain->objects.first; ob; ob = ob->id.next) { - LodLevel *level; - for (level = ob->lodlevels.first; level; level = level->next) { - level->obhysteresis = 10; - } - } - } } if (!MAIN_VERSION_ATLEAST(bmain, 274, 4)) { @@ -924,7 +913,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) srv = scene->r.views.last; BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix)); - SEQ_BEGIN (scene->ed, seq) { + SEQ_ALL_BEGIN (scene->ed, seq) { seq->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format"); #define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19) @@ -940,7 +929,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) #undef SEQ_USE_PROXY_CUSTOM_DIR #undef SEQ_USE_PROXY_CUSTOM_FILE } - SEQ_END; + SEQ_ALL_END; } for (screen = bmain->screens.first; screen; screen = screen->id.next) { @@ -1225,7 +1214,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { Sequence *seq; - SEQ_BEGIN (scene->ed, seq) { + SEQ_ALL_BEGIN (scene->ed, seq) { if (seq->type != SEQ_TYPE_TEXT) { continue; } @@ -1241,7 +1230,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) data->shadow_color[3] = 1.0f; } } - SEQ_END; + SEQ_ALL_END; } /* Adding "Properties" region to DopeSheet */ diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index fced95ee629..2434d9e9f74 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -3463,7 +3463,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (scene->ed) { Sequence *seq; - SEQ_BEGIN (scene->ed, seq) { + SEQ_ALL_BEGIN (scene->ed, seq) { seq->flag &= ~(SEQ_FLAG_UNUSED_6 | SEQ_FLAG_UNUSED_18 | SEQ_FLAG_UNUSED_19 | SEQ_FLAG_UNUSED_21); if (seq->type == SEQ_TYPE_SPEED) { @@ -3471,7 +3471,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) s->flags &= ~(SEQ_SPEED_UNUSED_1); } } - SEQ_END; + SEQ_ALL_END; } } @@ -4953,8 +4953,6 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) const View3D *v3d_default = DNA_struct_default_get(View3D); wm->xr.session_settings.shading = v3d_default->shading; - /* Don't rotate light with the viewer by default, make it fixed. */ - wm->xr.session_settings.shading.flag |= V3D_SHADING_WORLD_ORIENTATION; wm->xr.session_settings.draw_flags = (V3D_OFSDRAW_SHOW_GRIDFLOOR | V3D_OFSDRAW_SHOW_ANNOTATION); wm->xr.session_settings.clip_start = v3d_default->clip_start; @@ -5112,6 +5110,12 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } } + for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) { + /* Don't rotate light with the viewer by default, make it fixed. Shading settings can't be + * edited and this flag should always be set. So we can always execute this. */ + wm->xr.session_settings.shading.flag |= V3D_SHADING_WORLD_ORIENTATION; + } + /* Keep this block, even when empty. */ } } diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c index 12b5a297df5..3c326565557 100644 --- a/source/blender/blenloader/intern/versioning_290.c +++ b/source/blender/blenloader/intern/versioning_290.c @@ -190,22 +190,35 @@ void do_versions_after_linking_290(Main *bmain, ReportList *UNUSED(reports)) /* Patch first frame for old files. */ Scene *scene = bmain->scenes.first; - LISTBASE_FOREACH (Object *, ob, &bmain->objects) { - if (ob->type != OB_GPENCIL) { - continue; - } - bGPdata *gpd = ob->data; - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - bGPDframe *gpf = gpl->frames.first; - if (gpf && gpf->framenum > scene->r.sfra) { - bGPDframe *gpf_dup = BKE_gpencil_frame_duplicate(gpf); - gpf_dup->framenum = scene->r.sfra; - BLI_addhead(&gpl->frames, gpf_dup); + if (scene != NULL) { + LISTBASE_FOREACH (Object *, ob, &bmain->objects) { + if (ob->type != OB_GPENCIL) { + continue; + } + bGPdata *gpd = ob->data; + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + bGPDframe *gpf = gpl->frames.first; + if (gpf && gpf->framenum > scene->r.sfra) { + bGPDframe *gpf_dup = BKE_gpencil_frame_duplicate(gpf); + gpf_dup->framenum = scene->r.sfra; + BLI_addhead(&gpl->frames, gpf_dup); + } } } } } + if (!MAIN_VERSION_ATLEAST(bmain, 291, 1)) { + LISTBASE_FOREACH (Collection *, collection, &bmain->collections) { + if (BKE_collection_cycles_fix(bmain, collection)) { + printf( + "WARNING: Cycle detected in collection '%s', fixed as best as possible.\n" + "You may have to reconstruct your View Layers...\n", + collection->id.name); + } + } + } + /** * Versioning code until next subversion bump goes here. * @@ -217,18 +230,26 @@ void do_versions_after_linking_290(Main *bmain, ReportList *UNUSED(reports)) * \note Keep this message at the bottom of the function. */ { - LISTBASE_FOREACH (Collection *, collection, &bmain->collections) { - if (BKE_collection_cycles_fix(bmain, collection)) { - printf( - "WARNING: Cycle detected in collection '%s', fixed as best as possible.\n" - "You may have to reconstruct your View Layers...\n", - collection->id.name); - } - } + /* Keep this block, even when empty. */ } } +static void panels_remove_x_closed_flag_recursive(Panel *panel) +{ + const bool was_closed_x = panel->flag & PNL_UNUSED_1; + const bool was_closed_y = panel->flag & PNL_CLOSED; /* That value was the Y closed flag. */ + + SET_FLAG_FROM_TEST(panel->flag, was_closed_x || was_closed_y, PNL_CLOSED); + + /* Clear the old PNL_CLOSEDX flag. */ + panel->flag &= ~PNL_UNUSED_1; + + LISTBASE_FOREACH (Panel *, child_panel, &panel->children) { + panels_remove_x_closed_flag_recursive(child_panel); + } +} + void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain) { UNUSED_VARS(fd); @@ -407,17 +428,7 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain) } } - /** - * Versioning code until next subversion bump goes here. - * - * \note Be sure to check when bumping the version: - * - "versioning_userdef.c", #BLO_version_defaults_userpref_blend - * - "versioning_userdef.c", #do_versions_theme - * - * \note Keep this message at the bottom of the function. - */ - { - /* Keep this block, even when empty. */ + if (!MAIN_VERSION_ATLEAST(bmain, 291, 1)) { /* Initialize additional parameter of the Nishita sky model and change altitude unit. */ if (!DNA_struct_elem_find(fd->filesdna, "NodeTexSky", "float", "sun_intensity")) { @@ -482,5 +493,41 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain) } } } + + /* Remove panel X axis collapsing, a remnant of horizontal panel alignment. */ + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { + LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { + panels_remove_x_closed_flag_recursive(panel); + } + } + } + } + + /* Initialize solver for Boolean. */ + if (!DNA_struct_elem_find(fd->filesdna, "BooleanModifierData", "enum", "solver")) { + for (Object *object = bmain->objects.first; object != NULL; object = object->id.next) { + LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) { + if (md->type == eModifierType_Boolean) { + BooleanModifierData *bmd = (BooleanModifierData *)md; + bmd->solver = eBooleanModifierSolver_Fast; + } + } + } + } + } + + /** + * Versioning code until next subversion bump goes here. + * + * \note Be sure to check when bumping the version: + * - "versioning_userdef.c", #BLO_version_defaults_userpref_blend + * - "versioning_userdef.c", #do_versions_theme + * + * \note Keep this message at the bottom of the function. + */ + { + /* Keep this block, even when empty. */ } } diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index df0b2b380fa..b4bee9a3c7e 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -174,7 +174,7 @@ static void blo_update_defaults_screen(bScreen *screen, } else if (area->spacetype == SPACE_SEQ) { SpaceSeq *seq = area->spacedata.first; - seq->flag |= SEQ_SHOW_MARKERS | SEQ_SHOW_FCURVES; + seq->flag |= SEQ_SHOW_MARKERS | SEQ_SHOW_FCURVES | SEQ_ZOOM_TO_FIT; } else if (area->spacetype == SPACE_TEXT) { /* Show syntax and line numbers in Script workspace text editor. */ diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c index 88ccb551e16..58d57f12b8f 100644 --- a/source/blender/blenloader/intern/versioning_legacy.c +++ b/source/blender/blenloader/intern/versioning_legacy.c @@ -1251,12 +1251,12 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) while (sce) { ed = sce->ed; if (ed) { - SEQ_BEGIN (sce->ed, seq) { + SEQ_ALL_BEGIN (sce->ed, seq) { if (seq->type == SEQ_TYPE_IMAGE || seq->type == SEQ_TYPE_MOVIE) { seq->alpha_mode = SEQ_ALPHA_STRAIGHT; } } - SEQ_END; + SEQ_ALL_END; } sce = sce->id.next; @@ -2442,12 +2442,12 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) Sequence *seq; for (sce = bmain->scenes.first; sce; sce = sce->id.next) { - SEQ_BEGIN (sce->ed, seq) { + SEQ_ALL_BEGIN (sce->ed, seq) { if (seq->blend_mode == 0) { seq->blend_opacity = 100.0f; } } - SEQ_END; + SEQ_ALL_END; } } @@ -2595,12 +2595,12 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) while (sce) { ed = sce->ed; if (ed) { - SEQP_BEGIN (ed, seq) { + SEQ_CURRENT_BEGIN (ed, seq) { if (seq->strip && seq->strip->proxy) { seq->strip->proxy->quality = 90; } } - SEQ_END; + SEQ_CURRENT_END; } sce = sce->id.next; diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c index d1bd518baca..bfbf985b08f 100644 --- a/source/blender/blenloader/intern/versioning_userdef.c +++ b/source/blender/blenloader/intern/versioning_userdef.c @@ -38,6 +38,7 @@ #include "DNA_windowmanager_types.h" #include "BKE_addon.h" +#include "BKE_blender_version.h" #include "BKE_colorband.h" #include "BKE_idprop.h" #include "BKE_keyconfig.h" @@ -227,6 +228,12 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme) */ { /* Keep this block, even when empty. */ + + /* The new defaults for the file browser theme are the same as + * the outliner's, and it's less disruptive to just copy them. */ + copy_v4_v4_uchar(btheme->space_file.back, btheme->space_outliner.back); + copy_v4_v4_uchar(btheme->space_file.row_alternate, btheme->space_outliner.row_alternate); + FROM_DEFAULT_V4_UCHAR(space_graph.vertex_active); } @@ -758,6 +765,12 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef) userdef->statusbar_flag = STATUSBAR_SHOW_VERSION; } + if (!USER_VERSION_ATLEAST(291, 1)) { + if (userdef->collection_instance_empty_size == 0) { + userdef->collection_instance_empty_size = 1.0f; + } + } + /** * Versioning code until next subversion bump goes here. * @@ -769,10 +782,6 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef) */ { /* Keep this block, even when empty. */ - - if (userdef->collection_instance_empty_size == 0) { - userdef->collection_instance_empty_size = 1.0f; - } } if (userdef->pixelsize == 0.0f) { @@ -785,4 +794,23 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef) #undef USER_VERSION_ATLEAST } +void BLO_sanitize_experimental_features_userpref_blend(UserDef *userdef) +{ + /* User preference experimental settings are only supported in alpha builds. + * This prevents users corrupting data and relying on API that may change. + * + * If user preferences are saved this will be stored in disk as expected. + * This only starts to take effect when there is a release branch (on beta). + * + * At that time master already has its version bumped so its user preferences + * are not touched by these settings. */ + + if (BKE_blender_version_is_alpha()) { + return; + } + userdef->experimental.use_new_particle_system = false; + userdef->experimental.use_new_hair_type = false; + userdef->experimental.use_sculpt_vertex_colors = false; +} + #undef USER_LMOUSESELECT diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index ed4f997a856..a9c92719a33 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -152,6 +152,7 @@ #include "MEM_guardedalloc.h" // MEM_freeN #include "BKE_action.h" +#include "BKE_anim_data.h" #include "BKE_armature.h" #include "BKE_blender_version.h" #include "BKE_bpath.h" @@ -160,10 +161,12 @@ #include "BKE_constraint.h" #include "BKE_curve.h" #include "BKE_curveprofile.h" +#include "BKE_deform.h" #include "BKE_fcurve.h" #include "BKE_fcurve_driver.h" #include "BKE_global.h" // for G #include "BKE_gpencil_modifier.h" +#include "BKE_idprop.h" #include "BKE_idtype.h" #include "BKE_layer.h" #include "BKE_lib_id.h" @@ -656,108 +659,6 @@ static void writelist_id(WriteData *wd, int filecode, const char *structname, co * These functions are used by blender's .blend system for file saving/loading. * \{ */ -void IDP_WriteProperty_OnlyData(const IDProperty *prop, BlendWriter *writer); -void IDP_WriteProperty(const IDProperty *prop, BlendWriter *writer); - -static void IDP_WriteArray(const IDProperty *prop, BlendWriter *writer) -{ - /*REMEMBER to set totalen to len in the linking code!!*/ - if (prop->data.pointer) { - BLO_write_raw(writer, MEM_allocN_len(prop->data.pointer), prop->data.pointer); - - if (prop->subtype == IDP_GROUP) { - IDProperty **array = prop->data.pointer; - int a; - - for (a = 0; a < prop->len; a++) { - IDP_WriteProperty(array[a], writer); - } - } - } -} - -static void IDP_WriteIDPArray(const IDProperty *prop, BlendWriter *writer) -{ - /*REMEMBER to set totalen to len in the linking code!!*/ - if (prop->data.pointer) { - const IDProperty *array = prop->data.pointer; - int a; - - BLO_write_struct_array(writer, IDProperty, prop->len, array); - - for (a = 0; a < prop->len; a++) { - IDP_WriteProperty_OnlyData(&array[a], writer); - } - } -} - -static void IDP_WriteString(const IDProperty *prop, BlendWriter *writer) -{ - /*REMEMBER to set totalen to len in the linking code!!*/ - BLO_write_raw(writer, prop->len, prop->data.pointer); -} - -static void IDP_WriteGroup(const IDProperty *prop, BlendWriter *writer) -{ - IDProperty *loop; - - for (loop = prop->data.group.first; loop; loop = loop->next) { - IDP_WriteProperty(loop, writer); - } -} - -/* Functions to read/write ID Properties */ -void IDP_WriteProperty_OnlyData(const IDProperty *prop, BlendWriter *writer) -{ - switch (prop->type) { - case IDP_GROUP: - IDP_WriteGroup(prop, writer); - break; - case IDP_STRING: - IDP_WriteString(prop, writer); - break; - case IDP_ARRAY: - IDP_WriteArray(prop, writer); - break; - case IDP_IDPARRAY: - IDP_WriteIDPArray(prop, writer); - break; - } -} - -void IDP_WriteProperty(const IDProperty *prop, BlendWriter *writer) -{ - BLO_write_struct(writer, IDProperty, prop); - IDP_WriteProperty_OnlyData(prop, writer); -} - -static void write_iddata(BlendWriter *writer, ID *id) -{ - /* ID_WM's id->properties are considered runtime only, and never written in .blend file. */ - if (id->properties && !ELEM(GS(id->name), ID_WM)) { - IDP_WriteProperty(id->properties, writer); - } - - if (id->override_library) { - BLO_write_struct(writer, IDOverrideLibrary, id->override_library); - - BLO_write_struct_list(writer, IDOverrideLibraryProperty, &id->override_library->properties); - LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &id->override_library->properties) { - BLO_write_string(writer, op->rna_path); - - BLO_write_struct_list(writer, IDOverrideLibraryPropertyOperation, &op->operations); - LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) { - if (opop->subitem_reference_name) { - BLO_write_string(writer, opop->subitem_reference_name); - } - if (opop->subitem_local_name) { - BLO_write_string(writer, opop->subitem_local_name); - } - } - } - } -} - static void write_previews(BlendWriter *writer, const PreviewImage *prv_orig) { /* Note we write previews also for undo steps. It takes up some memory, @@ -782,107 +683,13 @@ static void write_previews(BlendWriter *writer, const PreviewImage *prv_orig) } } -static void write_fmodifiers(BlendWriter *writer, ListBase *fmodifiers) -{ - FModifier *fcm; - - /* Write all modifiers first (for faster reloading) */ - BLO_write_struct_list(writer, FModifier, fmodifiers); - - /* Modifiers */ - for (fcm = fmodifiers->first; fcm; fcm = fcm->next) { - const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); - - /* Write the specific data */ - if (fmi && fcm->data) { - /* firstly, just write the plain fmi->data struct */ - BLO_write_struct_by_name(writer, fmi->structName, fcm->data); - - /* do any modifier specific stuff */ - switch (fcm->type) { - case FMODIFIER_TYPE_GENERATOR: { - FMod_Generator *data = fcm->data; - - /* write coefficients array */ - if (data->coefficients) { - BLO_write_float_array(writer, data->arraysize, data->coefficients); - } - - break; - } - case FMODIFIER_TYPE_ENVELOPE: { - FMod_Envelope *data = fcm->data; - - /* write envelope data */ - if (data->data) { - BLO_write_struct_array(writer, FCM_EnvelopeData, data->totvert, data->data); - } - - break; - } - case FMODIFIER_TYPE_PYTHON: { - FMod_Python *data = fcm->data; - - /* Write ID Properties -- and copy this comment EXACTLY for easy finding - * of library blocks that implement this.*/ - IDP_WriteProperty(data->prop, writer); - - break; - } - } - } - } -} - -static void write_fcurves(BlendWriter *writer, ListBase *fcurves) -{ - FCurve *fcu; - - BLO_write_struct_list(writer, FCurve, fcurves); - for (fcu = fcurves->first; fcu; fcu = fcu->next) { - /* curve data */ - if (fcu->bezt) { - BLO_write_struct_array(writer, BezTriple, fcu->totvert, fcu->bezt); - } - if (fcu->fpt) { - BLO_write_struct_array(writer, FPoint, fcu->totvert, fcu->fpt); - } - - if (fcu->rna_path) { - BLO_write_string(writer, fcu->rna_path); - } - - /* driver data */ - if (fcu->driver) { - ChannelDriver *driver = fcu->driver; - DriverVar *dvar; - - BLO_write_struct(writer, ChannelDriver, driver); - - /* variables */ - BLO_write_struct_list(writer, DriverVar, &driver->variables); - for (dvar = driver->variables.first; dvar; dvar = dvar->next) { - DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) { - if (dtar->rna_path) { - BLO_write_string(writer, dtar->rna_path); - } - } - DRIVER_TARGETS_LOOPER_END; - } - } - - /* write F-Modifiers */ - write_fmodifiers(writer, &fcu->modifiers); - } -} - static void write_action(BlendWriter *writer, bAction *act, const void *id_address) { if (act->id.us > 0 || BLO_write_is_undo(writer)) { BLO_write_id_struct(writer, bAction, id_address, &act->id); - write_iddata(writer, &act->id); + BKE_id_blend_write(writer, &act->id); - write_fcurves(writer, &act->curves); + BKE_fcurve_blend_write(writer, &act->curves); LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) { BLO_write_struct(writer, bActionGroup, grp); @@ -896,15 +703,12 @@ static void write_action(BlendWriter *writer, bAction *act, const void *id_addre static void write_keyingsets(BlendWriter *writer, ListBase *list) { - KeyingSet *ks; - KS_Path *ksp; - - for (ks = list->first; ks; ks = ks->next) { + LISTBASE_FOREACH (KeyingSet *, ks, list) { /* KeyingSet */ BLO_write_struct(writer, KeyingSet, ks); /* Paths */ - for (ksp = ks->paths.first; ksp; ksp = ksp->next) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { /* Path */ BLO_write_struct(writer, KS_Path, ksp); @@ -915,59 +719,6 @@ static void write_keyingsets(BlendWriter *writer, ListBase *list) } } -static void write_nlastrips(BlendWriter *writer, ListBase *strips) -{ - NlaStrip *strip; - - BLO_write_struct_list(writer, NlaStrip, strips); - for (strip = strips->first; strip; strip = strip->next) { - /* write the strip's F-Curves and modifiers */ - write_fcurves(writer, &strip->fcurves); - write_fmodifiers(writer, &strip->modifiers); - - /* write the strip's children */ - write_nlastrips(writer, &strip->strips); - } -} - -static void write_nladata(BlendWriter *writer, ListBase *nlabase) -{ - NlaTrack *nlt; - - /* write all the tracks */ - for (nlt = nlabase->first; nlt; nlt = nlt->next) { - /* write the track first */ - BLO_write_struct(writer, NlaTrack, nlt); - - /* write the track's strips */ - write_nlastrips(writer, &nlt->strips); - } -} - -static void write_animdata(BlendWriter *writer, AnimData *adt) -{ - AnimOverride *aor; - - /* firstly, just write the AnimData block */ - BLO_write_struct(writer, AnimData, adt); - - /* write drivers */ - write_fcurves(writer, &adt->drivers); - - /* write overrides */ - // FIXME: are these needed? - for (aor = adt->overrides.first; aor; aor = aor->next) { - /* 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 */ - write_nladata(writer, &adt->nla_tracks); -} - static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *sock) { if (sock->default_value == NULL) { @@ -1017,7 +768,7 @@ static void write_node_socket(BlendWriter *writer, bNodeSocket *sock) BLO_write_struct(writer, bNodeSocket, sock); if (sock->prop) { - IDP_WriteProperty(sock->prop, writer); + IDP_BlendWrite(writer, sock->prop); } write_node_socket_default_value(writer, sock); @@ -1028,7 +779,7 @@ static void write_node_socket_interface(BlendWriter *writer, bNodeSocket *sock) BLO_write_struct(writer, bNodeSocket, sock); if (sock->prop) { - IDP_WriteProperty(sock->prop, writer); + IDP_BlendWrite(writer, sock->prop); } write_node_socket_default_value(writer, sock); @@ -1036,31 +787,27 @@ static void write_node_socket_interface(BlendWriter *writer, bNodeSocket *sock) /* this is only direct data, tree itself should have been written */ static void write_nodetree_nolib(BlendWriter *writer, bNodeTree *ntree) { - bNode *node; - bNodeSocket *sock; - bNodeLink *link; - /* for link_list() speed, we write per list */ if (ntree->adt) { - write_animdata(writer, ntree->adt); + BKE_animdata_blend_write(writer, ntree->adt); } - for (node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { BLO_write_struct(writer, bNode, node); if (node->prop) { - IDP_WriteProperty(node->prop, writer); + IDP_BlendWrite(writer, node->prop); } - for (sock = node->inputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { write_node_socket(writer, sock); } - for (sock = node->outputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { write_node_socket(writer, sock); } - for (link = node->internal_links.first; link; link = link->next) { + LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) { BLO_write_struct(writer, bNodeLink, link); } @@ -1124,26 +871,26 @@ static void write_nodetree_nolib(BlendWriter *writer, bNodeTree *ntree) if (node->type == CMP_NODE_OUTPUT_FILE) { /* inputs have own storage data */ - for (sock = node->inputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { BLO_write_struct(writer, NodeImageMultiFileSocket, sock->storage); } } if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS)) { /* write extra socket info */ - for (sock = node->outputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { BLO_write_struct(writer, NodeImageLayer, sock->storage); } } } - for (link = ntree->links.first; link; link = link->next) { + LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { BLO_write_struct(writer, bNodeLink, link); } - for (sock = ntree->inputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) { write_node_socket_interface(writer, sock); } - for (sock = ntree->outputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) { write_node_socket_interface(writer, sock); } } @@ -1205,15 +952,15 @@ typedef struct RenderInfo { static void write_renderinfo(WriteData *wd, Main *mainvar) { bScreen *curscreen; - Scene *sce, *curscene = NULL; + Scene *curscene = NULL; ViewLayer *view_layer; - RenderInfo data; /* XXX in future, handle multiple windows with multiple screens? */ current_screen_compat(mainvar, false, &curscreen, &curscene, &view_layer); - for (sce = mainvar->scenes.first; sce; sce = sce->id.next) { + LISTBASE_FOREACH (Scene *, sce, &mainvar->scenes) { if (sce->id.lib == NULL && (sce == curscene || (sce->r.scemode & R_BG_RENDER))) { + RenderInfo data; data.sfra = sce->r.sfra; data.efra = sce->r.efra; memset(data.scene_name, 0, sizeof(data.scene_name)); @@ -1229,7 +976,7 @@ static void write_keymapitem(BlendWriter *writer, const wmKeyMapItem *kmi) { BLO_write_struct(writer, wmKeyMapItem, kmi); if (kmi->properties) { - IDP_WriteProperty(kmi->properties, writer); + IDP_BlendWrite(writer, kmi->properties); } } @@ -1262,7 +1009,7 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef) LISTBASE_FOREACH (const wmKeyConfigPref *, kpt, &userdef->user_keyconfig_prefs) { BLO_write_struct(writer, wmKeyConfigPref, kpt); if (kpt->prop) { - IDP_WriteProperty(kpt->prop, writer); + IDP_BlendWrite(writer, kpt->prop); } } @@ -1273,7 +1020,7 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef) const bUserMenuItem_Op *umi_op = (const bUserMenuItem_Op *)umi; BLO_write_struct(writer, bUserMenuItem_Op, umi_op); if (umi_op->prop) { - IDP_WriteProperty(umi_op->prop, writer); + IDP_BlendWrite(writer, umi_op->prop); } } else if (umi->type == USER_MENU_TYPE_MENU) { @@ -1293,7 +1040,7 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef) LISTBASE_FOREACH (const bAddon *, bext, &userdef->addons) { BLO_write_struct(writer, bAddon, bext); if (bext->prop) { - IDP_WriteProperty(bext->prop, writer); + IDP_BlendWrite(writer, bext->prop); } } @@ -1308,11 +1055,9 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef) static void write_boid_state(BlendWriter *writer, BoidState *state) { - BoidRule *rule = state->rules.first; - BLO_write_struct(writer, BoidState, state); - for (; rule; rule = rule->next) { + LISTBASE_FOREACH (BoidRule *, rule, &state->rules) { switch (rule->type) { case eBoidRuleType_Goal: case eBoidRuleType_Avoid: @@ -1361,21 +1106,14 @@ static const char *ptcache_extra_struct[] = { }; static void write_pointcaches(BlendWriter *writer, ListBase *ptcaches) { - PointCache *cache = ptcaches->first; - int i; - - for (; cache; cache = cache->next) { + LISTBASE_FOREACH (PointCache *, cache, ptcaches) { BLO_write_struct(writer, PointCache, cache); if ((cache->flag & PTCACHE_DISK_CACHE) == 0) { - PTCacheMem *pm = cache->mem_cache.first; - - for (; pm; pm = pm->next) { - PTCacheExtra *extra = pm->extradata.first; - + LISTBASE_FOREACH (PTCacheMem *, pm, &cache->mem_cache) { BLO_write_struct(writer, PTCacheMem, pm); - for (i = 0; i < BPHYS_TOT_DATA; i++) { + for (int i = 0; i < BPHYS_TOT_DATA; i++) { if (pm->data[i] && pm->data_types & (1 << i)) { if (ptcache_data_struct[i][0] == '\0') { BLO_write_raw(writer, MEM_allocN_len(pm->data[i]), pm->data[i]); @@ -1387,7 +1125,7 @@ static void write_pointcaches(BlendWriter *writer, ListBase *ptcaches) } } - for (; extra; extra = extra->next) { + LISTBASE_FOREACH (PTCacheExtra *, extra, &pm->extradata) { if (ptcache_extra_struct[extra->type][0] == '\0') { continue; } @@ -1407,10 +1145,10 @@ static void write_particlesettings(BlendWriter *writer, if (part->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, ParticleSettings, id_address, &part->id); - write_iddata(writer, &part->id); + BKE_id_blend_write(writer, &part->id); if (part->adt) { - write_animdata(writer, part->adt); + BKE_animdata_blend_write(writer, part->adt); } BLO_write_struct(writer, PartDeflect, part->pd); BLO_write_struct(writer, PartDeflect, part->pd2); @@ -1464,11 +1202,7 @@ static void write_particlesettings(BlendWriter *writer, static void write_particlesystems(BlendWriter *writer, ListBase *particles) { - ParticleSystem *psys = particles->first; - ParticleTarget *pt; - int a; - - for (; psys; psys = psys->next) { + LISTBASE_FOREACH (ParticleSystem *, psys, particles) { BLO_write_struct(writer, ParticleSystem, psys); if (psys->particles) { @@ -1477,7 +1211,7 @@ static void write_particlesystems(BlendWriter *writer, ListBase *particles) if (psys->particles->hair) { ParticleData *pa = psys->particles; - for (a = 0; a < psys->totpart; a++, pa++) { + for (int a = 0; a < psys->totpart; a++, pa++) { BLO_write_struct_array(writer, HairKey, pa->totkey, pa->hair); } } @@ -1492,8 +1226,7 @@ static void write_particlesystems(BlendWriter *writer, ListBase *particles) writer, ParticleSpring, psys->tot_fluidsprings, psys->fluid_springs); } } - pt = psys->targets.first; - for (; pt; pt = pt->next) { + LISTBASE_FOREACH (ParticleTarget *, pt, &psys->targets) { BLO_write_struct(writer, ParticleTarget, pt); } @@ -1527,9 +1260,7 @@ static void write_motionpath(BlendWriter *writer, bMotionPath *mpath) static void write_constraints(BlendWriter *writer, ListBase *conlist) { - bConstraint *con; - - for (con = conlist->first; con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, conlist) { const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); /* Write the specific data */ @@ -1541,25 +1272,23 @@ static void write_constraints(BlendWriter *writer, ListBase *conlist) switch (con->type) { case CONSTRAINT_TYPE_PYTHON: { bPythonConstraint *data = con->data; - bConstraintTarget *ct; /* write targets */ - for (ct = data->targets.first; ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &data->targets) { BLO_write_struct(writer, bConstraintTarget, ct); } /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ - IDP_WriteProperty(data->prop, writer); + IDP_BlendWrite(writer, data->prop); break; } case CONSTRAINT_TYPE_ARMATURE: { bArmatureConstraint *data = con->data; - bConstraintTarget *ct; /* write targets */ - for (ct = data->targets.first; ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &data->targets) { BLO_write_struct(writer, bConstraintTarget, ct); } @@ -1583,9 +1312,6 @@ static void write_constraints(BlendWriter *writer, ListBase *conlist) static void write_pose(BlendWriter *writer, bPose *pose, bArmature *arm) { - bPoseChannel *chan; - bActionGroup *grp; - /* Write each channel */ if (pose == NULL) { return; @@ -1594,11 +1320,11 @@ static void write_pose(BlendWriter *writer, bPose *pose, bArmature *arm) BLI_assert(arm != NULL); /* Write channels */ - for (chan = pose->chanbase.first; chan; chan = chan->next) { + LISTBASE_FOREACH (bPoseChannel *, chan, &pose->chanbase) { /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ if (chan->prop) { - IDP_WriteProperty(chan->prop, writer); + IDP_BlendWrite(writer, chan->prop); } write_constraints(writer, &chan->constraints); @@ -1620,7 +1346,7 @@ static void write_pose(BlendWriter *writer, bPose *pose, bArmature *arm) } /* Write groups */ - for (grp = pose->agroups.first; grp; grp = grp->next) { + LISTBASE_FOREACH (bActionGroup *, grp, &pose->agroups) { BLO_write_struct(writer, bActionGroup, grp); } @@ -1652,13 +1378,11 @@ static void write_fmaps(BlendWriter *writer, ListBase *fbase) static void write_modifiers(BlendWriter *writer, ListBase *modbase) { - ModifierData *md; - if (modbase == NULL) { return; } - for (md = modbase->first; md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, modbase) { const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); if (mti == NULL) { return; @@ -1717,15 +1441,14 @@ static void write_modifiers(BlendWriter *writer, ListBase *modbase) DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; if (pmd->canvas) { - DynamicPaintSurface *surface; BLO_write_struct(writer, DynamicPaintCanvasSettings, pmd->canvas); /* write surfaces */ - for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { + LISTBASE_FOREACH (DynamicPaintSurface *, surface, &pmd->canvas->surfaces) { BLO_write_struct(writer, DynamicPaintSurface, surface); } /* write caches and effector weights */ - for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { + LISTBASE_FOREACH (DynamicPaintSurface *, surface, &pmd->canvas->surfaces) { write_pointcaches(writer, &(surface->ptcaches)); BLO_write_struct(writer, EffectorWeights, surface->effector_weights); @@ -1757,13 +1480,11 @@ static void write_modifiers(BlendWriter *writer, ListBase *modbase) static void write_gpencil_modifiers(BlendWriter *writer, ListBase *modbase) { - GpencilModifierData *md; - if (modbase == NULL) { return; } - for (md = modbase->first; md; md = md->next) { + LISTBASE_FOREACH (GpencilModifierData *, md, modbase) { const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type); if (mti == NULL) { return; @@ -1824,13 +1545,11 @@ static void write_gpencil_modifiers(BlendWriter *writer, ListBase *modbase) static void write_shaderfxs(BlendWriter *writer, ListBase *fxbase) { - ShaderFxData *fx; - if (fxbase == NULL) { return; } - for (fx = fxbase->first; fx; fx = fx->next) { + LISTBASE_FOREACH (ShaderFxData *, fx, fxbase) { const ShaderFxTypeInfo *fxi = BKE_shaderfx_get_info(fx->type); if (fxi == NULL) { return; @@ -1848,10 +1567,10 @@ static void write_object(BlendWriter *writer, Object *ob, const void *id_address /* write LibData */ BLO_write_id_struct(writer, Object, id_address, &ob->id); - write_iddata(writer, &ob->id); + BKE_id_blend_write(writer, &ob->id); if (ob->adt) { - write_animdata(writer, ob->adt); + BKE_animdata_blend_write(writer, ob->adt); } /* direct data */ @@ -1902,7 +1621,6 @@ static void write_object(BlendWriter *writer, Object *ob, const void *id_address write_shaderfxs(writer, &ob->shader_fx); BLO_write_struct_list(writer, LinkData, &ob->pc_ids); - BLO_write_struct_list(writer, LodLevel, &ob->lodlevels); write_previews(writer, ob->preview); } @@ -1917,7 +1635,7 @@ static void write_vfont(BlendWriter *writer, VFont *vf, const void *id_address) /* write LibData */ BLO_write_id_struct(writer, VFont, id_address, &vf->id); - write_iddata(writer, &vf->id); + BKE_id_blend_write(writer, &vf->id); /* direct data */ if (vf->packedfile) { @@ -1933,10 +1651,10 @@ static void write_key(BlendWriter *writer, Key *key, const void *id_address) if (key->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, Key, id_address, &key->id); - write_iddata(writer, &key->id); + BKE_id_blend_write(writer, &key->id); if (key->adt) { - write_animdata(writer, key->adt); + BKE_animdata_blend_write(writer, key->adt); } /* direct data */ @@ -1954,10 +1672,10 @@ static void write_camera(BlendWriter *writer, Camera *cam, const void *id_addres if (cam->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, Camera, id_address, &cam->id); - write_iddata(writer, &cam->id); + BKE_id_blend_write(writer, &cam->id); if (cam->adt) { - write_animdata(writer, cam->adt); + BKE_animdata_blend_write(writer, cam->adt); } LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) { @@ -1979,12 +1697,12 @@ static void write_mball(BlendWriter *writer, MetaBall *mb, const void *id_addres /* write LibData */ BLO_write_id_struct(writer, MetaBall, id_address, &mb->id); - write_iddata(writer, &mb->id); + BKE_id_blend_write(writer, &mb->id); /* direct data */ BLO_write_pointer_array(writer, mb->totcol, mb->mat); if (mb->adt) { - write_animdata(writer, mb->adt); + BKE_animdata_blend_write(writer, mb->adt); } LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) { @@ -2003,12 +1721,12 @@ static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address) /* write LibData */ BLO_write_id_struct(writer, Curve, id_address, &cu->id); - write_iddata(writer, &cu->id); + BKE_id_blend_write(writer, &cu->id); /* direct data */ BLO_write_pointer_array(writer, cu->totcol, cu->mat); if (cu->adt) { - write_animdata(writer, cu->adt); + BKE_animdata_blend_write(writer, cu->adt); } if (cu->vfont) { @@ -2040,206 +1758,6 @@ static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address) } } -static void write_dverts(BlendWriter *writer, int count, MDeformVert *dvlist) -{ - if (dvlist) { - - /* Write the dvert list */ - BLO_write_struct_array(writer, MDeformVert, count, dvlist); - - /* Write deformation data for each dvert */ - for (int i = 0; i < count; i++) { - if (dvlist[i].dw) { - BLO_write_struct_array(writer, MDeformWeight, dvlist[i].totweight, dvlist[i].dw); - } - } - } -} - -static void write_mdisps(BlendWriter *writer, int count, MDisps *mdlist, int external) -{ - if (mdlist) { - int i; - - BLO_write_struct_array(writer, MDisps, count, mdlist); - for (i = 0; i < count; i++) { - MDisps *md = &mdlist[i]; - if (md->disps) { - if (!external) { - BLO_write_float3_array(writer, md->totdisp, &md->disps[0][0]); - } - } - - if (md->hidden) { - BLO_write_raw(writer, BLI_BITMAP_SIZE(md->totdisp), md->hidden); - } - } - } -} - -static void write_grid_paint_mask(BlendWriter *writer, int count, GridPaintMask *grid_paint_mask) -{ - if (grid_paint_mask) { - int i; - - BLO_write_struct_array(writer, GridPaintMask, count, grid_paint_mask); - for (i = 0; i < count; i++) { - GridPaintMask *gpm = &grid_paint_mask[i]; - if (gpm->data) { - const int gridsize = BKE_ccg_gridsize(gpm->level); - BLO_write_raw(writer, sizeof(*gpm->data) * gridsize * gridsize, gpm->data); - } - } - } -} - -static void write_customdata(BlendWriter *writer, - ID *id, - int count, - CustomData *data, - CustomDataLayer *layers, - CustomDataMask cddata_mask) -{ - int i; - - /* write external customdata (not for undo) */ - if (data->external && !BLO_write_is_undo(writer)) { - CustomData_external_write(data, id, cddata_mask, count, 0); - } - - BLO_write_struct_array_at_address(writer, CustomDataLayer, data->totlayer, data->layers, layers); - - for (i = 0; i < data->totlayer; i++) { - CustomDataLayer *layer = &layers[i]; - const char *structname; - int structnum, datasize; - - if (layer->type == CD_MDEFORMVERT) { - /* layer types that allocate own memory need special handling */ - write_dverts(writer, count, layer->data); - } - else if (layer->type == CD_MDISPS) { - write_mdisps(writer, count, layer->data, layer->flag & CD_FLAG_EXTERNAL); - } - else if (layer->type == CD_PAINT_MASK) { - const float *layer_data = layer->data; - BLO_write_raw(writer, sizeof(*layer_data) * count, layer_data); - } - else if (layer->type == CD_SCULPT_FACE_SETS) { - const float *layer_data = layer->data; - BLO_write_raw(writer, sizeof(*layer_data) * count, layer_data); - } - else if (layer->type == CD_GRID_PAINT_MASK) { - write_grid_paint_mask(writer, count, layer->data); - } - else if (layer->type == CD_FACEMAP) { - const int *layer_data = layer->data; - BLO_write_raw(writer, sizeof(*layer_data) * count, layer_data); - } - else { - CustomData_file_write_info(layer->type, &structname, &structnum); - if (structnum) { - datasize = structnum * count; - BLO_write_struct_array_by_name(writer, structname, datasize, layer->data); - } - else if (!BLO_write_is_undo(writer)) { /* Do not warn on undo. */ - printf("%s error: layer '%s':%d - can't be written to file\n", - __func__, - structname, - layer->type); - } - } - } - - if (data->external) { - BLO_write_struct(writer, CustomDataExternal, data->external); - } -} - -static void write_mesh(BlendWriter *writer, Mesh *mesh, const void *id_address) -{ - if (mesh->id.us > 0 || BLO_write_is_undo(writer)) { - /* cache only - don't write */ - mesh->mface = NULL; - mesh->totface = 0; - memset(&mesh->fdata, 0, sizeof(mesh->fdata)); - memset(&mesh->runtime, 0, sizeof(mesh->runtime)); - - /* Reduce xdata layers, fill xlayers with layers to be written. - * This makes xdata invalid for Blender, which is why we made a - * temporary local copy. */ - CustomDataLayer *vlayers = NULL, vlayers_buff[CD_TEMP_CHUNK_SIZE]; - CustomDataLayer *elayers = NULL, elayers_buff[CD_TEMP_CHUNK_SIZE]; - CustomDataLayer *flayers = NULL, flayers_buff[CD_TEMP_CHUNK_SIZE]; - CustomDataLayer *llayers = NULL, llayers_buff[CD_TEMP_CHUNK_SIZE]; - CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; - - CustomData_file_write_prepare(&mesh->vdata, &vlayers, vlayers_buff, ARRAY_SIZE(vlayers_buff)); - CustomData_file_write_prepare(&mesh->edata, &elayers, elayers_buff, ARRAY_SIZE(elayers_buff)); - flayers = flayers_buff; - CustomData_file_write_prepare(&mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff)); - CustomData_file_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); - - BLO_write_id_struct(writer, Mesh, id_address, &mesh->id); - write_iddata(writer, &mesh->id); - - /* direct data */ - if (mesh->adt) { - write_animdata(writer, mesh->adt); - } - - BLO_write_pointer_array(writer, mesh->totcol, mesh->mat); - BLO_write_raw(writer, sizeof(MSelect) * mesh->totselect, mesh->mselect); - - write_customdata(writer, &mesh->id, mesh->totvert, &mesh->vdata, vlayers, CD_MASK_MESH.vmask); - write_customdata(writer, &mesh->id, mesh->totedge, &mesh->edata, elayers, CD_MASK_MESH.emask); - /* fdata is really a dummy - written so slots align */ - write_customdata(writer, &mesh->id, mesh->totface, &mesh->fdata, flayers, CD_MASK_MESH.fmask); - write_customdata(writer, &mesh->id, mesh->totloop, &mesh->ldata, llayers, CD_MASK_MESH.lmask); - write_customdata(writer, &mesh->id, mesh->totpoly, &mesh->pdata, players, CD_MASK_MESH.pmask); - - /* free temporary data */ - if (vlayers && vlayers != vlayers_buff) { - MEM_freeN(vlayers); - } - if (elayers && elayers != elayers_buff) { - MEM_freeN(elayers); - } - if (flayers && flayers != flayers_buff) { - MEM_freeN(flayers); - } - if (llayers && llayers != llayers_buff) { - MEM_freeN(llayers); - } - if (players && players != players_buff) { - MEM_freeN(players); - } - } -} - -static void write_lattice(BlendWriter *writer, Lattice *lt, const void *id_address) -{ - if (lt->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - lt->editlatt = NULL; - lt->batch_cache = NULL; - - /* write LibData */ - BLO_write_id_struct(writer, Lattice, id_address, <->id); - write_iddata(writer, <->id); - - /* write animdata */ - if (lt->adt) { - write_animdata(writer, lt->adt); - } - - /* direct data */ - BLO_write_struct_array(writer, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def); - - write_dverts(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert); - } -} - static void write_image(BlendWriter *writer, Image *ima, const void *id_address) { if (ima->id.us > 0 || BLO_write_is_undo(writer)) { @@ -2254,7 +1772,7 @@ static void write_image(BlendWriter *writer, Image *ima, const void *id_address) /* write LibData */ BLO_write_id_struct(writer, Image, id_address, &ima->id); - write_iddata(writer, &ima->id); + BKE_id_blend_write(writer, &ima->id); for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { BLO_write_struct(writer, ImagePackedFile, imapf); @@ -2285,10 +1803,10 @@ static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address) if (tex->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, Tex, id_address, &tex->id); - write_iddata(writer, &tex->id); + BKE_id_blend_write(writer, &tex->id); if (tex->adt) { - write_animdata(writer, tex->adt); + BKE_animdata_blend_write(writer, tex->adt); } /* direct data */ @@ -2315,10 +1833,10 @@ static void write_material(BlendWriter *writer, Material *ma, const void *id_add /* write LibData */ BLO_write_id_struct(writer, Material, id_address, &ma->id); - write_iddata(writer, &ma->id); + BKE_id_blend_write(writer, &ma->id); if (ma->adt) { - write_animdata(writer, ma->adt); + BKE_animdata_blend_write(writer, ma->adt); } /* nodetree is integral part of material, no libdata */ @@ -2344,10 +1862,10 @@ static void write_world(BlendWriter *writer, World *wrld, const void *id_address /* write LibData */ BLO_write_id_struct(writer, World, id_address, &wrld->id); - write_iddata(writer, &wrld->id); + BKE_id_blend_write(writer, &wrld->id); if (wrld->adt) { - write_animdata(writer, wrld->adt); + BKE_animdata_blend_write(writer, wrld->adt); } /* nodetree is integral part of world, no libdata */ @@ -2365,10 +1883,10 @@ static void write_light(BlendWriter *writer, Light *la, const void *id_address) if (la->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, Light, id_address, &la->id); - write_iddata(writer, &la->id); + BKE_id_blend_write(writer, &la->id); if (la->adt) { - write_animdata(writer, la->adt); + BKE_animdata_blend_write(writer, la->adt); } if (la->curfalloff) { @@ -2410,7 +1928,7 @@ static void write_collection(BlendWriter *writer, Collection *collection, const /* write LibData */ BLO_write_id_struct(writer, Collection, id_address, &collection->id); - write_iddata(writer, &collection->id); + BKE_id_blend_write(writer, &collection->id); write_collection_nolib(writer, collection); } @@ -2418,9 +1936,7 @@ static void write_collection(BlendWriter *writer, Collection *collection, const static void write_sequence_modifiers(BlendWriter *writer, ListBase *modbase) { - SequenceModifierData *smd; - - for (smd = modbase->first; smd; smd = smd->next) { + LISTBASE_FOREACH (SequenceModifierData *, smd, modbase) { const SequenceModifierTypeInfo *smti = BKE_sequence_modifier_type_info_get(smd->type); if (smti) { @@ -2453,7 +1969,7 @@ static void write_view_settings(BlendWriter *writer, ColorManagedViewSettings *v static void write_view3dshading(BlendWriter *writer, View3DShading *shading) { if (shading->prop) { - IDP_WriteProperty(shading->prop, writer); + IDP_BlendWrite(writer, shading->prop); } } @@ -2480,7 +1996,7 @@ static void write_view_layer(BlendWriter *writer, ViewLayer *view_layer) BLO_write_struct_list(writer, Base, &view_layer->object_bases); if (view_layer->id_properties) { - IDP_WriteProperty(view_layer->id_properties, writer); + IDP_BlendWrite(writer, view_layer->id_properties); } LISTBASE_FOREACH (FreestyleModuleConfig *, fmc, &view_layer->freestyle_config.modules) { @@ -2538,10 +2054,10 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address) /* write LibData */ BLO_write_id_struct(writer, Scene, id_address, &sce->id); - write_iddata(writer, &sce->id); + BKE_id_blend_write(writer, &sce->id); if (sce->adt) { - write_animdata(writer, sce->adt); + BKE_animdata_blend_write(writer, sce->adt); } write_keyingsets(writer, &sce->keyingsets); @@ -2607,15 +2123,15 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address) /* reset write flags too */ - SEQ_BEGIN (ed, seq) { + SEQ_ALL_BEGIN (ed, seq) { if (seq->strip) { seq->strip->done = false; } BLO_write_struct(writer, Sequence, seq); } - SEQ_END; + SEQ_ALL_END; - SEQ_BEGIN (ed, seq) { + SEQ_ALL_BEGIN (ed, seq) { if (seq->strip && seq->strip->done == 0) { /* write strip with 'done' at 0 because readfile */ @@ -2675,12 +2191,12 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address) } if (seq->prop) { - IDP_WriteProperty(seq->prop, writer); + IDP_BlendWrite(writer, seq->prop); } write_sequence_modifiers(writer, &seq->modifiers); } - SEQ_END; + SEQ_ALL_END; /* new; meta stack too, even when its nasty restore code */ LISTBASE_FOREACH (MetaStack *, ms, &ed->metastack) { @@ -2698,7 +2214,7 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address) } } if (sce->r.ffcodecdata.properties) { - IDP_WriteProperty(sce->r.ffcodecdata.properties, writer); + IDP_BlendWrite(writer, sce->r.ffcodecdata.properties); } /* writing dynamic list of TimeMarkers to the blend file */ @@ -2772,10 +2288,10 @@ static void write_gpencil(BlendWriter *writer, bGPdata *gpd, const void *id_addr /* write gpd data block to file */ BLO_write_id_struct(writer, bGPdata, id_address, &gpd->id); - write_iddata(writer, &gpd->id); + BKE_id_blend_write(writer, &gpd->id); if (gpd->adt) { - write_animdata(writer, gpd->adt); + BKE_animdata_blend_write(writer, gpd->adt); } BLO_write_pointer_array(writer, gpd->totcol, gpd->mat); @@ -2793,7 +2309,7 @@ static void write_gpencil(BlendWriter *writer, bGPdata *gpd, const void *id_addr LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { BLO_write_struct_array(writer, bGPDspoint, gps->totpoints, gps->points); BLO_write_struct_array(writer, bGPDtriangle, gps->tot_triangles, gps->triangles); - write_dverts(writer, gps->totpoints, gps->dvert); + BKE_defvert_blend_write(writer, gps->totpoints, gps->dvert); } } } @@ -2842,7 +2358,7 @@ static void write_uilist(BlendWriter *writer, uiList *ui_list) BLO_write_struct(writer, uiList, ui_list); if (ui_list->properties) { - IDP_WriteProperty(ui_list->properties, writer); + IDP_BlendWrite(writer, ui_list->properties); } } @@ -2988,18 +2504,16 @@ static void write_area_regions(BlendWriter *writer, ScrArea *area) } else if (sl->spacetype == SPACE_NODE) { SpaceNode *snode = (SpaceNode *)sl; - bNodeTreePath *path; BLO_write_struct(writer, SpaceNode, snode); - for (path = snode->treepath.first; path; path = path->next) { + LISTBASE_FOREACH (bNodeTreePath *, path, &snode->treepath) { BLO_write_struct(writer, bNodeTreePath, path); } } else if (sl->spacetype == SPACE_CONSOLE) { SpaceConsole *con = (SpaceConsole *)sl; - ConsoleLine *cl; - for (cl = con->history.first; cl; cl = cl->next) { + LISTBASE_FOREACH (ConsoleLine *, cl, &con->history) { /* 'len_alloc' is invalid on write, set from 'len' on read */ BLO_write_struct(writer, ConsoleLine, cl); BLO_write_raw(writer, cl->len + 1, cl->line); @@ -3048,7 +2562,7 @@ static void write_area_map(BlendWriter *writer, ScrAreaMap *area_map) static void write_windowmanager(BlendWriter *writer, wmWindowManager *wm, const void *id_address) { BLO_write_id_struct(writer, wmWindowManager, id_address, &wm->id); - write_iddata(writer, &wm->id); + BKE_id_blend_write(writer, &wm->id); write_wm_xr_data(writer, &wm->xr); LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { @@ -3083,7 +2597,7 @@ static void write_screen(BlendWriter *writer, bScreen *screen, const void *id_ad /* write LibData */ /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ writestruct_at_address(writer->wd, ID_SCRN, bScreen, 1, id_address, screen); - write_iddata(writer, &screen->id); + BKE_id_blend_write(writer, &screen->id); write_previews(writer, screen->preview); @@ -3103,7 +2617,7 @@ static void write_bone(BlendWriter *writer, Bone *bone) /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ if (bone->prop) { - IDP_WriteProperty(bone->prop, writer); + IDP_BlendWrite(writer, bone->prop); } /* Write Children */ @@ -3123,10 +2637,10 @@ static void write_armature(BlendWriter *writer, bArmature *arm, const void *id_a arm->act_edbone = NULL; BLO_write_id_struct(writer, bArmature, id_address, &arm->id); - write_iddata(writer, &arm->id); + BKE_id_blend_write(writer, &arm->id); if (arm->adt) { - write_animdata(writer, arm->adt); + BKE_animdata_blend_write(writer, arm->adt); } /* Direct data */ @@ -3148,7 +2662,7 @@ static void write_text(BlendWriter *writer, Text *text, const void *id_address) /* write LibData */ BLO_write_id_struct(writer, Text, id_address, &text->id); - write_iddata(writer, &text->id); + BKE_id_blend_write(writer, &text->id); if (text->filepath) { BLO_write_string(writer, text->filepath); @@ -3171,10 +2685,10 @@ static void write_speaker(BlendWriter *writer, Speaker *spk, const void *id_addr if (spk->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, Speaker, id_address, &spk->id); - write_iddata(writer, &spk->id); + BKE_id_blend_write(writer, &spk->id); if (spk->adt) { - write_animdata(writer, spk->adt); + BKE_animdata_blend_write(writer, spk->adt); } } } @@ -3190,7 +2704,7 @@ static void write_sound(BlendWriter *writer, bSound *sound, const void *id_addre /* write LibData */ BLO_write_id_struct(writer, bSound, id_address, &sound->id); - write_iddata(writer, &sound->id); + BKE_id_blend_write(writer, &sound->id); if (sound->packedfile) { PackedFile *pf = sound->packedfile; @@ -3205,10 +2719,10 @@ static void write_probe(BlendWriter *writer, LightProbe *prb, const void *id_add if (prb->id.us > 0 || BLO_write_is_undo(writer)) { /* write LibData */ BLO_write_id_struct(writer, LightProbe, id_address, &prb->id); - write_iddata(writer, &prb->id); + BKE_id_blend_write(writer, &prb->id); if (prb->adt) { - write_animdata(writer, prb->adt); + BKE_animdata_blend_write(writer, prb->adt); } } } @@ -3227,7 +2741,7 @@ static void write_nodetree(BlendWriter *writer, bNodeTree *ntree, const void *id BLO_write_id_struct(writer, bNodeTree, id_address, &ntree->id); /* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot * be linked, etc., so we write actual id data here only, for 'real' ID trees. */ - write_iddata(writer, &ntree->id); + BKE_id_blend_write(writer, &ntree->id); write_nodetree_nolib(writer, ntree); } @@ -3237,7 +2751,7 @@ static void write_brush(BlendWriter *writer, Brush *brush, const void *id_addres { if (brush->id.us > 0 || BLO_write_is_undo(writer)) { BLO_write_id_struct(writer, Brush, id_address, &brush->id); - write_iddata(writer, &brush->id); + BKE_id_blend_write(writer, &brush->id); if (brush->curve) { BKE_curvemapping_blend_write(writer, brush->curve); @@ -3285,7 +2799,7 @@ static void write_palette(BlendWriter *writer, Palette *palette, const void *id_ if (palette->id.us > 0 || BLO_write_is_undo(writer)) { PaletteColor *color; BLO_write_id_struct(writer, Palette, id_address, &palette->id); - write_iddata(writer, &palette->id); + BKE_id_blend_write(writer, &palette->id); for (color = palette->colors.first; color; color = color->next) { BLO_write_struct(writer, PaletteColor, color); @@ -3297,7 +2811,7 @@ static void write_paintcurve(BlendWriter *writer, PaintCurve *pc, const void *id { if (pc->id.us > 0 || BLO_write_is_undo(writer)) { BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id); - write_iddata(writer, &pc->id); + BKE_id_blend_write(writer, &pc->id); BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points); } @@ -3353,10 +2867,10 @@ static void write_movieclip(BlendWriter *writer, MovieClip *clip, const void *id MovieTrackingObject *object; BLO_write_id_struct(writer, MovieClip, id_address, &clip->id); - write_iddata(writer, &clip->id); + BKE_id_blend_write(writer, &clip->id); if (clip->adt) { - write_animdata(writer, clip->adt); + BKE_animdata_blend_write(writer, clip->adt); } write_movieTracks(writer, &tracking->tracks); @@ -3382,10 +2896,10 @@ static void write_mask(BlendWriter *writer, Mask *mask, const void *id_address) MaskLayer *masklay; BLO_write_id_struct(writer, Mask, id_address, &mask->id); - write_iddata(writer, &mask->id); + BKE_id_blend_write(writer, &mask->id); if (mask->adt) { - write_animdata(writer, mask->adt); + BKE_animdata_blend_write(writer, mask->adt); } for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { @@ -3692,10 +3206,10 @@ static void write_linestyle(BlendWriter *writer, { if (linestyle->id.us > 0 || BLO_write_is_undo(writer)) { BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id); - write_iddata(writer, &linestyle->id); + BKE_id_blend_write(writer, &linestyle->id); if (linestyle->adt) { - write_animdata(writer, linestyle->adt); + BKE_animdata_blend_write(writer, linestyle->adt); } write_linestyle_color_modifiers(writer, &linestyle->color_modifiers); @@ -3726,7 +3240,7 @@ static void write_cachefile(BlendWriter *writer, CacheFile *cache_file, const vo BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id); if (cache_file->adt) { - write_animdata(writer, cache_file->adt); + BKE_animdata_blend_write(writer, cache_file->adt); } } } @@ -3734,14 +3248,14 @@ static void write_cachefile(BlendWriter *writer, CacheFile *cache_file, const vo static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const void *id_address) { BLO_write_id_struct(writer, WorkSpace, id_address, &workspace->id); - write_iddata(writer, &workspace->id); + BKE_id_blend_write(writer, &workspace->id); BLO_write_struct_list(writer, WorkSpaceLayout, &workspace->layouts); BLO_write_struct_list(writer, WorkSpaceDataRelation, &workspace->hook_layout_relations); BLO_write_struct_list(writer, wmOwnerID, &workspace->owner_ids); BLO_write_struct_list(writer, bToolRef, &workspace->tools); LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { if (tref->properties) { - IDP_WriteProperty(tref->properties, writer); + IDP_BlendWrite(writer, tref->properties); } } } @@ -3749,29 +3263,16 @@ static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const voi static void write_hair(BlendWriter *writer, Hair *hair, const void *id_address) { if (hair->id.us > 0 || BLO_write_is_undo(writer)) { - CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; - CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE]; - CustomData_file_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); - CustomData_file_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff)); - /* Write LibData */ BLO_write_id_struct(writer, Hair, id_address, &hair->id); - write_iddata(writer, &hair->id); + BKE_id_blend_write(writer, &hair->id); /* Direct data */ - write_customdata(writer, &hair->id, hair->totpoint, &hair->pdata, players, CD_MASK_ALL); - write_customdata(writer, &hair->id, hair->totcurve, &hair->cdata, clayers, CD_MASK_ALL); + CustomData_blend_write(writer, &hair->pdata, hair->totpoint, CD_MASK_ALL, &hair->id); + CustomData_blend_write(writer, &hair->cdata, hair->totcurve, CD_MASK_ALL, &hair->id); BLO_write_pointer_array(writer, hair->totcol, hair->mat); if (hair->adt) { - write_animdata(writer, hair->adt); - } - - /* Remove temporary data. */ - if (players && players != players_buff) { - MEM_freeN(players); - } - if (clayers && clayers != clayers_buff) { - MEM_freeN(clayers); + BKE_animdata_blend_write(writer, hair->adt); } } } @@ -3785,14 +3286,14 @@ static void write_pointcloud(BlendWriter *writer, PointCloud *pointcloud, const /* Write LibData */ BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id); - write_iddata(writer, &pointcloud->id); + BKE_id_blend_write(writer, &pointcloud->id); /* Direct data */ - write_customdata( - writer, &pointcloud->id, pointcloud->totpoint, &pointcloud->pdata, players, CD_MASK_ALL); + CustomData_blend_write( + writer, &pointcloud->pdata, pointcloud->totpoint, CD_MASK_ALL, &pointcloud->id); BLO_write_pointer_array(writer, pointcloud->totcol, pointcloud->mat); if (pointcloud->adt) { - write_animdata(writer, pointcloud->adt); + BKE_animdata_blend_write(writer, pointcloud->adt); } /* Remove temporary data. */ @@ -3810,12 +3311,12 @@ static void write_volume(BlendWriter *writer, Volume *volume, const void *id_add /* write LibData */ BLO_write_id_struct(writer, Volume, id_address, &volume->id); - write_iddata(writer, &volume->id); + BKE_id_blend_write(writer, &volume->id); /* direct data */ BLO_write_pointer_array(writer, volume->totcol, volume->mat); if (volume->adt) { - write_animdata(writer, volume->adt); + BKE_animdata_blend_write(writer, volume->adt); } if (volume->packedfile) { @@ -3830,10 +3331,10 @@ static void write_simulation(BlendWriter *writer, Simulation *simulation, const { if (simulation->id.us > 0 || BLO_write_is_undo(writer)) { BLO_write_id_struct(writer, Simulation, id_address, &simulation->id); - write_iddata(writer, &simulation->id); + BKE_id_blend_write(writer, &simulation->id); if (simulation->adt) { - write_animdata(writer, simulation->adt); + BKE_animdata_blend_write(writer, simulation->adt); } /* nodetree is integral part of simulation, no libdata */ @@ -3850,21 +3351,11 @@ static void write_simulation(BlendWriter *writer, Simulation *simulation, const ParticleSimulationState *particle_state = (ParticleSimulationState *)state; BLO_write_struct(writer, ParticleSimulationState, particle_state); - CustomDataLayer *layers = NULL; - CustomDataLayer layers_buff[CD_TEMP_CHUNK_SIZE]; - CustomData_file_write_prepare( - &particle_state->attributes, &layers, layers_buff, ARRAY_SIZE(layers_buff)); - - write_customdata(writer, - &simulation->id, - particle_state->tot_particles, - &particle_state->attributes, - layers, - CD_MASK_ALL); - - if (layers != NULL && layers != layers_buff) { - MEM_freeN(layers); - } + CustomData_blend_write(writer, + &particle_state->attributes, + particle_state->tot_particles, + CD_MASK_ALL, + &simulation->id); } else if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_MESH_EMITTER)) { ParticleMeshEmitterSimulationState *emitter_state = (ParticleMeshEmitterSimulationState *) @@ -3920,7 +3411,7 @@ static void write_libraries(WriteData *wd, Main *main) BlendWriter writer = {wd}; writestruct(wd, ID_LI, Library, 1, main->curlib); - write_iddata(&writer, &main->curlib->id); + BKE_id_blend_write(&writer, &main->curlib->id); if (main->curlib->packedfile) { PackedFile *pf = main->curlib->packedfile; @@ -4125,12 +3616,17 @@ static bool write_file_handle(Main *mainvar, memcpy(id_buffer, id, idtype_struct_size); ((ID *)id_buffer)->tag = 0; - /* Those listbase data change every time we add/remove an ID, and also often when renaming - * one (due to re-sorting). This avoids generating a lot of false 'is changed' detections - * between undo steps. */ + /* Those listbase data change every time we add/remove an ID, and also often when + * renaming one (due to re-sorting). This avoids generating a lot of false 'is changed' + * detections between undo steps. */ ((ID *)id_buffer)->prev = NULL; ((ID *)id_buffer)->next = NULL; + const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id); + if (id_type->blend_write != NULL) { + id_type->blend_write(&writer, (ID *)id_buffer, id); + } + switch ((ID_Type)GS(id->name)) { case ID_WM: write_windowmanager(&writer, (wmWindowManager *)id_buffer, id); @@ -4165,9 +3661,6 @@ static bool write_file_handle(Main *mainvar, case ID_LA: write_light(&writer, (Light *)id_buffer, id); break; - case ID_LT: - write_lattice(&writer, (Lattice *)id_buffer, id); - break; case ID_VF: write_vfont(&writer, (VFont *)id_buffer, id); break; @@ -4207,9 +3700,6 @@ static bool write_file_handle(Main *mainvar, case ID_TE: write_texture(&writer, (Tex *)id_buffer, id); break; - case ID_ME: - write_mesh(&writer, (Mesh *)id_buffer, id); - break; case ID_PA: write_particlesettings(&writer, (ParticleSettings *)id_buffer, id); break; @@ -4246,6 +3736,10 @@ static bool write_file_handle(Main *mainvar, case ID_SIM: write_simulation(&writer, (Simulation *)id_buffer, id); break; + case ID_ME: + case ID_LT: + /* Do nothing, handled in IDTypeInfo callback. */ + break; case ID_LI: /* Do nothing, handled below - and should never be reached. */ BLI_assert(0); @@ -4404,7 +3898,8 @@ bool BLO_write_file(Main *mainvar, if (remap_mode != BLO_WRITE_PATH_REMAP_NONE) { if (remap_mode == BLO_WRITE_PATH_REMAP_RELATIVE) { - /* Make all relative as none of the existing paths can be relative in an unsaved document. */ + /* Make all relative as none of the existing paths can be relative in an unsaved document. + */ if (G.relbase_valid == false) { remap_mode = BLO_WRITE_PATH_REMAP_RELATIVE_ALL; } |