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

@ -37,6 +37,7 @@ public:
void testRLECompression();
void testZlibCompression();
void testZlibLargeData();
void testZstdLargeData();
void testZlibLimit();
void _testZlibLimit(u32 size, u32 limit);
};
@ -48,6 +49,7 @@ void TestCompression::runTests(IGameDef *gamedef)
TEST(testRLECompression);
TEST(testZlibCompression);
TEST(testZlibLargeData);
TEST(testZstdLargeData);
TEST(testZlibLimit);
}
@ -111,7 +113,7 @@ void TestCompression::testZlibCompression()
fromdata[3]=1;
std::ostringstream os(std::ios_base::binary);
compress(fromdata, os, SER_FMT_VER_HIGHEST_READ);
compressZlib(*fromdata, fromdata.getSize(), os);
std::string str_out = os.str();
@ -124,7 +126,7 @@ void TestCompression::testZlibCompression()
std::istringstream is(str_out, std::ios_base::binary);
std::ostringstream os2(std::ios_base::binary);
decompress(is, os2, SER_FMT_VER_HIGHEST_READ);
decompressZlib(is, os2);
std::string str_out2 = os2.str();
infostream << "decompress: ";
@ -174,6 +176,42 @@ void TestCompression::testZlibLargeData()
}
}
void TestCompression::testZstdLargeData()
{
infostream << "Test: Testing zstd wrappers with a large amount "
"of pseudorandom data" << std::endl;
u32 size = 500000;
infostream << "Test: Input size of large compressZstd is "
<< size << std::endl;
std::string data_in;
data_in.resize(size);
PseudoRandom pseudorandom(9420);
for (u32 i = 0; i < size; i++)
data_in[i] = pseudorandom.range(0, 255);
std::ostringstream os_compressed(std::ios::binary);
compressZstd(data_in, os_compressed, 0);
infostream << "Test: Output size of large compressZstd is "
<< os_compressed.str().size()<<std::endl;
std::istringstream is_compressed(os_compressed.str(), std::ios::binary);
std::ostringstream os_decompressed(std::ios::binary);
decompressZstd(is_compressed, os_decompressed);
infostream << "Test: Output size of large decompressZstd is "
<< os_decompressed.str().size() << std::endl;
std::string str_decompressed = os_decompressed.str();
UASSERTEQ(size_t, str_decompressed.size(), data_in.size());
for (u32 i = 0; i < size && i < str_decompressed.size(); i++) {
UTEST(str_decompressed[i] == data_in[i],
"index out[%i]=%i differs from in[%i]=%i",
i, str_decompressed[i], i, data_in[i]);
}
}
void TestCompression::testZlibLimit()
{
// edge cases