1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Switch MapBlock compression to zstd (#10788)

* Add zstd support.
* Rearrange serialization order
* Compress entire mapblock

Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
lhofhansl 2021-08-31 17:32:31 -07:00 committed by GitHub
parent beac4a2c98
commit d1624a5521
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 494 additions and 152 deletions

View file

@ -730,9 +730,10 @@ void MapNode::deSerialize(u8 *source, u8 version)
}
}
}
void MapNode::serializeBulk(std::ostream &os, int version,
SharedBuffer<u8> MapNode::serializeBulk(int version,
const MapNode *nodes, u32 nodecount,
u8 content_width, u8 params_width, int compression_level)
u8 content_width, u8 params_width)
{
if (!ser_ver_supported(version))
throw VersionMismatchException("ERROR: MapNode format not supported");
@ -746,8 +747,7 @@ void MapNode::serializeBulk(std::ostream &os, int version,
throw SerializationError("MapNode::serializeBulk: serialization to "
"version < 24 not possible");
size_t databuf_size = nodecount * (content_width + params_width);
u8 *databuf = new u8[databuf_size];
SharedBuffer<u8> databuf(nodecount * (content_width + params_width));
u32 start1 = content_width * nodecount;
u32 start2 = (content_width + 1) * nodecount;
@ -758,14 +758,7 @@ void MapNode::serializeBulk(std::ostream &os, int version,
writeU8(&databuf[start1 + i], nodes[i].param1);
writeU8(&databuf[start2 + i], nodes[i].param2);
}
/*
Compress data to output stream
*/
compressZlib(databuf, databuf_size, os, compression_level);
delete [] databuf;
return databuf;
}
// Deserialize bulk node data
@ -781,15 +774,10 @@ void MapNode::deSerializeBulk(std::istream &is, int version,
|| params_width != 2)
FATAL_ERROR("Deserialize bulk node data error");
// Uncompress or read data
u32 len = nodecount * (content_width + params_width);
std::ostringstream os(std::ios_base::binary);
decompressZlib(is, os);
std::string s = os.str();
if(s.size() != len)
throw SerializationError("deSerializeBulkNodes: "
"decompress resulted in invalid size");
const u8 *databuf = reinterpret_cast<const u8*>(s.c_str());
// read data
const u32 len = nodecount * (content_width + params_width);
Buffer<u8> databuf(len);
is.read(reinterpret_cast<char*>(*databuf), len);
// Deserialize content
if(content_width == 1)