From 8e84938dd0428c0aa9705077b017bad85d490cc9 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 15 Jun 2021 19:28:24 +0200 Subject: Cleanup: Add files for version independent versioning helpers Adds `source/blender/blendloader/intern/versioning_common.cc` and `versioning_common.h` for version independent versioning functions. I only placed `do_versions_add_region_if_not_found()` in there for now. `blo_do_version_old_trackto_to_constraints()` could also be added, but that's so old, I prefer keeping that in `versioning_legacy.c`. --- source/blender/blenloader/CMakeLists.txt | 2 + source/blender/blenloader/intern/versioning_290.c | 21 +-------- .../blender/blenloader/intern/versioning_common.cc | 50 ++++++++++++++++++++++ .../blender/blenloader/intern/versioning_common.h | 37 ++++++++++++++++ 4 files changed, 90 insertions(+), 20 deletions(-) create mode 100644 source/blender/blenloader/intern/versioning_common.cc create mode 100644 source/blender/blenloader/intern/versioning_common.h diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index 36802fc8842..61a00ccdaa4 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -59,6 +59,7 @@ set(SRC intern/versioning_290.c intern/versioning_300.c intern/versioning_cycles.c + intern/versioning_common.cc intern/versioning_defaults.c intern/versioning_dna.c intern/versioning_legacy.c @@ -72,6 +73,7 @@ set(SRC BLO_undofile.h BLO_writefile.h intern/readfile.h + intern/versioning_common.h ) set(LIB diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c index 565e62158ff..bd739452f8e 100644 --- a/source/blender/blenloader/intern/versioning_290.c +++ b/source/blender/blenloader/intern/versioning_290.c @@ -80,6 +80,7 @@ #include "BLO_readfile.h" #include "readfile.h" +#include "versioning_common.h" /* Make preferences read-only, use versioning_userdef.c. */ #define U (*((const UserDef *)&U)) @@ -861,26 +862,6 @@ static void version_node_join_geometry_for_multi_input_socket(bNodeTree *ntree) } } -static ARegion *do_versions_add_region_if_not_found(ListBase *regionbase, - int region_type, - const char *name, - int link_after_region_type) -{ - ARegion *link_after_region = NULL; - LISTBASE_FOREACH (ARegion *, region, regionbase) { - if (region->regiontype == region_type) { - return NULL; - } - if (region->regiontype == link_after_region_type) { - link_after_region = region; - } - } - ARegion *new_region = MEM_callocN(sizeof(ARegion), name); - new_region->regiontype = region_type; - BLI_insertlinkafter(regionbase, link_after_region, new_region); - return new_region; -} - /* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain) { diff --git a/source/blender/blenloader/intern/versioning_common.cc b/source/blender/blenloader/intern/versioning_common.cc new file mode 100644 index 00000000000..da3ff08a7dd --- /dev/null +++ b/source/blender/blenloader/intern/versioning_common.cc @@ -0,0 +1,50 @@ +/* + * 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 + */ +/* allow readfile to use deprecated functionality */ +#define DNA_DEPRECATED_ALLOW + +#include "DNA_screen_types.h" + +#include "BLI_listbase.h" + +#include "MEM_guardedalloc.h" + +#include "versioning_common.h" + +ARegion *do_versions_add_region_if_not_found(ListBase *regionbase, + int region_type, + const char *name, + int link_after_region_type) +{ + ARegion *link_after_region = NULL; + LISTBASE_FOREACH (ARegion *, region, regionbase) { + if (region->regiontype == region_type) { + return NULL; + } + if (region->regiontype == link_after_region_type) { + link_after_region = region; + } + } + + ARegion *new_region = static_cast(MEM_callocN(sizeof(ARegion), name)); + new_region->regiontype = region_type; + BLI_insertlinkafter(regionbase, link_after_region, new_region); + return new_region; +} diff --git a/source/blender/blenloader/intern/versioning_common.h b/source/blender/blenloader/intern/versioning_common.h new file mode 100644 index 00000000000..a1769d4639e --- /dev/null +++ b/source/blender/blenloader/intern/versioning_common.h @@ -0,0 +1,37 @@ +/* + * 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 + */ + +#pragma once + +struct ARegion; +struct ListBase; + +#ifdef __cplusplus +extern "C" { +#endif + +struct ARegion *do_versions_add_region_if_not_found(struct ListBase *regionbase, + int region_type, + const char *name, + int link_after_region_type); + +#ifdef __cplusplus +} +#endif -- cgit v1.2.3