Remove compatibility code for blendfiles from early 2.80 development era.

Remove the 'SceneCollection' structure definition from DNA, and the
compatibility code converting it to the 'modern' viewlayer system.

'SceneCollection' was part at some point of the new collection system
during 2.80 development, but was never in any published Blender release.
So this code was only ensuring compatibility with a few potential
Blender files saved from in-development builds over four years ago.

Implements #110918.

Pull Request: https://projects.blender.org/blender/blender/pulls/110926
This commit is contained in:
Bastien Montagne 2023-08-08 15:03:25 +02:00 committed by Gitea
parent db4f926c92
commit 23835a393c
8 changed files with 2 additions and 343 deletions

View File

@ -34,7 +34,6 @@ struct Library;
struct Main;
struct Object;
struct Scene;
struct SceneCollection;
struct ViewLayer;
typedef struct CollectionParent {
@ -322,14 +321,6 @@ void BKE_collection_blend_read_lib(struct BlendLibReader *reader, struct Collect
void BKE_collection_blend_read_expand(struct BlendExpander *expander,
struct Collection *collection);
void BKE_collection_compat_blend_read_data(struct BlendDataReader *reader,
struct SceneCollection *sc);
void BKE_collection_compat_blend_read_lib(struct BlendLibReader *reader,
struct ID *self_id,
struct SceneCollection *sc);
void BKE_collection_compat_blend_read_expand(struct BlendExpander *expander,
struct SceneCollection *sc);
/* Iteration callbacks. */
typedef void (*BKE_scene_objects_Cb)(struct Object *ob, void *data);

View File

@ -256,18 +256,6 @@ static void collection_blend_write(BlendWriter *writer, ID *id, const void *id_a
BKE_collection_blend_write_nolib(writer, collection);
}
#ifdef USE_COLLECTION_COMPAT_28
void BKE_collection_compat_blend_read_data(BlendDataReader *reader, SceneCollection *sc)
{
BLO_read_list(reader, &sc->objects);
BLO_read_list(reader, &sc->scene_collections);
LISTBASE_FOREACH (SceneCollection *, nsc, &sc->scene_collections) {
BKE_collection_compat_blend_read_data(reader, nsc);
}
}
#endif
void BKE_collection_blend_read_data(BlendDataReader *reader, Collection *collection, ID *owner_id)
{
/* Special case for this pointer, do not rely on regular `lib_link` process here. Avoids needs
@ -306,19 +294,6 @@ void BKE_collection_blend_read_data(BlendDataReader *reader, Collection *collect
BLO_read_data_address(reader, &collection->preview);
BKE_previewimg_blend_read(reader, collection->preview);
#ifdef USE_COLLECTION_COMPAT_28
/* This runs before the very first doversion. */
BLO_read_data_address(reader, &collection->collection);
if (collection->collection != nullptr) {
BKE_collection_compat_blend_read_data(reader, collection->collection);
}
BLO_read_data_address(reader, &collection->view_layer);
if (collection->view_layer != nullptr) {
BKE_view_layer_blend_read_data(reader, collection->view_layer);
}
#endif
}
static void collection_blend_read_data(BlendDataReader *reader, ID *id)
@ -343,32 +318,8 @@ static void lib_link_collection_data(BlendLibReader *reader, ID *self_id, Collec
}
}
#ifdef USE_COLLECTION_COMPAT_28
void BKE_collection_compat_blend_read_lib(BlendLibReader *reader, ID *self_id, SceneCollection *sc)
{
LISTBASE_FOREACH (LinkData *, link, &sc->objects) {
BLO_read_id_address(reader, self_id, &link->data);
BLI_assert(link->data);
}
LISTBASE_FOREACH (SceneCollection *, nsc, &sc->scene_collections) {
BKE_collection_compat_blend_read_lib(reader, self_id, nsc);
}
}
#endif
void BKE_collection_blend_read_lib(BlendLibReader *reader, Collection *collection)
{
#ifdef USE_COLLECTION_COMPAT_28
if (collection->collection) {
BKE_collection_compat_blend_read_lib(reader, &collection->id, collection->collection);
}
if (collection->view_layer) {
BKE_view_layer_blend_read_lib(reader, &collection->id, collection->view_layer);
}
#endif
lib_link_collection_data(reader, &collection->id, collection);
}
@ -378,19 +329,6 @@ static void collection_blend_read_lib(BlendLibReader *reader, ID *id)
BKE_collection_blend_read_lib(reader, collection);
}
#ifdef USE_COLLECTION_COMPAT_28
void BKE_collection_compat_blend_read_expand(BlendExpander *expander, SceneCollection *sc)
{
LISTBASE_FOREACH (LinkData *, link, &sc->objects) {
BLO_expand(expander, link->data);
}
LISTBASE_FOREACH (SceneCollection *, nsc, &sc->scene_collections) {
BKE_collection_compat_blend_read_expand(expander, nsc);
}
}
#endif
void BKE_collection_blend_read_expand(BlendExpander *expander, Collection *collection)
{
LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
@ -400,12 +338,6 @@ void BKE_collection_blend_read_expand(BlendExpander *expander, Collection *colle
LISTBASE_FOREACH (CollectionChild *, child, &collection->children) {
BLO_expand(expander, child->collection);
}
#ifdef USE_COLLECTION_COMPAT_28
if (collection->collection != nullptr) {
BKE_collection_compat_blend_read_expand(expander, collection->collection);
}
#endif
}
static void collection_blend_read_expand(BlendExpander *expander, ID *id)

View File

@ -2399,10 +2399,6 @@ static void direct_link_layer_collections(BlendDataReader *reader, ListBase *lb,
{
BLO_read_list(reader, lb);
LISTBASE_FOREACH (LayerCollection *, lc, lb) {
#ifdef USE_COLLECTION_COMPAT_28
BLO_read_data_address(reader, &lc->scene_collection);
#endif
/* Master collection is not a real data-block. */
if (master) {
BLO_read_data_address(reader, &lc->collection);

View File

@ -1486,14 +1486,6 @@ static void scene_blend_read_data(BlendDataReader *reader, ID *id)
BKE_curvemapping_blend_read(reader, &sce->r.mblur_shutter_curve);
#ifdef USE_COLLECTION_COMPAT_28
/* this runs before the very first doversion */
if (sce->collection) {
BLO_read_data_address(reader, &sce->collection);
BKE_collection_compat_blend_read_data(reader, sce->collection);
}
#endif
/* insert into global old-new map for reading without UI (link_global accesses it again) */
BLO_read_glob_list(reader, &sce->view_layers);
LISTBASE_FOREACH (ViewLayer *, view_layer, &sce->view_layers) {
@ -1651,12 +1643,6 @@ static void scene_blend_read_lib(BlendLibReader *reader, ID *id)
/* Motion Tracking */
BLO_read_id_address(reader, id, &sce->clip);
#ifdef USE_COLLECTION_COMPAT_28
if (sce->collection) {
BKE_collection_compat_blend_read_lib(reader, id, sce->collection);
}
#endif
LISTBASE_FOREACH (ViewLayer *, view_layer, &sce->view_layers) {
BKE_view_layer_blend_read_lib(reader, id, view_layer);
}
@ -1743,12 +1729,6 @@ static void scene_blend_read_expand(BlendExpander *expander, ID *id)
BLO_expand(expander, sce->clip);
#ifdef USE_COLLECTION_COMPAT_28
if (sce->collection) {
BKE_collection_compat_blend_read_expand(expander, sce->collection);
}
#endif
if (sce->r.bake.cage_object) {
BLO_expand(expander, sce->r.bake.cage_object);
}

View File

@ -251,168 +251,6 @@ static void do_version_workspaces_after_lib_link(Main *bmain)
}
}
#ifdef USE_COLLECTION_COMPAT_28
enum {
COLLECTION_DEPRECATED_VISIBLE = (1 << 0),
COLLECTION_DEPRECATED_VIEWPORT = (1 << 0),
COLLECTION_DEPRECATED_SELECTABLE = (1 << 1),
COLLECTION_DEPRECATED_DISABLED = (1 << 2),
COLLECTION_DEPRECATED_RENDER = (1 << 3),
};
static void do_version_view_layer_visibility(ViewLayer *view_layer)
{
/* Convert from deprecated VISIBLE flag to DISABLED */
LISTBASE_FOREACH (LayerCollection *, lc, &view_layer->layer_collections) {
if (lc->flag & COLLECTION_DEPRECATED_DISABLED) {
lc->flag &= ~COLLECTION_DEPRECATED_DISABLED;
}
if ((lc->flag & COLLECTION_DEPRECATED_VISIBLE) == 0) {
lc->flag |= COLLECTION_DEPRECATED_DISABLED;
}
lc->flag |= COLLECTION_DEPRECATED_VIEWPORT | COLLECTION_DEPRECATED_RENDER;
}
}
static void do_version_layer_collection_pre(ViewLayer *view_layer,
ListBase *lb,
GSet *enabled_set,
GSet *selectable_set)
{
/* Convert from deprecated DISABLED to new layer collection and collection flags */
LISTBASE_FOREACH (LayerCollection *, lc, lb) {
if (lc->scene_collection) {
if (!(lc->flag & COLLECTION_DEPRECATED_DISABLED)) {
BLI_gset_insert(enabled_set, lc->scene_collection);
}
if (lc->flag & COLLECTION_DEPRECATED_SELECTABLE) {
BLI_gset_insert(selectable_set, lc->scene_collection);
}
}
do_version_layer_collection_pre(
view_layer, &lc->layer_collections, enabled_set, selectable_set);
}
}
static void do_version_layer_collection_post(ViewLayer *view_layer,
ListBase *lb,
GSet *enabled_set,
GSet *selectable_set,
GHash *collection_map)
{
/* Apply layer collection exclude flags. */
LISTBASE_FOREACH (LayerCollection *, lc, lb) {
if (!(lc->collection->flag & COLLECTION_IS_MASTER)) {
SceneCollection *sc = static_cast<SceneCollection *>(
BLI_ghash_lookup(collection_map, lc->collection));
const bool enabled = (sc && BLI_gset_haskey(enabled_set, sc));
const bool selectable = (sc && BLI_gset_haskey(selectable_set, sc));
if (!enabled) {
lc->flag |= LAYER_COLLECTION_EXCLUDE;
}
if (enabled && !selectable) {
lc->collection->flag |= COLLECTION_HIDE_SELECT;
}
}
do_version_layer_collection_post(
view_layer, &lc->layer_collections, enabled_set, selectable_set, collection_map);
}
}
static void do_version_scene_collection_convert(
Main *bmain, ID *id, SceneCollection *sc, Collection *collection, GHash *collection_map)
{
if (collection_map) {
BLI_ghash_insert(collection_map, collection, sc);
}
for (SceneCollection *nsc = static_cast<SceneCollection *>(sc->scene_collections.first);
nsc != nullptr;)
{
SceneCollection *nsc_next = nsc->next;
Collection *ncollection = BKE_collection_add(bmain, collection, nsc->name);
ncollection->id.lib = id->lib;
do_version_scene_collection_convert(bmain, id, nsc, ncollection, collection_map);
nsc = nsc_next;
}
LISTBASE_FOREACH (LinkData *, link, &sc->objects) {
Object *ob = static_cast<Object *>(link->data);
if (ob) {
BKE_collection_object_add_notest(bmain, collection, ob);
id_us_min(&ob->id);
}
}
BLI_freelistN(&sc->objects);
MEM_freeN(sc);
}
static void do_version_group_collection_to_collection(Main *bmain, Collection *group)
{
/* Convert old 2.8 group collections to new unified collections. */
if (group->collection) {
do_version_scene_collection_convert(bmain, &group->id, group->collection, group, nullptr);
}
group->collection = nullptr;
group->view_layer = nullptr;
id_fake_user_set(&group->id);
}
static void do_version_scene_collection_to_collection(Main *bmain, Scene *scene)
{
/* Convert old 2.8 scene collections to new unified collections. */
/* Temporarily clear view layers so we don't do any layer collection syncing
* and destroy old flags that we want to restore. */
ListBase view_layers = scene->view_layers;
BLI_listbase_clear(&scene->view_layers);
if (!scene->master_collection) {
scene->master_collection = BKE_collection_master_add(scene);
}
/* Convert scene collections. */
GHash *collection_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
if (scene->collection) {
do_version_scene_collection_convert(
bmain, &scene->id, scene->collection, scene->master_collection, collection_map);
scene->collection = nullptr;
}
scene->view_layers = view_layers;
/* Convert layer collections. */
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
GSet *enabled_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
GSet *selectable_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
do_version_layer_collection_pre(
view_layer, &view_layer->layer_collections, enabled_set, selectable_set);
BKE_layer_collection_doversion_2_80(scene, view_layer);
BKE_layer_collection_sync(scene, view_layer);
do_version_layer_collection_post(
view_layer, &view_layer->layer_collections, enabled_set, selectable_set, collection_map);
BLI_gset_free(enabled_set, nullptr);
BLI_gset_free(selectable_set, nullptr);
BKE_layer_collection_sync(scene, view_layer);
}
BLI_ghash_free(collection_map, nullptr, nullptr);
}
#endif
static void do_version_layers_to_collections(Main *bmain, Scene *scene)
{
/* Since we don't have access to FileData we check the (always valid) first
@ -2342,11 +2180,7 @@ static void update_wave_node_directions_and_offset(bNodeTree *ntree)
void do_versions_after_linking_280(FileData *fd, Main *bmain)
{
bool use_collection_compat_28 = true;
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 280, 0)) {
use_collection_compat_28 = false;
/* Convert group layer visibility flags to hidden nested collection. */
LISTBASE_FOREACH (Collection *, collection, &bmain->collections) {
/* Add fake user for all existing groups. */
@ -2568,18 +2402,6 @@ void do_versions_after_linking_280(FileData *fd, Main *bmain)
}
}
#ifdef USE_COLLECTION_COMPAT_28
if (use_collection_compat_28 && !MAIN_VERSION_FILE_ATLEAST(bmain, 280, 14)) {
LISTBASE_FOREACH (Collection *, group, &bmain->collections) {
do_version_group_collection_to_collection(bmain, group);
}
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
do_version_scene_collection_to_collection(bmain, scene);
}
}
#endif
/* Update Curve object Shape Key data layout to include the Radius property */
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 280, 23)) {
LISTBASE_FOREACH (Curve *, cu, &bmain->curves) {
@ -3150,11 +2972,7 @@ ENUM_OPERATORS(eNTreeDoVersionErrors, ~int8_t{});
/* NOLINTNEXTLINE: readability-function-size */
void blo_do_versions_280(FileData *fd, Library * /*lib*/, Main *bmain)
{
bool use_collection_compat_28 = true;
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 280, 0)) {
use_collection_compat_28 = false;
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
scene->r.gauss = 1.5f;
}
@ -3272,24 +3090,6 @@ void blo_do_versions_280(FileData *fd, Library * /*lib*/, Main *bmain)
"shader nodes.\n");
}
#ifdef USE_COLLECTION_COMPAT_28
if (use_collection_compat_28 &&
(DNA_struct_elem_find(fd->filesdna, "ViewLayer", "FreestyleConfig", "freestyle_config") ==
false) &&
DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers"))
{
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
view_layer->flag |= VIEW_LAYER_FREESTYLE;
view_layer->layflag = 0x7FFF; /* solid Z-transparency halo edge strand. */
view_layer->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
view_layer->pass_alpha_threshold = 0.5f;
BKE_freestyle_config_init(&view_layer->freestyle_config);
}
}
}
#endif
{
/* Init grease pencil edit line color */
if (!DNA_struct_elem_find(fd->filesdna, "bGPdata", "float", "line_color[4]")) {
@ -3334,22 +3134,6 @@ void blo_do_versions_280(FileData *fd, Library * /*lib*/, Main *bmain)
}
}
#ifdef USE_COLLECTION_COMPAT_28
if (use_collection_compat_28 && !MAIN_VERSION_FILE_ATLEAST(bmain, 280, 3)) {
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
do_version_view_layer_visibility(view_layer);
}
}
LISTBASE_FOREACH (Collection *, group, &bmain->collections) {
if (group->view_layer != nullptr) {
do_version_view_layer_visibility(group->view_layer);
}
}
}
#endif
/* Files from this version included do get a valid `win->screen` pointer written for backward
* compatibility, however this should never be used nor needed, so clear these pointers here. */
if (MAIN_VERSION_FILE_ATLEAST(bmain, 280, 1)) {

View File

@ -135,7 +135,7 @@ typedef struct Collection {
uint8_t lineart_intersection_mask;
uint8_t lineart_intersection_priority;
struct SceneCollection *collection DNA_DEPRECATED;
void *_pad1;
struct ViewLayer *view_layer DNA_DEPRECATED;
/* Keep last. */

View File

@ -107,7 +107,7 @@ typedef struct ViewLayerEngineData {
typedef struct LayerCollection {
struct LayerCollection *next, *prev;
struct Collection *collection;
struct SceneCollection *scene_collection DNA_DEPRECATED;
void *_pad1;
short flag;
short runtime_flag;
char _pad[4];
@ -279,27 +279,6 @@ enum {
VIEW_LAYER_OUT_OF_SYNC = (1 << 3),
};
/****************************** Deprecated ******************************/
/* Compatibility with collections saved in early 2.8 versions,
* used in file reading and versioning code. */
#define USE_COLLECTION_COMPAT_28
typedef struct SceneCollection {
struct SceneCollection *next, *prev;
/** MAX_NAME. */
char name[64];
/** For UI. */
int active_object_index;
short flag;
char type;
char _pad;
/** (Object *)LinkData->data. */
ListBase objects;
/** Nested collections. */
ListBase scene_collections;
} SceneCollection;
#ifdef __cplusplus
}
#endif

View File

@ -44,7 +44,6 @@ struct Image;
struct MovieClip;
struct Object;
struct Scene;
struct SceneCollection;
struct World;
struct bGPdata;
struct bNodeTree;
@ -2050,11 +2049,9 @@ typedef struct Scene {
ListBase view_layers;
/** Not an actual data-block, but memory owned by scene. */
struct Collection *master_collection;
struct SceneCollection *collection DNA_DEPRECATED;
/** Settings to be override by work-spaces. */
IDProperty *layer_properties;
void *_pad9;
struct SceneDisplay display;
struct SceneEEVEE eevee;