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

Review comments

This commit is contained in:
Lars 2025-05-20 12:52:22 -07:00
parent de90495eda
commit 0c9d6220a2
2 changed files with 23 additions and 28 deletions

View file

@ -210,10 +210,7 @@ void MapBlock::copyTo(VoxelManipulator &dst)
v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
VoxelArea data_area(v3s16(0,0,0), data_size - v3s16(1,1,1));
if (m_is_mono_block) {
reallocate(nodecount, data[0]);
m_is_mono_block = false;
}
deconvertMonoblock();
// Copy from data to VoxelManipulator
dst.copyFrom(data, data_area, v3s16(0,0,0),
getPosRelative(), data_size);
@ -224,18 +221,16 @@ void MapBlock::copyFrom(const VoxelManipulator &src)
v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
VoxelArea data_area(v3s16(0,0,0), data_size - v3s16(1,1,1));
if (m_is_mono_block) {
reallocate(nodecount, data[0]);
m_is_mono_block = false;
}
deconvertMonoblock();
// Copy from VoxelManipulator to data
src.copyTo(data, data_area, v3s16(0,0,0),
getPosRelative(), data_size);
checkForMonoblock();
tryConvertToMonoblock();
}
void MapBlock::checkForMonoblock() {
void MapBlock::tryConvertToMonoblock()
{
if (m_is_mono_block)
return;
@ -258,6 +253,14 @@ void MapBlock::checkForMonoblock() {
}
}
void MapBlock::deconvertMonoblock()
{
if (m_is_mono_block) {
reallocate(nodecount, data[0]);
m_is_mono_block = false;
}
}
void MapBlock::actuallyUpdateIsAir()
{
// Running this function un-expires m_is_air
@ -635,7 +638,7 @@ void MapBlock::deSerialize(std::istream &in_compressed, u8 version, bool disk)
}
if (nimap.size() == 1) {
checkForMonoblock();
tryConvertToMonoblock();
u16 dummy;
if (nimap.getId("air", dummy)) {
m_is_air = true;

View file

@ -75,10 +75,7 @@ public:
MapNode* getData()
{
if (m_is_mono_block) {
reallocate(nodecount, data[0]);
m_is_mono_block = false;
}
deconvertMonoblock();
return data;
}
@ -255,10 +252,7 @@ public:
if (!isValidPosition(x, y, z))
throw InvalidPositionException();
if (m_is_mono_block) {
reallocate(nodecount, data[0]);
m_is_mono_block = false;
}
deconvertMonoblock();
data[z * zstride + y * ystride + x] = n;
raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_SET_NODE);
}
@ -287,10 +281,7 @@ public:
inline void setNodeNoCheck(s16 x, s16 y, s16 z, MapNode n)
{
if (m_is_mono_block) {
reallocate(nodecount, data[0]);
m_is_mono_block = false;
}
deconvertMonoblock();
data[z * zstride + y * ystride + x] = n;
raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_SET_NODE);
}
@ -449,7 +440,8 @@ private:
*/
void deSerialize_pre22(std::istream &is, u8 version, bool disk);
void checkForMonoblock();
void tryConvertToMonoblock();
void deconvertMonoblock();
void reallocate(u32 c, MapNode n)
{
@ -497,11 +489,11 @@ private:
short m_refcount = 0;
/*
* Note that this is not an inline array because that has implications for
* heap fragmentation (the array is exactly 16K), CPU caches and/or
* optimizability of algorithms working on this array.
* Note that this is not an inline array because that has implications for heap
* fragmentation (the array is exactly 16K, or exactly 4 bytes for a "monoblock"),
* CPU caches and/or optimizability of algorithms working on this array.
*/
MapNode * data = nullptr; // of `nodecount` elements
MapNode * data = nullptr;
// provides the item and node definitions
IGameDef *m_gamedef;