diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-02-12 01:29:18 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-02-12 01:38:46 +0300 |
commit | 3ec4c2f842841ca0d0f51694dc3e88dfe22195b1 (patch) | |
tree | 7fca8a48b2acd11529b2983edee13a794fa3ed07 /source/blender/blenloader | |
parent | 2a6d03493c9dbf9cc142ef1cdeb191e3929081d1 (diff) |
DNA: support versioning structs & struct members
This is only to be used rarely because it's not forwards compatible.
Replace version patching of old 2.80 DNA with a more generic API.
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r-- | source/blender/blenloader/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 19 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.h | 2 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_dna.c | 59 |
4 files changed, 80 insertions, 1 deletions
diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index efd64b1a328..b9bec1b97b3 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -54,6 +54,7 @@ set(SRC intern/versioning_270.c intern/versioning_280.c intern/versioning_defaults.c + intern/versioning_dna.c intern/versioning_legacy.c intern/versioning_userdef.c intern/writefile.c diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index c4fdb878b86..55a72e363e9 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -932,13 +932,30 @@ static void decode_blender_header(FileData *fd) static bool read_file_dna(FileData *fd, const char **r_error_message) { BHead *bhead; + int subversion = 0; for (bhead = blo_firstbhead(fd); bhead; bhead = blo_nextbhead(fd, bhead)) { - if (bhead->code == DNA1) { + if (bhead->code == GLOB) { + /* Before this, the subversion didn't exist in 'FileGlobal' so the subversion + * value isn't accessible for the purpose of DNA versioning in this case. */ + if (fd->fileversion <= 242) { + continue; + } + /* We can't use read_global because this needs 'DNA1' to be decoded, + * however the first 4 chars are _always_ the subversion. */ + FileGlobal *fg = (void *)&bhead[1]; + BLI_STATIC_ASSERT(offsetof(FileGlobal, subvstr) == 0, "Must be first: subvstr"); + char num[5]; + memcpy(num, fg->subvstr, 4); + num[4] = 0; + subversion = atoi(num); + } + else if (bhead->code == DNA1) { const bool do_endian_swap = (fd->flags & FD_FLAGS_SWITCH_ENDIAN) != 0; fd->filesdna = DNA_sdna_from_data(&bhead[1], bhead->len, do_endian_swap, true, r_error_message); if (fd->filesdna) { + blo_do_versions_dna(fd->filesdna, fd->fileversion, subversion); fd->compflags = DNA_struct_get_compareflags(fd->filesdna, fd->memsdna); /* used to retrieve ID names from (bhead+1) */ fd->id_name_offs = DNA_elem_offset(fd->filesdna, "ID", "char", "name[]"); diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h index 85416892f25..39a474dfe49 100644 --- a/source/blender/blenloader/intern/readfile.h +++ b/source/blender/blenloader/intern/readfile.h @@ -150,6 +150,8 @@ const char *bhead_id_name(const FileData *fd, const BHead *bhead); void blo_reportf_wrap(struct ReportList *reports, ReportType type, const char *format, ...) ATTR_PRINTF_FORMAT(3, 4); +void blo_do_versions_dna(struct SDNA *sdna, const int versionfile, const int subversionfile); + void blo_do_versions_oldnewmap_insert(struct OldNewMap *onm, const void *oldaddr, void *newaddr, int nr); void *blo_do_versions_newlibadr(struct FileData *fd, const void *lib, const void *adr); void *blo_do_versions_newlibadr_us(struct FileData *fd, const void *lib, const void *adr); diff --git a/source/blender/blenloader/intern/versioning_dna.c b/source/blender/blenloader/intern/versioning_dna.c new file mode 100644 index 00000000000..d379edd83f6 --- /dev/null +++ b/source/blender/blenloader/intern/versioning_dna.c @@ -0,0 +1,59 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file \ingroup blenloader + * + * Apply edits to DNA at load time + * to behave as if old files were written new names. + */ + +#include "BLI_compiler_attrs.h" +#include "BLI_utildefines.h" + +#include "DNA_genfile.h" +#include "DNA_listBase.h" + +#include "BLO_readfile.h" +#include "readfile.h" + +/** + * Manipulates SDNA before calling #DNA_struct_get_compareflags, + * allowing us to rename structs and struct members. + * + * \attention Changes here will cause breakages in forward compatbility, + * Use this only in the _rare_ cases when migrating to new naming is needed. + */ +void blo_do_versions_dna(SDNA *sdna, const int versionfile, const int subversionfile) +{ +#define DNA_VERSION_ATLEAST(ver, subver) \ + (versionfile > (ver) || (versionfile == (ver) && (subversionfile >= (subver)))) + + if (!DNA_VERSION_ATLEAST(280, 2)) { + /* Version files created in the 'blender2.8' branch + * between October 2016, and November 2017 (>=280.0 and < 280.2). */ + if (versionfile >= 280) { + DNA_sdna_patch_struct(sdna, "SceneLayer", "ViewLayer"); + DNA_sdna_patch_struct(sdna, "SceneLayerEngineData", "ViewLayerEngineData"); + DNA_sdna_patch_struct_member(sdna, "FileGlobal", "cur_render_layer", "cur_view_layer"); + DNA_sdna_patch_struct_member(sdna, "ParticleEditSettings", "scene_layer", "view_layer"); + DNA_sdna_patch_struct_member(sdna, "Scene", "active_layer", "active_view_layer"); + DNA_sdna_patch_struct_member(sdna, "Scene", "render_layers", "view_layers"); + DNA_sdna_patch_struct_member(sdna, "WorkSpace", "render_layer", "view_layer"); + } + } + +#undef DNA_VERSION_ATLEAST +} |