1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-21 18:11:11 +00:00

MapBlock::getData be gone (#16292)

* Remove Mapblock::getData and all its uses

* Do not leak ystride, zstride, and nodecount
This commit is contained in:
lhofhansl 2025-06-29 13:36:47 -07:00 committed by GitHub
parent fd0ca20ce9
commit 43aad3711b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 21 deletions

View file

@ -68,10 +68,12 @@ void TestMapBlock::testSaveLoad(IGameDef *gamedef, const u8 version)
MapBlock block({}, gamedef);
// Fill with data
PcgRandom r(seed);
for (size_t i = 0; i < MapBlock::nodecount; ++i) {
for (s16 z=0; z < MAP_BLOCKSIZE; z++)
for (s16 y=0; y < MAP_BLOCKSIZE; y++)
for (s16 x=0; x < MAP_BLOCKSIZE; x++) {
u32 rval = r.next();
block.getData()[i] =
MapNode(rval % max, (rval >> 16) & 0xff, (rval >> 24) & 0xff);
block.setNodeNoCheck(x, y, z,
MapNode(rval % max, (rval >> 16) & 0xff, (rval >> 24) & 0xff));
}
// Serialize
@ -85,11 +87,13 @@ void TestMapBlock::testSaveLoad(IGameDef *gamedef, const u8 version)
// Check data
PcgRandom r(seed);
for (size_t i = 0; i < MapBlock::nodecount; ++i) {
for (s16 z=0; z < MAP_BLOCKSIZE; z++)
for (s16 y=0; y < MAP_BLOCKSIZE; y++)
for (s16 x=0; x < MAP_BLOCKSIZE; x++) {
u32 rval = r.next();
auto expect =
MapNode(rval % max, (rval >> 16) & 0xff, (rval >> 24) & 0xff);
UASSERT(block.getData()[i] == expect);
UASSERT(block.getNodeNoCheck(x, y, z) == expect);
}
}
}
@ -104,8 +108,11 @@ void TestMapBlock::testSave29(IGameDef *gamedef)
{
// Prepare test block
MapBlock block({}, gamedef);
for (size_t i = 0; i < MapBlock::nodecount; ++i)
block.getData()[i] = MapNode(CONTENT_AIR);
for (s16 z=0; z < MAP_BLOCKSIZE; z++)
for (s16 y=0; y < MAP_BLOCKSIZE; y++)
for (s16 x=0; x < MAP_BLOCKSIZE; x++) {
block.setNodeNoCheck(x, y, z, MapNode(CONTENT_AIR));
}
block.setNode({0, 0, 0}, MapNode(t_CONTENT_STONE));
block.serialize(ss, 29, true, -1);
@ -294,8 +301,11 @@ void TestMapBlock::testLoad20(IGameDef *gamedef)
UASSERTEQ(auto, get_node(10, 6, 4), "air");
UASSERTEQ(auto, get_node(11, 6, 3), "default:furnace");
for (size_t i = 0; i < MapBlock::nodecount; ++i)
UASSERT(block.getData()[i].getContent() != CONTENT_IGNORE);
for (s16 z=0; z < MAP_BLOCKSIZE; z++)
for (s16 y=0; y < MAP_BLOCKSIZE; y++)
for (s16 x=0; x < MAP_BLOCKSIZE; x++) {
UASSERT(block.getNodeNoCheck(x, y, z).getContent() != CONTENT_IGNORE);
}
// metadata is also translated
auto *meta = block.m_node_metadata.get({11, 6, 3});