1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00

Refactor MMVManip to get rid of m_loaded_blocks

This commit is contained in:
sfan5 2025-05-25 14:50:13 +02:00
parent 41651c7317
commit 6274a8dec4
5 changed files with 123 additions and 38 deletions

View file

@ -264,6 +264,10 @@ void TestVoxelArea::test_intersect()
UASSERT(v3.intersect(v1) == v1.intersect(v3));
UASSERT(v1.intersect(v4) ==
VoxelArea({-10, -2, -10}, {10, 2, 10}));
// edge cases
UASSERT(VoxelArea().intersect(v1).hasEmptyExtent());
UASSERT(v1.intersect(VoxelArea()).hasEmptyExtent());
}
void TestVoxelArea::test_index_xyz_all_pos()

View file

@ -22,6 +22,7 @@ public:
void testBasic(const NodeDefManager *nodedef);
void testEmerge(IGameDef *gamedef);
void testBlitBack(IGameDef *gamedef);
void testBlitBack2(IGameDef *gamedef);
};
static TestVoxelManipulator g_test_instance;
@ -31,6 +32,7 @@ void TestVoxelManipulator::runTests(IGameDef *gamedef)
TEST(testBasic, gamedef->ndef());
TEST(testEmerge, gamedef);
TEST(testBlitBack, gamedef);
TEST(testBlitBack2, gamedef);
}
////////////////////////////////////////////////////////////////////////////////
@ -90,7 +92,7 @@ void TestVoxelManipulator::testEmerge(IGameDef *gamedef)
UASSERTEQ(auto, vm.getNodeNoExNoEmerge({0,bs+1,0}).getContent(), t_CONTENT_BRICK);
// emerge out of bounds: should produce empty data
vm.initialEmerge({0,0,0}, {0,2,0}, false);
vm.initialEmerge({0,2,0}, {0,2,0}, false);
UASSERTEQ(auto, vm.m_area.getExtent(), v3s32(bs,3*bs,bs));
UASSERTEQ(auto, vm.getNodeNoExNoEmerge({0,2*bs,0}).getContent(), CONTENT_IGNORE);
@ -133,3 +135,47 @@ void TestVoxelManipulator::testBlitBack(IGameDef *gamedef)
// ignore nodes are not written (is this an intentional feature?)
UASSERTEQ(auto, map.getNode({2,2,2}).getContent(), CONTENT_AIR);
}
void TestVoxelManipulator::testBlitBack2(IGameDef *gamedef)
{
constexpr int bs = MAP_BLOCKSIZE;
DummyMap map(gamedef, {0,0,0}, {1,1,1});
map.fill({0,0,0}, {1,1,1}, CONTENT_AIR);
// Create a vmanip "manually" without using initialEmerge
MMVManip vm(&map);
vm.addArea(VoxelArea({0,0,0}, v3s16(1,2,1) * bs - v3s16(1)));
// Lower block is initialized with ignore, upper with lava
for(s16 z=0; z<bs; z++)
for(s16 y=0; y<2*bs; y++)
for(s16 x=0; x<bs; x++) {
auto c = y >= bs ? t_CONTENT_LAVA : CONTENT_IGNORE;
vm.setNodeNoEmerge({x,y,z}, c);
}
// But pretend the upper block was not actually initialized
vm.setFlags(VoxelArea({0,bs,0}, v3s16(1,2,1) * bs - v3s16(1)), VOXELFLAG_NO_DATA);
// Add a node to the lower one
vm.setNodeNoEmerge({0,1,0}, t_CONTENT_TORCH);
// Verify covered blocks
{
auto cov = vm.getCoveredBlocks();
UASSERTEQ(size_t, cov.size(), 2);
auto it = cov.find({0,0,0});
UASSERT(it != cov.end() && it->second);
it = cov.find({0,1,0});
UASSERT(it != cov.end() && !it->second);
}
// Now blit it back
std::map<v3s16, MapBlock*> modified;
vm.blitBackAll(&modified);
// The lower block data should have been written
UASSERTEQ(size_t, modified.size(), 1);
UASSERTEQ(auto, modified.begin()->first, v3s16(0,0,0));
UASSERTEQ(auto, map.getNode({0,1,0}).getContent(), t_CONTENT_TORCH);
// The upper one should not!
UASSERTEQ(auto, map.getNode({0,bs,0}).getContent(), CONTENT_AIR);
}