1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-30 19:22:14 +00:00

Monoblocks: optimize blocks that contain a single type of node (#16293)

Reduces memory usage on the server, especially with many user and/or large viewing distances.
Currently disabled on the client due to known data races on a block's data.
This commit is contained in:
lhofhansl 2025-09-21 13:19:30 -07:00 committed by GitHub
parent afd681d013
commit 08b7870c79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 245 additions and 47 deletions

View file

@ -589,7 +589,7 @@ void MapNode::deSerialize(const u8 *source, u8 version)
Buffer<u8> MapNode::serializeBulk(int version,
const MapNode *nodes, u32 nodecount,
u8 content_width, u8 params_width)
u8 content_width, u8 params_width, bool is_mono_block)
{
if (!ser_ver_supported_write(version))
throw VersionMismatchException("ERROR: MapNode format not supported");
@ -601,14 +601,22 @@ Buffer<u8> MapNode::serializeBulk(int version,
// Writing to the buffer linearly is faster
u8 *p = &databuf[0];
for (u32 i = 0; i < nodecount; i++, p += 2)
writeU16(p, nodes[i].param0);
for (u32 i = 0; i < nodecount; i++, p++)
writeU8(p, nodes[i].param1);
for (u32 i = 0; i < nodecount; i++, p++)
writeU8(p, nodes[i].param2);
if (is_mono_block) {
MapNode n = nodes[0];
for (u32 i = 0; i < nodecount; i++, p += 2)
writeU16(p, n.param0);
for (u32 i = 0; i < nodecount; i++, p++)
writeU8(p, n.param1);
for (u32 i = 0; i < nodecount; i++, p++)
writeU8(p, n.param2);
} else {
for (u32 i = 0; i < nodecount; i++, p += 2)
writeU16(p, nodes[i].param0);
for (u32 i = 0; i < nodecount; i++, p++)
writeU8(p, nodes[i].param1);
for (u32 i = 0; i < nodecount; i++, p++)
writeU8(p, nodes[i].param2);
}
return databuf;
}