VoxelManipulator code cleanup (#15114)

* Cache node in voxel area index when possible

The index function according to the MSVC profiler actually takes up a significant time slice (around ~5% of total time for the process) during normal game-play.
Might not be accurate but still good to not recalculate it twice.

* Remove `setNodeNoRef` from VM

* VM: remove old commented out print statement
This commit is contained in:
red-001 2024-09-04 14:20:39 +01:00 committed by GitHub
parent 074700b35e
commit 486dc3288d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 19 deletions

@ -87,7 +87,7 @@ void TestVoxelManipulator::testVoxelManipulator(const NodeDefManager *nodedef)
v.print(infostream, nodedef);
infostream << "*** Setting (-1,0,-1)=2 ***" << std::endl;
v.setNodeNoRef(v3s16(-1,0,-1), MapNode(t_CONTENT_GRASS));
v.setNode(v3s16(-1,0,-1), MapNode(t_CONTENT_GRASS));
v.print(infostream, nodedef);
UASSERT(v.getNode(v3s16(-1,0,-1)).getContent() == t_CONTENT_GRASS);

@ -392,36 +392,36 @@ public:
VoxelArea voxel_area(p);
addArea(voxel_area);
if (m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA) {
/*dstream<<"EXCEPT: VoxelManipulator::getNode(): "
<<"p=("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<", index="<<m_area.index(p)
<<", flags="<<(int)m_flags[m_area.index(p)]
<<" is inexistent"<<std::endl;*/
const s32 index = m_area.index(p);
if (m_flags[index] & VOXELFLAG_NO_DATA) {
throw InvalidPositionException
("VoxelManipulator: getNode: inexistent");
}
return m_data[m_area.index(p)];
return m_data[index];
}
MapNode getNodeNoEx(const v3s16 &p)
{
VoxelArea voxel_area(p);
addArea(voxel_area);
if (m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA) {
const s32 index = m_area.index(p);
if (m_flags[index] & VOXELFLAG_NO_DATA) {
return {CONTENT_IGNORE};
}
return m_data[m_area.index(p)];
return m_data[index];
}
MapNode getNodeNoExNoEmerge(const v3s16 &p)
{
if (!m_area.contains(p))
return {CONTENT_IGNORE};
if (m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA)
const s32 index = m_area.index(p);
if (m_flags[index] & VOXELFLAG_NO_DATA)
return {CONTENT_IGNORE};
return m_data[m_area.index(p)];
return m_data[index];
}
// Stuff explodes if non-emerged area is touched with this.
// Emerge first, and check VOXELFLAG_NO_DATA if appropriate.
@ -456,13 +456,10 @@ public:
VoxelArea voxel_area(p);
addArea(voxel_area);
m_data[m_area.index(p)] = n;
m_flags[m_area.index(p)] &= ~VOXELFLAG_NO_DATA;
}
// TODO: Should be removed and replaced with setNode
void setNodeNoRef(const v3s16 &p, const MapNode &n)
{
setNode(p, n);
const s32 index = m_area.index(p);
m_data[index] = n;
m_flags[index] &= ~VOXELFLAG_NO_DATA;
}
/*