VoxelManipulator code cleanup (#15114)
Some checks failed
android / build (push) Has been cancelled
cpp_lint / clang_tidy (push) Has been cancelled
linux / gcc_7 (push) Has been cancelled
linux / gcc_14 (push) Has been cancelled
linux / clang_7 (push) Has been cancelled
linux / clang_18 (push) Has been cancelled
linux / clang_11 (PROMETHEUS=1) (push) Has been cancelled
lua_lint / Compile and run multiplayer tests (push) Has been cancelled
lua_lint / Builtin Luacheck and Unit Tests (push) Has been cancelled
macos / build (push) Has been cancelled
whitespace_checks / trailing_whitespaces (push) Has been cancelled
whitespace_checks / tabs_lua_api_files (push) Has been cancelled
windows / MinGW cross-compiler (${{ matrix.bits }}-bit) (32) (push) Has been cancelled
windows / MinGW cross-compiler (${{ matrix.bits }}-bit) (64) (push) Has been cancelled
windows / VS 2019 ${{ matrix.config.arch }}-${{ matrix.type }} (map[arch:x64 generator:-G'Visual Studio 16 2019' -A x64 vcpkg_triplet:x64-windows], portable) (push) Has been cancelled
windows / VS 2019 ${{ matrix.config.arch }}-${{ matrix.type }} (map[arch:x86 generator:-G'Visual Studio 16 2019' -A Win32 vcpkg_triplet:x86-windows], portable) (push) Has been cancelled

* 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

View File

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

View File

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