Cleanup: use BLO_CODE_ prefix for BHead codes
Having names like `DATA`, `TEST` and `USER` in the global namespace feels a bit wrong. Pull Request: https://projects.blender.org/blender/blender/pulls/106673
This commit is contained in:
@@ -25,35 +25,35 @@ enum {
|
||||
* Arbitrary allocated memory
|
||||
* (typically owned by #ID's, will be freed when there are no users).
|
||||
*/
|
||||
DATA = BLEND_MAKE_ID('D', 'A', 'T', 'A'),
|
||||
BLO_CODE_DATA = BLEND_MAKE_ID('D', 'A', 'T', 'A'),
|
||||
/**
|
||||
* Used for #Global struct.
|
||||
*/
|
||||
GLOB = BLEND_MAKE_ID('G', 'L', 'O', 'B'),
|
||||
BLO_CODE_GLOB = BLEND_MAKE_ID('G', 'L', 'O', 'B'),
|
||||
/**
|
||||
* Used for storing the encoded SDNA string
|
||||
* (decoded into an #SDNA on load).
|
||||
*/
|
||||
DNA1 = BLEND_MAKE_ID('D', 'N', 'A', '1'),
|
||||
BLO_CODE_DNA1 = BLEND_MAKE_ID('D', 'N', 'A', '1'),
|
||||
/**
|
||||
* Used to store thumbnail previews, written between #REND and #GLOB blocks,
|
||||
* (ignored for regular file reading).
|
||||
*/
|
||||
TEST = BLEND_MAKE_ID('T', 'E', 'S', 'T'),
|
||||
BLO_CODE_TEST = BLEND_MAKE_ID('T', 'E', 'S', 'T'),
|
||||
/**
|
||||
* Used for #RenderInfo, basic Scene and frame range info,
|
||||
* can be easily read by other applications without writing a full blend file parser.
|
||||
*/
|
||||
REND = BLEND_MAKE_ID('R', 'E', 'N', 'D'),
|
||||
BLO_CODE_REND = BLEND_MAKE_ID('R', 'E', 'N', 'D'),
|
||||
/**
|
||||
* Used for #UserDef, (user-preferences data).
|
||||
* (written to #BLENDER_STARTUP_FILE & #BLENDER_USERPREF_FILE).
|
||||
*/
|
||||
USER = BLEND_MAKE_ID('U', 'S', 'E', 'R'),
|
||||
BLO_CODE_USER = BLEND_MAKE_ID('U', 'S', 'E', 'R'),
|
||||
/**
|
||||
* Terminate reading (no data).
|
||||
*/
|
||||
ENDB = BLEND_MAKE_ID('E', 'N', 'D', 'B'),
|
||||
BLO_CODE_ENDB = BLEND_MAKE_ID('E', 'N', 'D', 'B'),
|
||||
};
|
||||
|
||||
#define BLEN_THUMB_MEMSIZE_FILE(_x, _y) (sizeof(int) * (2 + (size_t)(_x) * (size_t)(_y)))
|
||||
|
||||
@@ -89,7 +89,7 @@ void BLO_blendhandle_print_sizes(BlendHandle *bh, void *fp)
|
||||
|
||||
fprintf(static_cast<FILE *>(fp), "[\n");
|
||||
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
|
||||
if (bhead->code == ENDB) {
|
||||
if (bhead->code == BLO_CODE_ENDB) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh,
|
||||
BLI_linklist_prepend(&names, BLI_strdup(idname + 2));
|
||||
tot++;
|
||||
}
|
||||
else if (bhead->code == ENDB) {
|
||||
else if (bhead->code == BLO_CODE_ENDB) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh,
|
||||
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) {
|
||||
if (bhead->code == BLO_CODE_ENDB) {
|
||||
break;
|
||||
}
|
||||
if (bhead->code == ofblocktype) {
|
||||
@@ -190,7 +190,7 @@ LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh,
|
||||
|
||||
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;
|
||||
for (BHead *data_bhead = blo_bhead_next(fd, id_bhead); data_bhead->code == BLO_CODE_DATA;
|
||||
data_bhead = blo_bhead_next(fd, data_bhead)) {
|
||||
if (data_bhead->SDNAnr == sdna_nr_preview_image) {
|
||||
has_preview = true;
|
||||
@@ -260,7 +260,7 @@ PreviewImage *BLO_blendhandle_get_preview_for_id(BlendHandle *bh,
|
||||
const int sdna_preview_image = DNA_struct_find_nr(fd->filesdna, "PreviewImage");
|
||||
|
||||
for (BHead *bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
|
||||
if (bhead->code == DATA) {
|
||||
if (bhead->code == BLO_CODE_DATA) {
|
||||
if (looking && bhead->SDNAnr == sdna_preview_image) {
|
||||
PreviewImage *preview_from_file = static_cast<PreviewImage *>(
|
||||
BLO_library_read_struct(fd, bhead, "PreviewImage"));
|
||||
@@ -275,7 +275,7 @@ PreviewImage *BLO_blendhandle_get_preview_for_id(BlendHandle *bh,
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (looking || bhead->code == ENDB) {
|
||||
else if (looking || bhead->code == BLO_CODE_ENDB) {
|
||||
/* We were looking for a preview image, but didn't find any belonging to block. So it doesn't
|
||||
* exist. */
|
||||
break;
|
||||
@@ -324,7 +324,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *r_
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (bhead->code == DATA) {
|
||||
else if (bhead->code == BLO_CODE_DATA) {
|
||||
if (looking) {
|
||||
if (bhead->SDNAnr == DNA_struct_find_nr(fd->filesdna, "PreviewImage")) {
|
||||
prv = static_cast<PreviewImage *>(BLO_library_read_struct(fd, bhead, "PreviewImage"));
|
||||
@@ -337,7 +337,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *r_
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (bhead->code == ENDB) {
|
||||
else if (bhead->code == BLO_CODE_ENDB) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
@@ -359,7 +359,7 @@ LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh)
|
||||
BHead *bhead;
|
||||
|
||||
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
|
||||
if (bhead->code == ENDB) {
|
||||
if (bhead->code == BLO_CODE_ENDB) {
|
||||
break;
|
||||
}
|
||||
if (BKE_idtype_idcode_is_valid(bhead->code)) {
|
||||
|
||||
@@ -199,7 +199,7 @@ struct BHeadN {
|
||||
* We could change this in the future, for now it's simplest if only data is delayed
|
||||
* because ID names are used in lookup tables.
|
||||
*/
|
||||
#define BHEAD_USE_READ_ON_DEMAND(bhead) ((bhead)->code == DATA)
|
||||
#define BHEAD_USE_READ_ON_DEMAND(bhead) ((bhead)->code == BLO_CODE_DATA)
|
||||
|
||||
void BLO_reportf_wrap(BlendFileReadReport *reports, eReportType type, const char *format, ...)
|
||||
{
|
||||
@@ -423,7 +423,7 @@ static void read_file_version(FileData *fd, Main *main)
|
||||
BHead *bhead;
|
||||
|
||||
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
|
||||
if (bhead->code == GLOB) {
|
||||
if (bhead->code == BLO_CODE_GLOB) {
|
||||
FileGlobal *fg = static_cast<FileGlobal *>(read_struct(fd, bhead, "Global"));
|
||||
if (fg) {
|
||||
main->subversionfile = fg->subversion;
|
||||
@@ -431,7 +431,7 @@ static void read_file_version(FileData *fd, Main *main)
|
||||
main->minsubversionfile = fg->minsubversion;
|
||||
MEM_freeN(fg);
|
||||
}
|
||||
else if (bhead->code == ENDB) {
|
||||
else if (bhead->code == BLO_CODE_ENDB) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -466,7 +466,7 @@ static void read_file_bhead_idname_map_create(FileData *fd)
|
||||
|
||||
/* dummy values */
|
||||
bool is_link = false;
|
||||
int code_prev = ENDB;
|
||||
int code_prev = BLO_CODE_ENDB;
|
||||
uint reserve = 0;
|
||||
|
||||
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
|
||||
@@ -595,7 +595,7 @@ static void switch_endian_bh4(BHead4 *bhead)
|
||||
bhead->code >>= 16;
|
||||
}
|
||||
|
||||
if (bhead->code != ENDB) {
|
||||
if (bhead->code != BLO_CODE_ENDB) {
|
||||
BLI_endian_switch_int32(&bhead->len);
|
||||
BLI_endian_switch_int32(&bhead->SDNAnr);
|
||||
BLI_endian_switch_int32(&bhead->nr);
|
||||
@@ -609,7 +609,7 @@ static void switch_endian_bh8(BHead8 *bhead)
|
||||
bhead->code >>= 16;
|
||||
}
|
||||
|
||||
if (bhead->code != ENDB) {
|
||||
if (bhead->code != BLO_CODE_ENDB) {
|
||||
BLI_endian_switch_int32(&bhead->len);
|
||||
BLI_endian_switch_int32(&bhead->SDNAnr);
|
||||
BLI_endian_switch_int32(&bhead->nr);
|
||||
@@ -624,7 +624,7 @@ static void bh4_from_bh8(BHead *bhead, BHead8 *bhead8, bool do_endian_swap)
|
||||
bhead4->code = bhead8->code;
|
||||
bhead4->len = bhead8->len;
|
||||
|
||||
if (bhead4->code != ENDB) {
|
||||
if (bhead4->code != BLO_CODE_ENDB) {
|
||||
/* perform a endian swap on 64bit pointers, otherwise the pointer might map to zero
|
||||
* 0x0000000000000000000012345678 would become 0x12345678000000000000000000000000
|
||||
*/
|
||||
@@ -649,7 +649,7 @@ static void bh8_from_bh4(BHead *bhead, BHead4 *bhead4)
|
||||
bhead8->code = bhead4->code;
|
||||
bhead8->len = bhead4->len;
|
||||
|
||||
if (bhead8->code != ENDB) {
|
||||
if (bhead8->code != BLO_CODE_ENDB) {
|
||||
bhead8->old = bhead4->old;
|
||||
bhead8->SDNAnr = bhead4->SDNAnr;
|
||||
bhead8->nr = bhead4->nr;
|
||||
@@ -677,10 +677,10 @@ static BHeadN *get_bhead(FileData *fd)
|
||||
* needs some special handling. We don't want to EOF just yet.
|
||||
*/
|
||||
if (fd->flags & FD_FLAGS_FILE_POINTSIZE_IS_4) {
|
||||
bhead4.code = DATA;
|
||||
bhead4.code = BLO_CODE_DATA;
|
||||
readsize = fd->file->read(fd->file, &bhead4, sizeof(bhead4));
|
||||
|
||||
if (readsize == sizeof(bhead4) || bhead4.code == ENDB) {
|
||||
if (readsize == sizeof(bhead4) || bhead4.code == BLO_CODE_ENDB) {
|
||||
if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
|
||||
switch_endian_bh4(&bhead4);
|
||||
}
|
||||
@@ -700,10 +700,10 @@ static BHeadN *get_bhead(FileData *fd)
|
||||
}
|
||||
}
|
||||
else {
|
||||
bhead8.code = DATA;
|
||||
bhead8.code = BLO_CODE_DATA;
|
||||
readsize = fd->file->read(fd->file, &bhead8, sizeof(bhead8));
|
||||
|
||||
if (readsize == sizeof(bhead8) || bhead8.code == ENDB) {
|
||||
if (readsize == sizeof(bhead8) || bhead8.code == BLO_CODE_ENDB) {
|
||||
if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
|
||||
switch_endian_bh8(&bhead8);
|
||||
}
|
||||
@@ -957,7 +957,7 @@ static bool read_file_dna(FileData *fd, const char **r_error_message)
|
||||
int subversion = 0;
|
||||
|
||||
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
|
||||
if (bhead->code == GLOB) {
|
||||
if (bhead->code == BLO_CODE_GLOB) {
|
||||
/* Before this, the subversion didn't exist in 'FileGlobal' so the subversion
|
||||
* value isn't accessible for the purpose of DNA versioning in this case. */
|
||||
if (fd->fileversion <= 242) {
|
||||
@@ -972,7 +972,7 @@ static bool read_file_dna(FileData *fd, const char **r_error_message)
|
||||
num[4] = 0;
|
||||
subversion = atoi(num);
|
||||
}
|
||||
else if (bhead->code == DNA1) {
|
||||
else if (bhead->code == BLO_CODE_DNA1) {
|
||||
const bool do_endian_swap = (fd->flags & FD_FLAGS_SWITCH_ENDIAN) != 0;
|
||||
|
||||
fd->filesdna = DNA_sdna_from_data(
|
||||
@@ -993,7 +993,7 @@ static bool read_file_dna(FileData *fd, const char **r_error_message)
|
||||
|
||||
return false;
|
||||
}
|
||||
else if (bhead->code == ENDB) {
|
||||
else if (bhead->code == BLO_CODE_ENDB) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1008,7 +1008,7 @@ static int *read_file_thumbnail(FileData *fd)
|
||||
int *blend_thumb = nullptr;
|
||||
|
||||
for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) {
|
||||
if (bhead->code == TEST) {
|
||||
if (bhead->code == BLO_CODE_TEST) {
|
||||
const bool do_endian_swap = (fd->flags & FD_FLAGS_SWITCH_ENDIAN) != 0;
|
||||
int *data = (int *)(bhead + 1);
|
||||
|
||||
@@ -1033,7 +1033,7 @@ static int *read_file_thumbnail(FileData *fd)
|
||||
blend_thumb = data;
|
||||
break;
|
||||
}
|
||||
if (bhead->code != REND) {
|
||||
if (bhead->code != BLO_CODE_REND) {
|
||||
/* Thumbnail is stored in TEST immediately after first REND... */
|
||||
break;
|
||||
}
|
||||
@@ -2952,7 +2952,7 @@ static BHead *read_data_into_datamap(FileData *fd, BHead *bhead, const char *all
|
||||
{
|
||||
bhead = blo_bhead_next(fd, bhead);
|
||||
|
||||
while (bhead && bhead->code == DATA) {
|
||||
while (bhead && bhead->code == BLO_CODE_DATA) {
|
||||
/* The code below is useful for debugging leaks in data read from the blend file.
|
||||
* Without this the messages only tell us what ID-type the memory came from,
|
||||
* eg: `Data from OB len 64`, see #dataname.
|
||||
@@ -2995,7 +2995,7 @@ static bool read_libblock_is_identical(FileData *fd, BHead *bhead)
|
||||
/* Test any other data that is part of ID (logic must match read_data_into_datamap). */
|
||||
bhead = blo_bhead_next(fd, bhead);
|
||||
|
||||
while (bhead && bhead->code == DATA) {
|
||||
while (bhead && bhead->code == BLO_CODE_DATA) {
|
||||
if (bhead->len && !BHEADN_FROM_BHEAD(bhead)->is_memchunk_identical) {
|
||||
return false;
|
||||
}
|
||||
@@ -3837,16 +3837,16 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
|
||||
|
||||
while (bhead) {
|
||||
switch (bhead->code) {
|
||||
case DATA:
|
||||
case DNA1:
|
||||
case TEST: /* used as preview since 2.5x */
|
||||
case REND:
|
||||
case BLO_CODE_DATA:
|
||||
case BLO_CODE_DNA1:
|
||||
case BLO_CODE_TEST: /* used as preview since 2.5x */
|
||||
case BLO_CODE_REND:
|
||||
bhead = blo_bhead_next(fd, bhead);
|
||||
break;
|
||||
case GLOB:
|
||||
case BLO_CODE_GLOB:
|
||||
bhead = read_global(bfd, fd, bhead);
|
||||
break;
|
||||
case USER:
|
||||
case BLO_CODE_USER:
|
||||
if (fd->skip_flags & BLO_READ_SKIP_USERDEF) {
|
||||
bhead = blo_bhead_next(fd, bhead);
|
||||
}
|
||||
@@ -3854,7 +3854,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
|
||||
bhead = read_userdef(bfd, fd, bhead);
|
||||
}
|
||||
break;
|
||||
case ENDB:
|
||||
case BLO_CODE_ENDB:
|
||||
bhead = nullptr;
|
||||
break;
|
||||
|
||||
|
||||
@@ -841,7 +841,7 @@ static void write_renderinfo(WriteData *wd, Main *mainvar)
|
||||
|
||||
BLI_strncpy(data.scene_name, sce->id.name + 2, sizeof(data.scene_name));
|
||||
|
||||
writedata(wd, REND, sizeof(data), &data);
|
||||
writedata(wd, BLO_CODE_REND, sizeof(data), &data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -856,7 +856,7 @@ static void write_keymapitem(BlendWriter *writer, const wmKeyMapItem *kmi)
|
||||
|
||||
static void write_userdef(BlendWriter *writer, const UserDef *userdef)
|
||||
{
|
||||
writestruct(writer->wd, USER, UserDef, 1, userdef);
|
||||
writestruct(writer->wd, BLO_CODE_USER, UserDef, 1, userdef);
|
||||
|
||||
LISTBASE_FOREACH (const bTheme *, btheme, &userdef->themes) {
|
||||
BLO_write_struct(writer, bTheme, btheme);
|
||||
@@ -1063,7 +1063,7 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar)
|
||||
fg.build_commit_timestamp = 0;
|
||||
BLI_strncpy(fg.build_hash, "unknown", sizeof(fg.build_hash));
|
||||
#endif
|
||||
writestruct(wd, GLOB, FileGlobal, 1, &fg);
|
||||
writestruct(wd, BLO_CODE_GLOB, FileGlobal, 1, &fg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1074,7 +1074,7 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar)
|
||||
static void write_thumb(WriteData *wd, const BlendThumbnail *thumb)
|
||||
{
|
||||
if (thumb) {
|
||||
writedata(wd, TEST, BLEN_THUMB_MEMSIZE_FILE(thumb->width, thumb->height), thumb);
|
||||
writedata(wd, BLO_CODE_TEST, BLEN_THUMB_MEMSIZE_FILE(thumb->width, thumb->height), thumb);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1332,11 +1332,11 @@ 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, BLO_CODE_DNA1, size_t(wd->sdna->data_len), wd->sdna->data);
|
||||
|
||||
/* end of file */
|
||||
memset(&bhead, 0, sizeof(BHead));
|
||||
bhead.code = ENDB;
|
||||
bhead.code = BLO_CODE_ENDB;
|
||||
mywrite(wd, &bhead, sizeof(BHead));
|
||||
|
||||
blo_join_main(&mainlist);
|
||||
@@ -1569,7 +1569,7 @@ bool BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int w
|
||||
|
||||
void BLO_write_raw(BlendWriter *writer, size_t size_in_bytes, const void *data_ptr)
|
||||
{
|
||||
writedata(writer->wd, DATA, size_in_bytes, data_ptr);
|
||||
writedata(writer->wd, BLO_CODE_DATA, size_in_bytes, data_ptr);
|
||||
}
|
||||
|
||||
void BLO_write_struct_by_name(BlendWriter *writer, const char *struct_name, const void *data_ptr)
|
||||
@@ -1592,7 +1592,7 @@ void BLO_write_struct_array_by_name(BlendWriter *writer,
|
||||
|
||||
void BLO_write_struct_by_id(BlendWriter *writer, int struct_id, const void *data_ptr)
|
||||
{
|
||||
writestruct_nr(writer->wd, DATA, struct_id, 1, data_ptr);
|
||||
writestruct_nr(writer->wd, BLO_CODE_DATA, struct_id, 1, data_ptr);
|
||||
}
|
||||
|
||||
void BLO_write_struct_at_address_by_id(BlendWriter *writer,
|
||||
@@ -1600,7 +1600,8 @@ void BLO_write_struct_at_address_by_id(BlendWriter *writer,
|
||||
const void *address,
|
||||
const void *data_ptr)
|
||||
{
|
||||
BLO_write_struct_at_address_by_id_with_filecode(writer, DATA, struct_id, address, data_ptr);
|
||||
BLO_write_struct_at_address_by_id_with_filecode(
|
||||
writer, BLO_CODE_DATA, struct_id, address, data_ptr);
|
||||
}
|
||||
|
||||
void BLO_write_struct_at_address_by_id_with_filecode(
|
||||
@@ -1614,18 +1615,18 @@ void BLO_write_struct_array_by_id(BlendWriter *writer,
|
||||
int array_size,
|
||||
const void *data_ptr)
|
||||
{
|
||||
writestruct_nr(writer->wd, DATA, struct_id, array_size, data_ptr);
|
||||
writestruct_nr(writer->wd, BLO_CODE_DATA, struct_id, array_size, data_ptr);
|
||||
}
|
||||
|
||||
void BLO_write_struct_array_at_address_by_id(
|
||||
BlendWriter *writer, int struct_id, int array_size, const void *address, const void *data_ptr)
|
||||
{
|
||||
writestruct_at_address_nr(writer->wd, DATA, struct_id, array_size, address, data_ptr);
|
||||
writestruct_at_address_nr(writer->wd, BLO_CODE_DATA, struct_id, array_size, address, data_ptr);
|
||||
}
|
||||
|
||||
void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, ListBase *list)
|
||||
{
|
||||
writelist_nr(writer->wd, DATA, struct_id, list);
|
||||
writelist_nr(writer->wd, BLO_CODE_DATA, struct_id, list);
|
||||
}
|
||||
|
||||
void BLO_write_struct_list_by_name(BlendWriter *writer, const char *struct_name, ListBase *list)
|
||||
|
||||
Reference in New Issue
Block a user