Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r--source/blender/blenloader/intern/blend_validate.cc (renamed from source/blender/blenloader/intern/blend_validate.c)30
-rw-r--r--source/blender/blenloader/intern/readblenentry.cc (renamed from source/blender/blenloader/intern/readblenentry.c)99
-rw-r--r--source/blender/blenloader/intern/readfile.cc (renamed from source/blender/blenloader/intern/readfile.c)1043
-rw-r--r--source/blender/blenloader/intern/readfile.h12
-rw-r--r--source/blender/blenloader/intern/readfile_tempload.cc (renamed from source/blender/blenloader/intern/readfile_tempload.c)3
-rw-r--r--source/blender/blenloader/intern/undofile.cc (renamed from source/blender/blenloader/intern/undofile.c)77
-rw-r--r--source/blender/blenloader/intern/versioning_250.c11
-rw-r--r--source/blender/blenloader/intern/versioning_280.c27
-rw-r--r--source/blender/blenloader/intern/versioning_290.c28
-rw-r--r--source/blender/blenloader/intern/versioning_300.cc (renamed from source/blender/blenloader/intern/versioning_300.c)760
-rw-r--r--source/blender/blenloader/intern/versioning_400.cc55
-rw-r--r--source/blender/blenloader/intern/versioning_common.cc31
-rw-r--r--source/blender/blenloader/intern/versioning_common.h11
-rw-r--r--source/blender/blenloader/intern/versioning_cycles.c5
-rw-r--r--source/blender/blenloader/intern/versioning_defaults.cc (renamed from source/blender/blenloader/intern/versioning_defaults.c)156
-rw-r--r--source/blender/blenloader/intern/versioning_legacy.c8
-rw-r--r--source/blender/blenloader/intern/versioning_userdef.c7
-rw-r--r--source/blender/blenloader/intern/writefile.cc (renamed from source/blender/blenloader/intern/writefile.c)229
18 files changed, 1608 insertions, 984 deletions
diff --git a/source/blender/blenloader/intern/blend_validate.c b/source/blender/blenloader/intern/blend_validate.cc
index e1527201e22..7ac0a4fe1af 100644
--- a/source/blender/blenloader/intern/blend_validate.c
+++ b/source/blender/blenloader/intern/blend_validate.cc
@@ -9,7 +9,7 @@
* \note Does not *fix* anything, only reports found errors.
*/
-#include <string.h> /* for #strrchr #strncmp #strstr */
+#include <cstring> /* for #strrchr #strncmp #strstr */
#include "BLI_utildefines.h"
@@ -45,7 +45,8 @@ bool BLO_main_validate_libraries(Main *bmain, ReportList *reports)
ListBase *lbarray[INDEX_ID_MAX];
int i = set_listbasepointers(bmain, lbarray);
while (i--) {
- for (ID *id = lbarray[i]->first; id != NULL; id = id->next) {
+ for (ID *id = static_cast<ID *>(lbarray[i]->first); id != nullptr;
+ id = static_cast<ID *>(id->next)) {
if (ID_IS_LINKED(id)) {
is_valid = false;
BKE_reportf(reports,
@@ -57,18 +58,19 @@ bool BLO_main_validate_libraries(Main *bmain, ReportList *reports)
}
}
- for (Main *curmain = bmain->next; curmain != NULL; curmain = curmain->next) {
+ for (Main *curmain = bmain->next; curmain != nullptr; curmain = curmain->next) {
Library *curlib = curmain->curlib;
- if (curlib == NULL) {
- BKE_report(reports, RPT_ERROR, "Library database with NULL library data-block!");
+ if (curlib == nullptr) {
+ BKE_report(reports, RPT_ERROR, "Library database with null library data-block pointer!");
continue;
}
BKE_library_filepath_set(bmain, curlib, curlib->filepath);
- BlendFileReadReport bf_reports = {.reports = reports};
+ BlendFileReadReport bf_reports{};
+ bf_reports.reports = reports;
BlendHandle *bh = BLO_blendhandle_from_file(curlib->filepath_abs, &bf_reports);
- if (bh == NULL) {
+ if (bh == nullptr) {
BKE_reportf(reports,
RPT_ERROR,
"Library ID %s not found at expected path %s!",
@@ -79,8 +81,8 @@ bool BLO_main_validate_libraries(Main *bmain, ReportList *reports)
i = set_listbasepointers(curmain, lbarray);
while (i--) {
- ID *id = lbarray[i]->first;
- if (id == NULL) {
+ ID *id = static_cast<ID *>(lbarray[i]->first);
+ if (id == nullptr) {
continue;
}
@@ -96,12 +98,12 @@ bool BLO_main_validate_libraries(Main *bmain, ReportList *reports)
int totnames = 0;
LinkNode *names = BLO_blendhandle_get_datablock_names(bh, GS(id->name), false, &totnames);
- for (; id != NULL; id = id->next) {
+ for (; id != nullptr; id = static_cast<ID *>(id->next)) {
if (!ID_IS_LINKED(id)) {
is_valid = false;
BKE_reportf(reports,
RPT_ERROR,
- "ID %s has NULL lib pointer while being in library %s!",
+ "ID %s has null lib pointer while being in library %s!",
id->name,
curlib->filepath);
continue;
@@ -120,7 +122,7 @@ bool BLO_main_validate_libraries(Main *bmain, ReportList *reports)
}
}
- if (name == NULL) {
+ if (name == nullptr) {
is_valid = false;
BKE_reportf(reports,
RPT_ERROR,
@@ -163,7 +165,7 @@ bool BLO_main_validate_shapekeys(Main *bmain, ReportList *reports)
if (!ID_IS_LINKED(id)) {
/* We assume lib data is valid... */
Key *shapekey = BKE_key_from_id(id);
- if (shapekey != NULL && shapekey->from != id) {
+ if (shapekey != nullptr && shapekey->from != id) {
is_valid = false;
BKE_reportf(reports,
RPT_ERROR,
@@ -184,7 +186,7 @@ bool BLO_main_validate_shapekeys(Main *bmain, ReportList *reports)
/* NOTE: #BKE_id_delete also locks `bmain`, so we need to do this loop outside of the lock here.
*/
LISTBASE_FOREACH_MUTABLE (Key *, shapekey, &bmain->shapekeys) {
- if (shapekey->from != NULL) {
+ if (shapekey->from != nullptr) {
continue;
}
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.cc
index 1bfa3b0e2bb..ead796c0e28 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.cc
@@ -6,12 +6,11 @@
* `.blend` file reading entry point.
*/
-#include <stddef.h>
-
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstddef>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
#include "MEM_guardedalloc.h"
@@ -70,7 +69,7 @@ void BLO_blendhandle_print_sizes(BlendHandle *bh, void *fp)
FileData *fd = (FileData *)bh;
BHead *bhead;
- fprintf(fp, "[\n");
+ fprintf(static_cast<FILE *>(fp), "[\n");
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
if (bhead->code == ENDB) {
break;
@@ -90,14 +89,14 @@ void BLO_blendhandle_print_sizes(BlendHandle *bh, void *fp)
buf[2] = buf[2] ? buf[2] : ' ';
buf[3] = buf[3] ? buf[3] : ' ';
- fprintf(fp,
+ fprintf(static_cast<FILE *>(fp),
"['%.4s', '%s', %d, %ld ],\n",
buf,
name,
bhead->nr,
(long int)(bhead->len + sizeof(BHead)));
}
- fprintf(fp, "]\n");
+ fprintf(static_cast<FILE *>(fp), "]\n");
}
LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh,
@@ -106,14 +105,14 @@ LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh,
int *r_tot_names)
{
FileData *fd = (FileData *)bh;
- LinkNode *names = NULL;
+ LinkNode *names = nullptr;
BHead *bhead;
int tot = 0;
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
if (bhead->code == ofblocktype) {
const char *idname = blo_bhead_id_name(fd, bhead);
- if (use_assets_only && blo_bhead_id_asset_data_address(fd, bhead) == NULL) {
+ if (use_assets_only && blo_bhead_id_asset_data_address(fd, bhead) == nullptr) {
continue;
}
@@ -135,24 +134,29 @@ LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh,
int *r_tot_info_items)
{
FileData *fd = (FileData *)bh;
- LinkNode *infos = NULL;
+ LinkNode *infos = nullptr;
BHead *bhead;
int tot = 0;
+ const int sdna_nr_preview_image = DNA_struct_find_nr(fd->filesdna, "PreviewImage");
+
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
if (bhead->code == ENDB) {
break;
}
if (bhead->code == ofblocktype) {
+ BHead *id_bhead = bhead;
+
const char *name = blo_bhead_id_name(fd, bhead) + 2;
AssetMetaData *asset_meta_data = blo_bhead_id_asset_data_address(fd, bhead);
- const bool is_asset = asset_meta_data != NULL;
+ const bool is_asset = asset_meta_data != nullptr;
const bool skip_datablock = use_assets_only && !is_asset;
if (skip_datablock) {
continue;
}
- struct BLODataBlockInfo *info = MEM_mallocN(sizeof(*info), __func__);
+ struct BLODataBlockInfo *info = static_cast<BLODataBlockInfo *>(
+ MEM_mallocN(sizeof(*info), __func__));
/* Lastly, read asset data from the following blocks. */
if (asset_meta_data) {
@@ -165,6 +169,17 @@ LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh,
STRNCPY(info->name, name);
info->asset_data = asset_meta_data;
+ bool has_preview = false;
+ /* See if we can find a preview in the data of this ID. */
+ for (BHead *data_bhead = blo_bhead_next(fd, id_bhead); data_bhead->code == DATA;
+ data_bhead = blo_bhead_next(fd, data_bhead)) {
+ if (data_bhead->SDNAnr == sdna_nr_preview_image) {
+ has_preview = true;
+ break;
+ }
+ }
+ info->no_preview_found = !has_preview;
+
BLI_linklist_prepend(&infos, info);
tot++;
}
@@ -186,7 +201,7 @@ LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh,
* bhead is consumed. the new bhead is returned by this function.
* \param result: the Preview Image where the preview rect will be stored.
* \param preview_from_file: The read PreviewImage where the bhead points to. The rects of this
- * \return PreviewImage or NULL when no preview Images have been found. Caller owns the returned
+ * \return PreviewImage or nullptr when no preview Images have been found. Caller owns the returned
*/
static BHead *blo_blendhandle_read_preview_rects(FileData *fd,
BHead *bhead,
@@ -199,15 +214,16 @@ static BHead *blo_blendhandle_read_preview_rects(FileData *fd,
bhead = blo_bhead_next(fd, bhead);
BLI_assert((preview_from_file->w[preview_index] * preview_from_file->h[preview_index] *
sizeof(uint)) == bhead->len);
- result->rect[preview_index] = BLO_library_read_struct(fd, bhead, "PreviewImage Icon Rect");
+ result->rect[preview_index] = static_cast<uint *>(
+ BLO_library_read_struct(fd, bhead, "PreviewImage Icon Rect"));
}
else {
/* This should not be needed, but can happen in 'broken' .blend files,
* better handle this gracefully than crashing. */
- BLI_assert(preview_from_file->rect[preview_index] == NULL &&
+ BLI_assert(preview_from_file->rect[preview_index] == nullptr &&
preview_from_file->w[preview_index] == 0 &&
preview_from_file->h[preview_index] == 0);
- result->rect[preview_index] = NULL;
+ result->rect[preview_index] = nullptr;
result->w[preview_index] = result->h[preview_index] = 0;
}
BKE_previewimg_finish(result, preview_index);
@@ -227,13 +243,14 @@ PreviewImage *BLO_blendhandle_get_preview_for_id(BlendHandle *bh,
for (BHead *bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
if (bhead->code == DATA) {
if (looking && bhead->SDNAnr == sdna_preview_image) {
- PreviewImage *preview_from_file = BLO_library_read_struct(fd, bhead, "PreviewImage");
+ PreviewImage *preview_from_file = static_cast<PreviewImage *>(
+ BLO_library_read_struct(fd, bhead, "PreviewImage"));
- if (preview_from_file == NULL) {
+ if (preview_from_file == nullptr) {
break;
}
- PreviewImage *result = MEM_dupallocN(preview_from_file);
+ PreviewImage *result = static_cast<PreviewImage *>(MEM_dupallocN(preview_from_file));
bhead = blo_blendhandle_read_preview_rects(fd, bhead, result, preview_from_file);
MEM_freeN(preview_from_file);
return result;
@@ -252,17 +269,17 @@ PreviewImage *BLO_blendhandle_get_preview_for_id(BlendHandle *bh,
}
}
- return NULL;
+ return nullptr;
}
LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *r_tot_prev)
{
FileData *fd = (FileData *)bh;
- LinkNode *previews = NULL;
+ LinkNode *previews = nullptr;
BHead *bhead;
int looking = 0;
- PreviewImage *prv = NULL;
- PreviewImage *new_prv = NULL;
+ PreviewImage *prv = nullptr;
+ PreviewImage *new_prv = nullptr;
int tot = 0;
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
@@ -279,7 +296,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *r_
case ID_SCE: /* fall through */
case ID_AC: /* fall through */
case ID_NT: /* fall through */
- new_prv = MEM_callocN(sizeof(PreviewImage), "newpreview");
+ new_prv = static_cast<PreviewImage *>(MEM_callocN(sizeof(PreviewImage), "newpreview"));
BLI_linklist_prepend(&previews, new_prv);
tot++;
looking = 1;
@@ -291,7 +308,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *r_
else if (bhead->code == DATA) {
if (looking) {
if (bhead->SDNAnr == DNA_struct_find_nr(fd->filesdna, "PreviewImage")) {
- prv = BLO_library_read_struct(fd, bhead, "PreviewImage");
+ prv = static_cast<PreviewImage *>(BLO_library_read_struct(fd, bhead, "PreviewImage"));
if (prv) {
memcpy(new_prv, prv, sizeof(PreviewImage));
@@ -306,8 +323,8 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *r_
}
else {
looking = 0;
- new_prv = NULL;
- prv = NULL;
+ new_prv = nullptr;
+ prv = nullptr;
}
}
@@ -319,7 +336,7 @@ LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh)
{
FileData *fd = (FileData *)bh;
GSet *gathered = BLI_gset_ptr_new("linkable_groups gh");
- LinkNode *names = NULL;
+ LinkNode *names = nullptr;
BHead *bhead;
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
@@ -337,7 +354,7 @@ LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh)
}
}
- BLI_gset_free(gathered, NULL);
+ BLI_gset_free(gathered, nullptr);
return names;
}
@@ -355,7 +372,7 @@ BlendFileData *BLO_read_from_file(const char *filepath,
eBLOReadSkip skip_flags,
BlendFileReadReport *reports)
{
- BlendFileData *bfd = NULL;
+ BlendFileData *bfd = nullptr;
FileData *fd;
fd = blo_filedata_from_file(filepath, reports);
@@ -373,9 +390,10 @@ BlendFileData *BLO_read_from_memory(const void *mem,
eBLOReadSkip skip_flags,
ReportList *reports)
{
- BlendFileData *bfd = NULL;
+ BlendFileData *bfd = nullptr;
FileData *fd;
- BlendFileReadReport bf_reports = {.reports = reports};
+ BlendFileReadReport bf_reports{};
+ bf_reports.reports = reports;
fd = blo_filedata_from_memory(mem, memsize, &bf_reports);
if (fd) {
@@ -393,14 +411,15 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain,
const struct BlendFileReadParams *params,
ReportList *reports)
{
- BlendFileData *bfd = NULL;
+ BlendFileData *bfd = nullptr;
FileData *fd;
ListBase old_mainlist;
- BlendFileReadReport bf_reports = {.reports = reports};
+ BlendFileReadReport bf_reports{};
+ bf_reports.reports = reports;
fd = blo_filedata_from_memfile(memfile, params, &bf_reports);
if (fd) {
- fd->skip_flags = params->skip_flags;
+ fd->skip_flags = eBLOReadSkip(params->skip_flags);
BLI_strncpy(fd->relabase, filepath, sizeof(fd->relabase));
/* separate libraries from old main */
@@ -411,7 +430,7 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain,
if ((params->skip_flags & BLO_READ_SKIP_UNDO_OLD_MAIN) == 0) {
/* Build idmap of old main (we only care about local data here, so we can do that after
* split_main() call. */
- blo_make_old_idmap_from_main(fd, old_mainlist.first);
+ blo_make_old_idmap_from_main(fd, static_cast<Main *>(old_mainlist.first));
}
/* removed packed data from this trick - it's internal data that needs saves */
@@ -429,8 +448,8 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain,
* but oldmain itself shall *never* be 'transferred' to new mainlist! */
BLI_assert(old_mainlist.first == oldmain);
- /* That way, libs (aka mains) we did not reuse in new undone/redone state
- * will be cleared together with oldmain... */
+ /* That way, libraries (aka mains) we did not reuse in new undone/redone state
+ * will be cleared together with `oldmain`. */
blo_join_main(&old_mainlist);
blo_filedata_free(fd);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.cc
index f0d390677bb..ec1768232c8 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.cc
@@ -5,13 +5,14 @@
* \ingroup blenloader
*/
-#include <ctype.h> /* for isdigit. */
+#include <cctype> /* for isdigit. */
+#include <cerrno>
+#include <climits>
+#include <cstdarg> /* for va_start/end. */
+#include <cstddef> /* for offsetof. */
+#include <cstdlib> /* for atoi. */
+#include <ctime> /* for gmtime. */
#include <fcntl.h> /* for open flags (O_BINARY, O_RDONLY). */
-#include <limits.h>
-#include <stdarg.h> /* for va_start/end. */
-#include <stddef.h> /* for offsetof. */
-#include <stdlib.h> /* for atoi. */
-#include <time.h> /* for gmtime. */
#include "BLI_utildefines.h"
#ifndef WIN32
@@ -73,6 +74,7 @@
#include "BKE_main.h" /* for Main */
#include "BKE_main_idmap.h"
#include "BKE_material.h"
+#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_node.h" /* for tree type defines */
#include "BKE_object.h"
@@ -101,8 +103,6 @@
#include "readfile.h"
-#include <errno.h>
-
/* Make preferences read-only. */
#define U (*((const UserDef *)&U))
@@ -180,7 +180,7 @@ static void *read_struct(FileData *fd, BHead *bh, const char *blockname);
static BHead *find_bhead_from_code_name(FileData *fd, const short idcode, const char *name);
static BHead *find_bhead_from_idname(FileData *fd, const char *idname);
-typedef struct BHeadN {
+struct BHeadN {
struct BHeadN *next, *prev;
#ifdef USE_BHEAD_READ_ON_DEMAND
/** Use to read the data from the file directly into memory as needed. */
@@ -190,9 +190,9 @@ typedef struct BHeadN {
#endif
bool is_memchunk_identical;
struct BHead bhead;
-} BHeadN;
+};
-#define BHEADN_FROM_BHEAD(bh) ((BHeadN *)POINTER_OFFSET(bh, -(int)offsetof(BHeadN, bhead)))
+#define BHEADN_FROM_BHEAD(bh) ((BHeadN *)POINTER_OFFSET(bh, -int(offsetof(BHeadN, bhead))))
/**
* We could change this in the future, for now it's simplest if only data is delayed
@@ -229,14 +229,14 @@ static const char *library_parent_filepath(Library *lib)
/** \name OldNewMap API
* \{ */
-typedef struct OldNew {
+struct OldNew {
const void *oldp;
void *newp;
/* `nr` is "user count" for data, and ID code for libdata. */
int nr;
-} OldNew;
+};
-typedef struct OldNewMap {
+struct OldNewMap {
/* Array that stores the actual entries. */
OldNew *entries;
int nentries;
@@ -244,7 +244,7 @@ typedef struct OldNewMap {
int32_t *map;
int capacity_exp;
-} OldNewMap;
+};
#define ENTRIES_CAPACITY(onm) (1ll << (onm)->capacity_exp)
#define MAP_CAPACITY(onm) (1ll << ((onm)->capacity_exp + 1))
@@ -299,7 +299,7 @@ static OldNew *oldnewmap_lookup_entry(const OldNewMap *onm, const void *addr)
}
}
else {
- return NULL;
+ return nullptr;
}
}
}
@@ -312,8 +312,9 @@ static void oldnewmap_clear_map(OldNewMap *onm)
static void oldnewmap_increase_size(OldNewMap *onm)
{
onm->capacity_exp++;
- onm->entries = MEM_reallocN(onm->entries, sizeof(*onm->entries) * ENTRIES_CAPACITY(onm));
- onm->map = MEM_reallocN(onm->map, sizeof(*onm->map) * MAP_CAPACITY(onm));
+ onm->entries = static_cast<OldNew *>(
+ MEM_reallocN(onm->entries, sizeof(*onm->entries) * ENTRIES_CAPACITY(onm)));
+ onm->map = static_cast<int32_t *>(MEM_reallocN(onm->map, sizeof(*onm->map) * MAP_CAPACITY(onm)));
oldnewmap_clear_map(onm);
for (int i = 0; i < onm->nentries; i++) {
oldnewmap_insert_index_in_map(onm, onm->entries[i].oldp, i);
@@ -327,15 +328,16 @@ static void oldnewmap_init_data(OldNewMap *onm, const int capacity_exp)
memset(onm, 0x0, sizeof(*onm));
onm->capacity_exp = capacity_exp;
- onm->entries = MEM_malloc_arrayN(
- ENTRIES_CAPACITY(onm), sizeof(*onm->entries), "OldNewMap.entries");
- onm->map = MEM_malloc_arrayN(MAP_CAPACITY(onm), sizeof(*onm->map), "OldNewMap.map");
+ onm->entries = static_cast<OldNew *>(
+ MEM_malloc_arrayN(ENTRIES_CAPACITY(onm), sizeof(*onm->entries), "OldNewMap.entries"));
+ onm->map = static_cast<int32_t *>(
+ MEM_malloc_arrayN(MAP_CAPACITY(onm), sizeof(*onm->map), "OldNewMap.map"));
oldnewmap_clear_map(onm);
}
-static OldNewMap *oldnewmap_new(void)
+static OldNewMap *oldnewmap_new()
{
- OldNewMap *onm = MEM_mallocN(sizeof(*onm), "OldNewMap");
+ OldNewMap *onm = static_cast<OldNewMap *>(MEM_mallocN(sizeof(*onm), "OldNewMap"));
oldnewmap_init_data(onm, DEFAULT_SIZE_EXP);
@@ -344,7 +346,7 @@ static OldNewMap *oldnewmap_new(void)
static void oldnewmap_insert(OldNewMap *onm, const void *oldaddr, void *newaddr, int nr)
{
- if (oldaddr == NULL || newaddr == NULL) {
+ if (oldaddr == nullptr || newaddr == nullptr) {
return;
}
@@ -359,6 +361,11 @@ static void oldnewmap_insert(OldNewMap *onm, const void *oldaddr, void *newaddr,
oldnewmap_insert_or_replace(onm, entry);
}
+static void oldnewmap_lib_insert(FileData *fd, const void *oldaddr, ID *newaddr, int nr)
+{
+ oldnewmap_insert(fd->libmap, oldaddr, newaddr, nr);
+}
+
void blo_do_versions_oldnewmap_insert(OldNewMap *onm, const void *oldaddr, void *newaddr, int nr)
{
oldnewmap_insert(onm, oldaddr, newaddr, nr);
@@ -367,8 +374,8 @@ void blo_do_versions_oldnewmap_insert(OldNewMap *onm, const void *oldaddr, void
static void *oldnewmap_lookup_and_inc(OldNewMap *onm, const void *addr, bool increase_users)
{
OldNew *entry = oldnewmap_lookup_entry(onm, addr);
- if (entry == NULL) {
- return NULL;
+ if (entry == nullptr) {
+ return nullptr;
}
if (increase_users) {
entry->nr++;
@@ -379,18 +386,18 @@ static void *oldnewmap_lookup_and_inc(OldNewMap *onm, const void *addr, bool inc
/* for libdata, OldNew.nr has ID code, no increment */
static void *oldnewmap_liblookup(OldNewMap *onm, const void *addr, const void *lib)
{
- if (addr == NULL) {
- return NULL;
+ if (addr == nullptr) {
+ return nullptr;
}
- ID *id = oldnewmap_lookup_and_inc(onm, addr, false);
- if (id == NULL) {
- return NULL;
+ ID *id = static_cast<ID *>(oldnewmap_lookup_and_inc(onm, addr, false));
+ if (id == nullptr) {
+ return nullptr;
}
if (!lib || id->lib) {
return id;
}
- return NULL;
+ return nullptr;
}
static void oldnewmap_clear(OldNewMap *onm)
@@ -400,7 +407,7 @@ static void oldnewmap_clear(OldNewMap *onm)
OldNew *entry = &onm->entries[i];
if (entry->nr == 0) {
MEM_freeN(entry->newp);
- entry->newp = NULL;
+ entry->newp = nullptr;
}
}
@@ -446,12 +453,12 @@ void blo_join_main(ListBase *mainlist)
{
Main *tojoin, *mainl;
- mainl = mainlist->first;
+ mainl = static_cast<Main *>(mainlist->first);
- if (mainl->id_map != NULL) {
+ if (mainl->id_map != nullptr) {
/* Cannot keep this since we add some IDs from joined mains. */
BKE_main_idmap_destroy(mainl->id_map);
- mainl->id_map = NULL;
+ mainl->id_map = nullptr;
}
while ((tojoin = mainl->next)) {
@@ -463,11 +470,11 @@ void blo_join_main(ListBase *mainlist)
static void split_libdata(ListBase *lb_src, Main **lib_main_array, const uint lib_main_array_len)
{
- for (ID *id = lb_src->first, *idnext; id; id = idnext) {
- idnext = id->next;
+ for (ID *id = static_cast<ID *>(lb_src->first), *idnext; id; id = idnext) {
+ idnext = static_cast<ID *>(id->next);
if (id->lib) {
- if (((uint)id->lib->temp_index < lib_main_array_len) &&
+ if ((uint(id->lib->temp_index) < lib_main_array_len) &&
/* this check should never fail, just in case 'id->lib' is a dangling pointer. */
(lib_main_array[id->lib->temp_index]->curlib == id->lib)) {
Main *mainvar = lib_main_array[id->lib->temp_index];
@@ -485,24 +492,26 @@ static void split_libdata(ListBase *lb_src, Main **lib_main_array, const uint li
void blo_split_main(ListBase *mainlist, Main *main)
{
mainlist->first = mainlist->last = main;
- main->next = NULL;
+ main->next = nullptr;
if (BLI_listbase_is_empty(&main->libraries)) {
return;
}
- if (main->id_map != NULL) {
+ if (main->id_map != nullptr) {
/* Cannot keep this since we remove some IDs from given main. */
BKE_main_idmap_destroy(main->id_map);
- main->id_map = NULL;
+ main->id_map = nullptr;
}
/* (Library.temp_index -> Main), lookup table */
const uint lib_main_array_len = BLI_listbase_count(&main->libraries);
- Main **lib_main_array = MEM_malloc_arrayN(lib_main_array_len, sizeof(*lib_main_array), __func__);
+ Main **lib_main_array = static_cast<Main **>(
+ MEM_malloc_arrayN(lib_main_array_len, sizeof(*lib_main_array), __func__));
int i = 0;
- for (Library *lib = main->libraries.first; lib; lib = lib->id.next, i++) {
+ for (Library *lib = static_cast<Library *>(main->libraries.first); lib;
+ lib = static_cast<Library *>(lib->id.next), i++) {
Main *libmain = BKE_main_new();
libmain->curlib = lib;
libmain->versionfile = lib->versionfile;
@@ -515,9 +524,9 @@ void blo_split_main(ListBase *mainlist, Main *main)
ListBase *lbarray[INDEX_ID_MAX];
i = set_listbasepointers(main, lbarray);
while (i--) {
- ID *id = lbarray[i]->first;
- if (id == NULL || GS(id->name) == ID_LI) {
- /* No ID_LI data-lock should ever be linked anyway, but just in case, better be explicit. */
+ ID *id = static_cast<ID *>(lbarray[i]->first);
+ if (id == nullptr || GS(id->name) == ID_LI) {
+ /* No ID_LI data-block should ever be linked anyway, but just in case, better be explicit. */
continue;
}
split_libdata(lbarray[i], lib_main_array, lib_main_array_len);
@@ -532,7 +541,7 @@ static void read_file_version(FileData *fd, Main *main)
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
if (bhead->code == GLOB) {
- FileGlobal *fg = read_struct(fd, bhead, "Global");
+ FileGlobal *fg = static_cast<FileGlobal *>(read_struct(fd, bhead, "Global"));
if (fg) {
main->subversionfile = fg->subversion;
main->minversionfile = fg->minversion;
@@ -581,7 +590,7 @@ static void read_file_bhead_idname_map_create(FileData *fd)
if (code_prev != bhead->code) {
code_prev = bhead->code;
is_link = blo_bhead_is_id_valid_type(bhead) ?
- BKE_idtype_idcode_is_linkable((short)code_prev) :
+ BKE_idtype_idcode_is_linkable(short(code_prev)) :
false;
}
@@ -590,7 +599,7 @@ static void read_file_bhead_idname_map_create(FileData *fd)
}
}
- BLI_assert(fd->bhead_idname_hash == NULL);
+ BLI_assert(fd->bhead_idname_hash == nullptr);
fd->bhead_idname_hash = BLI_ghash_str_new_ex(__func__, reserve);
@@ -598,7 +607,7 @@ static void read_file_bhead_idname_map_create(FileData *fd)
if (code_prev != bhead->code) {
code_prev = bhead->code;
is_link = blo_bhead_is_id_valid_type(bhead) ?
- BKE_idtype_idcode_is_linkable((short)code_prev) :
+ BKE_idtype_idcode_is_linkable(short(code_prev)) :
false;
}
@@ -623,7 +632,7 @@ static Main *blo_find_main(FileData *fd, const char *filepath, const char *relab
// printf("blo_find_main: original in %s\n", filepath);
// printf("blo_find_main: converted to %s\n", name1);
- for (m = mainlist->first; m; m = m->next) {
+ for (m = static_cast<Main *>(mainlist->first); m; m = m->next) {
const char *libname = (m->curlib) ? m->curlib->filepath_abs : m->filepath;
if (BLI_path_cmp(name1, libname) == 0) {
@@ -639,7 +648,8 @@ static Main *blo_find_main(FileData *fd, const char *filepath, const char *relab
/* Add library data-block itself to 'main' Main, since libraries are **never** linked data.
* Fixes bug where you could end with all ID_LI data-blocks having the same name... */
- lib = BKE_libblock_alloc(mainlist->first, ID_LI, BLI_path_basename(filepath), 0);
+ lib = static_cast<Library *>(BKE_libblock_alloc(
+ static_cast<Main *>(mainlist->first), ID_LI, BLI_path_basename(filepath), 0));
/* Important, consistency with main ID reading code from read_libblock(). */
lib->id.us = ID_FAKE_USERS(lib);
@@ -666,19 +676,19 @@ static Main *blo_find_main(FileData *fd, const char *filepath, const char *relab
/** \name File Parsing
* \{ */
-typedef struct BlendDataReader {
+struct BlendDataReader {
FileData *fd;
-} BlendDataReader;
+};
-typedef struct BlendLibReader {
+struct BlendLibReader {
FileData *fd;
Main *main;
-} BlendLibReader;
+};
-typedef struct BlendExpander {
+struct BlendExpander {
FileData *fd;
Main *main;
-} BlendExpander;
+};
static void switch_endian_bh4(BHead4 *bhead)
{
@@ -727,7 +737,7 @@ static void bh4_from_bh8(BHead *bhead, BHead8 *bhead8, bool do_endian_swap)
/* this patch is to avoid `intptr_t` being read from not-eight aligned positions
* is necessary on any modern 64bit architecture) */
memcpy(&old, &bhead8->old, 8);
- bhead4->old = (int)(old >> 3);
+ bhead4->old = int(old >> 3);
bhead4->SDNAnr = bhead8->SDNAnr;
bhead4->nr = bhead8->nr;
@@ -750,7 +760,7 @@ static void bh8_from_bh4(BHead *bhead, BHead4 *bhead4)
static BHeadN *get_bhead(FileData *fd)
{
- BHeadN *new_bhead = NULL;
+ BHeadN *new_bhead = nullptr;
ssize_t readsize;
if (fd) {
@@ -827,11 +837,11 @@ static BHeadN *get_bhead(FileData *fd)
/* pass */
}
#ifdef USE_BHEAD_READ_ON_DEMAND
- else if (fd->file->seek != NULL && BHEAD_USE_READ_ON_DEMAND(&bhead)) {
+ else if (fd->file->seek != nullptr && BHEAD_USE_READ_ON_DEMAND(&bhead)) {
/* Delay reading bhead content. */
- new_bhead = MEM_mallocN(sizeof(BHeadN), "new_bhead");
+ new_bhead = static_cast<BHeadN *>(MEM_mallocN(sizeof(BHeadN), "new_bhead"));
if (new_bhead) {
- new_bhead->next = new_bhead->prev = NULL;
+ new_bhead->next = new_bhead->prev = nullptr;
new_bhead->file_offset = fd->file->offset;
new_bhead->has_data = false;
new_bhead->is_memchunk_identical = false;
@@ -840,7 +850,7 @@ static BHeadN *get_bhead(FileData *fd)
if (seek_new == -1) {
fd->is_eof = true;
MEM_freeN(new_bhead);
- new_bhead = NULL;
+ new_bhead = nullptr;
}
BLI_assert(fd->file->offset == seek_new);
}
@@ -850,9 +860,10 @@ static BHeadN *get_bhead(FileData *fd)
}
#endif
else {
- new_bhead = MEM_mallocN(sizeof(BHeadN) + (size_t)bhead.len, "new_bhead");
+ new_bhead = static_cast<BHeadN *>(
+ MEM_mallocN(sizeof(BHeadN) + size_t(bhead.len), "new_bhead"));
if (new_bhead) {
- new_bhead->next = new_bhead->prev = NULL;
+ new_bhead->next = new_bhead->prev = nullptr;
#ifdef USE_BHEAD_READ_ON_DEMAND
new_bhead->file_offset = 0; /* don't seek. */
new_bhead->has_data = true;
@@ -860,12 +871,12 @@ static BHeadN *get_bhead(FileData *fd)
new_bhead->is_memchunk_identical = false;
new_bhead->bhead = bhead;
- readsize = fd->file->read(fd->file, new_bhead + 1, (size_t)bhead.len);
+ readsize = fd->file->read(fd->file, new_bhead + 1, size_t(bhead.len));
if (readsize != bhead.len) {
fd->is_eof = true;
MEM_freeN(new_bhead);
- new_bhead = NULL;
+ new_bhead = nullptr;
}
if (fd->flags & FD_FLAGS_IS_MEMFILE) {
@@ -892,13 +903,13 @@ static BHeadN *get_bhead(FileData *fd)
BHead *blo_bhead_first(FileData *fd)
{
BHeadN *new_bhead;
- BHead *bhead = NULL;
+ BHead *bhead = nullptr;
/* Rewind the file
* Read in a new block if necessary
*/
- new_bhead = fd->bhead_list.first;
- if (new_bhead == NULL) {
+ new_bhead = static_cast<BHeadN *>(fd->bhead_list.first);
+ if (new_bhead == nullptr) {
new_bhead = get_bhead(fd);
}
@@ -909,18 +920,18 @@ BHead *blo_bhead_first(FileData *fd)
return bhead;
}
-BHead *blo_bhead_prev(FileData *UNUSED(fd), BHead *thisblock)
+BHead *blo_bhead_prev(FileData * /*fd*/, BHead *thisblock)
{
BHeadN *bheadn = BHEADN_FROM_BHEAD(thisblock);
BHeadN *prev = bheadn->prev;
- return (prev) ? &prev->bhead : NULL;
+ return (prev) ? &prev->bhead : nullptr;
}
BHead *blo_bhead_next(FileData *fd, BHead *thisblock)
{
- BHeadN *new_bhead = NULL;
- BHead *bhead = NULL;
+ BHeadN *new_bhead = nullptr;
+ BHead *bhead = nullptr;
if (thisblock) {
/* bhead is actually a sub part of BHeadN
@@ -929,7 +940,7 @@ BHead *blo_bhead_next(FileData *fd, BHead *thisblock)
/* get the next BHeadN. If it doesn't exist we read in the next one */
new_bhead = new_bhead->next;
- if (new_bhead == NULL) {
+ if (new_bhead == nullptr) {
new_bhead = get_bhead(fd);
}
}
@@ -954,7 +965,7 @@ static bool blo_bhead_read_data(FileData *fd, BHead *thisblock, void *buf)
success = false;
}
else {
- if (fd->file->read(fd->file, buf, (size_t)new_bhead->bhead.len) != new_bhead->bhead.len) {
+ if (fd->file->read(fd->file, buf, size_t(new_bhead->bhead.len)) != new_bhead->bhead.len) {
success = false;
}
if (fd->flags & FD_FLAGS_IS_MEMFILE) {
@@ -970,14 +981,15 @@ static bool blo_bhead_read_data(FileData *fd, BHead *thisblock, void *buf)
static BHead *blo_bhead_read_full(FileData *fd, BHead *thisblock)
{
BHeadN *new_bhead = BHEADN_FROM_BHEAD(thisblock);
- BHeadN *new_bhead_data = MEM_mallocN(sizeof(BHeadN) + new_bhead->bhead.len, "new_bhead");
+ BHeadN *new_bhead_data = static_cast<BHeadN *>(
+ MEM_mallocN(sizeof(BHeadN) + new_bhead->bhead.len, "new_bhead"));
new_bhead_data->bhead = new_bhead->bhead;
new_bhead_data->file_offset = new_bhead->file_offset;
new_bhead_data->has_data = true;
new_bhead_data->is_memchunk_identical = false;
if (!blo_bhead_read_data(fd, thisblock, new_bhead_data + 1)) {
MEM_freeN(new_bhead_data);
- return NULL;
+ return nullptr;
}
return &new_bhead_data->bhead;
}
@@ -993,7 +1005,7 @@ AssetMetaData *blo_bhead_id_asset_data_address(const FileData *fd, const BHead *
BLI_assert(blo_bhead_is_id_valid_type(bhead));
return (fd->id_asset_data_offset >= 0) ?
*(AssetMetaData **)POINTER_OFFSET(bhead, sizeof(*bhead) + fd->id_asset_data_offset) :
- NULL;
+ nullptr;
}
static void decode_blender_header(FileData *fd)
@@ -1053,7 +1065,7 @@ static bool read_file_dna(FileData *fd, const char **r_error_message)
}
/* 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];
+ FileGlobal *fg = reinterpret_cast<FileGlobal *>(&bhead[1]);
BLI_STATIC_ASSERT(offsetof(FileGlobal, subvstr) == 0, "Must be first: subvstr")
char num[5];
memcpy(num, fg->subvstr, 4);
@@ -1093,14 +1105,14 @@ static bool read_file_dna(FileData *fd, const char **r_error_message)
static int *read_file_thumbnail(FileData *fd)
{
BHead *bhead;
- int *blend_thumb = NULL;
+ int *blend_thumb = nullptr;
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
if (bhead->code == TEST) {
const bool do_endian_swap = (fd->flags & FD_FLAGS_SWITCH_ENDIAN) != 0;
int *data = (int *)(bhead + 1);
- if (bhead->len < (sizeof(int[2]))) {
+ if (bhead->len < sizeof(int[2])) {
break;
}
@@ -1138,9 +1150,9 @@ static int *read_file_thumbnail(FileData *fd)
static FileData *filedata_new(BlendFileReadReport *reports)
{
- BLI_assert(reports != NULL);
+ BLI_assert(reports != nullptr);
- FileData *fd = MEM_callocN(sizeof(FileData), "FileData");
+ FileData *fd = static_cast<FileData *>(MEM_callocN(sizeof(FileData), "FileData"));
fd->memsdna = DNA_sdna_current_get();
@@ -1158,19 +1170,19 @@ static FileData *blo_decode_and_check(FileData *fd, ReportList *reports)
decode_blender_header(fd);
if (fd->flags & FD_FLAGS_FILE_OK) {
- const char *error_message = NULL;
+ const char *error_message = nullptr;
if (read_file_dna(fd, &error_message) == false) {
BKE_reportf(
reports, RPT_ERROR, "Failed to read blend file '%s': %s", fd->relabase, error_message);
blo_filedata_free(fd);
- fd = NULL;
+ fd = nullptr;
}
}
else {
BKE_reportf(
reports, RPT_ERROR, "Failed to read blend file '%s', not a blend file", fd->relabase);
blo_filedata_free(fd);
- fd = NULL;
+ fd = nullptr;
}
return fd;
@@ -1182,11 +1194,11 @@ static FileData *blo_filedata_from_file_descriptor(const char *filepath,
{
char header[7];
FileReader *rawfile = BLI_filereader_new_file(filedes);
- FileReader *file = NULL;
+ FileReader *file = nullptr;
errno = 0;
/* If opening the file failed or we can't read the header, give up. */
- if (rawfile == NULL || rawfile->read(rawfile, header, sizeof(header)) != sizeof(header)) {
+ if (rawfile == nullptr || rawfile->read(rawfile, header, sizeof(header)) != sizeof(header)) {
BKE_reportf(reports->reports,
RPT_WARNING,
"Unable to read '%s': %s",
@@ -1198,7 +1210,7 @@ static FileData *blo_filedata_from_file_descriptor(const char *filepath,
else {
close(filedes);
}
- return NULL;
+ return nullptr;
}
/* Rewind the file after reading the header. */
@@ -1208,32 +1220,32 @@ static FileData *blo_filedata_from_file_descriptor(const char *filepath,
if (memcmp(header, "BLENDER", sizeof(header)) == 0) {
/* Try opening the file with memory-mapped IO. */
file = BLI_filereader_new_mmap(filedes);
- if (file == NULL) {
+ if (file == nullptr) {
/* mmap failed, so just keep using rawfile. */
file = rawfile;
- rawfile = NULL;
+ rawfile = nullptr;
}
}
else if (BLI_file_magic_is_gzip(header)) {
file = BLI_filereader_new_gzip(rawfile);
- if (file != NULL) {
- rawfile = NULL; /* The `Gzip` #FileReader takes ownership of `rawfile`. */
+ if (file != nullptr) {
+ rawfile = nullptr; /* The `Gzip` #FileReader takes ownership of `rawfile`. */
}
}
else if (BLI_file_magic_is_zstd(header)) {
file = BLI_filereader_new_zstd(rawfile);
- if (file != NULL) {
- rawfile = NULL; /* The `Zstd` #FileReader takes ownership of `rawfile`. */
+ if (file != nullptr) {
+ rawfile = nullptr; /* The `Zstd` #FileReader takes ownership of `rawfile`. */
}
}
/* Clean up `rawfile` if it wasn't taken over. */
- if (rawfile != NULL) {
+ if (rawfile != nullptr) {
rawfile->close(rawfile);
}
- if (file == NULL) {
+ if (file == nullptr) {
BKE_reportf(reports->reports, RPT_WARNING, "Unrecognized file format '%s'", filepath);
- return NULL;
+ return nullptr;
}
FileData *fd = filedata_new(reports);
@@ -1252,7 +1264,7 @@ static FileData *blo_filedata_from_file_open(const char *filepath, BlendFileRead
"Unable to open '%s': %s",
filepath,
errno ? strerror(errno) : TIP_("unknown error reading file"));
- return NULL;
+ return nullptr;
}
return blo_filedata_from_file_descriptor(filepath, reports, file);
}
@@ -1260,13 +1272,13 @@ static FileData *blo_filedata_from_file_open(const char *filepath, BlendFileRead
FileData *blo_filedata_from_file(const char *filepath, BlendFileReadReport *reports)
{
FileData *fd = blo_filedata_from_file_open(filepath, reports);
- if (fd != NULL) {
+ if (fd != nullptr) {
/* needed for library_append and read_libraries */
BLI_strncpy(fd->relabase, filepath, sizeof(fd->relabase));
return blo_decode_and_check(fd, reports->reports);
}
- return NULL;
+ return nullptr;
}
/**
@@ -1275,15 +1287,16 @@ FileData *blo_filedata_from_file(const char *filepath, BlendFileReadReport *repo
*/
static FileData *blo_filedata_from_file_minimal(const char *filepath)
{
- FileData *fd = blo_filedata_from_file_open(filepath, &(BlendFileReadReport){.reports = NULL});
- if (fd != NULL) {
+ BlendFileReadReport read_report{};
+ FileData *fd = blo_filedata_from_file_open(filepath, &read_report);
+ if (fd != nullptr) {
decode_blender_header(fd);
if (fd->flags & FD_FLAGS_FILE_OK) {
return fd;
}
blo_filedata_free(fd);
}
- return NULL;
+ return nullptr;
}
FileData *blo_filedata_from_memory(const void *mem, int memsize, BlendFileReadReport *reports)
@@ -1291,23 +1304,23 @@ FileData *blo_filedata_from_memory(const void *mem, int memsize, BlendFileReadRe
if (!mem || memsize < SIZEOFBLENDERHEADER) {
BKE_report(
reports->reports, RPT_WARNING, (mem) ? TIP_("Unable to read") : TIP_("Unable to open"));
- return NULL;
+ return nullptr;
}
FileReader *mem_file = BLI_filereader_new_memory(mem, memsize);
FileReader *file = mem_file;
- if (BLI_file_magic_is_gzip(mem)) {
+ if (BLI_file_magic_is_gzip(static_cast<const char *>(mem))) {
file = BLI_filereader_new_gzip(mem_file);
}
- else if (BLI_file_magic_is_zstd(mem)) {
+ else if (BLI_file_magic_is_zstd(static_cast<const char *>(mem))) {
file = BLI_filereader_new_zstd(mem_file);
}
- if (file == NULL) {
+ if (file == nullptr) {
/* Compression initialization failed. */
mem_file->close(mem_file);
- return NULL;
+ return nullptr;
}
FileData *fd = filedata_new(reports);
@@ -1317,12 +1330,12 @@ FileData *blo_filedata_from_memory(const void *mem, int memsize, BlendFileReadRe
}
FileData *blo_filedata_from_memfile(MemFile *memfile,
- const struct BlendFileReadParams *params,
+ const BlendFileReadParams *params,
BlendFileReadReport *reports)
{
if (!memfile) {
BKE_report(reports->reports, RPT_WARNING, "Unable to open blend <memory>");
- return NULL;
+ return nullptr;
}
FileData *fd = filedata_new(reports);
@@ -1343,7 +1356,7 @@ void blo_filedata_free(FileData *fd)
#else
/* Sanity check we're not keeping memory we don't need. */
LISTBASE_FOREACH_MUTABLE (BHeadN *, new_bhead, &fd->bhead_list) {
- if (fd->file->seek != NULL && BHEAD_USE_READ_ON_DEMAND(&new_bhead->bhead)) {
+ if (fd->file->seek != nullptr && BHEAD_USE_READ_ON_DEMAND(&new_bhead->bhead)) {
BLI_assert(new_bhead->has_data == 0);
}
MEM_freeN(new_bhead);
@@ -1373,7 +1386,7 @@ void blo_filedata_free(FileData *fd)
if (fd->libmap && !(fd->flags & FD_FLAGS_NOT_MY_LIBMAP)) {
oldnewmap_free(fd->libmap);
}
- if (fd->old_idmap != NULL) {
+ if (fd->old_idmap != nullptr) {
BKE_main_idmap_destroy(fd->old_idmap);
}
blo_cache_storage_end(fd);
@@ -1383,7 +1396,7 @@ void blo_filedata_free(FileData *fd)
#ifdef USE_GHASH_BHEAD
if (fd->bhead_idname_hash) {
- BLI_ghash_free(fd->bhead_idname_hash, NULL, NULL);
+ BLI_ghash_free(fd->bhead_idname_hash, nullptr, nullptr);
}
#endif
@@ -1399,7 +1412,7 @@ void blo_filedata_free(FileData *fd)
bool BLO_has_bfile_extension(const char *str)
{
- const char *ext_test[4] = {".blend", ".ble", ".blend.gz", NULL};
+ const char *ext_test[4] = {".blend", ".ble", ".blend.gz", nullptr};
return BLI_path_extension_check_array(str, ext_test);
}
@@ -1408,14 +1421,14 @@ bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, cha
/* We might get some data names with slashes,
* so we have to go up in path until we find blend file itself,
* then we know next path item is group, and everything else is data name. */
- char *slash = NULL, *prev_slash = NULL, c = '\0';
+ char *slash = nullptr, *prev_slash = nullptr, c = '\0';
r_dir[0] = '\0';
if (r_group) {
- *r_group = NULL;
+ *r_group = nullptr;
}
if (r_name) {
- *r_name = NULL;
+ *r_name = nullptr;
}
/* if path leads to an existing directory, we can be sure we're not (in) a library */
@@ -1466,18 +1479,18 @@ bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, cha
BlendThumbnail *BLO_thumbnail_from_file(const char *filepath)
{
FileData *fd;
- BlendThumbnail *data = NULL;
+ BlendThumbnail *data = nullptr;
int *fd_data;
fd = blo_filedata_from_file_minimal(filepath);
- fd_data = fd ? read_file_thumbnail(fd) : NULL;
+ fd_data = fd ? read_file_thumbnail(fd) : nullptr;
if (fd_data) {
const int width = fd_data[0];
const int height = fd_data[1];
if (BLEN_THUMB_MEMSIZE_IS_VALID(width, height)) {
const size_t data_size = BLEN_THUMB_MEMSIZE(width, height);
- data = MEM_mallocN(data_size, __func__);
+ data = static_cast<BlendThumbnail *>(MEM_mallocN(data_size, __func__));
if (data) {
BLI_assert((data_size - sizeof(*data)) ==
(BLEN_THUMB_MEMSIZE_FILE(width, height) - (sizeof(*fd_data) * 2)));
@@ -1538,15 +1551,17 @@ void *blo_do_versions_newlibadr(FileData *fd, const void *lib, const void *adr)
}
/* increases user number */
-static void change_link_placeholder_to_real_ID_pointer_fd(FileData *fd, const void *old, void *new)
+static void change_link_placeholder_to_real_ID_pointer_fd(FileData *fd,
+ const void *old,
+ void *newp)
{
for (int i = 0; i < fd->libmap->nentries; i++) {
OldNew *entry = &fd->libmap->entries[i];
if (old == entry->newp && entry->nr == ID_LINK_PLACEHOLDER) {
- entry->newp = new;
- if (new) {
- entry->nr = GS(((ID *)new)->name);
+ entry->newp = newp;
+ if (newp) {
+ entry->nr = GS(((ID *)newp)->name);
}
}
}
@@ -1555,7 +1570,7 @@ static void change_link_placeholder_to_real_ID_pointer_fd(FileData *fd, const vo
static void change_link_placeholder_to_real_ID_pointer(ListBase *mainlist,
FileData *basefd,
void *old,
- void *new)
+ void *newp)
{
LISTBASE_FOREACH (Main *, mainptr, mainlist) {
FileData *fd;
@@ -1568,7 +1583,7 @@ static void change_link_placeholder_to_real_ID_pointer(ListBase *mainlist,
}
if (fd) {
- change_link_placeholder_to_real_ID_pointer_fd(fd, old, new);
+ change_link_placeholder_to_real_ID_pointer_fd(fd, old, newp);
}
}
}
@@ -1630,32 +1645,32 @@ void blo_end_packed_pointer_map(FileData *fd, Main *oldmain)
/* used entries were restored, so we put them to zero */
for (int i = 0; i < fd->packedmap->nentries; i++, entry++) {
if (entry->nr > 0) {
- entry->newp = NULL;
+ entry->newp = nullptr;
}
}
LISTBASE_FOREACH (Image *, ima, &oldmain->images) {
- ima->packedfile = newpackedadr(fd, ima->packedfile);
+ ima->packedfile = static_cast<PackedFile *>(newpackedadr(fd, ima->packedfile));
LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) {
- imapf->packedfile = newpackedadr(fd, imapf->packedfile);
+ imapf->packedfile = static_cast<PackedFile *>(newpackedadr(fd, imapf->packedfile));
}
}
LISTBASE_FOREACH (VFont *, vfont, &oldmain->fonts) {
- vfont->packedfile = newpackedadr(fd, vfont->packedfile);
+ vfont->packedfile = static_cast<PackedFile *>(newpackedadr(fd, vfont->packedfile));
}
LISTBASE_FOREACH (bSound *, sound, &oldmain->sounds) {
- sound->packedfile = newpackedadr(fd, sound->packedfile);
+ sound->packedfile = static_cast<PackedFile *>(newpackedadr(fd, sound->packedfile));
}
LISTBASE_FOREACH (Library *, lib, &oldmain->libraries) {
- lib->packedfile = newpackedadr(fd, lib->packedfile);
+ lib->packedfile = static_cast<PackedFile *>(newpackedadr(fd, lib->packedfile));
}
LISTBASE_FOREACH (Volume *, volume, &oldmain->volumes) {
- volume->packedfile = newpackedadr(fd, volume->packedfile);
+ volume->packedfile = static_cast<PackedFile *>(newpackedadr(fd, volume->packedfile));
}
}
@@ -1667,7 +1682,7 @@ void blo_add_library_pointer_map(ListBase *old_mainlist, FileData *fd)
int i = set_listbasepointers(ptr, lbarray);
while (i--) {
LISTBASE_FOREACH (ID *, id, lbarray[i]) {
- oldnewmap_insert(fd->libmap, id, id, GS(id->name));
+ oldnewmap_lib_insert(fd, id, id, GS(id->name));
}
}
}
@@ -1677,36 +1692,37 @@ void blo_add_library_pointer_map(ListBase *old_mainlist, FileData *fd)
void blo_make_old_idmap_from_main(FileData *fd, Main *bmain)
{
- if (fd->old_idmap != NULL) {
+ if (fd->old_idmap != nullptr) {
BKE_main_idmap_destroy(fd->old_idmap);
}
- fd->old_idmap = BKE_main_idmap_create(bmain, false, NULL, MAIN_IDMAP_TYPE_UUID);
+ fd->old_idmap = BKE_main_idmap_create(bmain, false, nullptr, MAIN_IDMAP_TYPE_UUID);
}
-typedef struct BLOCacheStorage {
+struct BLOCacheStorage {
GHash *cache_map;
MemArena *memarena;
-} BLOCacheStorage;
+};
-typedef struct BLOCacheStorageValue {
+struct BLOCacheStorageValue {
void *cache_v;
uint new_usage_count;
-} BLOCacheStorageValue;
+};
/** Register a cache data entry to be preserved when reading some undo memfile. */
static void blo_cache_storage_entry_register(
- ID *id, const IDCacheKey *key, void **cache_p, uint UNUSED(flags), void *cache_storage_v)
+ ID *id, const IDCacheKey *key, void **cache_p, uint /*flags*/, void *cache_storage_v)
{
BLI_assert(key->id_session_uuid == id->session_uuid);
UNUSED_VARS_NDEBUG(id);
- BLOCacheStorage *cache_storage = cache_storage_v;
+ BLOCacheStorage *cache_storage = static_cast<BLOCacheStorage *>(cache_storage_v);
BLI_assert(!BLI_ghash_haskey(cache_storage->cache_map, key));
- IDCacheKey *storage_key = BLI_memarena_alloc(cache_storage->memarena, sizeof(*storage_key));
+ IDCacheKey *storage_key = static_cast<IDCacheKey *>(
+ BLI_memarena_alloc(cache_storage->memarena, sizeof(*storage_key)));
*storage_key = *key;
- BLOCacheStorageValue *storage_value = BLI_memarena_alloc(cache_storage->memarena,
- sizeof(*storage_value));
+ BLOCacheStorageValue *storage_value = static_cast<BLOCacheStorageValue *>(
+ BLI_memarena_alloc(cache_storage->memarena, sizeof(*storage_value)));
storage_value->cache_v = *cache_p;
storage_value->new_usage_count = 0;
BLI_ghash_insert(cache_storage->cache_map, storage_key, storage_value);
@@ -1714,23 +1730,24 @@ static void blo_cache_storage_entry_register(
/** 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, uint flags, void *cache_storage_v)
+ ID * /*id*/, const IDCacheKey *key, void **cache_p, uint flags, void *cache_storage_v)
{
- BLOCacheStorage *cache_storage = cache_storage_v;
+ BLOCacheStorage *cache_storage = static_cast<BLOCacheStorage *>(cache_storage_v);
- if (cache_storage == NULL) {
+ if (cache_storage == nullptr) {
/* In non-undo case, only clear the pointer if it is a purely runtime one.
* If it may be stored in a persistent way in the .blend file, direct_link code is responsible
* to properly deal with it. */
if ((flags & IDTYPE_CACHE_CB_FLAGS_PERSISTENT) == 0) {
- *cache_p = NULL;
+ *cache_p = nullptr;
}
return;
}
- BLOCacheStorageValue *storage_value = BLI_ghash_lookup(cache_storage->cache_map, key);
- if (storage_value == NULL) {
- *cache_p = NULL;
+ BLOCacheStorageValue *storage_value = static_cast<BLOCacheStorageValue *>(
+ BLI_ghash_lookup(cache_storage->cache_map, key));
+ if (storage_value == nullptr) {
+ *cache_p = nullptr;
return;
}
storage_value->new_usage_count++;
@@ -1738,23 +1755,21 @@ static void blo_cache_storage_entry_restore_in_new(
}
/** Clear as needed a cache data entry from old ID, when reading some undo memfile. */
-static void blo_cache_storage_entry_clear_in_old(ID *UNUSED(id),
- const IDCacheKey *key,
- void **cache_p,
- uint UNUSED(flags),
- void *cache_storage_v)
+static void blo_cache_storage_entry_clear_in_old(
+ ID * /*id*/, const IDCacheKey *key, void **cache_p, uint /*flags*/, void *cache_storage_v)
{
- BLOCacheStorage *cache_storage = cache_storage_v;
+ BLOCacheStorage *cache_storage = static_cast<BLOCacheStorage *>(cache_storage_v);
- BLOCacheStorageValue *storage_value = BLI_ghash_lookup(cache_storage->cache_map, key);
- if (storage_value == NULL) {
- *cache_p = NULL;
+ BLOCacheStorageValue *storage_value = static_cast<BLOCacheStorageValue *>(
+ BLI_ghash_lookup(cache_storage->cache_map, key));
+ if (storage_value == nullptr) {
+ *cache_p = nullptr;
return;
}
/* If that cache has been restored into some new ID, we want to remove it from old one, otherwise
* keep it there so that it gets properly freed together with its ID. */
if (storage_value->new_usage_count != 0) {
- *cache_p = NULL;
+ *cache_p = nullptr;
}
else {
BLI_assert(*cache_p == storage_value->cache_v);
@@ -1764,21 +1779,22 @@ static void blo_cache_storage_entry_clear_in_old(ID *UNUSED(id),
void blo_cache_storage_init(FileData *fd, Main *bmain)
{
if (fd->flags & FD_FLAGS_IS_MEMFILE) {
- BLI_assert(fd->cache_storage == NULL);
- fd->cache_storage = MEM_mallocN(sizeof(*fd->cache_storage), __func__);
+ BLI_assert(fd->cache_storage == nullptr);
+ fd->cache_storage = static_cast<BLOCacheStorage *>(
+ MEM_mallocN(sizeof(*fd->cache_storage), __func__));
fd->cache_storage->memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
fd->cache_storage->cache_map = BLI_ghash_new(
BKE_idtype_cache_key_hash, BKE_idtype_cache_key_cmp, __func__);
ListBase *lb;
FOREACH_MAIN_LISTBASE_BEGIN (bmain, lb) {
- ID *id = lb->first;
- if (id == NULL) {
+ ID *id = static_cast<ID *>(lb->first);
+ if (id == nullptr) {
continue;
}
const IDTypeInfo *type_info = BKE_idtype_get_info_from_id(id);
- if (type_info->foreach_cache == NULL) {
+ if (type_info->foreach_cache == nullptr) {
continue;
}
@@ -1793,22 +1809,22 @@ void blo_cache_storage_init(FileData *fd, Main *bmain)
FOREACH_MAIN_LISTBASE_END;
}
else {
- fd->cache_storage = NULL;
+ fd->cache_storage = nullptr;
}
}
void blo_cache_storage_old_bmain_clear(FileData *fd, Main *bmain_old)
{
- if (fd->cache_storage != NULL) {
+ if (fd->cache_storage != nullptr) {
ListBase *lb;
FOREACH_MAIN_LISTBASE_BEGIN (bmain_old, lb) {
- ID *id = lb->first;
- if (id == NULL) {
+ ID *id = static_cast<ID *>(lb->first);
+ if (id == nullptr) {
continue;
}
const IDTypeInfo *type_info = BKE_idtype_get_info_from_id(id);
- if (type_info->foreach_cache == NULL) {
+ if (type_info->foreach_cache == nullptr) {
continue;
}
@@ -1826,11 +1842,11 @@ void blo_cache_storage_old_bmain_clear(FileData *fd, Main *bmain_old)
void blo_cache_storage_end(FileData *fd)
{
- if (fd->cache_storage != NULL) {
- BLI_ghash_free(fd->cache_storage->cache_map, NULL, NULL);
+ if (fd->cache_storage != nullptr) {
+ BLI_ghash_free(fd->cache_storage->cache_map, nullptr, nullptr);
BLI_memarena_free(fd->cache_storage->memarena);
MEM_freeN(fd->cache_storage);
- fd->cache_storage = NULL;
+ fd->cache_storage = nullptr;
}
}
@@ -1840,7 +1856,7 @@ void blo_cache_storage_end(FileData *fd)
/** \name DNA Struct Loading
* \{ */
-static void switch_endian_structs(const struct SDNA *filesdna, BHead *bhead)
+static void switch_endian_structs(const SDNA *filesdna, BHead *bhead)
{
int blocksize, nblocks;
char *data;
@@ -1858,7 +1874,7 @@ static void switch_endian_structs(const struct SDNA *filesdna, BHead *bhead)
static void *read_struct(FileData *fd, BHead *bh, const char *blockname)
{
- void *temp = NULL;
+ void *temp = nullptr;
if (bh->len) {
#ifdef USE_BHEAD_READ_ON_DEMAND
@@ -1870,9 +1886,9 @@ static void *read_struct(FileData *fd, BHead *bh, const char *blockname)
#ifdef USE_BHEAD_READ_ON_DEMAND
if (BHEADN_FROM_BHEAD(bh)->has_data == false) {
bh = blo_bhead_read_full(fd, bh);
- if (UNLIKELY(bh == NULL)) {
+ if (UNLIKELY(bh == nullptr)) {
fd->flags &= ~FD_FLAGS_FILE_OK;
- return NULL;
+ return nullptr;
}
}
#endif
@@ -1884,9 +1900,9 @@ static void *read_struct(FileData *fd, BHead *bh, const char *blockname)
#ifdef USE_BHEAD_READ_ON_DEMAND
if (BHEADN_FROM_BHEAD(bh)->has_data == false) {
bh = blo_bhead_read_full(fd, bh);
- if (UNLIKELY(bh == NULL)) {
+ if (UNLIKELY(bh == nullptr)) {
fd->flags &= ~FD_FLAGS_FILE_OK;
- return NULL;
+ return nullptr;
}
}
#endif
@@ -1905,7 +1921,7 @@ static void *read_struct(FileData *fd, BHead *bh, const char *blockname)
if (UNLIKELY(!blo_bhead_read_data(fd, bh, temp))) {
fd->flags &= ~FD_FLAGS_FILE_OK;
MEM_freeN(temp);
- temp = NULL;
+ temp = nullptr;
}
}
#else
@@ -1930,7 +1946,7 @@ static const void *peek_struct_undo(FileData *fd, BHead *bhead)
{
BLI_assert(fd->flags & FD_FLAGS_IS_MEMFILE);
UNUSED_VARS_NDEBUG(fd);
- return (bhead->len) ? (const void *)(bhead + 1) : NULL;
+ return (bhead->len) ? (const void *)(bhead + 1) : nullptr;
}
static void link_glob_list(FileData *fd, ListBase *lb) /* for glob data */
@@ -1947,14 +1963,14 @@ static void link_glob_list(FileData *fd, ListBase *lb) /* for glob data */
}
lb->first = poin;
- ln = lb->first;
- prev = NULL;
+ ln = static_cast<Link *>(lb->first);
+ prev = nullptr;
while (ln) {
poin = newdataadr(fd, ln->next);
if (ln->next) {
oldnewmap_insert(fd->globmap, ln->next, poin, 0);
}
- ln->next = poin;
+ ln->next = static_cast<Link *>(poin);
ln->prev = prev;
prev = ln;
ln = ln->next;
@@ -1975,14 +1991,14 @@ static void lib_link_id_embedded_id(BlendLibReader *reader, ID *id)
/* Handle 'private IDs'. */
bNodeTree *nodetree = ntreeFromID(id);
- if (nodetree != NULL) {
+ if (nodetree != nullptr) {
lib_link_id(reader, &nodetree->id);
ntreeBlendReadLib(reader, nodetree);
}
if (GS(id->name) == ID_SCE) {
Scene *scene = (Scene *)id;
- if (scene->master_collection != NULL) {
+ if (scene->master_collection != nullptr) {
lib_link_id(reader, &scene->master_collection->id);
BKE_collection_blend_read_lib(reader, scene->master_collection);
}
@@ -1991,12 +2007,12 @@ static void lib_link_id_embedded_id(BlendLibReader *reader, ID *id)
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_BlendReadLib(reader, id->properties);
+ /* NOTE: WM IDProperties are never written to file, hence they should always be nullptr here. */
+ BLI_assert((GS(id->name) != ID_WM) || id->properties == nullptr);
+ IDP_BlendReadLib(reader, id->lib, id->properties);
AnimData *adt = BKE_animdata_from_id(id);
- if (adt != NULL) {
+ if (adt != nullptr) {
BKE_animdata_blend_read_lib(reader, id, adt);
}
@@ -2011,7 +2027,8 @@ static void lib_link_id(BlendLibReader *reader, ID *id)
static void direct_link_id_override_property_operation_cb(BlendDataReader *reader, void *data)
{
- IDOverrideLibraryPropertyOperation *opop = data;
+ IDOverrideLibraryPropertyOperation *opop = static_cast<IDOverrideLibraryPropertyOperation *>(
+ data);
BLO_read_data_address(reader, &opop->subitem_reference_name);
BLO_read_data_address(reader, &opop->subitem_local_name);
@@ -2021,7 +2038,7 @@ static void direct_link_id_override_property_operation_cb(BlendDataReader *reade
static void direct_link_id_override_property_cb(BlendDataReader *reader, void *data)
{
- IDOverrideLibraryProperty *op = data;
+ IDOverrideLibraryProperty *op = static_cast<IDOverrideLibraryProperty *>(data);
BLO_read_data_address(reader, &op->rna_path);
@@ -2040,26 +2057,27 @@ static void direct_link_id_embedded_id(BlendDataReader *reader,
{
/* Handle 'private IDs'. */
bNodeTree **nodetree = BKE_ntree_ptr_from_id(id);
- if (nodetree != NULL && *nodetree != NULL) {
+ if (nodetree != nullptr && *nodetree != nullptr) {
BLO_read_data_address(reader, nodetree);
direct_link_id_common(reader,
current_library,
(ID *)*nodetree,
- id_old != NULL ? (ID *)ntreeFromID(id_old) : NULL,
+ id_old != nullptr ? (ID *)ntreeFromID(id_old) : nullptr,
0);
- ntreeBlendReadData(reader, *nodetree);
+ ntreeBlendReadData(reader, id, *nodetree);
}
if (GS(id->name) == ID_SCE) {
Scene *scene = (Scene *)id;
- if (scene->master_collection != NULL) {
+ if (scene->master_collection != nullptr) {
BLO_read_data_address(reader, &scene->master_collection);
direct_link_id_common(reader,
current_library,
&scene->master_collection->id,
- id_old != NULL ? &((Scene *)id_old)->master_collection->id : NULL,
+ id_old != nullptr ? &((Scene *)id_old)->master_collection->id :
+ nullptr,
0);
- BKE_collection_blend_read_data(reader, scene->master_collection);
+ BKE_collection_blend_read_data(reader, scene->master_collection, &scene->id);
}
}
}
@@ -2085,7 +2103,7 @@ static int direct_link_id_restore_recalc(const FileData *fd,
* flush back changes to the original datablock. */
int recalc = id_target->recalc;
- if (id_current == NULL) {
+ if (id_current == nullptr) {
/* ID does not currently exist in the database, so also will not exist in
* the dependency graphs. That means it will be newly created and as a
* result also fully re-evaluated regardless of the recalc flag set here. */
@@ -2137,15 +2155,15 @@ static void direct_link_id_common(
id->lib = current_library;
id->us = ID_FAKE_USERS(id);
id->icon_id = 0;
- id->newid = NULL; /* Needed because .blend may have been saved with crap value here... */
- id->orig_id = NULL;
- id->py_instance = NULL;
+ id->newid = nullptr; /* Needed because .blend may have been saved with crap value here... */
+ id->orig_id = nullptr;
+ id->py_instance = nullptr;
/* Initialize with provided tag. */
id->tag = tag;
if (ID_IS_LINKED(id)) {
- id->library_weak_reference = NULL;
+ id->library_weak_reference = nullptr;
}
else {
BLO_read_data_address(reader, &id->library_weak_reference);
@@ -2195,10 +2213,10 @@ static void direct_link_id_common(
if (id->override_library) {
BLO_read_data_address(reader, &id->override_library);
/* Work around file corruption on writing, see T86853. */
- if (id->override_library != NULL) {
+ if (id->override_library != nullptr) {
BLO_read_list_cb(
reader, &id->override_library->properties, direct_link_id_override_property_cb);
- id->override_library->runtime = NULL;
+ id->override_library->runtime = nullptr;
}
}
@@ -2239,14 +2257,14 @@ void blo_do_versions_key_uidgen(Key *key)
#ifdef USE_SETSCENE_CHECK
/**
- * A version of #BKE_scene_validate_setscene with special checks for linked libs.
+ * A version of #BKE_scene_validate_setscene with special checks for linked libraries.
*/
static bool scene_validate_setscene__liblink(Scene *sce, const int totscene)
{
Scene *sce_iter;
int a;
- if (sce->set == NULL) {
+ if (sce->set == nullptr) {
return true;
}
@@ -2264,7 +2282,7 @@ static bool scene_validate_setscene__liblink(Scene *sce, const int totscene)
}
if (a > totscene) {
- sce->set = NULL;
+ sce->set = nullptr;
return false;
}
}
@@ -2299,10 +2317,10 @@ static void lib_link_scenes_check_set(Main *bmain)
* \{ */
/* how to handle user count on pointer restore */
-typedef enum ePointerUserMode {
+enum ePointerUserMode {
USER_IGNORE = 0, /* ignore user count */
USER_REAL = 1, /* ensure at least one real user (fake user ignored) */
-} ePointerUserMode;
+};
static void restore_pointer_user(ID *id, ID *newid, ePointerUserMode user)
{
@@ -2338,7 +2356,7 @@ static void *restore_pointer_by_name_main(Main *mainp, ID *id, ePointerUserMode
return idn;
}
}
- return NULL;
+ return nullptr;
}
#endif
@@ -2352,7 +2370,7 @@ static void *restore_pointer_by_name_main(Main *mainp, ID *id, ePointerUserMode
* this could be made an optional argument (falling back to a full lookup),
* however at the moment it's always available.
*/
-static void *restore_pointer_by_name(struct IDNameLib_Map *id_map, ID *id, ePointerUserMode user)
+static void *restore_pointer_by_name(IDNameLib_Map *id_map, ID *id, ePointerUserMode user)
{
#ifdef USE_GHASH_RESTORE_POINTER
if (id) {
@@ -2363,24 +2381,24 @@ static void *restore_pointer_by_name(struct IDNameLib_Map *id_map, ID *id, ePoin
}
return idn;
}
- return NULL;
+ return nullptr;
#else
Main *mainp = BKE_main_idmap_main_get(id_map);
return restore_pointer_by_name_main(mainp, id, user);
#endif
}
-static void lib_link_seq_clipboard_pt_restore(ID *id, struct IDNameLib_Map *id_map)
+static void lib_link_seq_clipboard_pt_restore(ID *id, IDNameLib_Map *id_map)
{
if (id) {
/* clipboard must ensure this */
- BLI_assert(id->newid != NULL);
- id->newid = restore_pointer_by_name(id_map, id->newid, USER_REAL);
+ BLI_assert(id->newid != nullptr);
+ id->newid = static_cast<ID *>(restore_pointer_by_name(id_map, id->newid, USER_REAL));
}
}
static bool lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt)
{
- struct IDNameLib_Map *id_map = arg_pt;
+ IDNameLib_Map *id_map = static_cast<IDNameLib_Map *>(arg_pt);
lib_link_seq_clipboard_pt_restore((ID *)seq->scene, id_map);
lib_link_seq_clipboard_pt_restore((ID *)seq->scene_camera, id_map);
@@ -2390,7 +2408,7 @@ static bool lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt)
return true;
}
-static void lib_link_clipboard_restore(struct IDNameLib_Map *id_map)
+static void lib_link_clipboard_restore(IDNameLib_Map *id_map)
{
/* update IDs stored in sequencer clipboard */
SEQ_for_each_callback(&seqbase_clipboard, lib_link_seq_clipboard_cb, id_map);
@@ -2400,7 +2418,7 @@ static int lib_link_main_data_restore_cb(LibraryIDLinkCallbackData *cb_data)
{
const int cb_flag = cb_data->cb_flag;
ID **id_pointer = cb_data->id_pointer;
- if (cb_flag & IDWALK_CB_EMBEDDED || *id_pointer == NULL) {
+ if (cb_flag & IDWALK_CB_EMBEDDED || *id_pointer == nullptr) {
return IDWALK_RET_NOP;
}
@@ -2417,18 +2435,18 @@ static int lib_link_main_data_restore_cb(LibraryIDLinkCallbackData *cb_data)
}
}
- struct IDNameLib_Map *id_map = cb_data->user_data;
+ IDNameLib_Map *id_map = static_cast<IDNameLib_Map *>(cb_data->user_data);
- /* NOTE: Handling of usercount here is really bad, defining its own system...
+ /* NOTE: Handling of user-count here is really bad, defining its own system...
* Will have to be refactored at some point, but that is not top priority task for now.
* And all user-counts are properly recomputed at the end of the undo management code anyway. */
- *id_pointer = restore_pointer_by_name(
- id_map, *id_pointer, (cb_flag & IDWALK_CB_USER_ONE) ? USER_REAL : USER_IGNORE);
+ *id_pointer = static_cast<ID *>(restore_pointer_by_name(
+ id_map, *id_pointer, (cb_flag & IDWALK_CB_USER_ONE) ? USER_REAL : USER_IGNORE));
return IDWALK_RET_NOP;
}
-static void lib_link_main_data_restore(struct IDNameLib_Map *id_map, Main *newmain)
+static void lib_link_main_data_restore(IDNameLib_Map *id_map, Main *newmain)
{
ID *id;
FOREACH_MAIN_ID_BEGIN (newmain, id) {
@@ -2437,10 +2455,10 @@ static void lib_link_main_data_restore(struct IDNameLib_Map *id_map, Main *newma
FOREACH_MAIN_ID_END;
}
-static void lib_link_wm_xr_data_restore(struct IDNameLib_Map *id_map, wmXrData *xr_data)
+static void lib_link_wm_xr_data_restore(IDNameLib_Map *id_map, wmXrData *xr_data)
{
- xr_data->session_settings.base_pose_object = restore_pointer_by_name(
- id_map, (ID *)xr_data->session_settings.base_pose_object, USER_REAL);
+ xr_data->session_settings.base_pose_object = static_cast<Object *>(restore_pointer_by_name(
+ id_map, (ID *)xr_data->session_settings.base_pose_object, USER_REAL));
}
static void lib_link_window_scene_data_restore(wmWindow *win, Scene *scene, ViewLayer *view_layer)
@@ -2452,25 +2470,26 @@ static void lib_link_window_scene_data_restore(wmWindow *win, Scene *scene, View
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
- if (v3d->camera == NULL || v3d->scenelock) {
+ if (v3d->camera == nullptr || v3d->scenelock) {
v3d->camera = scene->camera;
}
if (v3d->localvd) {
- Base *base = NULL;
+ Base *base = nullptr;
v3d->localvd->camera = scene->camera;
/* Local-view can become invalid during undo/redo steps,
* so we exit it when no could be found. */
- for (base = view_layer->object_bases.first; base; base = base->next) {
+ for (base = static_cast<Base *>(view_layer->object_bases.first); base;
+ base = base->next) {
if (base->local_view_bits & v3d->local_view_uuid) {
break;
}
}
- if (base == NULL) {
+ if (base == nullptr) {
MEM_freeN(v3d->localvd);
- v3d->localvd = NULL;
+ v3d->localvd = nullptr;
v3d->local_view_uuid = 0;
/* Region-base storage is different depending if the space is active. */
@@ -2478,10 +2497,10 @@ static void lib_link_window_scene_data_restore(wmWindow *win, Scene *scene, View
&sl->regionbase;
LISTBASE_FOREACH (ARegion *, region, regionbase) {
if (region->regiontype == RGN_TYPE_WINDOW) {
- RegionView3D *rv3d = region->regiondata;
+ RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
if (rv3d->localvd) {
MEM_freeN(rv3d->localvd);
- rv3d->localvd = NULL;
+ rv3d->localvd = nullptr;
}
}
}
@@ -2492,7 +2511,18 @@ static void lib_link_window_scene_data_restore(wmWindow *win, Scene *scene, View
}
}
-static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map,
+static void lib_link_restore_viewer_path(IDNameLib_Map *id_map, ViewerPath *viewer_path)
+{
+ LISTBASE_FOREACH (ViewerPathElem *, elem, &viewer_path->path) {
+ if (elem->type == VIEWER_PATH_ELEM_TYPE_ID) {
+ IDViewerPathElem *typed_elem = reinterpret_cast<IDViewerPathElem *>(elem);
+ typed_elem->id = static_cast<ID *>(
+ restore_pointer_by_name(id_map, (ID *)typed_elem->id, USER_IGNORE));
+ }
+ }
+}
+
+static void lib_link_workspace_layout_restore(IDNameLib_Map *id_map,
Main *newmain,
WorkSpaceLayout *layout)
{
@@ -2505,19 +2535,24 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map,
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
- v3d->camera = restore_pointer_by_name(id_map, (ID *)v3d->camera, USER_REAL);
- v3d->ob_center = restore_pointer_by_name(id_map, (ID *)v3d->ob_center, USER_REAL);
+ v3d->camera = static_cast<Object *>(
+ restore_pointer_by_name(id_map, (ID *)v3d->camera, USER_REAL));
+ v3d->ob_center = static_cast<Object *>(
+ restore_pointer_by_name(id_map, (ID *)v3d->ob_center, USER_REAL));
+
+ lib_link_restore_viewer_path(id_map, &v3d->viewer_path);
}
else if (sl->spacetype == SPACE_GRAPH) {
SpaceGraph *sipo = (SpaceGraph *)sl;
bDopeSheet *ads = sipo->ads;
if (ads) {
- ads->source = restore_pointer_by_name(id_map, (ID *)ads->source, USER_REAL);
+ ads->source = static_cast<ID *>(
+ restore_pointer_by_name(id_map, (ID *)ads->source, USER_REAL));
if (ads->filter_grp) {
- ads->filter_grp = restore_pointer_by_name(
- id_map, (ID *)ads->filter_grp, USER_IGNORE);
+ ads->filter_grp = static_cast<Collection *>(
+ restore_pointer_by_name(id_map, (ID *)ads->filter_grp, USER_IGNORE));
}
}
@@ -2528,8 +2563,9 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map,
}
else if (sl->spacetype == SPACE_PROPERTIES) {
SpaceProperties *sbuts = (SpaceProperties *)sl;
- sbuts->pinid = restore_pointer_by_name(id_map, sbuts->pinid, USER_IGNORE);
- if (sbuts->pinid == NULL) {
+ sbuts->pinid = static_cast<ID *>(
+ restore_pointer_by_name(id_map, sbuts->pinid, USER_IGNORE));
+ if (sbuts->pinid == nullptr) {
sbuts->flag &= ~SB_PIN_CONTEXT;
}
@@ -2539,19 +2575,20 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map,
}
else if (sl->spacetype == SPACE_FILE) {
SpaceFile *sfile = (SpaceFile *)sl;
- sfile->op = NULL;
+ sfile->op = nullptr;
sfile->tags = FILE_TAG_REBUILD_MAIN_FILES;
}
else if (sl->spacetype == SPACE_ACTION) {
SpaceAction *saction = (SpaceAction *)sl;
- saction->action = restore_pointer_by_name(id_map, (ID *)saction->action, USER_REAL);
- saction->ads.source = restore_pointer_by_name(
- id_map, (ID *)saction->ads.source, USER_REAL);
+ saction->action = static_cast<bAction *>(
+ restore_pointer_by_name(id_map, (ID *)saction->action, USER_REAL));
+ saction->ads.source = static_cast<ID *>(
+ restore_pointer_by_name(id_map, (ID *)saction->ads.source, USER_REAL));
if (saction->ads.filter_grp) {
- saction->ads.filter_grp = restore_pointer_by_name(
- id_map, (ID *)saction->ads.filter_grp, USER_IGNORE);
+ saction->ads.filter_grp = static_cast<Collection *>(
+ restore_pointer_by_name(id_map, (ID *)saction->ads.filter_grp, USER_IGNORE));
}
/* force recalc of list of channels, potentially updating the active action
@@ -2562,11 +2599,12 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map,
else if (sl->spacetype == SPACE_IMAGE) {
SpaceImage *sima = (SpaceImage *)sl;
- sima->image = restore_pointer_by_name(id_map, (ID *)sima->image, USER_REAL);
+ sima->image = static_cast<Image *>(
+ restore_pointer_by_name(id_map, (ID *)sima->image, USER_REAL));
/* this will be freed, not worth attempting to find same scene,
* since it gets initialized later */
- sima->iuser.scene = NULL;
+ sima->iuser.scene = nullptr;
#if 0
/* Those are allocated and freed by space code, no need to handle them here. */
@@ -2580,9 +2618,10 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map,
/* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
* so assume that here we're doing for undo only...
*/
- sima->gpd = restore_pointer_by_name(id_map, (ID *)sima->gpd, USER_REAL);
- sima->mask_info.mask = restore_pointer_by_name(
- id_map, (ID *)sima->mask_info.mask, USER_REAL);
+ sima->gpd = static_cast<bGPdata *>(
+ restore_pointer_by_name(id_map, (ID *)sima->gpd, USER_REAL));
+ sima->mask_info.mask = static_cast<Mask *>(
+ restore_pointer_by_name(id_map, (ID *)sima->mask_info.mask, USER_REAL));
}
else if (sl->spacetype == SPACE_SEQ) {
SpaceSeq *sseq = (SpaceSeq *)sl;
@@ -2590,35 +2629,39 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map,
/* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
* so assume that here we're doing for undo only...
*/
- sseq->gpd = restore_pointer_by_name(id_map, (ID *)sseq->gpd, USER_REAL);
+ sseq->gpd = static_cast<bGPdata *>(
+ restore_pointer_by_name(id_map, (ID *)sseq->gpd, USER_REAL));
}
else if (sl->spacetype == SPACE_NLA) {
SpaceNla *snla = (SpaceNla *)sl;
bDopeSheet *ads = snla->ads;
if (ads) {
- ads->source = restore_pointer_by_name(id_map, (ID *)ads->source, USER_REAL);
+ ads->source = static_cast<ID *>(
+ restore_pointer_by_name(id_map, (ID *)ads->source, USER_REAL));
if (ads->filter_grp) {
- ads->filter_grp = restore_pointer_by_name(
- id_map, (ID *)ads->filter_grp, USER_IGNORE);
+ ads->filter_grp = static_cast<Collection *>(
+ restore_pointer_by_name(id_map, (ID *)ads->filter_grp, USER_IGNORE));
}
}
}
else if (sl->spacetype == SPACE_TEXT) {
SpaceText *st = (SpaceText *)sl;
- st->text = restore_pointer_by_name(id_map, (ID *)st->text, USER_IGNORE);
- if (st->text == NULL) {
- st->text = newmain->texts.first;
+ st->text = static_cast<Text *>(
+ restore_pointer_by_name(id_map, (ID *)st->text, USER_IGNORE));
+ if (st->text == nullptr) {
+ st->text = static_cast<Text *>(newmain->texts.first);
}
}
else if (sl->spacetype == SPACE_SCRIPT) {
SpaceScript *scpt = (SpaceScript *)sl;
- scpt->script = restore_pointer_by_name(id_map, (ID *)scpt->script, USER_REAL);
+ scpt->script = static_cast<Script *>(
+ restore_pointer_by_name(id_map, (ID *)scpt->script, USER_REAL));
- // screen->script = NULL; /* 2.45 set to null, better re-run the script. */
+ // screen->script = nullptr; /* 2.45 set to null, better re-run the script. */
if (scpt->script) {
SCRIPT_SET_NULL(scpt->script);
}
@@ -2626,22 +2669,20 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map,
else if (sl->spacetype == SPACE_OUTLINER) {
SpaceOutliner *space_outliner = (SpaceOutliner *)sl;
- space_outliner->search_tse.id = restore_pointer_by_name(
- id_map, space_outliner->search_tse.id, USER_IGNORE);
-
if (space_outliner->treestore) {
TreeStoreElem *tselem;
BLI_mempool_iter iter;
BLI_mempool_iternew(space_outliner->treestore, &iter);
- while ((tselem = BLI_mempool_iterstep(&iter))) {
+ while ((tselem = static_cast<TreeStoreElem *>(BLI_mempool_iterstep(&iter)))) {
/* Do not try to restore pointers to drivers/sequence/etc.,
* can crash in undo case! */
if (TSE_IS_REAL_ID(tselem)) {
- tselem->id = restore_pointer_by_name(id_map, tselem->id, USER_IGNORE);
+ tselem->id = static_cast<ID *>(
+ restore_pointer_by_name(id_map, tselem->id, USER_IGNORE));
}
else {
- tselem->id = NULL;
+ tselem->id = nullptr;
}
}
/* rebuild hash table, because it depends on ids too */
@@ -2654,21 +2695,24 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map,
bNodeTree *ntree;
/* node tree can be stored locally in id too, link this first */
- snode->id = restore_pointer_by_name(id_map, snode->id, USER_REAL);
- snode->from = restore_pointer_by_name(id_map, snode->from, USER_IGNORE);
+ snode->id = static_cast<ID *>(restore_pointer_by_name(id_map, snode->id, USER_REAL));
+ snode->from = static_cast<ID *>(
+ restore_pointer_by_name(id_map, snode->from, USER_IGNORE));
- ntree = snode->id ? ntreeFromID(snode->id) : NULL;
- snode->nodetree = ntree ?
- ntree :
- restore_pointer_by_name(id_map, (ID *)snode->nodetree, USER_REAL);
+ ntree = snode->id ? ntreeFromID(snode->id) : nullptr;
+ snode->nodetree = ntree ? ntree :
+ static_cast<bNodeTree *>(restore_pointer_by_name(
+ id_map, (ID *)snode->nodetree, USER_REAL));
- for (path = snode->treepath.first; path; path = path->next) {
+ for (path = static_cast<bNodeTreePath *>(snode->treepath.first); path;
+ path = path->next) {
if (path == snode->treepath.first) {
/* first nodetree in path is same as snode->nodetree */
path->nodetree = snode->nodetree;
}
else {
- path->nodetree = restore_pointer_by_name(id_map, (ID *)path->nodetree, USER_REAL);
+ path->nodetree = static_cast<bNodeTree *>(
+ restore_pointer_by_name(id_map, (ID *)path->nodetree, USER_REAL));
}
if (!path->nodetree) {
@@ -2687,32 +2731,26 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map,
/* edittree is just the last in the path,
* set this directly since the path may have been shortened above */
if (snode->treepath.last) {
- path = snode->treepath.last;
+ path = static_cast<bNodeTreePath *>(snode->treepath.last);
snode->edittree = path->nodetree;
}
else {
- snode->edittree = NULL;
+ snode->edittree = nullptr;
}
}
else if (sl->spacetype == SPACE_CLIP) {
SpaceClip *sclip = (SpaceClip *)sl;
- sclip->clip = restore_pointer_by_name(id_map, (ID *)sclip->clip, USER_REAL);
- sclip->mask_info.mask = restore_pointer_by_name(
- id_map, (ID *)sclip->mask_info.mask, USER_REAL);
+ sclip->clip = static_cast<MovieClip *>(
+ restore_pointer_by_name(id_map, (ID *)sclip->clip, USER_REAL));
+ sclip->mask_info.mask = static_cast<Mask *>(
+ restore_pointer_by_name(id_map, (ID *)sclip->mask_info.mask, USER_REAL));
sclip->scopes.ok = 0;
}
else if (sl->spacetype == SPACE_SPREADSHEET) {
SpaceSpreadsheet *sspreadsheet = (SpaceSpreadsheet *)sl;
-
- LISTBASE_FOREACH (SpreadsheetContext *, context, &sspreadsheet->context_path) {
- if (context->type == SPREADSHEET_CONTEXT_OBJECT) {
- SpreadsheetContextObject *object_context = (SpreadsheetContextObject *)context;
- object_context->object = restore_pointer_by_name(
- id_map, (ID *)object_context->object, USER_IGNORE);
- }
- }
+ lib_link_restore_viewer_path(id_map, &sspreadsheet->viewer_path);
}
}
}
@@ -2725,15 +2763,15 @@ void blo_lib_link_restore(Main *oldmain,
Scene *curscene,
ViewLayer *cur_view_layer)
{
- struct IDNameLib_Map *id_map = BKE_main_idmap_create(
- newmain, true, oldmain, MAIN_IDMAP_TYPE_NAME);
+ IDNameLib_Map *id_map = BKE_main_idmap_create(newmain, true, oldmain, MAIN_IDMAP_TYPE_NAME);
LISTBASE_FOREACH (WorkSpace *, workspace, &newmain->workspaces) {
LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) {
lib_link_workspace_layout_restore(id_map, newmain, layout);
}
- workspace->pin_scene = restore_pointer_by_name(
- id_map, (ID *)workspace->pin_scene, USER_IGNORE);
+ workspace->pin_scene = static_cast<Scene *>(
+ restore_pointer_by_name(id_map, (ID *)workspace->pin_scene, USER_IGNORE));
+ lib_link_restore_viewer_path(id_map, &workspace->viewer_path);
}
LISTBASE_FOREACH (wmWindow *, win, &curwm->windows) {
@@ -2741,14 +2779,16 @@ void blo_lib_link_restore(Main *oldmain,
ID *workspace_id = (ID *)workspace;
Scene *oldscene = win->scene;
- workspace = restore_pointer_by_name(id_map, workspace_id, USER_REAL);
+ workspace = static_cast<WorkSpace *>(restore_pointer_by_name(id_map, workspace_id, USER_REAL));
BKE_workspace_active_set(win->workspace_hook, workspace);
- win->scene = restore_pointer_by_name(id_map, (ID *)win->scene, USER_REAL);
- if (win->scene == NULL) {
+ win->scene = static_cast<Scene *>(
+ restore_pointer_by_name(id_map, (ID *)win->scene, USER_REAL));
+ if (win->scene == nullptr) {
win->scene = curscene;
}
- win->unpinned_scene = restore_pointer_by_name(id_map, (ID *)win->unpinned_scene, USER_IGNORE);
- if (BKE_view_layer_find(win->scene, win->view_layer_name) == NULL) {
+ win->unpinned_scene = static_cast<Scene *>(
+ restore_pointer_by_name(id_map, (ID *)win->unpinned_scene, USER_IGNORE));
+ if (BKE_view_layer_find(win->scene, win->view_layer_name) == nullptr) {
STRNCPY(win->view_layer_name, cur_view_layer->name);
}
BKE_workspace_active_set(win->workspace_hook, workspace);
@@ -2763,7 +2803,7 @@ void blo_lib_link_restore(Main *oldmain,
* potential local view, and needs window's scene pointer to be final... */
lib_link_window_scene_data_restore(win, win->scene, cur_view_layer);
- BLI_assert(win->screen == NULL);
+ BLI_assert(win->screen == nullptr);
}
lib_link_wm_xr_data_restore(id_map, &curwm->xr);
@@ -2793,7 +2833,7 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
Main *newmain;
/* check if the library was already read */
- for (newmain = fd->mainlist->first; newmain; newmain = newmain->next) {
+ for (newmain = static_cast<Main *>(fd->mainlist->first); newmain; newmain = newmain->next) {
if (newmain->curlib) {
if (BLI_path_cmp(newmain->curlib->filepath_abs, lib->filepath_abs) == 0) {
BLO_reportf_wrap(fd->reports,
@@ -2837,12 +2877,12 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
BLI_addtail(fd->mainlist, newmain);
newmain->curlib = lib;
- lib->parent = NULL;
+ lib->parent = nullptr;
id_us_ensure_real(&lib->id);
}
-static void lib_link_library(BlendLibReader *UNUSED(reader), Library *UNUSED(lib))
+static void lib_link_library(BlendLibReader * /*reader*/, Library * /*lib*/)
{
}
@@ -2851,7 +2891,7 @@ static void lib_link_library(BlendLibReader *UNUSED(reader), Library *UNUSED(lib
static void fix_relpaths_library(const char *basepath, Main *main)
{
/* #BLO_read_from_memory uses a blank file-path. */
- if (basepath == NULL || basepath[0] == '\0') {
+ if (basepath == nullptr || basepath[0] == '\0') {
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
@@ -2866,7 +2906,7 @@ static void fix_relpaths_library(const char *basepath, Main *main)
else {
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 the blend file since indirectly linked libraries will be
* relative to their direct linked library. */
if (BLI_path_is_rel(lib->filepath)) { /* if this is relative to begin with? */
BLI_strncpy(lib->filepath, lib->filepath_abs, sizeof(lib->filepath));
@@ -2885,7 +2925,7 @@ static void fix_relpaths_library(const char *basepath, Main *main)
static ID *create_placeholder(Main *mainvar, const short idcode, const char *idname, const int tag)
{
ListBase *lb = which_libbase(mainvar, idcode);
- ID *ph_id = BKE_libblock_alloc_notest(idcode);
+ ID *ph_id = static_cast<ID *>(BKE_libblock_alloc_notest(idcode));
*((short *)ph_id->name) = idcode;
BLI_strncpy(ph_id->name + 2, idname, sizeof(ph_id->name) - 2);
@@ -2896,9 +2936,9 @@ static ID *create_placeholder(Main *mainvar, const short idcode, const char *idn
ph_id->icon_id = 0;
BLI_addtail(lb, ph_id);
- id_sort_by_name(lb, ph_id, NULL);
+ id_sort_by_name(lb, ph_id, nullptr);
- if (mainvar->id_map != NULL) {
+ if (mainvar->id_map != nullptr) {
BKE_main_idmap_insert_id(mainvar->id_map, ph_id);
}
@@ -2914,8 +2954,8 @@ 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?). */
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
- ID *obdata = ob->data;
- if (obdata != NULL && obdata->tag & LIB_TAG_MISSING) {
+ ID *obdata = static_cast<ID *>(ob->data);
+ if (obdata != nullptr && obdata->tag & LIB_TAG_MISSING) {
BKE_object_materials_test(bmain, ob, obdata);
}
}
@@ -3022,7 +3062,7 @@ 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) {
+ if (id_type->blend_read_data != nullptr) {
id_type->blend_read_data(&reader, id);
}
@@ -3043,7 +3083,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
}
/* try to restore (when undoing) or clear ID's cache pointers. */
- if (id_type->foreach_cache != NULL) {
+ if (id_type->foreach_cache != nullptr) {
BKE_idtype_id_foreach_cache(
id, blo_cache_storage_entry_restore_in_new, reader.fd->cache_storage);
}
@@ -3063,9 +3103,13 @@ static BHead *read_data_into_datamap(FileData *fd, BHead *bhead, const char *all
* With the code below we get the struct-name to help tracking down the leak.
* This is kept disabled as the #malloc for the text always leaks memory. */
#if 0
- {
- const short *sp = fd->filesdna->structs[bhead->SDNAnr];
- allocname = fd->filesdna->types[sp[0]];
+ if (bhead->SDNAnr == 0) {
+ /* The data type here is unclear because #writedata sets SDNAnr to 0. */
+ allocname = "likely raw data";
+ }
+ else {
+ SDNA_Struct *sp = fd->filesdna->structs[bhead->SDNAnr];
+ allocname = fd->filesdna->types[sp->type];
size_t allocname_size = strlen(allocname) + 1;
char *allocname_buf = malloc(allocname_size);
memcpy(allocname_buf, allocname, allocname_size);
@@ -3109,7 +3153,7 @@ static bool read_libblock_is_identical(FileData *fd, BHead *bhead)
/* For undo, restore matching library datablock from the old main. */
static bool read_libblock_undo_restore_library(FileData *fd, Main *main, const ID *id)
{
- /* In undo case, most libs and linked data should be kept as is from previous state
+ /* In undo case, most libraries and linked data should be kept as is from previous state
* (see BLO_read_from_memfile).
* However, some needed by the snapshot being read may have been removed in previous one,
* and would go missing.
@@ -3119,15 +3163,15 @@ static bool read_libblock_undo_restore_library(FileData *fd, Main *main, const I
* otherwise we have to do a full read of that bhead... */
CLOG_INFO(&LOG_UNDO, 2, "UNDO: restore library %s", id->name);
- Main *libmain = fd->old_mainlist->first;
+ Main *libmain = static_cast<Main *>(fd->old_mainlist->first);
/* Skip oldmain itself... */
for (libmain = libmain->next; libmain; libmain = libmain->next) {
if (libmain->curlib && STREQ(id->name, libmain->curlib->id.name)) {
- Main *oldmain = fd->old_mainlist->first;
+ Main *oldmain = static_cast<Main *>(fd->old_mainlist->first);
CLOG_INFO(&LOG_UNDO,
2,
" compare with %s -> match",
- libmain->curlib ? libmain->curlib->id.name : "<NULL>");
+ libmain->curlib ? libmain->curlib->id.name : "<nullptr>");
/* In case of a library, we need to re-add its main to fd->mainlist,
* because if we have later a missing ID_LINK_PLACEHOLDER,
* we need to get the correct lib it is linked to!
@@ -3142,7 +3186,7 @@ static bool read_libblock_undo_restore_library(FileData *fd, Main *main, const I
CLOG_INFO(&LOG_UNDO,
2,
" compare with %s -> NO match",
- libmain->curlib ? libmain->curlib->id.name : "<NULL>");
+ libmain->curlib ? libmain->curlib->id.name : "<nullptr>");
}
return false;
@@ -3154,16 +3198,16 @@ static bool read_libblock_undo_restore_linked(FileData *fd, Main *main, const ID
CLOG_INFO(&LOG_UNDO, 2, "UNDO: restore linked datablock %s", id->name);
ID *id_old = BKE_libblock_find_name(main, GS(id->name), id->name + 2);
- if (id_old != NULL) {
+ if (id_old != nullptr) {
CLOG_INFO(&LOG_UNDO,
2,
" from %s (%s): found",
- main->curlib ? main->curlib->id.name : "<NULL>",
- main->curlib ? main->curlib->filepath : "<NULL>");
+ main->curlib ? main->curlib->id.name : "<nullptr>",
+ main->curlib ? main->curlib->filepath : "<nullptr>");
/* Even though we found our linked ID, there is no guarantee its address
* is still the same. */
if (id_old != bhead->old) {
- oldnewmap_insert(fd->libmap, bhead->old, id_old, GS(id_old->name));
+ oldnewmap_lib_insert(fd, bhead->old, id_old, GS(id_old->name));
}
/* No need to do anything else for ID_LINK_PLACEHOLDER, it's assumed
@@ -3174,17 +3218,17 @@ static bool read_libblock_undo_restore_linked(FileData *fd, Main *main, const ID
CLOG_INFO(&LOG_UNDO,
2,
" from %s (%s): NOT found",
- main->curlib ? main->curlib->id.name : "<NULL>",
- main->curlib ? main->curlib->filepath : "<NULL>");
+ main->curlib ? main->curlib->id.name : "<nullptr>",
+ main->curlib ? main->curlib->filepath : "<nullptr>");
return false;
}
/* For undo, restore unchanged datablock from old main. */
static void read_libblock_undo_restore_identical(
- FileData *fd, Main *main, const ID *UNUSED(id), ID *id_old, const int tag)
+ FileData *fd, Main *main, const ID * /*id*/, ID *id_old, const int tag)
{
BLI_assert((fd->skip_flags & BLO_READ_SKIP_UNDO_OLD_MAIN) == 0);
- BLI_assert(id_old != NULL);
+ BLI_assert(id_old != nullptr);
/* Some tags need to be preserved here. */
id_old->tag = tag | (id_old->tag & LIB_TAG_EXTRAUSER);
@@ -3192,11 +3236,11 @@ static void read_libblock_undo_restore_identical(
id_old->us = ID_FAKE_USERS(id_old);
/* Do not reset id->icon_id here, memory allocated for it remains valid. */
/* Needed because .blend may have been saved with crap value here... */
- id_old->newid = NULL;
- id_old->orig_id = NULL;
+ id_old->newid = nullptr;
+ id_old->orig_id = nullptr;
const short idcode = GS(id_old->name);
- Main *old_bmain = fd->old_mainlist->first;
+ Main *old_bmain = static_cast<Main *>(fd->old_mainlist->first);
ListBase *old_lb = which_libbase(old_bmain, idcode);
ListBase *new_lb = which_libbase(main, idcode);
BLI_remlink(old_lb, id_old);
@@ -3223,11 +3267,11 @@ static void read_libblock_undo_restore_at_old_address(FileData *fd, Main *main,
* helps reducing further detected changes by the depsgraph (since unchanged IDs remain fully
* unchanged, even if they are using/pointing to a changed one). */
BLI_assert((fd->skip_flags & BLO_READ_SKIP_UNDO_OLD_MAIN) == 0);
- BLI_assert(id_old != NULL);
+ BLI_assert(id_old != nullptr);
const short idcode = GS(id->name);
- Main *old_bmain = fd->old_mainlist->first;
+ Main *old_bmain = static_cast<Main *>(fd->old_mainlist->first);
ListBase *old_lb = which_libbase(old_bmain, idcode);
ListBase *new_lb = which_libbase(main, idcode);
BLI_remlink(old_lb, id_old);
@@ -3235,8 +3279,8 @@ static void read_libblock_undo_restore_at_old_address(FileData *fd, Main *main,
/* We do not need any remapping from this call here, since no ID pointer is valid in the data
* currently (they are all pointing to old addresses, and need to go through `lib_link`
- * process). So we can pass NULL for the Main pointer parameter. */
- BKE_lib_id_swap_full(NULL, id, id_old);
+ * process). So we can pass nullptr for the Main pointer parameter. */
+ BKE_lib_id_swap_full(nullptr, id, id_old);
/* Special temporary usage of this pointer, necessary for the `undo_preserve` call after
* lib-linking to restore some data that should never be affected by undo, e.g. the 3D cursor of
@@ -3251,7 +3295,7 @@ static bool read_libblock_undo_restore(
FileData *fd, Main *main, BHead *bhead, const int tag, ID **r_id_old)
{
/* Get pointer to memory of new ID that we will be reading. */
- const ID *id = peek_struct_undo(fd, bhead);
+ const ID *id = static_cast<const ID *>(peek_struct_undo(fd, bhead));
const short idcode = GS(id->name);
if (bhead->code == ID_LI) {
@@ -3274,19 +3318,19 @@ static bool read_libblock_undo_restore(
}
/* Restore local datablocks. */
- ID *id_old = NULL;
+ ID *id_old = nullptr;
const bool do_partial_undo = (fd->skip_flags & BLO_READ_SKIP_UNDO_OLD_MAIN) == 0;
if (do_partial_undo && (bhead->code != ID_LINK_PLACEHOLDER)) {
/* This code should only ever be reached for local data-blocks. */
- BLI_assert(main->curlib == NULL);
+ BLI_assert(main->curlib == nullptr);
/* Find the 'current' existing ID we want to reuse instead of the one we
* would read from the undo memfile. */
- BLI_assert(fd->old_idmap != NULL);
+ BLI_assert(fd->old_idmap != nullptr);
id_old = BKE_main_idmap_lookup_uuid(fd->old_idmap, id->session_uuid);
}
- if (id_old != NULL && read_libblock_is_identical(fd, bhead)) {
+ if (id_old != nullptr && read_libblock_is_identical(fd, bhead)) {
/* Local datablock was unchanged, restore from the old main. */
CLOG_INFO(&LOG_UNDO,
2,
@@ -3305,12 +3349,12 @@ static bool read_libblock_undo_restore(
/* Insert into library map for lookup by newly read datablocks (with pointer value bhead->old).
* Note that existing datablocks in memory (which pointer value would be id_old) are not
* remapped anymore, so no need to store this info here. */
- oldnewmap_insert(fd->libmap, bhead->old, id_old, bhead->code);
+ oldnewmap_lib_insert(fd, bhead->old, id_old, bhead->code);
*r_id_old = id_old;
return true;
}
- if (id_old != NULL) {
+ if (id_old != nullptr) {
/* Local datablock was changed. Restore at the address of the old datablock. */
CLOG_INFO(&LOG_UNDO,
2,
@@ -3344,13 +3388,13 @@ static BHead *read_libblock(FileData *fd,
/* First attempt to restore existing datablocks for undo.
* When datablocks are changed but still exist, we restore them at the old
* address and inherit recalc flags for the dependency graph. */
- ID *id_old = NULL;
+ ID *id_old = nullptr;
if (fd->flags & FD_FLAGS_IS_MEMFILE) {
if (read_libblock_undo_restore(fd, main, bhead, tag, &id_old)) {
if (r_id) {
*r_id = id_old;
}
- if (main->id_map != NULL) {
+ if (main->id_map != nullptr) {
BKE_main_idmap_insert_id(main->id_map, id_old);
}
@@ -3359,10 +3403,10 @@ static BHead *read_libblock(FileData *fd,
}
/* Read libblock struct. */
- ID *id = read_struct(fd, bhead, "lib block");
- if (id == NULL) {
+ ID *id = static_cast<ID *>(read_struct(fd, bhead, "lib block"));
+ if (id == nullptr) {
if (r_id) {
- *r_id = NULL;
+ *r_id = nullptr;
}
return blo_bhead_next(fd, bhead);
}
@@ -3370,12 +3414,12 @@ static BHead *read_libblock(FileData *fd,
/* Determine ID type and add to main database list. */
const short idcode = GS(id->name);
ListBase *lb = which_libbase(main, idcode);
- if (lb == NULL) {
+ if (lb == nullptr) {
/* Unknown ID type. */
CLOG_WARN(&LOG, "Unknown id code '%c%c'", (idcode & 0xff), (idcode >> 8));
MEM_freeN(id);
if (r_id) {
- *r_id = NULL;
+ *r_id = nullptr;
}
return blo_bhead_next(fd, bhead);
}
@@ -3388,7 +3432,7 @@ static BHead *read_libblock(FileData *fd,
* Note that existing datablocks in memory (which pointer value would be id_old) are not remapped
* remapped anymore, so no need to store this info here. */
ID *id_target = id_old ? id_old : id;
- oldnewmap_insert(fd->libmap, bhead->old, id_target, bhead->code);
+ oldnewmap_lib_insert(fd, bhead->old, id_target, bhead->code);
if (r_id) {
*r_id = id_target;
@@ -3413,7 +3457,7 @@ static BHead *read_libblock(FileData *fd,
direct_link_id(fd, main, id_tag, id, id_old);
- if (main->id_map != NULL) {
+ if (main->id_map != nullptr) {
BKE_main_idmap_insert_id(main->id_map, id);
}
@@ -3433,19 +3477,19 @@ static BHead *read_libblock(FileData *fd,
* been added to the fd->libmap mapping, which in theory could lead to nice crashes...
* This should be properly solved at some point. */
BKE_id_free(main, id);
- if (r_id != NULL) {
- *r_id = NULL;
+ if (r_id != nullptr) {
+ *r_id = nullptr;
}
}
else if (id_old) {
/* For undo, store contents read into id at id_old. */
read_libblock_undo_restore_at_old_address(fd, main, id, id_old);
- if (main->id_map != NULL) {
+ if (main->id_map != nullptr) {
BKE_main_idmap_insert_id(main->id_map, id_old);
}
}
- else if (main->id_map != NULL) {
+ else if (main->id_map != nullptr) {
BKE_main_idmap_insert_id(main->id_map, id);
}
@@ -3483,7 +3527,7 @@ BHead *blo_read_asset_data_block(FileData *fd, BHead *bhead, AssetMetaData **r_a
/* also version info is written here */
static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead)
{
- FileGlobal *fg = read_struct(fd, bhead, "Global");
+ FileGlobal *fg = static_cast<FileGlobal *>(read_struct(fd, bhead, "Global"));
/* copy to bfd handle */
bfd->main->subversionfile = fg->subversion;
@@ -3530,11 +3574,12 @@ static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead)
/* NOTE: this has to be kept for reading older files... */
static void link_global(FileData *fd, BlendFileData *bfd)
{
- bfd->cur_view_layer = blo_read_get_new_globaldata_address(fd, bfd->cur_view_layer);
- bfd->curscreen = newlibadr(fd, NULL, bfd->curscreen);
- bfd->curscene = newlibadr(fd, NULL, bfd->curscene);
+ bfd->cur_view_layer = static_cast<ViewLayer *>(
+ blo_read_get_new_globaldata_address(fd, bfd->cur_view_layer));
+ bfd->curscreen = static_cast<bScreen *>(newlibadr(fd, nullptr, bfd->curscreen));
+ bfd->curscene = static_cast<Scene *>(newlibadr(fd, nullptr, bfd->curscene));
/* this happens in files older than 2.35 */
- if (bfd->curscene == NULL) {
+ if (bfd->curscene == nullptr) {
if (bfd->curscreen) {
bfd->curscene = bfd->curscreen->scene;
}
@@ -3547,11 +3592,11 @@ static void link_global(FileData *fd, BlendFileData *bfd)
/** \name Versioning
* \{ */
-static void do_versions_userdef(FileData *UNUSED(fd), BlendFileData *bfd)
+static void do_versions_userdef(FileData * /*fd*/, BlendFileData *bfd)
{
UserDef *user = bfd->user;
- if (user == NULL) {
+ if (user == nullptr) {
return;
}
@@ -3568,7 +3613,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
if (G.debug & G_DEBUG) {
char build_commit_datetime[32];
time_t temp_time = main->build_commit_timestamp;
- struct tm *tm = (temp_time) ? gmtime(&temp_time) : NULL;
+ struct tm *tm = (temp_time) ? gmtime(&temp_time) : nullptr;
if (LIKELY(tm)) {
strftime(build_commit_datetime, sizeof(build_commit_datetime), "%Y-%m-%d %H:%M", tm);
}
@@ -3593,6 +3638,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
blo_do_versions_280(fd, lib, main);
blo_do_versions_290(fd, lib, main);
blo_do_versions_300(fd, lib, main);
+ blo_do_versions_400(fd, lib, main);
blo_do_versions_cycles(fd, lib, main);
/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
@@ -3663,7 +3709,7 @@ 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) {
+ if (id_type->blend_read_lib != nullptr) {
id_type->blend_read_lib(&reader, id);
}
@@ -3675,7 +3721,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
/* Some data that should be persistent, like the 3DCursor or the tool settings, are
* stored in IDs affected by undo, like Scene. So this requires some specific handling. */
- if (id_type->blend_read_undo_preserve != NULL && id->orig_id != NULL) {
+ if (id_type->blend_read_undo_preserve != nullptr && id->orig_id != nullptr) {
id_type->blend_read_undo_preserve(&reader, id, id->orig_id);
}
}
@@ -3683,7 +3729,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
/* Cleanup `ID.orig_id`, this is now reserved for depsgraph/COW usage only. */
FOREACH_MAIN_ID_BEGIN (bmain, id) {
- id->orig_id = NULL;
+ id->orig_id = nullptr;
}
FOREACH_MAIN_ID_END;
@@ -3705,14 +3751,14 @@ static void lib_link_all(FileData *fd, Main *bmain)
static void after_liblink_merged_bmain_process(Main *bmain)
{
/* We only expect a merged Main here, not a split one. */
- BLI_assert((bmain->prev == NULL) && (bmain->next == NULL));
+ BLI_assert((bmain->prev == nullptr) && (bmain->next == nullptr));
/* Check for possible cycles in scenes' 'set' background property. */
lib_link_scenes_check_set(bmain);
/* We could integrate that to mesh/curve/lattice lib_link, but this is really cheap process,
* so simpler to just use it directly in this single call. */
- BLO_main_validate_shapekeys(bmain, NULL);
+ BLO_main_validate_shapekeys(bmain, nullptr);
/* We have to rebuild that runtime information *after* all data-blocks have been properly linked.
*/
@@ -3729,14 +3775,14 @@ static void direct_link_keymapitem(BlendDataReader *reader, wmKeyMapItem *kmi)
{
BLO_read_data_address(reader, &kmi->properties);
IDP_BlendDataRead(reader, &kmi->properties);
- kmi->ptr = NULL;
+ kmi->ptr = nullptr;
kmi->flag &= ~KMI_UPDATE;
}
static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead)
{
UserDef *user;
- bfd->user = user = read_struct(fd, bhead, "user def");
+ bfd->user = user = static_cast<UserDef *>(read_struct(fd, bhead, "user def"));
/* User struct has separate do-version handling */
user->versionfile = bfd->main->versionfile;
@@ -3757,8 +3803,8 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead)
BLO_read_list(reader, &user->asset_libraries);
LISTBASE_FOREACH (wmKeyMap *, keymap, &user->user_keymaps) {
- keymap->modal_items = NULL;
- keymap->poll = NULL;
+ keymap->modal_items = nullptr;
+ keymap->poll = nullptr;
keymap->flag &= ~KEYMAP_UPDATE;
BLO_read_list(reader, &keymap->diff_items);
@@ -3803,7 +3849,7 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead)
}
/* XXX */
- user->uifonts.first = user->uifonts.last = NULL;
+ user->uifonts.first = user->uifonts.last = nullptr;
BLO_read_list(reader, &user->uistyles);
@@ -3830,13 +3876,13 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
{
BHead *bhead = blo_bhead_first(fd);
BlendFileData *bfd;
- ListBase mainlist = {NULL, NULL};
+ ListBase mainlist = {nullptr, nullptr};
if (fd->flags & FD_FLAGS_IS_MEMFILE) {
CLOG_INFO(&LOG_UNDO, 2, "UNDO: read step");
}
- bfd = MEM_callocN(sizeof(BlendFileData), "blendfiledata");
+ bfd = static_cast<BlendFileData *>(MEM_callocN(sizeof(BlendFileData), "blendfiledata"));
bfd->main = BKE_main_new();
bfd->main->versionfile = fd->fileversion;
@@ -3860,7 +3906,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
const int height = data[1];
if (BLEN_THUMB_MEMSIZE_IS_VALID(width, height)) {
const size_t data_size = BLEN_THUMB_MEMSIZE(width, height);
- bfd->main->blen_thumb = MEM_mallocN(data_size, __func__);
+ bfd->main->blen_thumb = static_cast<BlendThumbnail *>(MEM_mallocN(data_size, __func__));
BLI_assert((data_size - sizeof(*bfd->main->blen_thumb)) ==
(BLEN_THUMB_MEMSIZE_FILE(width, height) - (sizeof(*data) * 2)));
@@ -3891,7 +3937,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
}
break;
case ENDB:
- bhead = NULL;
+ bhead = nullptr;
break;
case ID_LINK_PLACEHOLDER:
@@ -3903,8 +3949,8 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
* The library is the most recently loaded ID_LI block, according
* to the file format definition. So we can use the entry at the
* end of mainlist, added in direct_link_library. */
- Main *libmain = mainlist.last;
- bhead = read_libblock(fd, libmain, bhead, 0, true, NULL);
+ Main *libmain = static_cast<Main *>(mainlist.last);
+ bhead = read_libblock(fd, libmain, bhead, 0, true, nullptr);
}
break;
/* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
@@ -3917,7 +3963,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
bhead = blo_bhead_next(fd, bhead);
}
else {
- bhead = read_libblock(fd, bfd->main, bhead, LIB_TAG_LOCAL, false, NULL);
+ bhead = read_libblock(fd, bfd->main, bhead, LIB_TAG_LOCAL, false, nullptr);
}
}
}
@@ -3925,7 +3971,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
/* do before read_libraries, but skip undo case */
if ((fd->flags & FD_FLAGS_IS_MEMFILE) == 0) {
if ((fd->skip_flags & BLO_READ_SKIP_DATA) == 0) {
- do_versions(fd, NULL, bfd->main);
+ do_versions(fd, nullptr, bfd->main);
}
if ((fd->skip_flags & BLO_READ_SKIP_USERDEF) == 0) {
@@ -3999,9 +4045,9 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
link_global(fd, bfd); /* as last */
}
- fd->mainlist = NULL; /* Safety, this is local variable, shall not be used afterward. */
+ fd->mainlist = nullptr; /* Safety, this is local variable, shall not be used afterward. */
- BLI_assert(bfd->main->id_map == NULL);
+ BLI_assert(bfd->main->id_map == nullptr);
return bfd;
}
@@ -4021,7 +4067,8 @@ struct BHeadSort {
static int verg_bheadsort(const void *v1, const void *v2)
{
- const struct BHeadSort *x1 = v1, *x2 = v2;
+ const BHeadSort *x1 = static_cast<const BHeadSort *>(v1),
+ *x2 = static_cast<const BHeadSort *>(v2);
if (x1->old > x2->old) {
return 1;
@@ -4035,7 +4082,7 @@ static int verg_bheadsort(const void *v1, const void *v2)
static void sort_bhead_old_map(FileData *fd)
{
BHead *bhead;
- struct BHeadSort *bhs;
+ BHeadSort *bhs;
int tot = 0;
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
@@ -4047,21 +4094,22 @@ static void sort_bhead_old_map(FileData *fd)
return;
}
- bhs = fd->bheadmap = MEM_malloc_arrayN(tot, sizeof(struct BHeadSort), "BHeadSort");
+ bhs = fd->bheadmap = static_cast<BHeadSort *>(
+ MEM_malloc_arrayN(tot, sizeof(BHeadSort), "BHeadSort"));
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead), bhs++) {
bhs->bhead = bhead;
bhs->old = bhead->old;
}
- qsort(fd->bheadmap, tot, sizeof(struct BHeadSort), verg_bheadsort);
+ qsort(fd->bheadmap, tot, sizeof(BHeadSort), verg_bheadsort);
}
static BHead *find_previous_lib(FileData *fd, BHead *bhead)
{
/* Skip library data-blocks in undo, see comment in read_libblock. */
if (fd->flags & FD_FLAGS_IS_MEMFILE) {
- return NULL;
+ return nullptr;
}
for (; bhead; bhead = blo_bhead_prev(fd, bhead)) {
@@ -4078,18 +4126,19 @@ static BHead *find_bhead(FileData *fd, void *old)
#if 0
BHead* bhead;
#endif
- struct BHeadSort *bhs, bhs_s;
+ BHeadSort *bhs, bhs_s;
if (!old) {
- return NULL;
+ return nullptr;
}
- if (fd->bheadmap == NULL) {
+ if (fd->bheadmap == nullptr) {
sort_bhead_old_map(fd);
}
bhs_s.old = old;
- bhs = bsearch(&bhs_s, fd->bheadmap, fd->tot_bheadmap, sizeof(struct BHeadSort), verg_bheadsort);
+ bhs = static_cast<BHeadSort *>(
+ bsearch(&bhs_s, fd->bheadmap, fd->tot_bheadmap, sizeof(BHeadSort), verg_bheadsort));
if (bhs) {
return bhs->bhead;
@@ -4103,7 +4152,7 @@ static BHead *find_bhead(FileData *fd, void *old)
}
#endif
- return NULL;
+ return nullptr;
}
static BHead *find_bhead_from_code_name(FileData *fd, const short idcode, const char *name)
@@ -4115,7 +4164,7 @@ static BHead *find_bhead_from_code_name(FileData *fd, const short idcode, const
*((short *)idname_full) = idcode;
BLI_strncpy(idname_full + 2, name, sizeof(idname_full) - 2);
- return BLI_ghash_lookup(fd->bhead_idname_hash, idname_full);
+ return static_cast<BHead *>(BLI_ghash_lookup(fd->bhead_idname_hash, idname_full));
#else
BHead *bhead;
@@ -4132,14 +4181,14 @@ static BHead *find_bhead_from_code_name(FileData *fd, const short idcode, const
}
}
- return NULL;
+ return nullptr;
#endif
}
static BHead *find_bhead_from_idname(FileData *fd, const char *idname)
{
#ifdef USE_GHASH_BHEAD
- return BLI_ghash_lookup(fd->bhead_idname_hash, idname);
+ return static_cast<BHead *>(BLI_ghash_lookup(fd->bhead_idname_hash, idname));
#else
return find_bhead_from_code_name(fd, GS(idname), idname + 2);
#endif
@@ -4147,8 +4196,8 @@ static BHead *find_bhead_from_idname(FileData *fd, const char *idname)
static ID *is_yet_read(FileData *fd, Main *mainvar, BHead *bhead)
{
- if (mainvar->id_map == NULL) {
- mainvar->id_map = BKE_main_idmap_create(mainvar, false, NULL, MAIN_IDMAP_TYPE_NAME);
+ if (mainvar->id_map == nullptr) {
+ mainvar->id_map = BKE_main_idmap_create(mainvar, false, nullptr, MAIN_IDMAP_TYPE_NAME);
}
BLI_assert(BKE_main_idmap_main_get(mainvar->id_map) == mainvar);
@@ -4167,24 +4216,24 @@ static ID *is_yet_read(FileData *fd, Main *mainvar, BHead *bhead)
static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
{
- FileData *fd = fdhandle;
+ FileData *fd = static_cast<FileData *>(fdhandle);
BHead *bhead = find_bhead(fd, old);
- if (bhead == NULL) {
+ if (bhead == nullptr) {
return;
}
if (bhead->code == ID_LINK_PLACEHOLDER) {
- /* Placeholder link to data-lock in another library. */
+ /* Placeholder link to data-block in another library. */
BHead *bheadlib = find_previous_lib(fd, bhead);
- if (bheadlib == NULL) {
+ if (bheadlib == nullptr) {
return;
}
- Library *lib = read_struct(fd, bheadlib, "Library");
+ Library *lib = static_cast<Library *>(read_struct(fd, bheadlib, "Library"));
Main *libmain = blo_find_main(fd, lib->filepath, fd->relabase);
- if (libmain->curlib == NULL) {
+ if (libmain->curlib == nullptr) {
const char *idname = blo_bhead_id_name(fd, bhead);
BLO_reportf_wrap(fd->reports,
@@ -4197,11 +4246,12 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
ID *id = is_yet_read(fd, libmain, bhead);
- if (id == NULL) {
+ if (id == nullptr) {
/* ID has not been read yet, add placeholder to the main of the
* library it belongs to, so that it will be read later. */
read_libblock(fd, libmain, bhead, fd->id_tag_extra | LIB_TAG_INDIRECT, false, &id);
- id_sort_by_name(which_libbase(libmain, GS(id->name)), id, id->prev);
+ BLI_assert(id != nullptr);
+ id_sort_by_name(which_libbase(libmain, GS(id->name)), id, static_cast<ID *>(id->prev));
/* commented because this can print way too much */
// if (G.debug & G_DEBUG) printf("expand_doit: other lib %s\n", lib->filepath);
@@ -4227,9 +4277,9 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
* (B) forest.blend: contains Forest collection linking in Tree from tree.blend.
* (C) shot.blend: links in both Tree from tree.blend and Forest from forest.blend.
*/
- oldnewmap_insert(fd->libmap, bhead->old, id, bhead->code);
+ oldnewmap_lib_insert(fd, bhead->old, id, bhead->code);
- /* If "id" is a real data-lock and not a placeholder, we need to
+ /* If "id" is a real data-block and not a placeholder, we need to
* update fd->libmap to replace ID_LINK_PLACEHOLDER with the real
* ID_* code.
*
@@ -4256,14 +4306,15 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
}
ID *id = is_yet_read(fd, mainvar, bhead);
- if (id == NULL) {
+ if (id == nullptr) {
read_libblock(fd,
mainvar,
bhead,
fd->id_tag_extra | LIB_TAG_NEED_EXPAND | LIB_TAG_INDIRECT,
false,
&id);
- id_sort_by_name(which_libbase(mainvar, GS(id->name)), id, id->prev);
+ BLI_assert(id != nullptr);
+ id_sort_by_name(which_libbase(mainvar, GS(id->name)), id, static_cast<ID *>(id->prev));
}
else {
/* Convert any previously read weak link to regular link
@@ -4275,7 +4326,7 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
/* this is actually only needed on UI call? when ID was already read before,
* and another append happens which invokes same ID...
* in that case the lookup table needs this entry */
- oldnewmap_insert(fd->libmap, bhead->old, id, bhead->code);
+ oldnewmap_lib_insert(fd, bhead->old, id, bhead->code);
/* commented because this can print way too much */
// if (G.debug & G_DEBUG) printf("expand: already read %s\n", id->name);
}
@@ -4290,14 +4341,14 @@ static void expand_id_embedded_id(BlendExpander *expander, ID *id)
{
/* Handle 'private IDs'. */
bNodeTree *nodetree = ntreeFromID(id);
- if (nodetree != NULL) {
+ if (nodetree != nullptr) {
expand_id(expander, &nodetree->id);
ntreeBlendReadExpand(expander, nodetree);
}
if (GS(id->name) == ID_SCE) {
Scene *scene = (Scene *)id;
- if (scene->master_collection != NULL) {
+ if (scene->master_collection != nullptr) {
expand_id(expander, &scene->master_collection->id);
BKE_collection_blend_read_expand(expander, scene->master_collection);
}
@@ -4314,7 +4365,7 @@ static void expand_id(BlendExpander *expander, ID *id)
}
AnimData *adt = BKE_animdata_from_id(id);
- if (adt != NULL) {
+ if (adt != nullptr) {
BKE_animdata_blend_read_expand(expander, adt);
}
@@ -4329,7 +4380,7 @@ void BLO_main_expander(BLOExpandDoitCallback expand_doit_func)
void BLO_expand_main(void *fdhandle, Main *mainvar)
{
ListBase *lbarray[INDEX_ID_MAX];
- FileData *fd = fdhandle;
+ FileData *fd = static_cast<FileData *>(fdhandle);
ID *id;
int a;
bool do_it = true;
@@ -4341,20 +4392,20 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
a = set_listbasepointers(mainvar, lbarray);
while (a--) {
- id = lbarray[a]->first;
+ id = static_cast<ID *>(lbarray[a]->first);
while (id) {
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) {
+ if (id_type->blend_read_expand != nullptr) {
id_type->blend_read_expand(&expander, id);
}
do_it = true;
id->tag &= ~LIB_TAG_NEED_EXPAND;
}
- id = id->next;
+ id = static_cast<ID *>(id->next);
}
}
}
@@ -4381,7 +4432,7 @@ static ID *link_named_part(
if (bhead) {
id = is_yet_read(fd, mainl, bhead);
- if (id == NULL) {
+ if (id == nullptr) {
/* not read yet */
const int tag = ((force_indirect ? LIB_TAG_INDIRECT : LIB_TAG_EXTERN) | fd->id_tag_extra);
read_libblock(fd, mainl, bhead, tag | LIB_TAG_NEED_EXPAND, false, &id);
@@ -4389,13 +4440,13 @@ static ID *link_named_part(
if (id) {
/* sort by name in list */
ListBase *lb = which_libbase(mainl, idcode);
- id_sort_by_name(lb, id, NULL);
+ id_sort_by_name(lb, id, nullptr);
}
}
else {
/* already linked */
CLOG_WARN(&LOG, "Append: ID '%s' is already linked", id->name);
- oldnewmap_insert(fd->libmap, bhead->old, id, bhead->code);
+ oldnewmap_lib_insert(fd, bhead->old, id, bhead->code);
if (!force_indirect && (id->tag & LIB_TAG_INDIRECT)) {
id->tag &= ~LIB_TAG_INDIRECT;
id->flag &= ~LIB_INDIRECT_WEAK_LINK;
@@ -4409,11 +4460,11 @@ static ID *link_named_part(
mainl, idcode, name, force_indirect ? LIB_TAG_INDIRECT : LIB_TAG_EXTERN);
}
else {
- id = NULL;
+ id = nullptr;
}
- /* if we found the id but the id is NULL, this is really bad */
- BLI_assert(!((bhead != NULL) && (id == NULL)));
+ /* if we found the id but the id is nullptr, this is really bad */
+ BLI_assert(!((bhead != nullptr) && (id == nullptr)));
return id;
}
@@ -4422,7 +4473,7 @@ ID *BLO_library_link_named_part(Main *mainl,
BlendHandle **bh,
const short idcode,
const char *name,
- const struct LibraryLink_Params *params)
+ const LibraryLink_Params *params)
{
FileData *fd = (FileData *)(*bh);
return link_named_part(mainl, fd, idcode, name, params->flag);
@@ -4444,7 +4495,7 @@ static Main *library_link_begin(Main *mainvar,
(*fd)->id_tag_extra = id_tag_extra;
- (*fd)->mainlist = MEM_callocN(sizeof(ListBase), "FileData.mainlist");
+ (*fd)->mainlist = static_cast<ListBase *>(MEM_callocN(sizeof(ListBase), "FileData.mainlist"));
/* make mains */
blo_split_main((*fd)->mainlist, mainvar);
@@ -4462,8 +4513,8 @@ static Main *library_link_begin(Main *mainvar,
return mainl;
}
-void BLO_library_link_params_init(struct LibraryLink_Params *params,
- struct Main *bmain,
+void BLO_library_link_params_init(LibraryLink_Params *params,
+ Main *bmain,
const int flag,
const int id_tag_extra)
{
@@ -4473,17 +4524,17 @@ void BLO_library_link_params_init(struct LibraryLink_Params *params,
params->id_tag_extra = id_tag_extra;
}
-void BLO_library_link_params_init_with_context(struct LibraryLink_Params *params,
- struct Main *bmain,
+void BLO_library_link_params_init_with_context(LibraryLink_Params *params,
+ Main *bmain,
const int flag,
const int id_tag_extra,
/* Context arguments. */
- struct Scene *scene,
- struct ViewLayer *view_layer,
- const struct View3D *v3d)
+ Scene *scene,
+ ViewLayer *view_layer,
+ const View3D *v3d)
{
BLO_library_link_params_init(params, bmain, flag, id_tag_extra);
- if (scene != NULL) {
+ if (scene != nullptr) {
params->context.scene = scene;
params->context.view_layer = view_layer;
params->context.v3d = v3d;
@@ -4492,7 +4543,7 @@ void BLO_library_link_params_init_with_context(struct LibraryLink_Params *params
Main *BLO_library_link_begin(BlendHandle **bh,
const char *filepath,
- const struct LibraryLink_Params *params)
+ const LibraryLink_Params *params)
{
FileData *fd = (FileData *)(*bh);
return library_link_begin(params->bmain, &fd, filepath, params->id_tag_extra);
@@ -4527,8 +4578,8 @@ static void library_link_end(Main *mainl, FileData **fd, const int flag)
Main *mainvar;
Library *curlib;
- if (mainl->id_map == NULL) {
- mainl->id_map = BKE_main_idmap_create(mainl, false, NULL, MAIN_IDMAP_TYPE_NAME);
+ if (mainl->id_map == nullptr) {
+ mainl->id_map = BKE_main_idmap_create(mainl, false, nullptr, MAIN_IDMAP_TYPE_NAME);
}
/* expander now is callback function */
@@ -4537,7 +4588,7 @@ static void library_link_end(Main *mainl, FileData **fd, const int flag)
/* make main consistent */
BLO_expand_main(*fd, mainl);
- /* do this when expand found other libs */
+ /* Do this when expand found other libraries. */
read_libraries(*fd, (*fd)->mainlist);
curlib = mainl->curlib;
@@ -4552,8 +4603,8 @@ static void library_link_end(Main *mainl, FileData **fd, const int flag)
}
blo_join_main((*fd)->mainlist);
- mainvar = (*fd)->mainlist->first;
- mainl = NULL; /* blo_join_main free's mainl, can't use anymore */
+ mainvar = static_cast<Main *>((*fd)->mainlist->first);
+ mainl = nullptr; /* blo_join_main free's mainl, can't use anymore */
lib_link_all(*fd, mainvar);
after_liblink_merged_bmain_process(mainvar);
@@ -4581,7 +4632,7 @@ static void library_link_end(Main *mainl, FileData **fd, const int flag)
}
blo_join_main((*fd)->mainlist);
- mainvar = (*fd)->mainlist->first;
+ mainvar = static_cast<Main *>((*fd)->mainlist->first);
MEM_freeN((*fd)->mainlist);
/* This does not take into account old, deprecated data, so we also have to do it after
@@ -4610,11 +4661,11 @@ static void library_link_end(Main *mainl, FileData **fd, const int flag)
/* patch to prevent switch_endian happens twice */
if ((*fd)->flags & FD_FLAGS_SWITCH_ENDIAN) {
blo_filedata_free(*fd);
- *fd = NULL;
+ *fd = nullptr;
}
}
-void BLO_library_link_end(Main *mainl, BlendHandle **bh, const struct LibraryLink_Params *params)
+void BLO_library_link_end(Main *mainl, BlendHandle **bh, const LibraryLink_Params *params)
{
FileData *fd = (FileData *)(*bh);
library_link_end(mainl, &fd, params->flag);
@@ -4651,7 +4702,7 @@ static int has_linked_ids_to_read(Main *mainvar)
static void read_library_linked_id(
FileData *basefd, FileData *fd, Main *mainvar, ID *id, ID **r_id)
{
- BHead *bhead = NULL;
+ BHead *bhead = nullptr;
const bool is_valid = BKE_idtype_idcode_is_linkable(GS(id->name)) ||
((id->tag & LIB_TAG_EXTERN) == 0);
@@ -4690,7 +4741,8 @@ static void read_library_linked_id(
/* Generate a placeholder for this ID (simplified version of read_libblock actually...). */
if (r_id) {
- *r_id = is_valid ? create_placeholder(mainvar, GS(id->name), id->name + 2, id->tag) : NULL;
+ *r_id = is_valid ? create_placeholder(mainvar, GS(id->name), id->name + 2, id->tag) :
+ nullptr;
}
}
}
@@ -4706,14 +4758,14 @@ static void read_library_linked_ids(FileData *basefd,
int a = set_listbasepointers(mainvar, lbarray);
while (a--) {
- ID *id = lbarray[a]->first;
- ListBase pending_free_ids = {NULL};
+ ID *id = static_cast<ID *>(lbarray[a]->first);
+ ListBase pending_free_ids = {nullptr};
while (id) {
- ID *id_next = id->next;
+ ID *id_next = static_cast<ID *>(id->next);
if ((id->tag & LIB_TAG_ID_LINK_PLACEHOLDER) && !(id->flag & LIB_INDIRECT_WEAK_LINK)) {
BLI_remlink(lbarray[a], id);
- if (mainvar->id_map != NULL) {
+ if (mainvar->id_map != nullptr) {
BKE_main_idmap_remove_id(mainvar->id_map, id);
}
@@ -4721,14 +4773,14 @@ static void read_library_linked_ids(FileData *basefd,
* you have more than one linked ID of the same data-block from same
* library. This is absolutely horrible, hence we use a ghash to ensure
* we go back to a single linked data when loading the file. */
- ID **realid = NULL;
+ ID **realid = nullptr;
if (!BLI_ghash_ensure_p(loaded_ids, id->name, (void ***)&realid)) {
read_library_linked_id(basefd, fd, mainvar, id, realid);
}
- /* `realid` shall never be NULL - unless some source file/lib is broken
- * (known case: some directly linked shapekey from a missing lib...). */
- // BLI_assert(*realid != NULL);
+ /* `realid` shall never be nullptr - unless some source file/lib is broken
+ * (known case: some directly linked shape-key from a missing lib...). */
+ // BLI_assert(*realid != nullptr);
/* Now that we have a real ID, replace all pointers to placeholders in
* fd->libmap with pointers to the real data-blocks. We do this for all
@@ -4743,28 +4795,28 @@ static void read_library_linked_ids(FileData *basefd,
}
/* Clear GHash and free link placeholder IDs of the current type. */
- BLI_ghash_clear(loaded_ids, NULL, NULL);
+ BLI_ghash_clear(loaded_ids, nullptr, nullptr);
BLI_freelistN(&pending_free_ids);
}
- BLI_ghash_free(loaded_ids, NULL, NULL);
+ BLI_ghash_free(loaded_ids, nullptr, nullptr);
}
static void read_library_clear_weak_links(FileData *basefd, ListBase *mainlist, Main *mainvar)
{
/* Any remaining weak links at this point have been lost, silently drop
- * those by setting them to NULL pointers. */
+ * those by setting them to nullptr pointers. */
ListBase *lbarray[INDEX_ID_MAX];
int a = set_listbasepointers(mainvar, lbarray);
while (a--) {
- ID *id = lbarray[a]->first;
+ ID *id = static_cast<ID *>(lbarray[a]->first);
while (id) {
- ID *id_next = id->next;
+ ID *id_next = static_cast<ID *>(id->next);
if ((id->tag & LIB_TAG_ID_LINK_PLACEHOLDER) && (id->flag & LIB_INDIRECT_WEAK_LINK)) {
CLOG_INFO(&LOG, 3, "Dropping weak link to '%s'", id->name);
- change_link_placeholder_to_real_ID_pointer(mainlist, basefd, id, NULL);
+ change_link_placeholder_to_real_ID_pointer(mainlist, basefd, id, nullptr);
BLI_freelinkN(lbarray[a], id);
}
id = id_next;
@@ -4779,7 +4831,7 @@ static FileData *read_library_file_data(FileData *basefd,
{
FileData *fd = mainptr->curlib->filedata;
- if (fd != NULL) {
+ if (fd != nullptr) {
/* File already open. */
return fd;
}
@@ -4834,14 +4886,14 @@ static FileData *read_library_file_data(FileData *basefd,
#endif
}
else {
- mainptr->curlib->filedata = NULL;
+ mainptr->curlib->filedata = nullptr;
mainptr->curlib->id.tag |= LIB_TAG_MISSING;
/* Set lib version to current main one... Makes assert later happy. */
mainptr->versionfile = mainptr->curlib->versionfile = mainl->versionfile;
mainptr->subversionfile = mainptr->curlib->subversionfile = mainl->subversionfile;
}
- if (fd == NULL) {
+ if (fd == nullptr) {
BLO_reportf_wrap(
basefd->reports, RPT_INFO, TIP_("Cannot find lib '%s'"), mainptr->curlib->filepath_abs);
basefd->reports->count.missing_libraries++;
@@ -4852,7 +4904,7 @@ static FileData *read_library_file_data(FileData *basefd,
static void read_libraries(FileData *basefd, ListBase *mainlist)
{
- Main *mainl = mainlist->first;
+ Main *mainl = static_cast<Main *>(mainlist->first);
bool do_it = true;
/* Expander is now callback function. */
@@ -4885,28 +4937,32 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
if (fd) {
do_it = true;
- if (mainptr->id_map == NULL) {
- mainptr->id_map = BKE_main_idmap_create(mainptr, false, NULL, MAIN_IDMAP_TYPE_NAME);
+ if (mainptr->id_map == nullptr) {
+ mainptr->id_map = BKE_main_idmap_create(mainptr, false, nullptr, MAIN_IDMAP_TYPE_NAME);
}
}
- /* Read linked data-locks for each link placeholder, and replace
- * the placeholder with the real data-lock. */
+ /* Read linked data-blocks for each link placeholder, and replace
+ * the placeholder with the real data-block. */
read_library_linked_ids(basefd, fd, mainlist, mainptr);
- /* Test if linked data-locks need to read further linked data-locks
+ /* Test if linked data-blocks need to read further linked data-blocks
* and create link placeholders for them. */
BLO_expand_main(fd, mainptr);
}
}
}
- Main *main_newid = BKE_main_new();
for (Main *mainptr = mainl->next; mainptr; mainptr = mainptr->next) {
- /* Drop weak links for which no data-block was found. */
+ /* Drop weak links for which no data-block was found.
+ * Since this can remap pointers in `libmap` of all libraries, it needs to be performed in its
+ * own loop, before any call to `lib_link_all` (and the freeing of the libraries' filedata). */
read_library_clear_weak_links(basefd, mainlist, mainptr);
+ }
- /* Do versioning for newly added linked data-locks. If no data-locks
+ Main *main_newid = BKE_main_new();
+ for (Main *mainptr = mainl->next; mainptr; mainptr = mainptr->next) {
+ /* Do versioning for newly added linked data-blocks. If no data-blocks
* were read from a library versionfile will still be zero and we can
* skip it. */
if (mainptr->versionfile) {
@@ -4919,7 +4975,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
do_versions(mainptr->curlib->filedata, mainptr->curlib, main_newid);
}
else {
- do_versions(basefd, NULL, main_newid);
+ do_versions(basefd, nullptr, main_newid);
}
add_main_to_main(mainptr, main_newid);
@@ -4939,7 +4995,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
if (mainptr->curlib->filedata) {
blo_filedata_free(mainptr->curlib->filedata);
}
- mainptr->curlib->filedata = NULL;
+ mainptr->curlib->filedata = nullptr;
}
BKE_main_free(main_newid);
}
@@ -4961,7 +5017,12 @@ void *BLO_read_get_new_packed_address(BlendDataReader *reader, const void *old_a
ID *BLO_read_get_new_id_address(BlendLibReader *reader, Library *lib, ID *id)
{
- return newlibadr(reader->fd, lib, id);
+ return static_cast<ID *>(newlibadr(reader->fd, lib, id));
+}
+
+int BLO_read_fileversion_get(BlendDataReader *reader)
+{
+ return reader->fd->fileversion;
}
bool BLO_read_requires_endian_switch(BlendDataReader *reader)
@@ -4976,14 +5037,14 @@ void BLO_read_list_cb(BlendDataReader *reader, ListBase *list, BlendReadListFn c
}
BLO_read_data_address(reader, &list->first);
- if (callback != NULL) {
+ if (callback != nullptr) {
callback(reader, list->first);
}
- Link *ln = list->first;
- Link *prev = NULL;
+ Link *ln = static_cast<Link *>(list->first);
+ Link *prev = nullptr;
while (ln) {
BLO_read_data_address(reader, &ln->next);
- if (ln->next != NULL && callback != NULL) {
+ if (ln->next != nullptr && callback != nullptr) {
callback(reader, ln->next);
}
ln->prev = prev;
@@ -4993,9 +5054,9 @@ void BLO_read_list_cb(BlendDataReader *reader, ListBase *list, BlendReadListFn c
list->last = prev;
}
-void BLO_read_list(BlendDataReader *reader, struct ListBase *list)
+void BLO_read_list(BlendDataReader *reader, ListBase *list)
{
- BLO_read_list_cb(reader, list, NULL);
+ BLO_read_list_cb(reader, list, nullptr);
}
void BLO_read_int32_array(BlendDataReader *reader, int array_size, int32_t **ptr_p)
@@ -5045,17 +5106,17 @@ static void convert_pointer_array_64_to_32(BlendDataReader *reader,
for (int i = 0; i < array_size; i++) {
uint64_t ptr = src[i];
BLI_endian_switch_uint64(&ptr);
- dst[i] = (uint32_t)(ptr >> 3);
+ dst[i] = uint32_t(ptr >> 3);
}
}
else {
for (int i = 0; i < array_size; i++) {
- dst[i] = (uint32_t)(src[i] >> 3);
+ dst[i] = uint32_t(src[i] >> 3);
}
}
}
-static void convert_pointer_array_32_to_64(BlendDataReader *UNUSED(reader),
+static void convert_pointer_array_32_to_64(BlendDataReader * /*reader*/,
uint array_size,
const uint32_t *src,
uint64_t *dst)
@@ -5071,8 +5132,8 @@ void BLO_read_pointer_array(BlendDataReader *reader, void **ptr_p)
FileData *fd = reader->fd;
void *orig_array = newdataadr(fd, *ptr_p);
- if (orig_array == NULL) {
- *ptr_p = NULL;
+ if (orig_array == nullptr) {
+ *ptr_p = nullptr;
return;
}
@@ -5082,7 +5143,7 @@ void BLO_read_pointer_array(BlendDataReader *reader, void **ptr_p)
/* Over-allocation is fine, but might be better to pass the length as parameter. */
int array_size = MEM_allocN_len(orig_array) / file_pointer_size;
- void *final_array = NULL;
+ void *final_array = nullptr;
if (file_pointer_size == current_pointer_size) {
/* No pointer conversion necessary. */
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 4522adb2aef..a0f19512753 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -8,6 +8,8 @@
#pragma once
+#include <stdio.h> /* Include header using off_t before poisoning it below. */
+
#ifdef WIN32
# include "BLI_winstuff.h"
#endif
@@ -17,6 +19,10 @@
#include "DNA_space_types.h"
#include "DNA_windowmanager_types.h" /* for eReportType */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct BLI_mmap_file;
struct BLOCacheStorage;
struct IDNameLib_Map;
@@ -38,6 +44,7 @@ enum eFileDataFlag {
/* XXX Unused in practice (checked once but never set). */
FD_FLAGS_NOT_MY_LIBMAP = 1 << 5,
};
+ENUM_OPERATORS(eFileDataFlag, FD_FLAGS_NOT_MY_LIBMAP)
/* Disallow since it's 32bit on ms-windows. */
#ifdef __GNUC__
@@ -207,6 +214,7 @@ void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main *
void blo_do_versions_280(struct FileData *fd, struct Library *lib, struct Main *bmain);
void blo_do_versions_290(struct FileData *fd, struct Library *lib, struct Main *bmain);
void blo_do_versions_300(struct FileData *fd, struct Library *lib, struct Main *bmain);
+void blo_do_versions_400(struct FileData *fd, struct Library *lib, struct Main *bmain);
void blo_do_versions_cycles(struct FileData *fd, struct Library *lib, struct Main *bmain);
void do_versions_after_linking_250(struct Main *bmain);
@@ -224,3 +232,7 @@ void do_versions_after_linking_cycles(struct Main *bmain);
* but better use that nasty hack in do_version than readfile itself.
*/
void *blo_read_get_new_globaldata_address(struct FileData *fd, const void *adr);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenloader/intern/readfile_tempload.c b/source/blender/blenloader/intern/readfile_tempload.cc
index d642dbb5012..933077924f5 100644
--- a/source/blender/blenloader/intern/readfile_tempload.c
+++ b/source/blender/blenloader/intern/readfile_tempload.cc
@@ -20,7 +20,8 @@ TempLibraryContext *BLO_library_temp_load_id(struct Main *real_main,
const char *idname,
struct ReportList *reports)
{
- TempLibraryContext *temp_lib_ctx = MEM_callocN(sizeof(*temp_lib_ctx), __func__);
+ TempLibraryContext *temp_lib_ctx = static_cast<TempLibraryContext *>(
+ MEM_callocN(sizeof(*temp_lib_ctx), __func__));
temp_lib_ctx->bmain_base = BKE_main_new();
temp_lib_ctx->bf_reports.reports = reports;
diff --git a/source/blender/blenloader/intern/undofile.c b/source/blender/blenloader/intern/undofile.cc
index b5c2a73c268..99d1ca336fe 100644
--- a/source/blender/blenloader/intern/undofile.c
+++ b/source/blender/blenloader/intern/undofile.cc
@@ -42,7 +42,7 @@ void BLO_memfile_free(MemFile *memfile)
{
MemFileChunk *chunk;
- while ((chunk = BLI_pophead(&memfile->chunks))) {
+ while ((chunk = static_cast<MemFileChunk *>(BLI_pophead(&memfile->chunks)))) {
if (chunk->is_identical == false) {
MEM_freeN((void *)chunk->buf);
}
@@ -59,7 +59,8 @@ void BLO_memfile_merge(MemFile *first, MemFile *second)
BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
/* First, detect all memchunks in second memfile that are not owned by it. */
- for (MemFileChunk *sc = second->chunks.first; sc != NULL; sc = sc->next) {
+ for (MemFileChunk *sc = static_cast<MemFileChunk *>(second->chunks.first); sc != nullptr;
+ sc = static_cast<MemFileChunk *>(sc->next)) {
if (sc->is_identical) {
BLI_ghash_insert(buffer_to_second_memchunk, (void *)sc->buf, sc);
}
@@ -67,10 +68,12 @@ void BLO_memfile_merge(MemFile *first, MemFile *second)
/* Now, check all chunks from first memfile (the one we are removing), and if a memchunk owned by
* it is also used by the second memfile, transfer the ownership. */
- for (MemFileChunk *fc = first->chunks.first; fc != NULL; fc = fc->next) {
+ for (MemFileChunk *fc = static_cast<MemFileChunk *>(first->chunks.first); fc != nullptr;
+ fc = static_cast<MemFileChunk *>(fc->next)) {
if (!fc->is_identical) {
- MemFileChunk *sc = BLI_ghash_lookup(buffer_to_second_memchunk, fc->buf);
- if (sc != NULL) {
+ MemFileChunk *sc = static_cast<MemFileChunk *>(
+ BLI_ghash_lookup(buffer_to_second_memchunk, fc->buf));
+ if (sc != nullptr) {
BLI_assert(sc->is_identical);
sc->is_identical = false;
fc->is_identical = true;
@@ -81,7 +84,7 @@ void BLO_memfile_merge(MemFile *first, MemFile *second)
}
}
- BLI_ghash_free(buffer_to_second_memchunk, NULL, NULL);
+ BLI_ghash_free(buffer_to_second_memchunk, nullptr, nullptr);
BLO_memfile_free(first);
}
@@ -99,14 +102,16 @@ void BLO_memfile_write_init(MemFileWriteData *mem_data,
{
mem_data->written_memfile = written_memfile;
mem_data->reference_memfile = reference_memfile;
- mem_data->reference_current_chunk = reference_memfile ? reference_memfile->chunks.first : NULL;
+ mem_data->reference_current_chunk = reference_memfile ? static_cast<MemFileChunk *>(
+ reference_memfile->chunks.first) :
+ nullptr;
/* If we have a reference memfile, we generate a mapping between the session_uuid's of the
* IDs stored in that previous undo step, and its first matching memchunk. This will allow
* us to easily find the existing undo memory storage of IDs even when some re-ordering in
* current Main data-base broke the order matching with the memchunks from previous step.
*/
- if (reference_memfile != NULL) {
+ if (reference_memfile != nullptr) {
mem_data->id_session_uuid_mapping = BLI_ghash_new(
BLI_ghashutil_inthash_p_simple, BLI_ghashutil_intcmp, __func__);
uint current_session_uuid = MAIN_ID_SESSION_UUID_UNSET;
@@ -129,8 +134,8 @@ void BLO_memfile_write_init(MemFileWriteData *mem_data,
void BLO_memfile_write_finalize(MemFileWriteData *mem_data)
{
- if (mem_data->id_session_uuid_mapping != NULL) {
- BLI_ghash_free(mem_data->id_session_uuid_mapping, NULL, NULL);
+ if (mem_data->id_session_uuid_mapping != nullptr) {
+ BLI_ghash_free(mem_data->id_session_uuid_mapping, nullptr, nullptr);
}
}
@@ -139,9 +144,10 @@ void BLO_memfile_chunk_add(MemFileWriteData *mem_data, const char *buf, size_t s
MemFile *memfile = mem_data->written_memfile;
MemFileChunk **compchunk_step = &mem_data->reference_current_chunk;
- MemFileChunk *curchunk = MEM_mallocN(sizeof(MemFileChunk), "MemFileChunk");
+ MemFileChunk *curchunk = static_cast<MemFileChunk *>(
+ MEM_mallocN(sizeof(MemFileChunk), "MemFileChunk"));
curchunk->size = size;
- curchunk->buf = NULL;
+ curchunk->buf = nullptr;
curchunk->is_identical = false;
/* This is unsafe in the sense that an app handler or other code that does not
* perform an undo push may make changes after the last undo push that
@@ -151,7 +157,7 @@ void BLO_memfile_chunk_add(MemFileWriteData *mem_data, const char *buf, size_t s
BLI_addtail(&memfile->chunks, curchunk);
/* we compare compchunk with buf */
- if (*compchunk_step != NULL) {
+ if (*compchunk_step != nullptr) {
MemFileChunk *compchunk = *compchunk_step;
if (compchunk->size == curchunk->size) {
if (memcmp(compchunk->buf, buf, size) == 0) {
@@ -160,12 +166,12 @@ void BLO_memfile_chunk_add(MemFileWriteData *mem_data, const char *buf, size_t s
compchunk->is_identical_future = true;
}
}
- *compchunk_step = compchunk->next;
+ *compchunk_step = static_cast<MemFileChunk *>(compchunk->next);
}
/* not equal... */
- if (curchunk->buf == NULL) {
- char *buf_new = MEM_mallocN(size, "Chunk buffer");
+ if (curchunk->buf == nullptr) {
+ char *buf_new = static_cast<char *>(MEM_mallocN(size, "Chunk buffer"));
memcpy(buf_new, buf, size);
curchunk->buf = buf_new;
memfile->size += size;
@@ -176,12 +182,10 @@ struct Main *BLO_memfile_main_get(struct MemFile *memfile,
struct Main *bmain,
struct Scene **r_scene)
{
- struct Main *bmain_undo = NULL;
- BlendFileData *bfd = BLO_read_from_memfile(bmain,
- BKE_main_blendfile_path(bmain),
- memfile,
- &(const struct BlendFileReadParams){0},
- NULL);
+ struct Main *bmain_undo = nullptr;
+ BlendFileReadParams read_params{};
+ BlendFileData *bfd = BLO_read_from_memfile(
+ bmain, BKE_main_blendfile_path(bmain), memfile, &read_params, nullptr);
if (bfd) {
bmain_undo = bfd->main;
@@ -226,11 +230,12 @@ bool BLO_memfile_write_file(struct MemFile *memfile, const char *filepath)
return false;
}
- for (chunk = memfile->chunks.first; chunk; chunk = chunk->next) {
+ for (chunk = static_cast<MemFileChunk *>(memfile->chunks.first); chunk;
+ chunk = static_cast<MemFileChunk *>(chunk->next)) {
#ifdef _WIN32
- if ((size_t)write(file, chunk->buf, (uint)chunk->size) != chunk->size)
+ if (size_t(write(file, chunk->buf, uint(chunk->size))) != chunk->size)
#else
- if ((size_t)write(file, chunk->buf, chunk->size) != chunk->size)
+ if (size_t(write(file, chunk->buf, chunk->size)) != chunk->size)
#endif
{
break;
@@ -255,7 +260,7 @@ static ssize_t undo_read(FileReader *reader, void *buffer, size_t size)
static size_t seek = SIZE_MAX; /* The current position. */
static size_t offset = 0; /* Size of previous chunks. */
- static MemFileChunk *chunk = NULL;
+ static MemFileChunk *chunk = nullptr;
size_t chunkoffset, readsize, totread;
undo->memchunk_identical = true;
@@ -264,19 +269,19 @@ static ssize_t undo_read(FileReader *reader, void *buffer, size_t size)
return 0;
}
- if (seek != (size_t)undo->reader.offset) {
- chunk = undo->memfile->chunks.first;
+ if (seek != size_t(undo->reader.offset)) {
+ chunk = static_cast<MemFileChunk *>(undo->memfile->chunks.first);
seek = 0;
while (chunk) {
- if (seek + chunk->size > (size_t)undo->reader.offset) {
+ if (seek + chunk->size > size_t(undo->reader.offset)) {
break;
}
seek += chunk->size;
- chunk = chunk->next;
+ chunk = static_cast<MemFileChunk *>(chunk->next);
}
offset = seek;
- seek = (size_t)undo->reader.offset;
+ seek = size_t(undo->reader.offset);
}
if (chunk) {
@@ -286,11 +291,11 @@ static ssize_t undo_read(FileReader *reader, void *buffer, size_t size)
/* First check if it's on the end if current chunk. */
if (seek - offset == chunk->size) {
offset += chunk->size;
- chunk = chunk->next;
+ chunk = static_cast<MemFileChunk *>(chunk->next);
}
/* Debug, should never happen. */
- if (chunk == NULL) {
+ if (chunk == nullptr) {
printf("illegal read, chunk zero\n");
return 0;
}
@@ -318,7 +323,7 @@ static ssize_t undo_read(FileReader *reader, void *buffer, size_t size)
chunk->is_identical_future;
} while (totread < size);
- return (ssize_t)totread;
+ return ssize_t(totread);
}
return 0;
@@ -331,13 +336,13 @@ static void undo_close(FileReader *reader)
FileReader *BLO_memfile_new_filereader(MemFile *memfile, int undo_direction)
{
- UndoReader *undo = MEM_callocN(sizeof(UndoReader), __func__);
+ UndoReader *undo = static_cast<UndoReader *>(MEM_callocN(sizeof(UndoReader), __func__));
undo->memfile = memfile;
undo->undo_direction = undo_direction;
undo->reader.read = undo_read;
- undo->reader.seek = NULL;
+ undo->reader.seek = nullptr;
undo->reader.close = undo_close;
return (FileReader *)undo;
diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c
index ffa224ea9e0..0b543ad735b 100644
--- a/source/blender/blenloader/intern/versioning_250.c
+++ b/source/blender/blenloader/intern/versioning_250.c
@@ -54,6 +54,7 @@
#include "BKE_global.h" /* for G */
#include "BKE_lib_id.h"
#include "BKE_main.h"
+#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_multires.h"
#include "BKE_node_tree_update.h"
@@ -629,7 +630,7 @@ static bool seq_sound_proxy_update_cb(Sequence *seq, void *user_data)
Main *bmain = (Main *)user_data;
if (seq->type == SEQ_TYPE_SOUND_HD) {
char str[FILE_MAX];
- BLI_join_dirfile(str, sizeof(str), seq->strip->dir, seq->strip->stripdata->name);
+ BLI_path_join(str, sizeof(str), seq->strip->dir, seq->strip->stripdata->name);
BLI_path_abs(str, BKE_main_blendfile_path(bmain));
seq->sound = BKE_sound_new_file(bmain, str);
}
@@ -989,15 +990,15 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain)
int a, tot;
/* shape keys are no longer applied to the mesh itself, but rather
- * to the evaluated #Mesh / #DispList, so here we ensure that the basis
+ * to the evaluated #Mesh, so here we ensure that the basis
* shape key is always set in the mesh coordinates. */
for (me = bmain->meshes.first; me; me = me->id.next) {
if ((key = blo_do_versions_newlibadr(fd, lib, me->key)) && key->refkey) {
data = key->refkey->data;
tot = MIN2(me->totvert, key->refkey->totelem);
-
+ MVert *verts = BKE_mesh_verts_for_write(me);
for (a = 0; a < tot; a++, data += 3) {
- copy_v3_v3(me->mvert[a].co, data);
+ copy_v3_v3(verts[a].co, data);
}
}
}
@@ -2315,7 +2316,6 @@ static void lib_node_do_versions_group_indices(bNode *gnode)
/* deprecated */
sock->own_index = link->fromsock->own_index;
sock->to_index = 0;
- sock->groupsock = NULL;
}
}
}
@@ -2328,7 +2328,6 @@ static void lib_node_do_versions_group_indices(bNode *gnode)
/* deprecated */
sock->own_index = link->tosock->own_index;
sock->to_index = 0;
- sock->groupsock = NULL;
}
}
}
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 2ab7dd22be3..f3dd0ca9a46 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -53,6 +53,7 @@
#include "DNA_world_types.h"
#include "BKE_animsys.h"
+#include "BKE_blender.h"
#include "BKE_brush.h"
#include "BKE_cloth.h"
#include "BKE_collection.h"
@@ -367,7 +368,7 @@ static void do_version_scene_collection_to_collection(Main *bmain, Scene *scene)
BLI_listbase_clear(&scene->view_layers);
if (!scene->master_collection) {
- scene->master_collection = BKE_collection_master_add();
+ scene->master_collection = BKE_collection_master_add(scene);
}
/* Convert scene collections. */
@@ -411,7 +412,7 @@ 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
* render layer instead. */
if (!scene->master_collection) {
- scene->master_collection = BKE_collection_master_add();
+ scene->master_collection = BKE_collection_master_add(scene);
}
if (scene->view_layers.first) {
@@ -512,12 +513,13 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene)
}
}
+ BKE_view_layer_synced_ensure(scene, view_layer);
/* for convenience set the same active object in all the layers */
if (scene->basact) {
view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
}
- LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
+ LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
if ((base->flag & BASE_SELECTABLE) && (base->object->flag & SELECT)) {
base->flag |= BASE_SELECTED;
}
@@ -537,13 +539,14 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene)
view_layer->flag &= ~VIEW_LAYER_RENDER;
}
+ BKE_view_layer_synced_ensure(scene, view_layer);
/* convert active base */
if (scene->basact) {
view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
}
/* convert selected bases */
- LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
+ LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
if ((base->flag & BASE_SELECTABLE) && (base->object->flag & SELECT)) {
base->flag |= BASE_SELECTED;
}
@@ -592,7 +595,7 @@ static void do_versions_fix_annotations(bGPdata *gpd)
LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
- if ((gps->colorname[0] != '\0') && (STREQ(gps->colorname, palcolor->info))) {
+ if ((gps->colorname[0] != '\0') && STREQ(gps->colorname, palcolor->info)) {
/* copy color settings */
copy_v4_v4(gpl->color, palcolor->color);
}
@@ -1611,12 +1614,13 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports))
if (me->totface && !me->totpoly) {
/* temporarily switch main so that reading from
* external CustomData works */
- Main *gmain = G_MAIN;
- G_MAIN = bmain;
+ Main *orig_gmain = BKE_blender_globals_main_swap(bmain);
BKE_mesh_do_versions_convert_mfaces_to_mpolys(me);
- G_MAIN = gmain;
+ Main *tmp_gmain = BKE_blender_globals_main_swap(orig_gmain);
+ BLI_assert(tmp_gmain == bmain);
+ UNUSED_VARS_NDEBUG(tmp_gmain);
}
/* Deprecated, only kept for conversion. */
@@ -1794,10 +1798,9 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (DNA_struct_find(fd->filesdna, "MTexPoly")) {
for (Mesh *me = bmain->meshes.first; me; me = me->id.next) {
/* If we have UV's, so this file will have MTexPoly layers too! */
- if (me->mloopuv != NULL) {
+ if (CustomData_has_layer(&me->ldata, CD_MLOOPUV)) {
CustomData_update_typemap(&me->pdata);
CustomData_free_layers(&me->pdata, CD_MTEXPOLY, me->totpoly);
- BKE_mesh_update_customdata_pointers(me, false);
}
}
}
@@ -3376,7 +3379,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
SpaceImage *sima = (SpaceImage *)sl;
sima->flag &= ~(SI_FLAG_UNUSED_0 | SI_FLAG_UNUSED_1 | SI_FLAG_UNUSED_3 |
SI_FLAG_UNUSED_6 | SI_FLAG_UNUSED_7 | SI_FLAG_UNUSED_8 |
- SI_FLAG_UNUSED_17 | SI_CUSTOM_GRID | SI_FLAG_UNUSED_23 |
+ SI_FLAG_UNUSED_17 | SI_FLAG_UNUSED_18 | SI_FLAG_UNUSED_23 |
SI_FLAG_UNUSED_24);
break;
}
@@ -3384,7 +3387,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
View3D *v3d = (View3D *)sl;
v3d->flag &= ~(V3D_LOCAL_COLLECTIONS | V3D_FLAG_UNUSED_1 | V3D_FLAG_UNUSED_10 |
V3D_FLAG_UNUSED_12);
- v3d->flag2 &= ~(V3D_FLAG2_UNUSED_3 | V3D_FLAG2_UNUSED_6 | V3D_FLAG2_UNUSED_12 |
+ v3d->flag2 &= ~((1 << 3) | V3D_FLAG2_UNUSED_6 | V3D_FLAG2_UNUSED_12 |
V3D_FLAG2_UNUSED_13 | V3D_FLAG2_UNUSED_14 | V3D_FLAG2_UNUSED_15);
break;
}
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index 9ab744337a8..e4c476e1212 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -819,21 +819,21 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (MAIN_VERSION_ATLEAST(bmain, 290, 2) && MAIN_VERSION_OLDER(bmain, 291, 1)) {
/* In this range, the extrude manifold could generate meshes with degenerated face. */
LISTBASE_FOREACH (Mesh *, me, &bmain->meshes) {
- for (MPoly *mp = me->mpoly, *mp_end = mp + me->totpoly; mp < mp_end; mp++) {
+ for (const MPoly *mp = BKE_mesh_polys(me), *mp_end = mp + me->totpoly; mp < mp_end; mp++) {
if (mp->totloop == 2) {
bool changed;
BKE_mesh_validate_arrays(me,
- me->mvert,
+ BKE_mesh_verts_for_write(me),
me->totvert,
- me->medge,
+ BKE_mesh_edges_for_write(me),
me->totedge,
- me->mface,
+ (MFace *)CustomData_get_layer(&me->fdata, CD_MFACE),
me->totface,
- me->mloop,
+ BKE_mesh_loops_for_write(me),
me->totloop,
- me->mpoly,
+ BKE_mesh_polys_for_write(me),
me->totpoly,
- me->dvert,
+ BKE_mesh_deform_verts_for_write(me),
false,
true,
&changed);
@@ -926,7 +926,7 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
for (Object *object = bmain->objects.first; object != NULL; object = object->id.next) {
LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
if (md->mode & eModifierMode_Expanded_DEPRECATED) {
- md->ui_expand_flag = 1;
+ md->ui_expand_flag = UI_PANEL_DATA_EXPAND_ROOT;
}
else {
md->ui_expand_flag = 0;
@@ -954,7 +954,7 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
for (Object *object = bmain->objects.first; object != NULL; object = object->id.next) {
LISTBASE_FOREACH (bConstraint *, con, &object->constraints) {
if (con->flag & CONSTRAINT_EXPAND_DEPRECATED) {
- con->ui_expand_flag = 1;
+ con->ui_expand_flag = UI_PANEL_DATA_EXPAND_ROOT;
}
else {
con->ui_expand_flag = 0;
@@ -968,7 +968,7 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
for (Object *object = bmain->objects.first; object != NULL; object = object->id.next) {
LISTBASE_FOREACH (GpencilModifierData *, md, &object->greasepencil_modifiers) {
if (md->mode & eGpencilModifierMode_Expanded_DEPRECATED) {
- md->ui_expand_flag = 1;
+ md->ui_expand_flag = UI_PANEL_DATA_EXPAND_ROOT;
}
else {
md->ui_expand_flag = 0;
@@ -982,7 +982,7 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
for (Object *object = bmain->objects.first; object != NULL; object = object->id.next) {
LISTBASE_FOREACH (ShaderFxData *, fx, &object->shader_fx) {
if (fx->mode & eShaderFxMode_Expanded_DEPRECATED) {
- fx->ui_expand_flag = 1;
+ fx->ui_expand_flag = UI_PANEL_DATA_EXPAND_ROOT;
}
else {
fx->ui_expand_flag = 0;
@@ -1611,8 +1611,8 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
- if ((!MAIN_VERSION_ATLEAST(bmain, 292, 14)) ||
- ((bmain->versionfile == 293) && (!MAIN_VERSION_ATLEAST(bmain, 293, 1)))) {
+ if (!MAIN_VERSION_ATLEAST(bmain, 292, 14) ||
+ ((bmain->versionfile == 293) && !MAIN_VERSION_ATLEAST(bmain, 293, 1))) {
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
if (ntree->type != NTREE_GEOMETRY) {
continue;
@@ -1697,7 +1697,7 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
- /* Add subpanels for FModifiers, which requires a field to store expansion. */
+ /* Add sub-panels for FModifiers, which requires a field to store expansion. */
if (!DNA_struct_elem_find(fd->filesdna, "FModifier", "short", "ui_expand_flag")) {
LISTBASE_FOREACH (bAction *, act, &bmain->actions) {
LISTBASE_FOREACH (FCurve *, fcu, &act->curves) {
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.cc
index bbbeba4d687..a2bd7fd2fd1 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.cc
@@ -6,7 +6,7 @@
/* allow readfile to use deprecated functionality */
#define DNA_DEPRECATED_ALLOW
-#include <string.h>
+#include <cstring>
#include "CLG_log.h"
@@ -57,6 +57,7 @@
#include "BKE_lib_id.h"
#include "BKE_lib_override.h"
#include "BKE_main.h"
+#include "BKE_main_namemap.h"
#include "BKE_modifier.h"
#include "BKE_node.h"
#include "BKE_screen.h"
@@ -85,39 +86,40 @@ static IDProperty *idproperty_find_ui_container(IDProperty *idprop_group)
return prop;
}
}
- return NULL;
+ return nullptr;
}
static void version_idproperty_move_data_int(IDPropertyUIDataInt *ui_data,
const IDProperty *prop_ui_data)
{
IDProperty *min = IDP_GetPropertyFromGroup(prop_ui_data, "min");
- if (min != NULL) {
+ if (min != nullptr) {
ui_data->min = ui_data->soft_min = IDP_coerce_to_int_or_zero(min);
}
IDProperty *max = IDP_GetPropertyFromGroup(prop_ui_data, "max");
- if (max != NULL) {
+ if (max != nullptr) {
ui_data->max = ui_data->soft_max = IDP_coerce_to_int_or_zero(max);
}
IDProperty *soft_min = IDP_GetPropertyFromGroup(prop_ui_data, "soft_min");
- if (soft_min != NULL) {
+ if (soft_min != nullptr) {
ui_data->soft_min = IDP_coerce_to_int_or_zero(soft_min);
ui_data->soft_min = MIN2(ui_data->soft_min, ui_data->min);
}
IDProperty *soft_max = IDP_GetPropertyFromGroup(prop_ui_data, "soft_max");
- if (soft_max != NULL) {
+ if (soft_max != nullptr) {
ui_data->soft_max = IDP_coerce_to_int_or_zero(soft_max);
ui_data->soft_max = MAX2(ui_data->soft_max, ui_data->max);
}
IDProperty *step = IDP_GetPropertyFromGroup(prop_ui_data, "step");
- if (step != NULL) {
+ if (step != nullptr) {
ui_data->step = IDP_coerce_to_int_or_zero(soft_max);
}
IDProperty *default_value = IDP_GetPropertyFromGroup(prop_ui_data, "default");
- if (default_value != NULL) {
+ if (default_value != nullptr) {
if (default_value->type == IDP_ARRAY) {
if (default_value->subtype == IDP_INT) {
- ui_data->default_array = MEM_malloc_arrayN(default_value->len, sizeof(int), __func__);
+ ui_data->default_array = static_cast<int *>(
+ MEM_malloc_arrayN(default_value->len, sizeof(int), __func__));
memcpy(ui_data->default_array, IDP_Array(default_value), sizeof(int) * default_value->len);
ui_data->default_array_len = default_value->len;
}
@@ -132,45 +134,47 @@ static void version_idproperty_move_data_float(IDPropertyUIDataFloat *ui_data,
const IDProperty *prop_ui_data)
{
IDProperty *min = IDP_GetPropertyFromGroup(prop_ui_data, "min");
- if (min != NULL) {
+ if (min != nullptr) {
ui_data->min = ui_data->soft_min = IDP_coerce_to_double_or_zero(min);
}
IDProperty *max = IDP_GetPropertyFromGroup(prop_ui_data, "max");
- if (max != NULL) {
+ if (max != nullptr) {
ui_data->max = ui_data->soft_max = IDP_coerce_to_double_or_zero(max);
}
IDProperty *soft_min = IDP_GetPropertyFromGroup(prop_ui_data, "soft_min");
- if (soft_min != NULL) {
+ if (soft_min != nullptr) {
ui_data->soft_min = IDP_coerce_to_double_or_zero(soft_min);
ui_data->soft_min = MAX2(ui_data->soft_min, ui_data->min);
}
IDProperty *soft_max = IDP_GetPropertyFromGroup(prop_ui_data, "soft_max");
- if (soft_max != NULL) {
+ if (soft_max != nullptr) {
ui_data->soft_max = IDP_coerce_to_double_or_zero(soft_max);
ui_data->soft_max = MIN2(ui_data->soft_max, ui_data->max);
}
IDProperty *step = IDP_GetPropertyFromGroup(prop_ui_data, "step");
- if (step != NULL) {
+ if (step != nullptr) {
ui_data->step = IDP_coerce_to_float_or_zero(step);
}
IDProperty *precision = IDP_GetPropertyFromGroup(prop_ui_data, "precision");
- if (precision != NULL) {
+ if (precision != nullptr) {
ui_data->precision = IDP_coerce_to_int_or_zero(precision);
}
IDProperty *default_value = IDP_GetPropertyFromGroup(prop_ui_data, "default");
- if (default_value != NULL) {
+ if (default_value != nullptr) {
if (default_value->type == IDP_ARRAY) {
const int array_len = default_value->len;
ui_data->default_array_len = array_len;
if (default_value->subtype == IDP_FLOAT) {
- ui_data->default_array = MEM_malloc_arrayN(array_len, sizeof(double), __func__);
- const float *old_default_array = IDP_Array(default_value);
+ ui_data->default_array = static_cast<double *>(
+ MEM_malloc_arrayN(array_len, sizeof(double), __func__));
+ const float *old_default_array = static_cast<const float *>(IDP_Array(default_value));
for (int i = 0; i < ui_data->default_array_len; i++) {
- ui_data->default_array[i] = (double)old_default_array[i];
+ ui_data->default_array[i] = double(old_default_array[i]);
}
}
else if (default_value->subtype == IDP_DOUBLE) {
- ui_data->default_array = MEM_malloc_arrayN(array_len, sizeof(double), __func__);
+ ui_data->default_array = static_cast<double *>(
+ MEM_malloc_arrayN(array_len, sizeof(double), __func__));
memcpy(ui_data->default_array, IDP_Array(default_value), sizeof(double) * array_len);
}
}
@@ -184,25 +188,26 @@ static void version_idproperty_move_data_string(IDPropertyUIDataString *ui_data,
const IDProperty *prop_ui_data)
{
IDProperty *default_value = IDP_GetPropertyFromGroup(prop_ui_data, "default");
- if (default_value != NULL && default_value->type == IDP_STRING) {
+ if (default_value != nullptr && default_value->type == IDP_STRING) {
ui_data->default_value = BLI_strdup(IDP_String(default_value));
}
}
static void version_idproperty_ui_data(IDProperty *idprop_group)
{
- if (idprop_group == NULL) { /* NULL check here to reduce verbosity of calls to this function. */
+ if (idprop_group ==
+ nullptr) { /* nullptr check here to reduce verbosity of calls to this function. */
return;
}
IDProperty *ui_container = idproperty_find_ui_container(idprop_group);
- if (ui_container == NULL) {
+ if (ui_container == nullptr) {
return;
}
LISTBASE_FOREACH (IDProperty *, prop, &idprop_group->data.group) {
IDProperty *prop_ui_data = IDP_GetPropertyFromGroup(ui_container, prop->name);
- if (prop_ui_data == NULL) {
+ if (prop_ui_data == nullptr) {
continue;
}
@@ -213,7 +218,7 @@ static void version_idproperty_ui_data(IDProperty *idprop_group)
IDPropertyUIData *ui_data = IDP_ui_data_ensure(prop);
IDProperty *subtype = IDP_GetPropertyFromGroup(prop_ui_data, "subtype");
- if (subtype != NULL && subtype->type == IDP_STRING) {
+ if (subtype != nullptr && subtype->type == IDP_STRING) {
const char *subtype_string = IDP_String(subtype);
int result = PROP_NONE;
RNA_enum_value_from_id(rna_enum_property_subtype_items, subtype_string, &result);
@@ -221,7 +226,7 @@ static void version_idproperty_ui_data(IDProperty *idprop_group)
}
IDProperty *description = IDP_GetPropertyFromGroup(prop_ui_data, "description");
- if (description != NULL && description->type == IDP_STRING) {
+ if (description != nullptr && description->type == IDP_STRING) {
ui_data->description = BLI_strdup(IDP_String(description));
}
@@ -317,7 +322,7 @@ static void do_versions_idproperty_ui_data(Main *bmain)
}
/* Object post bones. */
- if (ob->type == OB_ARMATURE && ob->pose != NULL) {
+ if (ob->type == OB_ARMATURE && ob->pose != nullptr) {
LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) {
version_idproperty_ui_data(pchan->prop);
}
@@ -326,7 +331,7 @@ static void do_versions_idproperty_ui_data(Main *bmain)
/* Sequences. */
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
- if (scene->ed != NULL) {
+ if (scene->ed != nullptr) {
do_versions_idproperty_seq_recursive(&scene->ed->seqbase);
}
}
@@ -342,7 +347,7 @@ static void sort_linked_ids(Main *bmain)
if (ID_IS_LINKED(id)) {
BLI_remlink(lb, id);
BLI_addtail(&temp_list, id);
- id_sort_by_name(&temp_list, id, NULL);
+ id_sort_by_name(&temp_list, id, nullptr);
}
}
BLI_movelisttolist(lb, &temp_list);
@@ -355,9 +360,9 @@ static void assert_sorted_ids(Main *bmain)
#ifndef NDEBUG
ListBase *lb;
FOREACH_MAIN_LISTBASE_BEGIN (bmain, lb) {
- ID *id_prev = NULL;
+ ID *id_prev = nullptr;
LISTBASE_FOREACH (ID *, id, lb) {
- if (id_prev == NULL) {
+ if (id_prev == nullptr) {
continue;
}
BLI_assert(id_prev->lib != id->lib || BLI_strcasecmp(id_prev->name, id->name) < 0);
@@ -398,7 +403,7 @@ static void do_versions_sequencer_speed_effect_recursive(Scene *scene, const Lis
LISTBASE_FOREACH (Sequence *, seq, seqbase) {
if (seq->type == SEQ_TYPE_SPEED) {
SpeedControlVars *v = (SpeedControlVars *)seq->effectdata;
- const char *substr = NULL;
+ const char *substr = nullptr;
float globalSpeed = v->globalSpeed;
if (seq->flag & SEQ_USE_EFFECT_DEFAULT_FADE) {
if (globalSpeed == 1.0f) {
@@ -407,9 +412,9 @@ static void do_versions_sequencer_speed_effect_recursive(Scene *scene, const Lis
else {
v->speed_control_type = SEQ_SPEED_MULTIPLY;
v->speed_fader = globalSpeed *
- ((float)seq->seq1->len /
- max_ff((float)(SEQ_time_right_handle_frame_get(scene, seq->seq1) -
- seq->seq1->start),
+ (float(seq->seq1->len) /
+ max_ff(float(SEQ_time_right_handle_frame_get(scene, seq->seq1) -
+ seq->seq1->start),
1.0f));
}
}
@@ -425,14 +430,15 @@ static void do_versions_sequencer_speed_effect_recursive(Scene *scene, const Lis
}
else {
v->speed_control_type = SEQ_SPEED_FRAME_NUMBER;
- v->speed_fader_frame_number = (int)(seq->speed_fader * globalSpeed);
+ v->speed_fader_frame_number = int(seq->speed_fader * globalSpeed);
substr = "speed_frame_number";
}
v->flags &= ~(SEQ_SPEED_INTEGRATE | SEQ_SPEED_COMPRESS_IPO_Y);
if (substr || globalSpeed != 1.0f) {
- FCurve *fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_factor", 0, NULL);
+ FCurve *fcu = id_data_find_fcurve(
+ &scene->id, seq, &RNA_Sequence, "speed_factor", 0, nullptr);
if (fcu) {
if (globalSpeed != 1.0f) {
for (int i = 0; i < fcu->totvert; i++) {
@@ -459,13 +465,13 @@ static void do_versions_sequencer_speed_effect_recursive(Scene *scene, const Lis
#undef SEQ_SPEED_COMPRESS_IPO_Y
}
-static bool do_versions_sequencer_color_tags(Sequence *seq, void *UNUSED(user_data))
+static bool do_versions_sequencer_color_tags(Sequence *seq, void * /*user_data*/)
{
seq->color_tag = SEQUENCE_COLOR_NONE;
return true;
}
-static bool do_versions_sequencer_color_balance_sop(Sequence *seq, void *UNUSED(user_data))
+static bool do_versions_sequencer_color_balance_sop(Sequence *seq, void * /*user_data*/)
{
LISTBASE_FOREACH (SequenceModifierData *, smd, &seq->modifiers) {
if (smd->type == seqModifierType_ColorBalance) {
@@ -488,7 +494,7 @@ static bNodeLink *find_connected_link(bNodeTree *ntree, bNodeSocket *in_socket)
return link;
}
}
- return NULL;
+ return nullptr;
}
static void add_realize_instances_before_socket(bNodeTree *ntree,
@@ -497,7 +503,7 @@ static void add_realize_instances_before_socket(bNodeTree *ntree,
{
BLI_assert(geometry_socket->type == SOCK_GEOMETRY);
bNodeLink *link = find_connected_link(ntree, geometry_socket);
- if (link == NULL) {
+ if (link == nullptr) {
return;
}
@@ -506,13 +512,17 @@ static void add_realize_instances_before_socket(bNodeTree *ntree,
return;
}
- bNode *realize_node = nodeAddStaticNode(NULL, ntree, GEO_NODE_REALIZE_INSTANCES);
+ bNode *realize_node = nodeAddStaticNode(nullptr, ntree, GEO_NODE_REALIZE_INSTANCES);
realize_node->parent = node->parent;
realize_node->locx = node->locx - 100;
realize_node->locy = node->locy;
- nodeAddLink(ntree, link->fromnode, link->fromsock, realize_node, realize_node->inputs.first);
+ nodeAddLink(ntree,
+ link->fromnode,
+ link->fromsock,
+ realize_node,
+ static_cast<bNodeSocket *>(realize_node->inputs.first));
link->fromnode = realize_node;
- link->fromsock = realize_node->outputs.first;
+ link->fromsock = static_cast<bNodeSocket *>(realize_node->outputs.first);
}
/**
@@ -536,7 +546,7 @@ static void version_geometry_nodes_add_realize_instance_nodes(bNodeTree *ntree)
GEO_NODE_REPLACE_MATERIAL,
GEO_NODE_SUBDIVIDE_MESH,
GEO_NODE_TRIANGULATE)) {
- bNodeSocket *geometry_socket = node->inputs.first;
+ bNodeSocket *geometry_socket = static_cast<bNodeSocket *>(node->inputs.first);
add_realize_instances_before_socket(ntree, node, geometry_socket);
}
/* Also realize instances for the profile input of the curve to mesh node. */
@@ -559,33 +569,65 @@ static bNodeTree *add_realize_node_tree(Main *bmain)
ntreeAddSocketInterface(node_tree, SOCK_IN, "NodeSocketGeometry", "Geometry");
ntreeAddSocketInterface(node_tree, SOCK_OUT, "NodeSocketGeometry", "Geometry");
- bNode *group_input = nodeAddStaticNode(NULL, node_tree, NODE_GROUP_INPUT);
+ bNode *group_input = nodeAddStaticNode(nullptr, node_tree, NODE_GROUP_INPUT);
group_input->locx = -400.0f;
- bNode *group_output = nodeAddStaticNode(NULL, node_tree, NODE_GROUP_OUTPUT);
+ bNode *group_output = nodeAddStaticNode(nullptr, node_tree, NODE_GROUP_OUTPUT);
group_output->locx = 500.0f;
group_output->flag |= NODE_DO_OUTPUT;
- bNode *join = nodeAddStaticNode(NULL, node_tree, GEO_NODE_JOIN_GEOMETRY);
+ bNode *join = nodeAddStaticNode(nullptr, node_tree, GEO_NODE_JOIN_GEOMETRY);
join->locx = group_output->locx - 175.0f;
join->locy = group_output->locy;
- bNode *conv = nodeAddStaticNode(NULL, node_tree, GEO_NODE_POINTS_TO_VERTICES);
+ bNode *conv = nodeAddStaticNode(nullptr, node_tree, GEO_NODE_POINTS_TO_VERTICES);
conv->locx = join->locx - 175.0f;
conv->locy = join->locy - 70.0;
- bNode *separate = nodeAddStaticNode(NULL, node_tree, GEO_NODE_SEPARATE_COMPONENTS);
+ bNode *separate = nodeAddStaticNode(nullptr, node_tree, GEO_NODE_SEPARATE_COMPONENTS);
separate->locx = join->locx - 350.0f;
separate->locy = join->locy + 50.0f;
- bNode *realize = nodeAddStaticNode(NULL, node_tree, GEO_NODE_REALIZE_INSTANCES);
+ bNode *realize = nodeAddStaticNode(nullptr, node_tree, GEO_NODE_REALIZE_INSTANCES);
realize->locx = separate->locx - 200.0f;
realize->locy = join->locy;
- nodeAddLink(node_tree, group_input, group_input->outputs.first, realize, realize->inputs.first);
- nodeAddLink(node_tree, realize, realize->outputs.first, separate, separate->inputs.first);
- nodeAddLink(node_tree, conv, conv->outputs.first, join, join->inputs.first);
- nodeAddLink(node_tree, separate, BLI_findlink(&separate->outputs, 3), join, join->inputs.first);
- nodeAddLink(node_tree, separate, BLI_findlink(&separate->outputs, 1), conv, conv->inputs.first);
- nodeAddLink(node_tree, separate, BLI_findlink(&separate->outputs, 2), join, join->inputs.first);
- nodeAddLink(node_tree, separate, separate->outputs.first, join, join->inputs.first);
- nodeAddLink(node_tree, join, join->outputs.first, group_output, group_output->inputs.first);
+ nodeAddLink(node_tree,
+ group_input,
+ static_cast<bNodeSocket *>(group_input->outputs.first),
+ realize,
+ static_cast<bNodeSocket *>(realize->inputs.first));
+ nodeAddLink(node_tree,
+ realize,
+ static_cast<bNodeSocket *>(realize->outputs.first),
+ separate,
+ static_cast<bNodeSocket *>(separate->inputs.first));
+ nodeAddLink(node_tree,
+ conv,
+ static_cast<bNodeSocket *>(conv->outputs.first),
+ join,
+ static_cast<bNodeSocket *>(join->inputs.first));
+ nodeAddLink(node_tree,
+ separate,
+ static_cast<bNodeSocket *>(BLI_findlink(&separate->outputs, 3)),
+ join,
+ static_cast<bNodeSocket *>(join->inputs.first));
+ nodeAddLink(node_tree,
+ separate,
+ static_cast<bNodeSocket *>(BLI_findlink(&separate->outputs, 1)),
+ conv,
+ static_cast<bNodeSocket *>(conv->inputs.first));
+ nodeAddLink(node_tree,
+ separate,
+ static_cast<bNodeSocket *>(BLI_findlink(&separate->outputs, 2)),
+ join,
+ static_cast<bNodeSocket *>(join->inputs.first));
+ nodeAddLink(node_tree,
+ separate,
+ static_cast<bNodeSocket *>(separate->outputs.first),
+ join,
+ static_cast<bNodeSocket *>(join->inputs.first));
+ nodeAddLink(node_tree,
+ join,
+ static_cast<bNodeSocket *>(join->outputs.first),
+ group_output,
+ static_cast<bNodeSocket *>(group_output->inputs.first));
LISTBASE_FOREACH (bNode *, node, &node_tree->nodes) {
nodeSetSelected(node, false);
@@ -601,7 +643,7 @@ static void seq_speed_factor_fix_rna_path(Sequence *seq, ListBase *fcurves)
BLI_str_escape(name_esc, seq->name + 2, sizeof(name_esc));
char *path = BLI_sprintfN("sequence_editor.sequences_all[\"%s\"].pitch", name_esc);
FCurve *fcu = BKE_fcurve_find(fcurves, path, 0);
- if (fcu != NULL) {
+ if (fcu != nullptr) {
MEM_freeN(fcu->rna_path);
fcu->rna_path = BLI_sprintfN("sequence_editor.sequences_all[\"%s\"].speed_factor", name_esc);
}
@@ -610,7 +652,7 @@ static void seq_speed_factor_fix_rna_path(Sequence *seq, ListBase *fcurves)
static bool seq_speed_factor_set(Sequence *seq, void *user_data)
{
- const Scene *scene = user_data;
+ const Scene *scene = static_cast<const Scene *>(user_data);
if (seq->type == SEQ_TYPE_SOUND_RAM) {
/* Move `pitch` animation to `speed_factor` */
if (scene->adt && scene->adt->action) {
@@ -628,7 +670,148 @@ static bool seq_speed_factor_set(Sequence *seq, void *user_data)
return true;
}
-void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
+static void version_geometry_nodes_replace_transfer_attribute_node(bNodeTree *ntree)
+{
+ using namespace blender;
+ /* Otherwise `ntree->typeInfo` is null. */
+ ntreeSetTypes(nullptr, ntree);
+ LISTBASE_FOREACH_MUTABLE (bNode *, node, &ntree->nodes) {
+ if (node->type != GEO_NODE_TRANSFER_ATTRIBUTE_DEPRECATED) {
+ continue;
+ }
+ bNodeSocket *old_geometry_socket = nodeFindSocket(node, SOCK_IN, "Source");
+ const NodeGeometryTransferAttribute *storage = (const NodeGeometryTransferAttribute *)
+ node->storage;
+ switch (storage->mode) {
+ case GEO_NODE_ATTRIBUTE_TRANSFER_NEAREST_FACE_INTERPOLATED: {
+ bNode *sample_nearest_surface = nodeAddStaticNode(
+ nullptr, ntree, GEO_NODE_SAMPLE_NEAREST_SURFACE);
+ sample_nearest_surface->parent = node->parent;
+ sample_nearest_surface->custom1 = storage->data_type;
+ sample_nearest_surface->locx = node->locx;
+ sample_nearest_surface->locy = node->locy;
+ static auto socket_remap = []() {
+ Map<std::string, std::string> map;
+ map.add_new("Attribute", "Value_Vector");
+ map.add_new("Attribute_001", "Value_Float");
+ map.add_new("Attribute_002", "Value_Color");
+ map.add_new("Attribute_003", "Value_Bool");
+ map.add_new("Attribute_004", "Value_Int");
+ map.add_new("Source", "Mesh");
+ map.add_new("Source Position", "Sample Position");
+ return map;
+ }();
+ node_tree_relink_with_socket_id_map(*ntree, *node, *sample_nearest_surface, socket_remap);
+ break;
+ }
+ case GEO_NODE_ATTRIBUTE_TRANSFER_NEAREST: {
+ /* These domains weren't supported by the index transfer mode, but were selectable. */
+ const eAttrDomain domain = ELEM(storage->domain, ATTR_DOMAIN_INSTANCE, ATTR_DOMAIN_CURVE) ?
+ ATTR_DOMAIN_POINT :
+ eAttrDomain(storage->domain);
+
+ /* Use a sample index node to retrieve the data with this node's index output. */
+ bNode *sample_index = nodeAddStaticNode(nullptr, ntree, GEO_NODE_SAMPLE_INDEX);
+ NodeGeometrySampleIndex *sample_storage = static_cast<NodeGeometrySampleIndex *>(
+ sample_index->storage);
+ sample_storage->data_type = storage->data_type;
+ sample_storage->domain = domain;
+ sample_index->parent = node->parent;
+ sample_index->locx = node->locx + 25.0f;
+ sample_index->locy = node->locy;
+ if (old_geometry_socket->link) {
+ nodeAddLink(ntree,
+ old_geometry_socket->link->fromnode,
+ old_geometry_socket->link->fromsock,
+ sample_index,
+ nodeFindSocket(sample_index, SOCK_IN, "Geometry"));
+ }
+
+ bNode *sample_nearest = nodeAddStaticNode(nullptr, ntree, GEO_NODE_SAMPLE_NEAREST);
+ sample_nearest->parent = node->parent;
+ sample_nearest->custom1 = storage->data_type;
+ sample_nearest->custom2 = domain;
+ sample_nearest->locx = node->locx - 25.0f;
+ sample_nearest->locy = node->locy;
+ if (old_geometry_socket->link) {
+ nodeAddLink(ntree,
+ old_geometry_socket->link->fromnode,
+ old_geometry_socket->link->fromsock,
+ sample_nearest,
+ nodeFindSocket(sample_nearest, SOCK_IN, "Geometry"));
+ }
+ static auto sample_nearest_remap = []() {
+ Map<std::string, std::string> map;
+ map.add_new("Source Position", "Sample Position");
+ return map;
+ }();
+ node_tree_relink_with_socket_id_map(*ntree, *node, *sample_nearest, sample_nearest_remap);
+
+ static auto sample_index_remap = []() {
+ Map<std::string, std::string> map;
+ map.add_new("Attribute", "Value_Vector");
+ map.add_new("Attribute_001", "Value_Float");
+ map.add_new("Attribute_002", "Value_Color");
+ map.add_new("Attribute_003", "Value_Bool");
+ map.add_new("Attribute_004", "Value_Int");
+ map.add_new("Source Position", "Sample Position");
+ return map;
+ }();
+ node_tree_relink_with_socket_id_map(*ntree, *node, *sample_index, sample_index_remap);
+
+ nodeAddLink(ntree,
+ sample_nearest,
+ nodeFindSocket(sample_nearest, SOCK_OUT, "Index"),
+ sample_index,
+ nodeFindSocket(sample_index, SOCK_IN, "Index"));
+ break;
+ }
+ case GEO_NODE_ATTRIBUTE_TRANSFER_INDEX: {
+ bNode *sample_index = nodeAddStaticNode(nullptr, ntree, GEO_NODE_SAMPLE_INDEX);
+ NodeGeometrySampleIndex *sample_storage = static_cast<NodeGeometrySampleIndex *>(
+ sample_index->storage);
+ sample_storage->data_type = storage->data_type;
+ sample_storage->domain = storage->domain;
+ sample_storage->clamp = 1;
+ sample_index->parent = node->parent;
+ sample_index->locx = node->locx;
+ sample_index->locy = node->locy;
+ const bool index_was_linked = nodeFindSocket(node, SOCK_IN, "Index")->link != nullptr;
+ static auto socket_remap = []() {
+ Map<std::string, std::string> map;
+ map.add_new("Attribute", "Value_Vector");
+ map.add_new("Attribute_001", "Value_Float");
+ map.add_new("Attribute_002", "Value_Color");
+ map.add_new("Attribute_003", "Value_Bool");
+ map.add_new("Attribute_004", "Value_Int");
+ map.add_new("Source", "Geometry");
+ map.add_new("Index", "Index");
+ return map;
+ }();
+ node_tree_relink_with_socket_id_map(*ntree, *node, *sample_index, socket_remap);
+
+ if (!index_was_linked) {
+ /* Add an index input node, since the new node doesn't use an implicit input. */
+ bNode *index = nodeAddStaticNode(nullptr, ntree, GEO_NODE_INPUT_INDEX);
+ index->parent = node->parent;
+ index->locx = node->locx - 25.0f;
+ index->locy = node->locy - 25.0f;
+ nodeAddLink(ntree,
+ index,
+ nodeFindSocket(index, SOCK_OUT, "Index"),
+ sample_index,
+ nodeFindSocket(sample_index, SOCK_IN, "Index"));
+ }
+ break;
+ }
+ }
+ /* The storage must be freed manually because the node type isn't defined anymore. */
+ MEM_freeN(node->storage);
+ nodeRemoveNode(nullptr, ntree, node, false);
+ }
+}
+
+void do_versions_after_linking_300(Main *bmain, ReportList * /*reports*/)
{
if (MAIN_VERSION_ATLEAST(bmain, 300, 0) && !MAIN_VERSION_ATLEAST(bmain, 300, 1)) {
/* Set zero user text objects to have a fake user. */
@@ -654,7 +837,7 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
if (!MAIN_VERSION_ATLEAST(bmain, 300, 13)) {
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
- if (scene->ed != NULL) {
+ if (scene->ed != nullptr) {
do_versions_sequencer_speed_effect_recursive(scene, &scene->ed->seqbase);
}
}
@@ -668,24 +851,24 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
ToolSettings *tool_settings = scene->toolsettings;
ImagePaintSettings *imapaint = &tool_settings->imapaint;
- if (imapaint->canvas != NULL &&
+ if (imapaint->canvas != nullptr &&
ELEM(imapaint->canvas->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
- imapaint->canvas = NULL;
+ imapaint->canvas = nullptr;
}
- if (imapaint->stencil != NULL &&
+ if (imapaint->stencil != nullptr &&
ELEM(imapaint->stencil->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
- imapaint->stencil = NULL;
+ imapaint->stencil = nullptr;
}
- if (imapaint->clone != NULL &&
+ if (imapaint->clone != nullptr &&
ELEM(imapaint->clone->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
- imapaint->clone = NULL;
+ imapaint->clone = nullptr;
}
}
LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) {
- if (brush->clone.image != NULL &&
+ if (brush->clone.image != nullptr &&
ELEM(brush->clone.image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
- brush->clone.image = NULL;
+ brush->clone.image = nullptr;
}
}
}
@@ -744,20 +927,20 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
if (!MAIN_VERSION_ATLEAST(bmain, 300, 35)) {
/* Add a new modifier to realize instances from previous modifiers.
* Previously that was done automatically by geometry nodes. */
- bNodeTree *realize_instances_node_tree = NULL;
+ bNodeTree *realize_instances_node_tree = nullptr;
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
LISTBASE_FOREACH_MUTABLE (ModifierData *, md, &ob->modifiers) {
if (md->type != eModifierType_Nodes) {
continue;
}
- if (md->next == NULL) {
+ if (md->next == nullptr) {
break;
}
if (md->next->type == eModifierType_Nodes) {
continue;
}
NodesModifierData *nmd = (NodesModifierData *)md;
- if (nmd->node_group == NULL) {
+ if (nmd->node_group == nullptr) {
continue;
}
@@ -765,7 +948,7 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
STRNCPY(new_nmd->modifier.name, "Realize Instances 2.93 Legacy");
BKE_modifier_unique_name(&ob->modifiers, &new_nmd->modifier);
BLI_insertlinkafter(&ob->modifiers, md, new_nmd);
- if (realize_instances_node_tree == NULL) {
+ if (realize_instances_node_tree == nullptr) {
realize_instances_node_tree = add_realize_node_tree(bmain);
}
new_nmd->node_group = realize_instances_node_tree;
@@ -778,7 +961,7 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
if (ntree->type == NTREE_GEOMETRY) {
LISTBASE_FOREACH_MUTABLE (bNode *, node, &ntree->nodes) {
if (node->type == GEO_NODE_BOUNDING_BOX) {
- bNodeSocket *geometry_socket = node->inputs.first;
+ bNodeSocket *geometry_socket = static_cast<bNodeSocket *>(node->inputs.first);
add_realize_instances_before_socket(ntree, node, geometry_socket);
}
}
@@ -791,7 +974,7 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
ID *id;
FOREACH_MAIN_ID_BEGIN (bmain, id) {
AnimData *adt = BKE_animdata_from_id(id);
- if (adt == NULL) {
+ if (adt == nullptr) {
continue;
}
LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) {
@@ -824,7 +1007,7 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
if (!MAIN_VERSION_ATLEAST(bmain, 302, 14)) {
/* Sequencer channels region. */
- for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype != SPACE_SEQ) {
@@ -842,7 +1025,7 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
ARegion *timeline_region = BKE_region_find_in_listbase_by_type(regionbase,
RGN_TYPE_WINDOW);
- if (timeline_region == NULL) {
+ if (timeline_region == nullptr) {
continue;
}
@@ -856,13 +1039,51 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
if (!MAIN_VERSION_ATLEAST(bmain, 303, 5)) {
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
Editing *ed = SEQ_editing_get(scene);
- if (ed == NULL) {
+ if (ed == nullptr) {
continue;
}
SEQ_for_each_callback(&ed->seqbase, seq_speed_factor_set, scene);
}
}
+ if (!MAIN_VERSION_ATLEAST(bmain, 303, 6)) {
+ /* In the Dope Sheet, for every mode other than Timeline, open the Properties panel. */
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
+ LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+ LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+ if (sl->spacetype != SPACE_ACTION) {
+ continue;
+ }
+
+ /* Skip the timeline, it shouldn't get its Properties panel opened. */
+ SpaceAction *saction = (SpaceAction *)sl;
+ if (saction->mode == SACTCONT_TIMELINE) {
+ continue;
+ }
+
+ const bool is_first_space = sl == area->spacedata.first;
+ ListBase *regionbase = is_first_space ? &area->regionbase : &sl->regionbase;
+ ARegion *region = BKE_region_find_in_listbase_by_type(regionbase, RGN_TYPE_UI);
+ if (region == nullptr) {
+ continue;
+ }
+
+ region->flag &= ~RGN_FLAG_HIDDEN;
+ }
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(bmain, 304, 1)) {
+ /* Split the transfer attribute node into multiple smaller nodes. */
+ FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
+ if (ntree->type == NTREE_GEOMETRY) {
+ version_geometry_nodes_replace_transfer_attribute_node(ntree);
+ }
+ }
+ FOREACH_NODETREE_END;
+ }
+
/**
* Versioning code until next subversion bump goes here.
*
@@ -908,7 +1129,7 @@ static bool replace_bbone_len_scale_rnapath(char **p_old_path, int *p_index)
{
char *old_path = *p_old_path;
- if (old_path == NULL) {
+ if (old_path == nullptr) {
return false;
}
@@ -948,7 +1169,7 @@ static void do_version_bbone_len_scale_fcurve_fix(FCurve *fcu)
if (fcu->driver) {
LISTBASE_FOREACH (DriverVar *, dvar, &fcu->driver->variables) {
DRIVER_TARGETS_LOOPER_BEGIN (dvar) {
- replace_bbone_len_scale_rnapath(&dtar->rna_path, NULL);
+ replace_bbone_len_scale_rnapath(&dtar->rna_path, nullptr);
}
DRIVER_TARGETS_LOOPER_END;
}
@@ -958,9 +1179,9 @@ static void do_version_bbone_len_scale_fcurve_fix(FCurve *fcu)
replace_bbone_len_scale_rnapath(&fcu->rna_path, &fcu->array_index);
}
-static void do_version_bbone_len_scale_animdata_cb(ID *UNUSED(id),
+static void do_version_bbone_len_scale_animdata_cb(ID * /*id*/,
AnimData *adt,
- void *UNUSED(wrapper_data))
+ void * /*wrapper_data*/)
{
LISTBASE_FOREACH_MUTABLE (FCurve *, fcu, &adt->drivers) {
do_version_bbone_len_scale_fcurve_fix(fcu);
@@ -987,7 +1208,7 @@ static void do_version_constraints_spline_ik_joint_bindings(ListBase *lb)
LISTBASE_FOREACH (bConstraint *, con, lb) {
if (con->type == CONSTRAINT_TYPE_SPLINEIK) {
bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
- if (data->points == NULL) {
+ if (data->points == nullptr) {
data->numpoints = 0;
}
}
@@ -1008,25 +1229,25 @@ static bNodeSocket *do_version_replace_float_size_with_vector(bNodeTree *ntree,
return new_socket;
}
-static bool seq_transform_origin_set(Sequence *seq, void *UNUSED(user_data))
+static bool seq_transform_origin_set(Sequence *seq, void * /*user_data*/)
{
StripTransform *transform = seq->strip->transform;
- if (seq->strip->transform != NULL) {
+ if (seq->strip->transform != nullptr) {
transform->origin[0] = transform->origin[1] = 0.5f;
}
return true;
}
-static bool seq_transform_filter_set(Sequence *seq, void *UNUSED(user_data))
+static bool seq_transform_filter_set(Sequence *seq, void * /*user_data*/)
{
StripTransform *transform = seq->strip->transform;
- if (seq->strip->transform != NULL) {
+ if (seq->strip->transform != nullptr) {
transform->filter = SEQ_TRANSFORM_FILTER_BILINEAR;
}
return true;
}
-static bool seq_meta_channels_ensure(Sequence *seq, void *UNUSED(user_data))
+static bool seq_meta_channels_ensure(Sequence *seq, void * /*user_data*/)
{
if (seq->type == SEQ_TYPE_META) {
SEQ_channels_ensure(&seq->channels);
@@ -1050,7 +1271,7 @@ static void do_version_subsurface_methods(bNode *node)
static void version_geometry_nodes_add_attribute_input_settings(NodesModifierData *nmd)
{
- if (nmd->settings.properties == NULL) {
+ if (nmd->settings.properties == nullptr) {
return;
}
/* Before versioning the properties, make sure it hasn't been done already. */
@@ -1210,7 +1431,7 @@ static void version_geometry_nodes_set_position_node_offset(bNodeTree *ntree)
/* The offset socket didn't exist in the file yet. */
return;
}
- bNodeSocket *old_offset_socket = BLI_findlink(&node->inputs, 3);
+ bNodeSocket *old_offset_socket = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 3));
if (old_offset_socket->type == SOCK_VECTOR) {
/* Versioning happened already. */
return;
@@ -1228,7 +1449,8 @@ static void version_geometry_nodes_set_position_node_offset(bNodeTree *ntree)
if (!STREQ(link->tosock->identifier, "Position")) {
continue;
}
- bNodeSocket *old_offset_socket = BLI_findlink(&link->tonode->inputs, 3);
+ bNodeSocket *old_offset_socket = static_cast<bNodeSocket *>(
+ BLI_findlink(&link->tonode->inputs, 3));
/* This assumes that the offset is not linked to something else. That seems to be a reasonable
* assumption, because the node is probably only ever used in one or the other mode. */
const bool offset_enabled =
@@ -1244,7 +1466,7 @@ static void version_geometry_nodes_set_position_node_offset(bNodeTree *ntree)
if (node->type != GEO_NODE_SET_POSITION) {
continue;
}
- bNodeSocket *old_offset_socket = BLI_findlink(&node->inputs, 3);
+ bNodeSocket *old_offset_socket = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 3));
nodeRemoveSocket(ntree, node, old_offset_socket);
}
}
@@ -1270,7 +1492,7 @@ static bool version_fix_seq_meta_range(Sequence *seq, void *user_data)
return true;
}
-static bool version_merge_still_offsets(Sequence *seq, void *UNUSED(user_data))
+static bool version_merge_still_offsets(Sequence *seq, void * /*user_data*/)
{
seq->startofs -= seq->startstill;
seq->endofs -= seq->endstill;
@@ -1296,14 +1518,16 @@ static void version_liboverride_rnacollections_insertion_object_constraints(
if (opop->operation != IDOVERRIDE_LIBRARY_OP_INSERT_AFTER) {
continue;
}
- bConstraint *constraint_anchor = BLI_listbase_string_or_index_find(constraints,
- opop->subitem_local_name,
- offsetof(bConstraint, name),
- opop->subitem_local_index);
- bConstraint *constraint_src = constraint_anchor != NULL ? constraint_anchor->next :
- constraints->first;
+ bConstraint *constraint_anchor = static_cast<bConstraint *>(
+ BLI_listbase_string_or_index_find(constraints,
+ opop->subitem_local_name,
+ offsetof(bConstraint, name),
+ opop->subitem_local_index));
+ bConstraint *constraint_src = constraint_anchor != nullptr ?
+ constraint_anchor->next :
+ static_cast<bConstraint *>(constraints->first);
- if (constraint_src == NULL) {
+ if (constraint_src == nullptr) {
/* Invalid case, just remove that override property operation. */
CLOG_ERROR(&LOG, "Could not find source constraint in stored override data");
BKE_lib_override_library_property_operation_delete(op, opop);
@@ -1323,18 +1547,21 @@ static void version_liboverride_rnacollections_insertion_object(Object *object)
IDOverrideLibraryProperty *op;
op = BKE_lib_override_library_property_find(liboverride, "modifiers");
- if (op != NULL) {
+ if (op != nullptr) {
LISTBASE_FOREACH_MUTABLE (IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
if (opop->operation != IDOVERRIDE_LIBRARY_OP_INSERT_AFTER) {
continue;
}
- ModifierData *mod_anchor = BLI_listbase_string_or_index_find(&object->modifiers,
- opop->subitem_local_name,
- offsetof(ModifierData, name),
- opop->subitem_local_index);
- ModifierData *mod_src = mod_anchor != NULL ? mod_anchor->next : object->modifiers.first;
+ ModifierData *mod_anchor = static_cast<ModifierData *>(
+ BLI_listbase_string_or_index_find(&object->modifiers,
+ opop->subitem_local_name,
+ offsetof(ModifierData, name),
+ opop->subitem_local_index));
+ ModifierData *mod_src = mod_anchor != nullptr ?
+ mod_anchor->next :
+ static_cast<ModifierData *>(object->modifiers.first);
- if (mod_src == NULL) {
+ if (mod_src == nullptr) {
/* Invalid case, just remove that override property operation. */
CLOG_ERROR(&LOG, "Could not find source modifier in stored override data");
BKE_lib_override_library_property_operation_delete(op, opop);
@@ -1349,21 +1576,22 @@ static void version_liboverride_rnacollections_insertion_object(Object *object)
}
op = BKE_lib_override_library_property_find(liboverride, "grease_pencil_modifiers");
- if (op != NULL) {
+ if (op != nullptr) {
LISTBASE_FOREACH_MUTABLE (IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
if (opop->operation != IDOVERRIDE_LIBRARY_OP_INSERT_AFTER) {
continue;
}
- GpencilModifierData *gp_mod_anchor = BLI_listbase_string_or_index_find(
- &object->greasepencil_modifiers,
- opop->subitem_local_name,
- offsetof(GpencilModifierData, name),
- opop->subitem_local_index);
- GpencilModifierData *gp_mod_src = gp_mod_anchor != NULL ?
+ GpencilModifierData *gp_mod_anchor = static_cast<GpencilModifierData *>(
+ BLI_listbase_string_or_index_find(&object->greasepencil_modifiers,
+ opop->subitem_local_name,
+ offsetof(GpencilModifierData, name),
+ opop->subitem_local_index));
+ GpencilModifierData *gp_mod_src = gp_mod_anchor != nullptr ?
gp_mod_anchor->next :
- object->greasepencil_modifiers.first;
+ static_cast<GpencilModifierData *>(
+ object->greasepencil_modifiers.first);
- if (gp_mod_src == NULL) {
+ if (gp_mod_src == nullptr) {
/* Invalid case, just remove that override property operation. */
CLOG_ERROR(&LOG, "Could not find source GP modifier in stored override data");
BKE_lib_override_library_property_operation_delete(op, opop);
@@ -1378,18 +1606,18 @@ static void version_liboverride_rnacollections_insertion_object(Object *object)
}
op = BKE_lib_override_library_property_find(liboverride, "constraints");
- if (op != NULL) {
+ if (op != nullptr) {
version_liboverride_rnacollections_insertion_object_constraints(&object->constraints, op);
}
- if (object->pose != NULL) {
+ if (object->pose != nullptr) {
LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
char rna_path[26 + (sizeof(pchan->name) * 2) + 1];
char name_esc[sizeof(pchan->name) * 2];
BLI_str_escape(name_esc, pchan->name, sizeof(name_esc));
SNPRINTF(rna_path, "pose.bones[\"%s\"].constraints", name_esc);
op = BKE_lib_override_library_property_find(liboverride, rna_path);
- if (op != NULL) {
+ if (op != nullptr) {
version_liboverride_rnacollections_insertion_object_constraints(&pchan->constraints, op);
}
}
@@ -1399,7 +1627,7 @@ static void version_liboverride_rnacollections_insertion_object(Object *object)
static void version_liboverride_rnacollections_insertion_animdata(ID *id)
{
AnimData *anim_data = BKE_animdata_from_id(id);
- if (anim_data == NULL) {
+ if (anim_data == nullptr) {
return;
}
@@ -1407,7 +1635,7 @@ static void version_liboverride_rnacollections_insertion_animdata(ID *id)
IDOverrideLibraryProperty *op;
op = BKE_lib_override_library_property_find(liboverride, "animation_data.nla_tracks");
- if (op != NULL) {
+ if (op != nullptr) {
LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
if (opop->operation != IDOVERRIDE_LIBRARY_OP_INSERT_AFTER) {
continue;
@@ -1417,7 +1645,7 @@ static void version_liboverride_rnacollections_insertion_animdata(ID *id)
*
* This makes things simple here. */
opop->subitem_reference_name = opop->subitem_local_name;
- opop->subitem_local_name = NULL;
+ opop->subitem_local_name = nullptr;
opop->subitem_reference_index = opop->subitem_local_index;
opop->subitem_local_index++;
}
@@ -1668,6 +1896,27 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre
}
}
+static void versioning_replace_legacy_mix_rgb_node(bNodeTree *ntree)
+{
+ version_node_input_socket_name(ntree, SH_NODE_MIX_RGB_LEGACY, "Fac", "Factor_Float");
+ version_node_input_socket_name(ntree, SH_NODE_MIX_RGB_LEGACY, "Color1", "A_Color");
+ version_node_input_socket_name(ntree, SH_NODE_MIX_RGB_LEGACY, "Color2", "B_Color");
+ version_node_output_socket_name(ntree, SH_NODE_MIX_RGB_LEGACY, "Color", "Result_Color");
+ LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+ if (node->type == SH_NODE_MIX_RGB_LEGACY) {
+ strcpy(node->idname, "ShaderNodeMix");
+ node->type = SH_NODE_MIX;
+ NodeShaderMix *data = (NodeShaderMix *)MEM_callocN(sizeof(NodeShaderMix), __func__);
+ data->blend_type = node->custom1;
+ data->clamp_result = (node->custom2 & SHD_MIXRGB_CLAMP) ? 1 : 0;
+ data->clamp_factor = 1;
+ data->data_type = SOCK_RGBA;
+ data->factor_mode = NODE_MIX_MODE_UNIFORM;
+ node->storage = data;
+ }
+ }
+}
+
static void version_fix_image_format_copy(Main *bmain, ImageFormatData *format)
{
/* Fix bug where curves in image format were not properly copied to file output
@@ -1685,16 +1934,16 @@ static void version_fix_image_format_copy(Main *bmain, ImageFormatData *format)
}
/* Remove any invalid curves with missing data. */
- if (format->view_settings.curve_mapping->cm[0].curve == NULL) {
+ if (format->view_settings.curve_mapping->cm[0].curve == nullptr) {
BKE_curvemapping_free(format->view_settings.curve_mapping);
- format->view_settings.curve_mapping = NULL;
+ format->view_settings.curve_mapping = nullptr;
format->view_settings.flag &= ~COLORMANAGE_VIEW_USE_CURVES;
}
}
}
/* NOLINTNEXTLINE: readability-function-size */
-void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
+void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
{
/* The #SCE_SNAP_SEQ flag has been removed in favor of the #SCE_SNAP which can be used for each
* snap_flag member individually. */
@@ -1728,7 +1977,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "custom_scale_xyz[3]")) {
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
- if (ob->pose == NULL) {
+ if (ob->pose == nullptr) {
continue;
}
LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) {
@@ -1748,7 +1997,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
&sl->regionbase;
ARegion *new_sidebar = do_versions_add_region_if_not_found(
regionbase, RGN_TYPE_UI, "sidebar for spreadsheet", RGN_TYPE_FOOTER);
- if (new_sidebar != NULL) {
+ if (new_sidebar != nullptr) {
new_sidebar->alignment = RGN_ALIGN_RIGHT;
new_sidebar->flag |= RGN_FLAG_HIDDEN;
}
@@ -1814,7 +2063,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
- BKE_animdata_main_cb(bmain, do_version_bbone_len_scale_animdata_cb, NULL);
+ BKE_animdata_main_cb(bmain, do_version_bbone_len_scale_animdata_cb, nullptr);
}
}
@@ -1891,7 +2140,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (!MAIN_VERSION_ATLEAST(bmain, 300, 8)) {
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
- if (scene->master_collection != NULL) {
+ if (scene->master_collection != nullptr) {
BLI_strncpy(scene->master_collection->id.name + 2,
BKE_SCENE_COLLECTION_NAME,
sizeof(scene->master_collection->id.name) - 2);
@@ -1945,7 +2194,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (smd->bind_verts_num && smd->verts) {
smd->mesh_verts_num = smd->bind_verts_num;
- for (unsigned int i = 0; i < smd->bind_verts_num; i++) {
+ for (uint i = 0; i < smd->bind_verts_num; i++) {
smd->verts[i].vertex_idx = i;
}
}
@@ -2088,7 +2337,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (!MAIN_VERSION_ATLEAST(bmain, 300, 19)) {
/* Disable Fade Inactive Overlay by default as it is redundant after introducing flash on
* mode transfer. */
- for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype == SPACE_VIEW3D) {
@@ -2159,7 +2408,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
if (!MAIN_VERSION_ATLEAST(bmain, 300, 23)) {
- for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype == SPACE_FILE) {
@@ -2203,8 +2452,8 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
SequencerToolSettings *sequencer_tool_settings = SEQ_tool_settings_ensure(scene);
sequencer_tool_settings->pivot_point = V3D_AROUND_CENTER_MEDIAN;
- if (scene->ed != NULL) {
- SEQ_for_each_callback(&scene->ed->seqbase, seq_transform_origin_set, NULL);
+ if (scene->ed != nullptr) {
+ SEQ_for_each_callback(&scene->ed->seqbase, seq_transform_origin_set, nullptr);
}
}
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
@@ -2303,11 +2552,6 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
break;
}
- case SPACE_IMAGE: {
- SpaceImage *sima = (SpaceImage *)sl;
- sima->custom_grid_subdiv = 10;
- break;
- }
}
}
}
@@ -2316,12 +2560,12 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (!MAIN_VERSION_ATLEAST(bmain, 300, 31)) {
/* Swap header with the tool header so the regular header is always on the edge. */
- for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase :
&sl->regionbase;
- ARegion *region_tool = NULL, *region_head = NULL;
+ ARegion *region_tool = nullptr, *region_head = nullptr;
int region_tool_index = -1, region_head_index = -1, i;
LISTBASE_FOREACH_INDEX (ARegion *, region, regionbase, i) {
if (region->regiontype == RGN_TYPE_TOOL_HEADER) {
@@ -2342,8 +2586,8 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
/* Set strip color tags to SEQUENCE_COLOR_NONE. */
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
- if (scene->ed != NULL) {
- SEQ_for_each_callback(&scene->ed->seqbase, do_versions_sequencer_color_tags, NULL);
+ if (scene->ed != nullptr) {
+ SEQ_for_each_callback(&scene->ed->seqbase, do_versions_sequencer_color_tags, nullptr);
}
}
@@ -2361,14 +2605,15 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
/* Set defaults for new color balance modifier parameters. */
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
- if (scene->ed != NULL) {
- SEQ_for_each_callback(&scene->ed->seqbase, do_versions_sequencer_color_balance_sop, NULL);
+ if (scene->ed != nullptr) {
+ SEQ_for_each_callback(
+ &scene->ed->seqbase, do_versions_sequencer_color_balance_sop, nullptr);
}
}
}
if (!MAIN_VERSION_ATLEAST(bmain, 300, 33)) {
- for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
switch (sl->spacetype) {
@@ -2478,7 +2723,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->type == GEO_NODE_VIEWER) {
- if (node->storage == NULL) {
+ if (node->storage == nullptr) {
NodeGeometryViewer *data = (NodeGeometryViewer *)MEM_callocN(
sizeof(NodeGeometryViewer), __func__);
data->data_type = CD_PROP_FLOAT;
@@ -2575,7 +2820,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
* It was possible to save .blend file with incorrect state of meta strip
* range. The root cause is expected to be fixed, but need to ensure files
* with invalid meta strip range are corrected. */
- if (ed != NULL) {
+ if (ed != nullptr) {
SEQ_for_each_callback(&ed->seqbase, version_fix_seq_meta_range, scene);
}
}
@@ -2613,7 +2858,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
/* Convert float compare into a more general compare node. */
if (node->type == FN_NODE_COMPARE) {
- if (node->storage == NULL) {
+ if (node->storage == nullptr) {
NodeFunctionCompare *data = (NodeFunctionCompare *)MEM_callocN(
sizeof(NodeFunctionCompare), __func__);
data->data_type = SOCK_FLOAT;
@@ -2657,8 +2902,8 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->type == SH_NODE_MAP_RANGE) {
- if (node->storage == NULL) {
- NodeMapRange *data = MEM_callocN(sizeof(NodeMapRange), __func__);
+ if (node->storage == nullptr) {
+ NodeMapRange *data = MEM_cnew<NodeMapRange>(__func__);
data->clamp = node->custom1;
data->data_type = CD_PROP_FLOAT;
data->interpolation_type = node->custom2;
@@ -2688,7 +2933,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
/* Initialize the bone wireframe opacity setting. */
if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "bone_wire_alpha")) {
- for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype == SPACE_VIEW3D) {
@@ -2709,7 +2954,8 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
ntree, GEO_NODE_INPUT_MESH_EDGE_ANGLE, "Angle", "Unsigned Angle");
version_node_output_socket_name(
ntree, GEO_NODE_INPUT_MESH_ISLAND, "Index", "Island Index");
- version_node_input_socket_name(ntree, GEO_NODE_TRANSFER_ATTRIBUTE, "Target", "Source");
+ version_node_input_socket_name(
+ ntree, GEO_NODE_TRANSFER_ATTRIBUTE_DEPRECATED, "Target", "Source");
}
}
}
@@ -2731,8 +2977,8 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (!MAIN_VERSION_ATLEAST(bmain, 302, 2)) {
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
- if (scene->ed != NULL) {
- SEQ_for_each_callback(&scene->ed->seqbase, seq_transform_filter_set, NULL);
+ if (scene->ed != nullptr) {
+ SEQ_for_each_callback(&scene->ed->seqbase, seq_transform_filter_set, nullptr);
}
}
}
@@ -2746,7 +2992,8 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
ToolSettings *tool_settings = scene->toolsettings;
- tool_settings->snap_flag_seq = tool_settings->snap_flag & ~(SCE_SNAP | SCE_SNAP_SEQ);
+ tool_settings->snap_flag_seq = tool_settings->snap_flag &
+ ~(short(SCE_SNAP) | short(SCE_SNAP_SEQ));
if (tool_settings->snap_flag & SCE_SNAP_SEQ) {
tool_settings->snap_flag_seq |= SCE_SNAP;
tool_settings->snap_flag &= ~SCE_SNAP_SEQ;
@@ -2798,9 +3045,9 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
gpmd->factor *= 2.0f;
}
else {
- gpmd->step = 1 + (int)(gpmd->factor * max_ff(0.0f,
- min_ff(5.1f * sqrtf(gpmd->step) - 3.0f,
- gpmd->step + 2.0f)));
+ gpmd->step = 1 + int(gpmd->factor * max_ff(0.0f,
+ min_ff(5.1f * sqrtf(gpmd->step) - 3.0f,
+ gpmd->step + 2.0f)));
gpmd->factor = 1.0f;
}
}
@@ -2824,7 +3071,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
LISTBASE_FOREACH (Mesh *, me, &bmain->meshes) {
for (int step = 0; step < 2; step++) {
- CustomDataLayer *actlayer = NULL;
+ CustomDataLayer *actlayer = nullptr;
int vact1, vact2;
@@ -2883,14 +3130,14 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (brush->ob_mode != OB_MODE_SCULPT_CURVES) {
continue;
}
- if (brush->curves_sculpt_settings != NULL) {
+ if (brush->curves_sculpt_settings != nullptr) {
continue;
}
- brush->curves_sculpt_settings = MEM_callocN(sizeof(BrushCurvesSculptSettings), __func__);
+ brush->curves_sculpt_settings = MEM_cnew<BrushCurvesSculptSettings>(__func__);
brush->curves_sculpt_settings->add_amount = 1;
}
- for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype == SPACE_OUTLINER) {
@@ -2904,7 +3151,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (!MAIN_VERSION_ATLEAST(bmain, 302, 9)) {
/* Sequencer channels region. */
- for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype != SPACE_SEQ) {
@@ -2929,7 +3176,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
ARegion *timeline_region = BKE_region_find_in_listbase_by_type(regionbase,
RGN_TYPE_WINDOW);
- if (timeline_region != NULL) {
+ if (timeline_region != nullptr) {
timeline_region->v2d.flag |= V2D_VIEWSYNC_AREA_VERTICAL;
}
}
@@ -2939,11 +3186,11 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
/* Initialize channels. */
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
Editing *ed = SEQ_editing_get(scene);
- if (ed == NULL) {
+ if (ed == nullptr) {
continue;
}
SEQ_channels_ensure(&ed->channels);
- SEQ_for_each_callback(&scene->ed->seqbase, seq_meta_channels_ensure, NULL);
+ SEQ_for_each_callback(&scene->ed->seqbase, seq_meta_channels_ensure, nullptr);
ed->displayed_channels = &ed->channels;
@@ -2958,7 +3205,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
if (!MAIN_VERSION_ATLEAST(bmain, 302, 10)) {
- for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype != SPACE_FILE) {
@@ -2989,7 +3236,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
/* Rebuild active/render color attribute references. */
LISTBASE_FOREACH (Mesh *, me, &bmain->meshes) {
for (int step = 0; step < 2; step++) {
- CustomDataLayer *actlayer = NULL;
+ CustomDataLayer *actlayer = nullptr;
int vact1, vact2;
@@ -3058,9 +3305,8 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (ntree->type == NTREE_GEOMETRY) {
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->type == GEO_NODE_MERGE_BY_DISTANCE) {
- if (node->storage == NULL) {
- NodeGeometryMergeByDistance *data = MEM_callocN(sizeof(NodeGeometryMergeByDistance),
- __func__);
+ if (node->storage == nullptr) {
+ NodeGeometryMergeByDistance *data = MEM_cnew<NodeGeometryMergeByDistance>(__func__);
data->mode = GEO_NODE_MERGE_BY_DISTANCE_MODE_ALL;
node->storage = data;
}
@@ -3093,7 +3339,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) {
BrushCurvesSculptSettings *settings = brush->curves_sculpt_settings;
- if (settings == NULL) {
+ if (settings == nullptr) {
continue;
}
if (settings->curve_length == 0.0f) {
@@ -3102,6 +3348,21 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
+ if (!DNA_struct_elem_find(fd->filesdna, "Sculpt", "float", "automasking_cavity_factor")) {
+ LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
+ if (scene->toolsettings && scene->toolsettings->sculpt) {
+ scene->toolsettings->sculpt->automasking_cavity_factor = 0.5f;
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(bmain, 302, 14)) {
+ /* Compensate for previously wrong squared distance. */
+ LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
+ scene->r.bake.max_ray_distance = sasqrt(scene->r.bake.max_ray_distance);
+ }
+ }
+
if (!MAIN_VERSION_ATLEAST(bmain, 303, 1)) {
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
versioning_replace_legacy_combined_and_separate_color_nodes(ntree);
@@ -3120,7 +3381,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
/* UDIM Packing. */
if (!DNA_struct_elem_find(fd->filesdna, "ImagePackedFile", "int", "tile_number")) {
- for (Image *ima = bmain->images.first; ima; ima = ima->id.next) {
+ LISTBASE_FOREACH (Image *, ima, &bmain->images) {
int view;
LISTBASE_FOREACH_INDEX (ImagePackedFile *, imapf, &ima->packedfiles, view) {
imapf->view = view;
@@ -3132,8 +3393,8 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
/* Merge still offsets into start/end offsets. */
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
Editing *ed = SEQ_editing_get(scene);
- if (ed != NULL) {
- SEQ_for_each_callback(&ed->seqbase, version_merge_still_offsets, NULL);
+ if (ed != nullptr) {
+ SEQ_for_each_callback(&ed->seqbase, version_merge_still_offsets, nullptr);
}
}
@@ -3239,7 +3500,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (!MAIN_VERSION_ATLEAST(bmain, 303, 5)) {
/* Fix for T98925 - remove channels region, that was initialized in incorrect editor types. */
- for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (ELEM(sl->spacetype, SPACE_ACTION, SPACE_CLIP, SPACE_GRAPH, SPACE_NLA, SPACE_SEQ)) {
@@ -3257,18 +3518,8 @@ void blo_do_versions_300(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_do_versions_userdef
- * - "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, 303, 6)) {
/* Initialize brush curves sculpt settings. */
LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) {
if (brush->ob_mode != OB_MODE_SCULPT_CURVES) {
@@ -3284,5 +3535,134 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
ob->dtx &= ~OB_DRAWBOUNDOX;
}
}
+
+ BKE_main_namemap_validate_and_fix(bmain);
+ }
+
+ if (!MAIN_VERSION_ATLEAST(bmain, 304, 1)) {
+ /* Image generation information transferred to tiles. */
+ if (!DNA_struct_elem_find(fd->filesdna, "ImageTile", "int", "gen_x")) {
+ LISTBASE_FOREACH (Image *, ima, &bmain->images) {
+ LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
+ tile->gen_x = ima->gen_x;
+ tile->gen_y = ima->gen_y;
+ tile->gen_type = ima->gen_type;
+ tile->gen_flag = ima->gen_flag;
+ tile->gen_depth = ima->gen_depth;
+ copy_v4_v4(tile->gen_color, ima->gen_color);
+ }
+ }
+ }
+
+ /* Convert mix rgb node to new mix node and add storage. */
+ FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
+ versioning_replace_legacy_mix_rgb_node(ntree);
+ }
+ FOREACH_NODETREE_END;
+
+ /* Face sets no longer store whether the corresponding face is hidden. */
+ LISTBASE_FOREACH (Mesh *, mesh, &bmain->meshes) {
+ int *face_sets = (int *)CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS);
+ if (face_sets) {
+ for (int i = 0; i < mesh->totpoly; i++) {
+ face_sets[i] = abs(face_sets[i]);
+ }
+ }
+ }
+
+ /* Custom grids in UV Editor have separate X and Y divisions. */
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
+ LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+ LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+ switch (sl->spacetype) {
+ case SPACE_IMAGE: {
+ SpaceImage *sima = (SpaceImage *)sl;
+ sima->custom_grid_subdiv[0] = 10;
+ sima->custom_grid_subdiv[1] = 10;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(bmain, 304, 2)) {
+ /* Initialize brush curves sculpt settings. */
+ LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) {
+ brush->automasking_cavity_factor = 0.5f;
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(bmain, 304, 3)) {
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
+ LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+ LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+ if (sl->spacetype == SPACE_VIEW3D) {
+ View3D *v3d = (View3D *)sl;
+ v3d->flag2 |= V3D_SHOW_VIEWER;
+ v3d->overlay.flag |= V3D_OVERLAY_VIEWER_ATTRIBUTE;
+ v3d->overlay.viewer_attribute_opacity = 1.0f;
+ }
+ if (sl->spacetype == SPACE_IMAGE) {
+ SpaceImage *sima = (SpaceImage *)sl;
+ if (sima->flag & SI_FLAG_UNUSED_18) { /* Was #SI_CUSTOM_GRID. */
+ sima->grid_shape_source = SI_GRID_SHAPE_FIXED;
+ sima->flag &= ~SI_FLAG_UNUSED_18;
+ }
+ }
+ }
+ }
+ }
+
+ LISTBASE_FOREACH (bNodeTree *, ntree, &bmain->nodetrees) {
+ if (ntree->type != NTREE_GEOMETRY) {
+ continue;
+ }
+ version_node_id(ntree, GEO_NODE_OFFSET_POINT_IN_CURVE, "GeometryNodeOffsetPointInCurve");
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(bmain, 304, 4)) {
+ /* Update brush sculpt settings. */
+ LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) {
+ brush->automasking_cavity_factor = 1.0f;
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(bmain, 304, 5)) {
+ /* Fix for T101622 - update flags of sequence editor regions that were not initialized
+ * properly. */
+ LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
+ LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+ LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+ ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase :
+ &sl->regionbase;
+ if (sl->spacetype == SPACE_SEQ) {
+ LISTBASE_FOREACH (ARegion *, region, regionbase) {
+ if (region->regiontype == RGN_TYPE_TOOLS) {
+ region->v2d.flag &= ~V2D_VIEWSYNC_AREA_VERTICAL;
+ }
+ if (region->regiontype == RGN_TYPE_CHANNELS) {
+ region->v2d.flag |= V2D_VIEWSYNC_AREA_VERTICAL;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Versioning code until next subversion bump goes here.
+ *
+ * \note Be sure to check when bumping the version:
+ * - "versioning_userdef.c", #blo_do_versions_userdef
+ * - "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_400.cc b/source/blender/blenloader/intern/versioning_400.cc
new file mode 100644
index 00000000000..2616bb890a3
--- /dev/null
+++ b/source/blender/blenloader/intern/versioning_400.cc
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup blenloader
+ */
+
+#define DNA_DEPRECATED_ALLOW
+
+#include "CLG_log.h"
+
+#include "BKE_main.h"
+#include "BKE_mesh_legacy_convert.h"
+
+#include "BLO_readfile.h"
+
+#include "readfile.h"
+
+#include "versioning_common.h"
+
+// static CLG_LogRef LOG = {"blo.readfile.doversion"};
+
+static void version_mesh_legacy_to_struct_of_array_format(Mesh &mesh)
+{
+ BKE_mesh_legacy_convert_flags_to_selection_layers(&mesh);
+ BKE_mesh_legacy_convert_flags_to_hide_layers(&mesh);
+ BKE_mesh_legacy_convert_mpoly_to_material_indices(&mesh);
+ BKE_mesh_legacy_bevel_weight_to_layers(&mesh);
+ BKE_mesh_legacy_face_set_to_generic(&mesh);
+ BKE_mesh_legacy_edge_crease_to_layers(&mesh);
+}
+
+void blo_do_versions_400(FileData * /*fd*/, Library * /*lib*/, Main *bmain)
+{
+ // if (!MAIN_VERSION_ATLEAST(bmain, 400, 0)) {
+ /* This is done here because we will continue to write with the old format until 4.0, so we need
+ * to convert even "current" files. Keep the check commented out for now so the versioning isn't
+ * turned off right after the 4.0 bump. */
+ LISTBASE_FOREACH (Mesh *, mesh, &bmain->meshes) {
+ version_mesh_legacy_to_struct_of_array_format(*mesh);
+ }
+ // }
+
+ /**
+ * Versioning code until next subversion bump goes here.
+ *
+ * \note Be sure to check when bumping the version:
+ * - "versioning_userdef.c", #blo_do_versions_userdef
+ * - "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_common.cc b/source/blender/blenloader/intern/versioning_common.cc
index d2a55f6f37e..56ada76eae6 100644
--- a/source/blender/blenloader/intern/versioning_common.cc
+++ b/source/blender/blenloader/intern/versioning_common.cc
@@ -12,18 +12,21 @@
#include "DNA_screen_types.h"
#include "BLI_listbase.h"
+#include "BLI_map.hh"
#include "BLI_string.h"
#include "BLI_string_ref.hh"
#include "BKE_animsys.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
+#include "BKE_main_namemap.h"
#include "BKE_node.h"
#include "MEM_guardedalloc.h"
#include "versioning_common.h"
+using blender::Map;
using blender::StringRef;
ARegion *do_versions_add_region_if_not_found(ListBase *regionbase,
@@ -66,6 +69,7 @@ ID *do_versions_rename_id(Main *bmain,
}
}
if (id != nullptr) {
+ BKE_main_namemap_remove_name(bmain, id, id->name + 2);
BLI_strncpy(id->name + 2, name_dst, sizeof(id->name) - 2);
/* We know it's unique, this just sorts. */
BLI_libblock_ensure_unique_name(bmain, id->name);
@@ -232,3 +236,30 @@ ARegion *do_versions_add_region(int regiontype, const char *name)
region->regiontype = regiontype;
return region;
}
+
+void node_tree_relink_with_socket_id_map(bNodeTree &ntree,
+ bNode &old_node,
+ bNode &new_node,
+ const Map<std::string, std::string> &map)
+{
+ LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree.links) {
+ if (link->tonode == &old_node) {
+ bNodeSocket *old_socket = link->tosock;
+ if (const std::string *new_identifier = map.lookup_ptr_as(old_socket->identifier)) {
+ bNodeSocket *new_socket = nodeFindSocket(&new_node, SOCK_IN, new_identifier->c_str());
+ link->tonode = &new_node;
+ link->tosock = new_socket;
+ old_socket->link = nullptr;
+ }
+ }
+ if (link->fromnode == &old_node) {
+ bNodeSocket *old_socket = link->fromsock;
+ if (const std::string *new_identifier = map.lookup_ptr_as(old_socket->identifier)) {
+ bNodeSocket *new_socket = nodeFindSocket(&new_node, SOCK_OUT, new_identifier->c_str());
+ link->fromnode = &new_node;
+ link->fromsock = new_socket;
+ old_socket->link = nullptr;
+ }
+ }
+ }
+}
diff --git a/source/blender/blenloader/intern/versioning_common.h b/source/blender/blenloader/intern/versioning_common.h
index c8c7dcc7cff..a8844d076b3 100644
--- a/source/blender/blenloader/intern/versioning_common.h
+++ b/source/blender/blenloader/intern/versioning_common.h
@@ -6,6 +6,10 @@
#pragma once
+#ifdef __cplusplus
+# include "BLI_map.hh"
+#endif
+
struct ARegion;
struct ListBase;
struct Main;
@@ -93,3 +97,10 @@ ARegion *do_versions_add_region(int regiontype, const char *name);
#ifdef __cplusplus
}
#endif
+
+#ifdef __cplusplus
+void node_tree_relink_with_socket_id_map(bNodeTree &ntree,
+ bNode &old_node,
+ bNode &new_node,
+ const blender::Map<std::string, std::string> &map);
+#endif
diff --git a/source/blender/blenloader/intern/versioning_cycles.c b/source/blender/blenloader/intern/versioning_cycles.c
index e1ceed82ba7..0a9d40e161a 100644
--- a/source/blender/blenloader/intern/versioning_cycles.c
+++ b/source/blender/blenloader/intern/versioning_cycles.c
@@ -689,7 +689,6 @@ static void update_vector_math_node_normalize_operator(bNodeTree *ntree)
* a value of -1 just to be identified later in the versioning code:
*
* Average Operator : 2 -> -1
- *
*/
static void update_vector_math_node_operators_enum_mapping(bNodeTree *ntree)
{
@@ -867,7 +866,6 @@ static void update_mapping_node_fcurve_rna_path_callback(ID *UNUSED(id),
* and check if they control a property of the node, if they do, we update
* the path to be that of the corresponding socket in the node or the added
* minimum/maximum node.
- *
*/
static void update_mapping_node_inputs_and_properties(bNodeTree *ntree)
{
@@ -1057,7 +1055,6 @@ static void update_voronoi_node_fac_output(bNodeTree *ntree)
* the inputs of the subtract node.
* 6. The output of the subtract node is connected to the
* appropriate sockets.
- *
*/
static void update_voronoi_node_crackle(bNodeTree *ntree)
{
@@ -1197,7 +1194,7 @@ static void update_voronoi_node_square_distance(bNodeTree *ntree)
NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage;
bNodeSocket *sockDistance = nodeFindSocket(node, SOCK_OUT, "Distance");
if (tex->distance == SHD_VORONOI_EUCLIDEAN &&
- (ELEM(tex->feature, SHD_VORONOI_F1, SHD_VORONOI_F2)) && socket_is_used(sockDistance)) {
+ ELEM(tex->feature, SHD_VORONOI_F1, SHD_VORONOI_F2) && socket_is_used(sockDistance)) {
bNode *multiplyNode = nodeAddStaticNode(NULL, ntree, SH_NODE_MATH);
multiplyNode->custom1 = NODE_MATH_MULTIPLY;
multiplyNode->locx = node->locx + node->width + 20.0f;
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.cc
index dfd98cb94f3..da23e9cb49f 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.cc
@@ -15,6 +15,7 @@
#include "BLI_listbase.h"
#include "BLI_math.h"
+#include "BLI_math_vec_types.hh"
#include "BLI_string.h"
#include "BLI_system.h"
#include "BLI_utildefines.h"
@@ -36,6 +37,7 @@
#include "DNA_workspace_types.h"
#include "BKE_appdir.h"
+#include "BKE_attribute.hh"
#include "BKE_brush.h"
#include "BKE_colortools.h"
#include "BKE_curveprofile.h"
@@ -45,6 +47,7 @@
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
+#include "BKE_main_namemap.h"
#include "BKE_material.h"
#include "BKE_mesh.h"
#include "BKE_node.h"
@@ -55,6 +58,8 @@
#include "BLO_readfile.h"
+#include "BLT_translation.h"
+
#include "versioning_common.h"
/* Make preferences read-only, use versioning_userdef.c. */
@@ -63,8 +68,9 @@
static bool blo_is_builtin_template(const char *app_template)
{
/* For all builtin templates shipped with Blender. */
- return (!app_template ||
- STR_ELEM(app_template, "2D_Animation", "Sculpting", "VFX", "Video_Editing"));
+ return (
+ !app_template ||
+ STR_ELEM(app_template, N_("2D_Animation"), N_("Sculpting"), N_("VFX"), N_("Video_Editing")));
}
static void blo_update_defaults_screen(bScreen *screen,
@@ -115,7 +121,7 @@ static void blo_update_defaults_screen(bScreen *screen,
if (area->spacetype == SPACE_IMAGE) {
if (STREQ(workspace_name, "UV Editing")) {
- SpaceImage *sima = area->spacedata.first;
+ SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
if (sima->mode == SI_MODE_VIEW) {
sima->mode = SI_MODE_UV;
}
@@ -123,7 +129,7 @@ static void blo_update_defaults_screen(bScreen *screen,
}
else if (area->spacetype == SPACE_ACTION) {
/* Show markers region, hide channels and collapse summary in timelines. */
- SpaceAction *saction = area->spacedata.first;
+ SpaceAction *saction = static_cast<SpaceAction *>(area->spacedata.first);
saction->flag |= SACTION_SHOW_MARKERS;
if (saction->mode == SACTCONT_TIMELINE) {
saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED;
@@ -134,17 +140,25 @@ static void blo_update_defaults_screen(bScreen *screen,
}
}
}
+ else {
+ /* Open properties panel by default. */
+ LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
+ if (region->regiontype == RGN_TYPE_UI) {
+ region->flag &= ~RGN_FLAG_HIDDEN;
+ }
+ }
+ }
}
else if (area->spacetype == SPACE_GRAPH) {
- SpaceGraph *sipo = area->spacedata.first;
+ SpaceGraph *sipo = static_cast<SpaceGraph *>(area->spacedata.first);
sipo->flag |= SIPO_SHOW_MARKERS;
}
else if (area->spacetype == SPACE_NLA) {
- SpaceNla *snla = area->spacedata.first;
+ SpaceNla *snla = static_cast<SpaceNla *>(area->spacedata.first);
snla->flag |= SNLA_SHOW_MARKERS;
}
else if (area->spacetype == SPACE_SEQ) {
- SpaceSeq *seq = area->spacedata.first;
+ SpaceSeq *seq = static_cast<SpaceSeq *>(area->spacedata.first);
seq->flag |= SEQ_SHOW_MARKERS | SEQ_ZOOM_TO_FIT | SEQ_USE_PROXIES | SEQ_SHOW_OVERLAY;
seq->render_size = SEQ_RENDER_SIZE_PROXY_100;
seq->timeline_overlay.flag |= SEQ_TIMELINE_SHOW_STRIP_SOURCE | SEQ_TIMELINE_SHOW_STRIP_NAME |
@@ -154,12 +168,12 @@ static void blo_update_defaults_screen(bScreen *screen,
}
else if (area->spacetype == SPACE_TEXT) {
/* Show syntax and line numbers in Script workspace text editor. */
- SpaceText *stext = area->spacedata.first;
+ SpaceText *stext = static_cast<SpaceText *>(area->spacedata.first);
stext->showsyntax = true;
stext->showlinenrs = true;
}
else if (area->spacetype == SPACE_VIEW3D) {
- View3D *v3d = area->spacedata.first;
+ View3D *v3d = static_cast<View3D *>(area->spacedata.first);
/* Screen space cavity by default for faster performance. */
v3d->shading.cavity_type = V3D_SHADING_CAVITY_CURVATURE;
v3d->shading.flag |= V3D_SHADING_SPECULAR_HIGHLIGHT;
@@ -183,7 +197,7 @@ static void blo_update_defaults_screen(bScreen *screen,
v3d->overlay.normals_constant_screen_size = 7.0f;
}
else if (area->spacetype == SPACE_CLIP) {
- SpaceClip *sclip = area->spacedata.first;
+ SpaceClip *sclip = static_cast<SpaceClip *>(area->spacedata.first);
sclip->around = V3D_AROUND_CENTER_MEDIAN;
sclip->mask_info.blend_factor = 0.7f;
sclip->mask_info.draw_flag = MASK_DRAWFLAG_SPLINE;
@@ -194,7 +208,9 @@ static void blo_update_defaults_screen(bScreen *screen,
const bool hide_image_tool_header = STREQ(workspace_name, "Rendering");
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
- ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase : &sl->regionbase;
+ ListBase *regionbase = (sl == static_cast<SpaceLink *>(area->spacedata.first)) ?
+ &area->regionbase :
+ &sl->regionbase;
LISTBASE_FOREACH (ARegion *, region, regionbase) {
if (region->regiontype == RGN_TYPE_TOOL_HEADER) {
@@ -214,12 +230,12 @@ static void blo_update_defaults_screen(bScreen *screen,
if (app_template && STREQ(app_template, "2D_Animation")) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
if (area->spacetype == SPACE_ACTION) {
- SpaceAction *saction = area->spacedata.first;
+ SpaceAction *saction = static_cast<SpaceAction *>(area->spacedata.first);
/* Enable Sliders. */
saction->flag |= SACTION_SLIDERS;
}
else if (area->spacetype == SPACE_VIEW3D) {
- View3D *v3d = area->spacedata.first;
+ View3D *v3d = static_cast<View3D *>(area->spacedata.first);
/* Set Material Color by default. */
v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR;
/* Enable Annotations. */
@@ -240,7 +256,7 @@ void BLO_update_defaults_workspace(WorkSpace *workspace, const char *app_templat
if (blo_is_builtin_template(app_template)) {
/* Clear all tools to use default options instead, ignore the tool saved in the file. */
while (!BLI_listbase_is_empty(&workspace->tools)) {
- BKE_workspace_tool_remove(workspace, workspace->tools.first);
+ BKE_workspace_tool_remove(workspace, static_cast<bToolRef *>(workspace->tools.first));
}
/* For 2D animation template. */
@@ -256,7 +272,7 @@ void BLO_update_defaults_workspace(WorkSpace *workspace, const char *app_templat
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
if (area->spacetype == SPACE_VIEW3D) {
- View3D *v3d = area->spacedata.first;
+ View3D *v3d = static_cast<View3D *>(area->spacedata.first);
v3d->shading.flag &= ~V3D_SHADING_CAVITY;
copy_v3_fl(v3d->shading.single_color, 1.0f);
STRNCPY(v3d->shading.matcap, "basic_1");
@@ -284,7 +300,8 @@ static void blo_update_defaults_scene(Main *bmain, Scene *scene)
}
/* Rename render layers. */
- BKE_view_layer_rename(bmain, scene, scene->view_layers.first, "ViewLayer");
+ BKE_view_layer_rename(
+ bmain, scene, static_cast<ViewLayer *>(scene->view_layers.first), "ViewLayer");
/* Disable Z pass by default. */
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
@@ -296,7 +313,7 @@ static void blo_update_defaults_scene(Main *bmain, Scene *scene)
scene->eevee.bloom_clamp = 0.0f;
scene->eevee.motion_blur_shutter = 0.5f;
- copy_v3_v3(scene->display.light_direction, (float[3]){M_SQRT1_3, M_SQRT1_3, M_SQRT1_3});
+ copy_v3_v3(scene->display.light_direction, blender::float3(M_SQRT1_3));
copy_v2_fl2(scene->safe_areas.title, 0.1f, 0.05f);
copy_v2_fl2(scene->safe_areas.action, 0.035f, 0.035f);
@@ -332,8 +349,9 @@ static void blo_update_defaults_scene(Main *bmain, Scene *scene)
}
/* Correct default startup UV's. */
- Mesh *me = BLI_findstring(&bmain->meshes, "Cube", offsetof(ID, name) + 2);
- if (me && (me->totloop == 24) && (me->mloopuv != NULL)) {
+ Mesh *me = static_cast<Mesh *>(BLI_findstring(&bmain->meshes, "Cube", offsetof(ID, name) + 2));
+ if (me && (me->totloop == 24) && CustomData_has_layer(&me->ldata, CD_MLOOPUV)) {
+ MLoopUV *mloopuv = static_cast<MLoopUV *>(CustomData_get_layer(&me->ldata, CD_MLOOPUV));
const float uv_values[24][2] = {
{0.625, 0.50}, {0.875, 0.50}, {0.875, 0.75}, {0.625, 0.75}, {0.375, 0.75}, {0.625, 0.75},
{0.625, 1.00}, {0.375, 1.00}, {0.375, 0.00}, {0.625, 0.00}, {0.625, 0.25}, {0.375, 0.25},
@@ -341,7 +359,7 @@ static void blo_update_defaults_scene(Main *bmain, Scene *scene)
{0.625, 0.75}, {0.375, 0.75}, {0.375, 0.25}, {0.625, 0.25}, {0.625, 0.50}, {0.375, 0.50},
};
for (int i = 0; i < ARRAY_SIZE(uv_values); i++) {
- copy_v2_v2(me->mloopuv[i].uv, uv_values[i]);
+ copy_v2_v2(mloopuv[i].uv, uv_values[i]);
}
}
@@ -360,7 +378,7 @@ static void blo_update_defaults_scene(Main *bmain, Scene *scene)
void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
{
/* For all app templates. */
- for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
+ LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) {
BLO_update_defaults_workspace(workspace, app_template);
}
@@ -376,7 +394,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
do_versions_rename_id(bmain, ID_BR, "Draw Pen", "Pen");
/* Pen Soft brush. */
- brush = (Brush *)do_versions_rename_id(bmain, ID_BR, "Draw Soft", "Pencil Soft");
+ brush = reinterpret_cast<Brush *>(
+ do_versions_rename_id(bmain, ID_BR, "Draw Soft", "Pencil Soft"));
if (brush) {
brush->gpencil_settings->icon_id = GP_BRUSH_ICON_PEN;
}
@@ -394,7 +413,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
do_versions_rename_id(bmain, ID_BR, "Draw Block", "Marker Chisel");
/* Remove useless Fill Area.001 brush. */
- brush = BLI_findstring(&bmain->brushes, "Fill Area.001", offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, "Fill Area.001", offsetof(ID, name) + 2));
if (brush) {
BKE_id_delete(bmain, brush);
}
@@ -408,21 +428,24 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
do_versions_rename_id(bmain, ID_MA, "Black Dots", "Dots Stroke");
/* Dots Stroke. */
- ma = BLI_findstring(&bmain->materials, "Dots Stroke", offsetof(ID, name) + 2);
+ ma = static_cast<Material *>(
+ BLI_findstring(&bmain->materials, "Dots Stroke", offsetof(ID, name) + 2));
if (ma == NULL) {
ma = BKE_gpencil_material_add(bmain, "Dots Stroke");
}
ma->gp_style->mode = GP_MATERIAL_MODE_DOT;
/* Squares Stroke. */
- ma = BLI_findstring(&bmain->materials, "Squares Stroke", offsetof(ID, name) + 2);
+ ma = static_cast<Material *>(
+ BLI_findstring(&bmain->materials, "Squares Stroke", offsetof(ID, name) + 2));
if (ma == NULL) {
ma = BKE_gpencil_material_add(bmain, "Squares Stroke");
}
ma->gp_style->mode = GP_MATERIAL_MODE_SQUARE;
/* Change Solid Stroke settings. */
- ma = BLI_findstring(&bmain->materials, "Solid Stroke", offsetof(ID, name) + 2);
+ ma = static_cast<Material *>(
+ BLI_findstring(&bmain->materials, "Solid Stroke", offsetof(ID, name) + 2));
if (ma != NULL) {
ma->gp_style->mix_rgba[3] = 1.0f;
ma->gp_style->texture_offset[0] = -0.5f;
@@ -430,7 +453,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
/* Change Solid Fill settings. */
- ma = BLI_findstring(&bmain->materials, "Solid Fill", offsetof(ID, name) + 2);
+ ma = static_cast<Material *>(
+ BLI_findstring(&bmain->materials, "Solid Fill", offsetof(ID, name) + 2));
if (ma != NULL) {
ma->gp_style->flag &= ~GP_MATERIAL_STROKE_SHOW;
ma->gp_style->mix_rgba[3] = 1.0f;
@@ -438,14 +462,15 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
ma->gp_style->mix_factor = 0.5f;
}
- Object *ob = BLI_findstring(&bmain->objects, "Stroke", offsetof(ID, name) + 2);
+ Object *ob = static_cast<Object *>(
+ BLI_findstring(&bmain->objects, "Stroke", offsetof(ID, name) + 2));
if (ob && ob->type == OB_GPENCIL) {
ob->dtx |= OB_USE_GPENCIL_LIGHTS;
}
}
/* Reset all grease pencil brushes. */
- Scene *scene = bmain->scenes.first;
+ Scene *scene = static_cast<Scene *>(bmain->scenes.first);
BKE_brush_gpencil_paint_presets(bmain, scene->toolsettings, true);
BKE_brush_gpencil_sculpt_presets(bmain, scene->toolsettings, true);
BKE_brush_gpencil_vertex_presets(bmain, scene->toolsettings, true);
@@ -480,6 +505,7 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
if (layout->screen) {
bScreen *screen = layout->screen;
if (!STREQ(screen->id.name + 2, workspace->id.name + 2)) {
+ BKE_main_namemap_remove_name(bmain, &screen->id, screen->id.name + 2);
BLI_strncpy(screen->id.name + 2, workspace->id.name + 2, sizeof(screen->id.name) - 2);
BLI_libblock_ensure_unique_name(bmain, screen->id.name);
}
@@ -497,7 +523,7 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
/* Scenes */
- for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
+ LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
blo_update_defaults_scene(bmain, scene);
if (app_template && STREQ(app_template, "Video_Editing")) {
@@ -523,7 +549,7 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
do_versions_rename_id(bmain, ID_LA, "Lamp", "Light");
if (app_template && STREQ(app_template, "2D_Animation")) {
- for (Object *object = bmain->objects.first; object; object = object->id.next) {
+ LISTBASE_FOREACH (Object *, object, &bmain->objects) {
if (object->type == OB_GPENCIL) {
/* Set grease pencil object in drawing mode */
bGPdata *gpd = (bGPdata *)object->data;
@@ -534,7 +560,7 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
}
- for (Mesh *mesh = bmain->meshes.first; mesh; mesh = mesh->id.next) {
+ LISTBASE_FOREACH (Mesh *, mesh, &bmain->meshes) {
/* Match default for new meshes. */
mesh->smoothresh = DEG2RADF(30);
/* Match voxel remesher options for all existing meshes in templates. */
@@ -551,31 +577,33 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
CustomData_free_layers(&mesh->vdata, CD_PAINT_MASK, mesh->totvert);
CustomData_free_layers(&mesh->ldata, CD_GRID_PAINT_MASK, mesh->totloop);
}
+ mesh->attributes_for_write().remove(".sculpt_face_set");
}
- for (Camera *camera = bmain->cameras.first; camera; camera = camera->id.next) {
+ LISTBASE_FOREACH (Camera *, camera, &bmain->cameras) {
/* Initialize to a useful value. */
camera->dof.focus_distance = 10.0f;
camera->dof.aperture_fstop = 2.8f;
}
- for (Light *light = bmain->lights.first; light; light = light->id.next) {
+ LISTBASE_FOREACH (Light *, light, &bmain->lights) {
/* Fix lights defaults. */
light->clipsta = 0.05f;
light->att_dist = 40.0f;
}
/* Materials */
- for (Material *ma = bmain->materials.first; ma; ma = ma->id.next) {
+ LISTBASE_FOREACH (Material *, ma, &bmain->materials) {
/* Update default material to be a bit more rough. */
- ma->roughness = 0.4f;
+ ma->roughness = 0.5f;
if (ma->nodetree) {
LISTBASE_FOREACH (bNode *, node, &ma->nodetree->nodes) {
if (node->type == SH_NODE_BSDF_PRINCIPLED) {
bNodeSocket *roughness_socket = nodeFindSocket(node, SOCK_IN, "Roughness");
- bNodeSocketValueFloat *roughness_data = roughness_socket->default_value;
- roughness_data->value = 0.4f;
+ bNodeSocketValueFloat *roughness_data = static_cast<bNodeSocketValueFloat *>(
+ roughness_socket->default_value);
+ roughness_data->value = 0.5f;
node->custom2 = SHD_SUBSURFACE_RANDOM_WALK;
BKE_ntree_update_tag_node_property(ma->nodetree, node);
}
@@ -592,13 +620,14 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
/* Enable for UV sculpt (other brush types will be created as needed),
* without this the grab brush will be active but not selectable from the list. */
const char *brush_name = "Grab";
- Brush *brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ Brush *brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (brush) {
brush->ob_mode |= OB_MODE_EDIT;
}
}
- for (Brush *brush = bmain->brushes.first; brush; brush = brush->id.next) {
+ LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) {
brush->blur_kernel_radius = 2;
/* Use full strength for all non-sculpt brushes,
@@ -618,13 +647,15 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
Brush *brush;
brush_name = "Smear";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (brush) {
brush->spacing = 3.0;
}
brush_name = "Draw Sharp";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -632,7 +663,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Elastic Deform";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -640,7 +672,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Pose";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -648,7 +681,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Multi-plane Scrape";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -656,7 +690,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Clay Thumb";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -664,7 +699,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Cloth";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -672,7 +708,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Slide Relax";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -680,7 +717,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Paint";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -688,7 +726,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Smear";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -696,7 +735,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Boundary";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -704,7 +744,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Simplify";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -712,7 +753,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Draw Face Sets";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -720,7 +762,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Multires Displacement Eraser";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -728,7 +771,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
brush_name = "Multires Displacement Smear";
- brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ brush = static_cast<Brush *>(
+ BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2));
if (!brush) {
brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
id_us_min(&brush->id);
@@ -736,7 +780,7 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
/* Use the same tool icon color in the brush cursor */
- for (brush = bmain->brushes.first; brush; brush = brush->id.next) {
+ LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) {
if (brush->ob_mode & OB_MODE_SCULPT) {
BLI_assert(brush->sculpt_tool != 0);
BKE_brush_sculpt_reset(brush);
diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c
index 75cc333e4b5..9a0568a3589 100644
--- a/source/blender/blenloader/intern/versioning_legacy.c
+++ b/source/blender/blenloader/intern/versioning_legacy.c
@@ -291,8 +291,8 @@ static void customdata_version_242(Mesh *me)
MEM_freeN(me->mcol);
}
- me->mcol = CustomData_add_layer(&me->fdata, CD_MCOL, CD_CALLOC, NULL, me->totface);
- me->mtface = CustomData_add_layer(&me->fdata, CD_MTFACE, CD_CALLOC, NULL, me->totface);
+ me->mcol = CustomData_add_layer(&me->fdata, CD_MCOL, CD_SET_DEFAULT, NULL, me->totface);
+ me->mtface = CustomData_add_layer(&me->fdata, CD_MTFACE, CD_SET_DEFAULT, NULL, me->totface);
mtf = me->mtface;
mcol = me->mcol;
@@ -342,8 +342,6 @@ static void customdata_version_242(Mesh *me)
mcoln++;
}
}
-
- BKE_mesh_update_customdata_pointers(me, true);
}
/* Only copy render texface layer from active. */
@@ -2533,7 +2531,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain)
Object *ob;
for (ob = bmain->objects.first; ob; ob = ob->id.next) {
if (ob->pd) {
- ob->pd->seed = ((uint)(ceil(PIL_check_seconds_timer())) + 1) % 128;
+ ob->pd->seed = ((uint)ceil(PIL_check_seconds_timer()) + 1) % 128;
}
}
}
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index 4f62be26196..b4890131861 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -83,6 +83,10 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
FROM_DEFAULT_V4_UCHAR(space_sequencer.list_text_hi);
}
+ if (!USER_VERSION_ATLEAST(303, 6)) {
+ btheme->tui.wcol_view_item = U_theme_default.tui.wcol_view_item;
+ }
+
/**
* Versioning code until next subversion bump goes here.
*
@@ -94,7 +98,6 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
*/
{
/* Keep this block, even when empty. */
- btheme->tui.wcol_view_item = U_theme_default.tui.wcol_view_item;
}
#undef FROM_DEFAULT_V4_UCHAR
@@ -532,7 +535,7 @@ void blo_do_versions_userdef(UserDef *userdef)
}
if (!USER_VERSION_ATLEAST(280, 44)) {
- userdef->uiflag &= ~(USER_UIFLAG_UNUSED_0 | USER_UIFLAG_UNUSED_1);
+ userdef->uiflag &= ~(USER_NO_MULTITOUCH_GESTURES | USER_UIFLAG_UNUSED_1);
userdef->uiflag2 &= ~(USER_UIFLAG2_UNUSED_0);
userdef->gp_settings &= ~(GP_PAINT_UNUSED_0);
}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.cc
index 1ec056a9f50..42bc884098e 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.cc
@@ -6,7 +6,6 @@
*/
/**
- *
* FILE FORMAT
* ===========
*
@@ -56,12 +55,13 @@
* - write #USER (#UserDef struct) if filename is `~/.config/blender/X.XX/config/startup.blend`.
*/
+#include <cerrno>
+#include <climits>
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
#include <fcntl.h>
-#include <limits.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#ifdef WIN32
# include "BLI_winstuff.h"
@@ -117,8 +117,6 @@
#include "readfile.h"
-#include <errno.h>
-
#include <zstd.h>
/* Make preferences read-only. */
@@ -127,8 +125,8 @@
/* ********* my write, buffered writing with minimum size chunks ************ */
/* Use optimal allocation since blocks of this size are kept in memory for undo. */
-#define MEM_BUFFER_SIZE (MEM_SIZE_OPTIMAL(1 << 17)) /* 128kb */
-#define MEM_CHUNK_SIZE (MEM_SIZE_OPTIMAL(1 << 15)) /* ~32kb */
+#define MEM_BUFFER_SIZE MEM_SIZE_OPTIMAL(1 << 17) /* 128kb */
+#define MEM_CHUNK_SIZE MEM_SIZE_OPTIMAL(1 << 15) /* ~32kb */
#define ZSTD_BUFFER_SIZE (1 << 21) /* 2mb */
#define ZSTD_CHUNK_SIZE (1 << 20) /* 1mb */
@@ -144,19 +142,18 @@ static CLG_LogRef LOG = {"blo.writefile"};
/** \name Internal Write Wrapper's (Abstracts Compression)
* \{ */
-typedef enum {
+enum eWriteWrapType {
WW_WRAP_NONE = 1,
WW_WRAP_ZSTD,
-} eWriteWrapType;
+};
-typedef struct ZstdFrame {
+struct ZstdFrame {
struct ZstdFrame *next, *prev;
uint32_t compressed_size;
uint32_t uncompressed_size;
-} ZstdFrame;
+};
-typedef struct WriteWrap WriteWrap;
struct WriteWrap {
/* callbacks */
bool (*open)(WriteWrap *ww, const char *filepath);
@@ -208,17 +205,17 @@ static size_t ww_write_none(WriteWrap *ww, const char *buf, size_t buf_len)
/* zstd */
-typedef struct {
- struct ZstdWriteBlockTask *next, *prev;
+struct ZstdWriteBlockTask {
+ ZstdWriteBlockTask *next, *prev;
void *data;
size_t size;
int frame_number;
WriteWrap *ww;
-} ZstdWriteBlockTask;
+};
static void *zstd_write_task(void *userdata)
{
- ZstdWriteBlockTask *task = userdata;
+ ZstdWriteBlockTask *task = static_cast<ZstdWriteBlockTask *>(userdata);
WriteWrap *ww = task->ww;
size_t out_buf_len = ZSTD_compressBound(task->size);
@@ -238,8 +235,9 @@ static void *zstd_write_task(void *userdata)
ww->zstd.write_error = true;
}
else {
- if (ww_write_none(ww, out_buf, out_size) == out_size) {
- ZstdFrame *frameinfo = MEM_mallocN(sizeof(ZstdFrame), "zstd frameinfo");
+ if (ww_write_none(ww, static_cast<const char *>(out_buf), out_size) == out_size) {
+ ZstdFrame *frameinfo = static_cast<ZstdFrame *>(
+ MEM_mallocN(sizeof(ZstdFrame), "zstd frameinfo"));
frameinfo->uncompressed_size = task->size;
frameinfo->compressed_size = out_size;
BLI_addtail(&ww->zstd.frames, frameinfo);
@@ -255,7 +253,7 @@ static void *zstd_write_task(void *userdata)
BLI_condition_notify_all(&ww->zstd.condition);
MEM_freeN(out_buf);
- return NULL;
+ return nullptr;
}
static bool ww_open_zstd(WriteWrap *ww, const char *filepath)
@@ -334,7 +332,8 @@ static size_t ww_write_zstd(WriteWrap *ww, const char *buf, size_t buf_len)
return 0;
}
- ZstdWriteBlockTask *task = MEM_mallocN(sizeof(ZstdWriteBlockTask), __func__);
+ ZstdWriteBlockTask *task = static_cast<ZstdWriteBlockTask *>(
+ MEM_mallocN(sizeof(ZstdWriteBlockTask), __func__));
task->data = MEM_mallocN(buf_len, __func__);
memcpy(task->data, buf, buf_len);
task->size = buf_len;
@@ -348,7 +347,7 @@ static size_t ww_write_zstd(WriteWrap *ww, const char *buf, size_t buf_len)
* Otherwise, we wait for the earliest thread to finish.
* We look up the earliest thread while holding the mutex, but release it
* before joining the thread to prevent a deadlock. */
- ZstdWriteBlockTask *first_task = ww->zstd.tasks.first;
+ ZstdWriteBlockTask *first_task = static_cast<ZstdWriteBlockTask *>(ww->zstd.tasks.first);
BLI_mutex_unlock(&ww->zstd.mutex);
if (!BLI_available_threads(&ww->zstd.threadpool)) {
BLI_threadpool_remove(&ww->zstd.threadpool, first_task);
@@ -394,8 +393,8 @@ static void ww_handle_init(eWriteWrapType ww_type, WriteWrap *r_ww)
/** \name Write Data Type & Functions
* \{ */
-typedef struct {
- const struct SDNA *sdna;
+struct WriteData {
+ const SDNA *sdna;
struct {
/** Use for file and memory writing (size stored in max_size). */
@@ -425,25 +424,25 @@ typedef struct {
/**
* Wrap writing, so we can use zstd or
* other compression types later, see: G_FILE_COMPRESS
- * Will be NULL for UNDO.
+ * Will be nullptr for UNDO.
*/
WriteWrap *ww;
-} WriteData;
+};
-typedef struct BlendWriter {
+struct BlendWriter {
WriteData *wd;
-} BlendWriter;
+};
static WriteData *writedata_new(WriteWrap *ww)
{
- WriteData *wd = MEM_callocN(sizeof(*wd), "writedata");
+ WriteData *wd = static_cast<WriteData *>(MEM_callocN(sizeof(*wd), "writedata"));
wd->sdna = DNA_sdna_current_get();
wd->ww = ww;
- if ((ww == NULL) || (ww->use_buf)) {
- if (ww == NULL) {
+ if ((ww == nullptr) || (ww->use_buf)) {
+ if (ww == nullptr) {
wd->buffer.max_size = MEM_BUFFER_SIZE;
wd->buffer.chunk_size = MEM_CHUNK_SIZE;
}
@@ -451,7 +450,7 @@ static WriteData *writedata_new(WriteWrap *ww)
wd->buffer.max_size = ZSTD_BUFFER_SIZE;
wd->buffer.chunk_size = ZSTD_CHUNK_SIZE;
}
- wd->buffer.buf = MEM_mallocN(wd->buffer.max_size, "wd->buffer.buf");
+ wd->buffer.buf = static_cast<uchar *>(MEM_mallocN(wd->buffer.max_size, "wd->buffer.buf"));
}
return wd;
@@ -459,7 +458,7 @@ static WriteData *writedata_new(WriteWrap *ww)
static void writedata_do_write(WriteData *wd, const void *mem, size_t memlen)
{
- if ((wd == NULL) || wd->error || (mem == NULL) || memlen < 1) {
+ if ((wd == nullptr) || wd->error || (mem == nullptr) || memlen < 1) {
return;
}
@@ -474,10 +473,10 @@ static void writedata_do_write(WriteData *wd, const void *mem, size_t memlen)
/* memory based save */
if (wd->use_memfile) {
- BLO_memfile_chunk_add(&wd->mem, mem, memlen);
+ BLO_memfile_chunk_add(&wd->mem, static_cast<const char *>(mem), memlen);
}
else {
- if (wd->ww->write(wd->ww, mem, memlen) != memlen) {
+ if (wd->ww->write(wd->ww, static_cast<const char *>(mem), memlen) != memlen) {
wd->error = true;
}
}
@@ -520,7 +519,7 @@ static void mywrite(WriteData *wd, const void *adr, size_t len)
return;
}
- if (UNLIKELY(adr == NULL)) {
+ if (UNLIKELY(adr == nullptr)) {
BLI_assert(0);
return;
}
@@ -529,7 +528,7 @@ static void mywrite(WriteData *wd, const void *adr, size_t len)
wd->write_len += len;
#endif
- if (wd->buffer.buf == NULL) {
+ if (wd->buffer.buf == nullptr) {
writedata_do_write(wd, adr, len);
}
else {
@@ -566,15 +565,15 @@ static void mywrite(WriteData *wd, const void *adr, size_t len)
/**
* BeGiN initializer for mywrite
* \param ww: File write wrapper.
- * \param compare: Previous memory file (can be NULL).
- * \param current: The current memory file (can be NULL).
+ * \param compare: Previous memory file (can be nullptr).
+ * \param current: The current memory file (can be nullptr).
* \warning Talks to other functions with global parameters
*/
static WriteData *mywrite_begin(WriteWrap *ww, MemFile *compare, MemFile *current)
{
WriteData *wd = writedata_new(ww);
- if (current != NULL) {
+ if (current != nullptr) {
BLO_memfile_write_init(&wd->mem, current, compare);
wd->use_memfile = true;
}
@@ -618,15 +617,17 @@ static void mywrite_id_begin(WriteData *wd, ID *id)
/* If current next memchunk does not match the ID we are about to write, or is not the _first_
* one for said ID, try to find the correct memchunk in the mapping using ID's session_uuid. */
MemFileChunk *curr_memchunk = wd->mem.reference_current_chunk;
- MemFileChunk *prev_memchunk = curr_memchunk != NULL ? curr_memchunk->prev : NULL;
- if (wd->mem.id_session_uuid_mapping != NULL &&
- (curr_memchunk == NULL || curr_memchunk->id_session_uuid != id->session_uuid ||
- (prev_memchunk != NULL &&
+ MemFileChunk *prev_memchunk = curr_memchunk != nullptr ?
+ static_cast<MemFileChunk *>(curr_memchunk->prev) :
+ nullptr;
+ if (wd->mem.id_session_uuid_mapping != nullptr &&
+ (curr_memchunk == nullptr || curr_memchunk->id_session_uuid != id->session_uuid ||
+ (prev_memchunk != nullptr &&
(prev_memchunk->id_session_uuid == curr_memchunk->id_session_uuid)))) {
void *ref = BLI_ghash_lookup(wd->mem.id_session_uuid_mapping,
POINTER_FROM_UINT(id->session_uuid));
- if (ref != NULL) {
- wd->mem.reference_current_chunk = ref;
+ if (ref != nullptr) {
+ wd->mem.reference_current_chunk = static_cast<MemFileChunk *>(ref);
}
/* Else, no existing memchunk found, i.e. this is supposed to be a new ID. */
}
@@ -640,7 +641,7 @@ static void mywrite_id_begin(WriteData *wd, ID *id)
*
* Only does something when storing an undo step.
*/
-static void mywrite_id_end(WriteData *wd, ID *UNUSED(id))
+static void mywrite_id_end(WriteData *wd, ID * /*id*/)
{
if (wd->use_memfile) {
/* Very important to do it after every ID write now, otherwise we cannot know whether a
@@ -663,7 +664,7 @@ static void writestruct_at_address_nr(
BLI_assert(struct_nr > 0 && struct_nr < SDNA_TYPE_MAX);
- if (adr == NULL || data == NULL || nr == 0) {
+ if (adr == nullptr || data == nullptr || nr == 0) {
return;
}
@@ -682,7 +683,7 @@ static void writestruct_at_address_nr(
}
mywrite(wd, &bh, sizeof(BHead));
- mywrite(wd, data, (size_t)bh.len);
+ mywrite(wd, data, size_t(bh.len));
}
static void writestruct_nr(
@@ -696,7 +697,7 @@ static void writedata(WriteData *wd, int filecode, size_t len, const void *adr)
{
BHead bh;
- if (adr == NULL || len == 0) {
+ if (adr == nullptr || len == 0) {
return;
}
@@ -706,14 +707,14 @@ static void writedata(WriteData *wd, int filecode, size_t len, const void *adr)
}
/* align to 4 (writes uninitialized bytes in some cases) */
- len = (len + 3) & ~((size_t)3);
+ len = (len + 3) & ~size_t(3);
/* init BHead */
bh.code = filecode;
bh.old = adr;
bh.nr = 1;
bh.SDNAnr = 0;
- bh.len = (int)len;
+ bh.len = int(len);
mywrite(wd, &bh, sizeof(BHead));
mywrite(wd, adr, len);
@@ -722,7 +723,7 @@ static void writedata(WriteData *wd, int filecode, size_t len, const void *adr)
/* use this to force writing of lists in same order as reading (using link_list) */
static void writelist_nr(WriteData *wd, int filecode, const int struct_nr, const ListBase *lb)
{
- const Link *link = lb->first;
+ const Link *link = static_cast<Link *>(lb->first);
while (link) {
writestruct_nr(wd, filecode, struct_nr, 1, link);
@@ -778,42 +779,42 @@ static void current_screen_compat(Main *mainvar,
ViewLayer **r_view_layer)
{
wmWindowManager *wm;
- wmWindow *window = NULL;
+ wmWindow *window = nullptr;
/* find a global current screen in the first open window, to have
* a reasonable default for reading in older versions */
- wm = mainvar->wm.first;
+ wm = static_cast<wmWindowManager *>(mainvar->wm.first);
if (wm) {
if (use_active_win) {
/* write the active window into the file, needed for multi-window undo T43424 */
- for (window = wm->windows.first; window; window = window->next) {
+ for (window = static_cast<wmWindow *>(wm->windows.first); window; window = window->next) {
if (window->active) {
break;
}
}
/* fallback */
- if (window == NULL) {
- window = wm->windows.first;
+ if (window == nullptr) {
+ window = static_cast<wmWindow *>(wm->windows.first);
}
}
else {
- window = wm->windows.first;
+ window = static_cast<wmWindow *>(wm->windows.first);
}
}
- *r_screen = (window) ? BKE_workspace_active_screen_get(window->workspace_hook) : NULL;
- *r_scene = (window) ? window->scene : NULL;
+ *r_screen = (window) ? BKE_workspace_active_screen_get(window->workspace_hook) : nullptr;
+ *r_scene = (window) ? window->scene : nullptr;
*r_view_layer = (window && *r_scene) ? BKE_view_layer_find(*r_scene, window->view_layer_name) :
- NULL;
+ nullptr;
}
-typedef struct RenderInfo {
+struct RenderInfo {
int sfra;
int efra;
char scene_name[MAX_ID_NAME - 2];
-} RenderInfo;
+};
/**
* This was originally added for the historic render-daemon feature,
@@ -824,7 +825,7 @@ typedef struct RenderInfo {
static void write_renderinfo(WriteData *wd, Main *mainvar)
{
bScreen *curscreen;
- Scene *curscene = NULL;
+ Scene *curscene = nullptr;
ViewLayer *view_layer;
/* XXX in future, handle multiple windows with multiple screens? */
@@ -952,7 +953,7 @@ static void write_libraries(WriteData *wd, Main *main)
else {
found_one = false;
while (!found_one && tot--) {
- for (id = lbarray[tot]->first; id; id = id->next) {
+ for (id = static_cast<ID *>(lbarray[tot]->first); id; id = static_cast<ID *>(id->next)) {
if (id->us > 0 &&
((id->tag & LIB_TAG_EXTERN) ||
((id->tag & LIB_TAG_INDIRECT) && (id->flag & LIB_INDIRECT_WEAK_LINK)))) {
@@ -971,13 +972,13 @@ static void write_libraries(WriteData *wd, Main *main)
/* Not overridable. */
void *runtime_name_data = main->curlib->runtime.name_map;
- main->curlib->runtime.name_map = NULL;
+ main->curlib->runtime.name_map = nullptr;
BlendWriter writer = {wd};
writestruct(wd, ID_LI, Library, 1, main->curlib);
BKE_id_blend_write(&writer, &main->curlib->id);
- main->curlib->runtime.name_map = runtime_name_data;
+ main->curlib->runtime.name_map = static_cast<UniqueName_Map *>(runtime_name_data);
if (main->curlib->packedfile) {
BKE_packedfile_blend_write(&writer, main->curlib->packedfile);
@@ -988,7 +989,7 @@ static void write_libraries(WriteData *wd, Main *main)
/* Write link placeholders for all direct linked IDs. */
while (a--) {
- for (id = lbarray[a]->first; id; id = id->next) {
+ for (id = static_cast<ID *>(lbarray[a]->first); id; id = static_cast<ID *>(id->next)) {
if (id->us > 0 &&
((id->tag & LIB_TAG_EXTERN) ||
((id->tag & LIB_TAG_INDIRECT) && (id->flag & LIB_INDIRECT_WEAK_LINK)))) {
@@ -1009,6 +1010,11 @@ static void write_libraries(WriteData *wd, Main *main)
mywrite_flush(wd);
}
+#ifdef WITH_BUILDINFO
+extern "C" unsigned long build_commit_timestamp;
+extern "C" char build_hash[];
+#endif
+
/* context is usually defined by WM, two cases where no WM is available:
* - for forward compatibility, curscreen has to be saved
* - for undofile, curscene needs to be saved */
@@ -1025,7 +1031,7 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar)
memset(fg._pad, 0, sizeof(fg._pad));
memset(fg.filepath, 0, sizeof(fg.filepath));
memset(fg.build_hash, 0, sizeof(fg.build_hash));
- fg._pad1 = NULL;
+ fg._pad1 = nullptr;
current_screen_compat(mainvar, is_undo, &screen, &scene, &view_layer);
@@ -1049,13 +1055,9 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar)
fg.minversion = BLENDER_FILE_MIN_VERSION;
fg.minsubversion = BLENDER_FILE_MIN_SUBVERSION;
#ifdef WITH_BUILDINFO
- {
- extern unsigned long build_commit_timestamp;
- extern char build_hash[];
- /* TODO(sergey): Add branch name to file as well? */
- fg.build_commit_timestamp = build_commit_timestamp;
- BLI_strncpy(fg.build_hash, build_hash, sizeof(fg.build_hash));
- }
+ /* TODO(sergey): Add branch name to file as well? */
+ fg.build_commit_timestamp = build_commit_timestamp;
+ BLI_strncpy(fg.build_hash, build_hash, sizeof(fg.build_hash));
#else
fg.build_commit_timestamp = 0;
BLI_strncpy(fg.build_hash, "unknown", sizeof(fg.build_hash));
@@ -1117,7 +1119,7 @@ static bool write_file_handle(Main *mainvar,
mywrite_flush(wd);
OverrideLibraryStorage *override_storage = wd->use_memfile ?
- NULL :
+ nullptr :
BKE_lib_override_library_operations_store_init();
#define ID_BUFFER_STATIC_SIZE 8192
@@ -1129,9 +1131,9 @@ static bool write_file_handle(Main *mainvar,
ListBase *lbarray[INDEX_ID_MAX];
int a = set_listbasepointers(bmain, lbarray);
while (a--) {
- ID *id = lbarray[a]->first;
+ ID *id = static_cast<ID *>(lbarray[a]->first);
- if (id == NULL || GS(id->name) == ID_LI) {
+ if (id == nullptr || GS(id->name) == ID_LI) {
continue; /* Libraries are handled separately below. */
}
@@ -1149,7 +1151,7 @@ static bool write_file_handle(Main *mainvar,
id_buffer = MEM_mallocN(idtype_struct_size, __func__);
}
- for (; id; id = id->next) {
+ for (; id; id = static_cast<ID *>(id->next)) {
/* We should never attempt to write non-regular IDs
* (i.e. all kind of temp/runtime ones). */
BLI_assert(
@@ -1157,13 +1159,13 @@ static bool write_file_handle(Main *mainvar,
/* We only write unused IDs in undo case.
* NOTE: All Scenes, WindowManagers and WorkSpaces should always be written to disk, so
- * their usercount should never be NULL currently. */
+ * their user-count should never be nullptr currently. */
if (id->us == 0 && !wd->use_memfile) {
BLI_assert(!ELEM(GS(id->name), ID_SCE, ID_WM, ID_WS));
continue;
}
- const bool do_override = !ELEM(override_storage, NULL, bmain) &&
+ const bool do_override = !ELEM(override_storage, nullptr, bmain) &&
ID_IS_OVERRIDE_LIBRARY_REAL(id);
if (do_override) {
@@ -1172,19 +1174,19 @@ static bool write_file_handle(Main *mainvar,
if (wd->use_memfile) {
/* Record the changes that happened up to this undo push in
- * recalc_up_to_undo_push, and clear recalc_after_undo_push again
+ * recalc_up_to_undo_push, and clear `recalc_after_undo_push` again
* to start accumulating for the next undo push. */
id->recalc_up_to_undo_push = id->recalc_after_undo_push;
id->recalc_after_undo_push = 0;
bNodeTree *nodetree = ntreeFromID(id);
- if (nodetree != NULL) {
+ if (nodetree != nullptr) {
nodetree->id.recalc_up_to_undo_push = nodetree->id.recalc_after_undo_push;
nodetree->id.recalc_after_undo_push = 0;
}
if (GS(id->name) == ID_SCE) {
Scene *scene = (Scene *)id;
- if (scene->master_collection != NULL) {
+ if (scene->master_collection != nullptr) {
scene->master_collection->id.recalc_up_to_undo_push =
scene->master_collection->id.recalc_after_undo_push;
scene->master_collection->id.recalc_after_undo_push = 0;
@@ -1203,18 +1205,18 @@ static bool write_file_handle(Main *mainvar,
/* 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;
+ ((ID *)id_buffer)->prev = nullptr;
+ ((ID *)id_buffer)->next = nullptr;
/* Those runtime pointers should never be set during writing stage, but just in case clear
* them too. */
- ((ID *)id_buffer)->orig_id = NULL;
- ((ID *)id_buffer)->newid = NULL;
+ ((ID *)id_buffer)->orig_id = nullptr;
+ ((ID *)id_buffer)->newid = nullptr;
/* Even though in theory we could be able to preserve this python instance across undo even
* when we need to re-read the ID into its original address, this is currently cleared in
* #direct_link_id_common in `readfile.c` anyway, */
- ((ID *)id_buffer)->py_instance = NULL;
+ ((ID *)id_buffer)->py_instance = nullptr;
- if (id_type->blend_write != NULL) {
+ if (id_type->blend_write != nullptr) {
id_type->blend_write(&writer, (ID *)id_buffer, id);
}
@@ -1235,7 +1237,7 @@ static bool write_file_handle(Main *mainvar,
if (override_storage) {
BKE_lib_override_library_operations_store_finalize(override_storage);
- override_storage = NULL;
+ override_storage = nullptr;
}
/* Special handling, operating over split Mains... */
@@ -1252,7 +1254,7 @@ static bool write_file_handle(Main *mainvar,
*
* Note that we *borrow* the pointer to 'DNAstr',
* so writing each time uses the same address and doesn't cause unnecessary undo overhead. */
- writedata(wd, DNA1, (size_t)wd->sdna->data_len, wd->sdna->data);
+ writedata(wd, DNA1, size_t(wd->sdna->data_len), wd->sdna->data);
/* end of file */
memset(&bhead, 0, sizeof(BHead));
@@ -1332,11 +1334,11 @@ bool BLO_write_file(Main *mainvar,
const bool relbase_valid = (mainvar->filepath[0] != '\0');
/* path backup/restore */
- void *path_list_backup = NULL;
+ void *path_list_backup = nullptr;
const eBPathForeachFlag path_list_flag = (BKE_BPATH_FOREACH_PATH_SKIP_LINKED |
BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE);
- if (G.debug & G_DEBUG_IO && mainvar->lock != NULL) {
+ if (G.debug & G_DEBUG_IO && mainvar->lock != nullptr) {
BKE_report(reports, RPT_INFO, "Checking sanity of current .blend file *BEFORE* save to disk");
BLO_main_validate_libraries(mainvar, reports);
BLO_main_validate_shapekeys(mainvar, reports);
@@ -1376,13 +1378,13 @@ bool BLO_write_file(Main *mainvar,
/* Normalize the paths in case there is some subtle difference (so they can be compared). */
if (relbase_valid) {
BLI_split_dir_part(mainvar->filepath, dir_src, sizeof(dir_src));
- BLI_path_normalize(NULL, dir_src);
+ BLI_path_normalize(nullptr, dir_src);
}
else {
dir_src[0] = '\0';
}
BLI_split_dir_part(filepath, dir_dst, sizeof(dir_dst));
- BLI_path_normalize(NULL, dir_dst);
+ BLI_path_normalize(nullptr, dir_dst);
/* Only for relative, not relative-all, as this means making existing paths relative. */
if (remap_mode == BLO_WRITE_PATH_REMAP_RELATIVE) {
@@ -1416,16 +1418,16 @@ bool BLO_write_file(Main *mainvar,
case BLO_WRITE_PATH_REMAP_RELATIVE:
/* Saved, make relative paths relative to new location (if possible). */
BLI_assert(relbase_valid);
- BKE_bpath_relative_rebase(mainvar, dir_src, dir_dst, NULL);
+ BKE_bpath_relative_rebase(mainvar, dir_src, dir_dst, nullptr);
break;
case BLO_WRITE_PATH_REMAP_RELATIVE_ALL:
/* Make all relative (when requested or unsaved). */
- BKE_bpath_relative_convert(mainvar, dir_dst, NULL);
+ BKE_bpath_relative_convert(mainvar, dir_dst, nullptr);
break;
case BLO_WRITE_PATH_REMAP_ABSOLUTE:
/* Make all absolute (when requested or unsaved). */
BLI_assert(relbase_valid);
- BKE_bpath_absolute_convert(mainvar, dir_src, NULL);
+ BKE_bpath_absolute_convert(mainvar, dir_src, nullptr);
break;
case BLO_WRITE_PATH_REMAP_NONE:
BLI_assert_unreachable(); /* Unreachable. */
@@ -1437,7 +1439,8 @@ bool BLO_write_file(Main *mainvar,
}
/* actual file writing */
- const bool err = write_file_handle(mainvar, &ww, NULL, NULL, write_flags, use_userdef, thumb);
+ const bool err = write_file_handle(
+ mainvar, &ww, nullptr, nullptr, write_flags, use_userdef, thumb);
ww.close(&ww);
@@ -1468,7 +1471,7 @@ bool BLO_write_file(Main *mainvar,
return false;
}
- if (G.debug & G_DEBUG_IO && mainvar->lock != NULL) {
+ if (G.debug & G_DEBUG_IO && mainvar->lock != nullptr) {
BKE_report(reports, RPT_INFO, "Checking sanity of current .blend file *AFTER* save to disk");
BLO_main_validate_libraries(mainvar, reports);
}
@@ -1481,7 +1484,7 @@ bool BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int w
bool use_userdef = false;
const bool err = write_file_handle(
- mainvar, NULL, compare, current, write_flags, use_userdef, NULL);
+ mainvar, nullptr, compare, current, write_flags, use_userdef, nullptr);
return (err == 0);
}
@@ -1570,37 +1573,37 @@ int BLO_get_struct_id_by_name(BlendWriter *writer, const char *struct_name)
void BLO_write_int32_array(BlendWriter *writer, uint num, const int32_t *data_ptr)
{
- BLO_write_raw(writer, sizeof(int32_t) * (size_t)num, data_ptr);
+ BLO_write_raw(writer, sizeof(int32_t) * size_t(num), data_ptr);
}
void BLO_write_uint32_array(BlendWriter *writer, uint num, const uint32_t *data_ptr)
{
- BLO_write_raw(writer, sizeof(uint32_t) * (size_t)num, data_ptr);
+ BLO_write_raw(writer, sizeof(uint32_t) * size_t(num), data_ptr);
}
void BLO_write_float_array(BlendWriter *writer, uint num, const float *data_ptr)
{
- BLO_write_raw(writer, sizeof(float) * (size_t)num, data_ptr);
+ BLO_write_raw(writer, sizeof(float) * size_t(num), data_ptr);
}
void BLO_write_double_array(BlendWriter *writer, uint num, const double *data_ptr)
{
- BLO_write_raw(writer, sizeof(double) * (size_t)num, data_ptr);
+ BLO_write_raw(writer, sizeof(double) * size_t(num), data_ptr);
}
void BLO_write_pointer_array(BlendWriter *writer, uint num, const void *data_ptr)
{
- BLO_write_raw(writer, sizeof(void *) * (size_t)num, data_ptr);
+ BLO_write_raw(writer, sizeof(void *) * size_t(num), data_ptr);
}
void BLO_write_float3_array(BlendWriter *writer, uint num, const float *data_ptr)
{
- BLO_write_raw(writer, sizeof(float[3]) * (size_t)num, data_ptr);
+ BLO_write_raw(writer, sizeof(float[3]) * size_t(num), data_ptr);
}
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
{
- if (data_ptr != NULL) {
+ if (data_ptr != nullptr) {
BLO_write_raw(writer, strlen(data_ptr) + 1, data_ptr);
}
}