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

Reuse some allocations in ClientMap rendering

This commit is contained in:
sfan5 2025-04-15 21:42:39 +02:00 committed by GitHub
parent a9c197b1e5
commit 37d2bc8a5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -120,6 +120,11 @@ namespace {
inline T subtract_or_zero(T a, T b) { inline T subtract_or_zero(T a, T b) {
return b >= a ? T(0) : (a - b); return b >= a ? T(0) : (a - b);
} }
// file-scope thread-local instances of the above two data structures, because
// allocating memory in a hot path can be expensive.
thread_local MeshBufListMaps tl_meshbuflistmaps;
thread_local DrawDescriptorList tl_drawdescriptorlist;
} }
void CachedMeshBuffer::drop() void CachedMeshBuffer::drop()
@ -978,8 +983,10 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
*/ */
TimeTaker tt_collect(""); TimeTaker tt_collect("");
MeshBufListMaps grouped_buffers; MeshBufListMaps &grouped_buffers = tl_meshbuflistmaps;
DrawDescriptorList draw_order; DrawDescriptorList &draw_order = tl_drawdescriptorlist;
grouped_buffers.clear();
draw_order.clear();
auto is_frustum_culled = m_client->getCamera()->getFrustumCuller(); auto is_frustum_culled = m_client->getCamera()->getFrustumCuller();
@ -1375,8 +1382,10 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver,
return intToFloat(mesh_grid.getMeshPos(pos) * MAP_BLOCKSIZE - m_camera_offset, BS); return intToFloat(mesh_grid.getMeshPos(pos) * MAP_BLOCKSIZE - m_camera_offset, BS);
}; };
MeshBufListMaps grouped_buffers; MeshBufListMaps &grouped_buffers = tl_meshbuflistmaps;
DrawDescriptorList draw_order; DrawDescriptorList &draw_order = tl_drawdescriptorlist;
grouped_buffers.clear();
draw_order.clear();
std::size_t count = 0; std::size_t count = 0;
std::size_t meshes_per_frame = m_drawlist_shadow.size() / total_frames + 1; std::size_t meshes_per_frame = m_drawlist_shadow.size() / total_frames + 1;