Don't use `sizeof(int)` for portability
parent
008f6d83a1
commit
d9c2d227ac
|
@ -361,11 +361,13 @@ Error RegionFile::save_block(Vector3i position, VoxelBufferInternal &block) {
|
|||
BlockSerializer::SerializeResult res = BlockSerializer::serialize_and_compress(block);
|
||||
ERR_FAIL_COND_V(!res.success, ERR_INVALID_PARAMETER);
|
||||
f->store_32(res.data.size());
|
||||
const unsigned int written_size = sizeof(int) + res.data.size();
|
||||
const unsigned int written_size = sizeof(uint32_t) + res.data.size();
|
||||
f->store_buffer(res.data.data(), res.data.size());
|
||||
|
||||
const unsigned int end_pos = f->get_position();
|
||||
CRASH_COND(written_size != (end_pos - block_offset));
|
||||
CRASH_COND_MSG(written_size != (end_pos - block_offset),
|
||||
String("written_size: {0}, block_offset: {1}, end_pos: {2}")
|
||||
.format(varray(written_size, end_pos, block_offset)));
|
||||
pad_to_sector_size(f);
|
||||
|
||||
block_info.set_sector_index((block_offset - _blocks_begin_offset) / _header.format.sector_size);
|
||||
|
@ -389,7 +391,7 @@ Error RegionFile::save_block(Vector3i position, VoxelBufferInternal &block) {
|
|||
BlockSerializer::SerializeResult res = BlockSerializer::serialize_and_compress(block);
|
||||
ERR_FAIL_COND_V(!res.success, ERR_INVALID_PARAMETER);
|
||||
const std::vector<uint8_t> &data = res.data;
|
||||
const int written_size = sizeof(int) + data.size();
|
||||
const int written_size = sizeof(uint32_t) + data.size();
|
||||
|
||||
const int new_sector_count = get_sector_count_from_bytes(written_size);
|
||||
CRASH_COND(new_sector_count < 1);
|
||||
|
|
|
@ -61,6 +61,8 @@ struct RegionBlockInfo {
|
|||
}
|
||||
};
|
||||
|
||||
static_assert(sizeof(RegionBlockInfo) == 4, "Data in this struct must have a consistent size on all target platforms.");
|
||||
|
||||
// Archive file storing voxels in a fixed sparse grid data structure.
|
||||
// The format is designed to be easily writable in chunks so it can be used for partial in-game loading and saving.
|
||||
// Inspired by https://www.seedofandromeda.com/blogs/1-creating-a-region-file-system-for-a-voxel-game
|
||||
|
|
Loading…
Reference in New Issue