Commit: 9829a3c496743e0e6a557c9283f8c2cf2d9c1aa2 Author: Bastien Montagne Date: Fri Jan 31 19:56:36 2020 +0100 Branches: readfile-rework-refcount-handling https://developer.blender.org/rB9829a3c496743e0e6a557c9283f8c2cf2d9c1aa2
Refactor readfile's liblink code. Liblink specific ID type function was so far running a loop over all IDs of relevant type, unlike almost any other 'ID-callback-like' functions in Blender, which usually let the looping controll to calling code. The latter approach is more convinient when one want to add generic (i.e. type-agnostic) code, since it typically only has to change code in one place (caller function) instead of tens of places (all the callback functions). This commit also changes/sanitizes a few things that had nothing to do in main liblink code, like mesh conversion from tessfaces to polys (which can be done in after-linking versionning code), or scenes' cycles detection/check regarding background 'set' scenes. Differential Revision: https://developer.blender.org/D6727 =================================================================== M source/blender/blenloader/intern/readfile.c M source/blender/blenloader/intern/versioning_280.c M source/blender/makesdna/DNA_scene_types.h =================================================================== diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 5a834f31528..bc3ddbe9bd3 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -105,6 +105,7 @@ #include "BLT_translation.h" #include "BKE_action.h" +#include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_brush.h" #include "BKE_collection.h" @@ -2612,27 +2613,20 @@ static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_p /** \name Read ID * \{ */ -static void lib_link_id(FileData *fd, Main *main) +static void lib_link_id(FileData *fd, Main *UNUSED(bmain), ID *id) { - ListBase *lbarray[MAX_LIBARRAY]; - int base_count, i; - - base_count = set_listbasepointers(main, lbarray); + /* 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, fd); - for (i = 0; i < base_count; i++) { - ListBase *lb = lbarray[i]; - ID *id; + AnimData *adt = BKE_animdata_from_id(id); + if (adt != NULL) { + lib_link_animdata(fd, id, adt); + } - for (id = lb->first; id; id = id->next) { - if (id->tag & LIB_TAG_NEED_LINK) { - if (id->override_library) { - id->override_library->reference = newlibadr_us( - fd, id->lib, id->override_library->reference); - id->override_library->storage = newlibadr_us(fd, id->lib, id->override_library->storage); - } - /* DO NOT clear LIB_TAG_NEED_LINK here, it is used again by per-ID-type linkers. */ - } - } + if (id->override_library) { + id->override_library->reference = newlibadr_us(fd, id->lib, id->override_library->reference); + id->override_library->storage = newlibadr_us(fd, id->lib, id->override_library->storage); } } @@ -2722,36 +2716,27 @@ static void direct_link_curveprofile(FileData *fd, CurveProfile *profile) * \{ */ /* library brush linking after fileread */ -static void lib_link_brush(FileData *fd, Main *main) -{ - /* only link ID pointers */ - for (Brush *brush = main->brushes.first; brush; brush = brush->id.next) { - if (brush->id.tag & LIB_TAG_NEED_LINK) { - IDP_LibLinkProperty(brush->id.properties, fd); - - /* brush->(mask_)mtex.obj is ignored on purpose? */ - brush->mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mtex.tex); - brush->mask_mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mask_mtex.tex); - brush->clone.image = newlibadr(fd, brush->id.lib, brush->clone.image); - brush->toggle_brush = newlibadr(fd, brush->id.lib, brush->toggle_brush); - brush->paint_curve = newlibadr_us(fd, brush->id.lib, brush->paint_curve); - - /* link default grease pencil palette */ - if (brush->gpencil_settings != NULL) { - if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) { - brush->gpencil_settings->material = newlibadr_us( - fd, brush->id.lib, brush->gpencil_settings->material); - - if (!brush->gpencil_settings->material) { - brush->gpencil_settings->flag &= ~GP_BRUSH_MATERIAL_PINNED; - } - } - else { - brush->gpencil_settings->material = NULL; - } - } +static void lib_link_brush(FileData *fd, Main *UNUSED(bmain), Brush *brush) +{ + /* brush->(mask_)mtex.obj is ignored on purpose? */ + brush->mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mtex.tex); + brush->mask_mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mask_mtex.tex); + brush->clone.image = newlibadr(fd, brush->id.lib, brush->clone.image); + brush->toggle_brush = newlibadr(fd, brush->id.lib, brush->toggle_brush); + brush->paint_curve = newlibadr_us(fd, brush->id.lib, brush->paint_curve); + + /* link default grease pencil palette */ + if (brush->gpencil_settings != NULL) { + if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) { + brush->gpencil_settings->material = newlibadr_us( + fd, brush->id.lib, brush->gpencil_settings->material); - brush->id.tag &= ~LIB_TAG_NEED_LINK; + if (!brush->gpencil_settings->material) { + brush->gpencil_settings->flag &= ~GP_BRUSH_MATERIAL_PINNED; + } + } + else { + brush->gpencil_settings->material = NULL; } } } @@ -2804,16 +2789,8 @@ static void direct_link_brush(FileData *fd, Brush *brush) /** \name Read ID: Palette * \{ */ -static void lib_link_palette(FileData *fd, Main *main) +static void lib_link_palette(FileData *UNUSED(fd), Main *UNUSED(bmain), Palette *UNUSED(palette)) { - /* only link ID pointers */ - for (Palette *palette = main->palettes.first; palette; palette = palette->id.next) { - if (palette->id.tag & LIB_TAG_NEED_LINK) { - IDP_LibLinkProperty(palette->id.properties, fd); - - palette->id.tag &= ~LIB_TAG_NEED_LINK; - } - } } static void direct_link_palette(FileData *fd, Palette *palette) @@ -2823,16 +2800,8 @@ static void direct_link_palette(FileData *fd, Palette *palette) link_list(fd, &palette->colors); } -static void lib_link_paint_curve(FileData *fd, Main *main) +static void lib_link_paint_curve(FileData *UNUSED(fd), Main *UNUSED(bmain), PaintCurve *UNUSED(pc)) { - /* only link ID pointers */ - for (PaintCurve *pc = main->paintcurves.first; pc; pc = pc->id.next) { - if (pc->id.tag & LIB_TAG_NEED_LINK) { - IDP_LibLinkProperty(pc->id.properties, fd); - - pc->id.tag &= ~LIB_TAG_NEED_LINK; - } - } } static void direct_link_paint_curve(FileData *fd, PaintCurve *pc) @@ -2870,19 +2839,11 @@ static PackedFile *direct_link_packedfile(FileData *fd, PackedFile *oldpf) * \{ */ // XXX deprecated - old animation system -static void lib_link_ipo(FileData *fd, Main *main) +static void lib_link_ipo(FileData *fd, Main *UNUSED(bmain), Ipo *ipo) { - Ipo *ipo; - - for (ipo = main->ipo.first; ipo; ipo = ipo->id.next) { - if (ipo->id.tag & LIB_TAG_NEED_LINK) { - IpoCurve *icu; - for (icu = ipo->curve.first; icu; icu = icu->next) { - if (icu->driver) { - icu->driver->ob = newlibadr(fd, ipo->id.lib, icu->driver->ob); - } - } - ipo->id.tag &= ~LIB_TAG_NEED_LINK; + for (IpoCurve *icu = ipo->curve.first; icu; icu = icu->next) { + if (icu->driver) { + icu->driver->ob = newlibadr(fd, ipo->id.lib, icu->driver->ob); } } } @@ -3098,28 +3059,20 @@ static void direct_link_fcurves(FileData *fd, ListBase *list) } } -static void lib_link_action(FileData *fd, Main *main) +static void lib_link_action(FileData *fd, Main *UNUSED(bmain), bAction *act) { - for (bAction *act = main->actions.first; act; act = act->id.next) { - if (act->id.tag & LIB_TAG_NEED_LINK) { - IDP_LibLinkProperty(act->id.properties, fd); - - // XXX deprecated - old animation system <<< - for (bActionChannel *chan = act->chanbase.first; chan; chan = chan->next) { - chan->ipo = newlibadr_us(fd, act->id.lib, chan->ipo); - lib_link_constraint_channels(fd, &act->id, &chan->constraintChannels); - } - // >>> XXX deprecated - old animation system - - lib_link_fcurves(fd, &act->id, &act->curves); + // XXX deprecated - old animation system <<< + for (bActionChannel *chan = act->chanbase.first; chan; chan = chan->next) { + chan->ipo = newlibadr_us(fd, act->id.lib, chan->ipo); + lib_link_constraint_channels(fd, &act->id, &chan->constraintChannels); + } + // >>> XXX deprecated - old animation system - for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { - if (marker->camera) { - marker->camera = newlibadr(fd, act->id.lib, marker->camera); - } - } + lib_link_fcurves(fd, &act->id, &act->curves); - act->id.tag &= ~LIB_TAG_NEED_LINK; + for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { + if (marker->camera) { + marker->camera = newlibadr(fd, act->id.lib, marker->camera); } } } @@ -3314,18 +3267,10 @@ static void direct_link_animdata(FileData *fd, AnimData *adt) /** \name Read ID: CacheFiles * \{ */ -static void lib_link_cachefiles(FileData *fd, Main *bmain) +static void lib_link_cachefiles(FileData *UNUSED(fd), + Main *UNUSED(bmain), + CacheFile *UNUSED(cache_file)) { - /* only link ID pointers */ - for (CacheFile *cache_file = bmain->cachefiles.first; cache_file; - cache_file = cache_file->id.next) { - if (cache_file->id.tag & LIB_TAG_NEED_LINK) { - IDP_LibLinkProperty(cache_file->id.properties, fd); - lib_link_animdata(fd, &cache_file->id, cache_file->adt); - - cache_file->id.tag &= ~LIB_TAG_NEED_LINK; - } - } } static void direct_link_cachefile(FileData *fd, CacheFile *cache_file) @@ -3346,39 +3291,31 @@ static void direct_link_cachefile(FileData *fd, CacheFile *cache_file) /** \name Read ID: WorkSpace * \{ */ -static void lib_link_workspaces(FileData *fd, Main *bmain) +static void lib_link_workspaces(FileData *fd, Main *bmain, WorkSpace *workspace) { - for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { - ListBase *layouts = BKE_workspace_layouts_get(workspace); - ID *id = (ID *)workspace; + ListBase *layouts = BKE_workspace_layouts_get(workspace); + ID *id = (ID *)workspace; - if ((id->tag & LIB_TAG_NEED_LINK) == 0) { - continue; - } - IDP_LibLinkProperty(id->properties, fd); - id_us_ensure_real(id); + id_us_ensure_real(id); - for (WorkSpaceLayout *layout = layouts->first, *layout_next; layout; layout = layout_next) { - layout->screen = newlibadr_us(fd, id->lib, layout->screen); + for (WorkSpaceLayout *layout = layouts->first, *layout_next; layout; layout = layout_next) { + layout->screen = newlibadr_us(fd, id->lib, layout->screen); - layout_next = layout->next; - if (layout->screen) { - if (ID_IS_LINKED(id)) { - layout->screen->winid = 0; - if (layout->screen->temp) { - /* delete temp layouts when appending */ - BKE_workspace_layout_remove(bmain, workspace, layout); - @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs