Cleanup: Blenloader: simplify writing BHead
This adds a `write_bhead` utility function and also reduces the scope of some `BHead` variables. The separate `write_bhead` function was quite useful for #129751 and will likely be useful in a potential separate implementation too. Pull Request: https://projects.blender.org/blender/blender/pulls/130457
This commit is contained in:
@@ -719,6 +719,11 @@ static bool write_at_address_validate(WriteData *wd, const int filecode, const v
|
||||
return true;
|
||||
}
|
||||
|
||||
static void write_bhead(WriteData *wd, const BHead &bhead)
|
||||
{
|
||||
mywrite(wd, &bhead, sizeof(BHead));
|
||||
}
|
||||
|
||||
static void writestruct_at_address_nr(WriteData *wd,
|
||||
const int filecode,
|
||||
const int struct_nr,
|
||||
@@ -726,8 +731,6 @@ static void writestruct_at_address_nr(WriteData *wd,
|
||||
const void *adr,
|
||||
const void *data)
|
||||
{
|
||||
BHead bh;
|
||||
|
||||
BLI_assert(struct_nr > 0 && struct_nr < SDNA_TYPE_MAX);
|
||||
|
||||
if (adr == nullptr || data == nullptr || nr == 0) {
|
||||
@@ -738,11 +741,10 @@ static void writestruct_at_address_nr(WriteData *wd,
|
||||
return;
|
||||
}
|
||||
|
||||
/* Initialize #BHead. */
|
||||
BHead bh;
|
||||
bh.code = filecode;
|
||||
bh.old = adr;
|
||||
bh.nr = nr;
|
||||
|
||||
bh.SDNAnr = struct_nr;
|
||||
bh.len = nr * DNA_struct_size(wd->sdna, bh.SDNAnr);
|
||||
|
||||
@@ -750,7 +752,7 @@ static void writestruct_at_address_nr(WriteData *wd,
|
||||
return;
|
||||
}
|
||||
|
||||
mywrite(wd, &bh, sizeof(BHead));
|
||||
write_bhead(wd, bh);
|
||||
mywrite(wd, data, size_t(bh.len));
|
||||
}
|
||||
|
||||
@@ -765,8 +767,6 @@ static void writestruct_nr(
|
||||
*/
|
||||
static void writedata(WriteData *wd, const int filecode, const size_t len, const void *adr)
|
||||
{
|
||||
BHead bh;
|
||||
|
||||
if (adr == nullptr || len == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -780,7 +780,7 @@ static void writedata(WriteData *wd, const int filecode, const size_t len, const
|
||||
return;
|
||||
}
|
||||
|
||||
/* Initialize #BHead. */
|
||||
BHead bh;
|
||||
bh.code = filecode;
|
||||
bh.old = adr;
|
||||
bh.nr = 1;
|
||||
@@ -788,7 +788,7 @@ static void writedata(WriteData *wd, const int filecode, const size_t len, const
|
||||
bh.SDNAnr = SDNA_RAW_DATA_STRUCT_INDEX;
|
||||
bh.len = int(len);
|
||||
|
||||
mywrite(wd, &bh, sizeof(BHead));
|
||||
write_bhead(wd, bh);
|
||||
mywrite(wd, adr, len);
|
||||
}
|
||||
|
||||
@@ -1306,7 +1306,6 @@ static bool write_file_handle(Main *mainvar,
|
||||
const bool use_userdef,
|
||||
const BlendThumbnail *thumb)
|
||||
{
|
||||
BHead bhead;
|
||||
ListBase mainlist;
|
||||
char buf[16];
|
||||
WriteData *wd;
|
||||
@@ -1505,9 +1504,9 @@ static bool write_file_handle(Main *mainvar,
|
||||
writedata(wd, BLO_CODE_DNA1, size_t(wd->sdna->data_size), wd->sdna->data);
|
||||
|
||||
/* End of file. */
|
||||
memset(&bhead, 0, sizeof(BHead));
|
||||
BHead bhead{};
|
||||
bhead.code = BLO_CODE_ENDB;
|
||||
mywrite(wd, &bhead, sizeof(BHead));
|
||||
write_bhead(wd, bhead);
|
||||
|
||||
blo_join_main(&mainlist);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user