diff options
author | lhofhansl <larsh@apache.org> | 2023-03-05 21:33:41 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-05 21:33:41 -0800 |
commit | 1f0d042377ed506ad460067495e5911b2fc2aacc (patch) | |
tree | beaf0785d4d0d2dc9f043d01d0a80d588f10fbfc /src/clientiface.cpp | |
parent | 9ef3c8ce388011f4f57adc9a7eb0326376aec750 (diff) | |
download | minetest-1f0d042377ed506ad460067495e5911b2fc2aacc.tar.xz |
Reduce server CPU consumed by occlusion culling. (#13260)
Cache blocks already occluded at a specific distance. The RemoteClient typically visits the same distance multiple time - especially at larger distances, so this saves significant CPU from recalculating the occlusion state of blocks.
Diffstat (limited to 'src/clientiface.cpp')
-rw-r--r-- | src/clientiface.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/clientiface.cpp b/src/clientiface.cpp index bb25a4265..49b668cf0 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -328,8 +328,15 @@ void RemoteClient::GetNextBlocks ( continue; } + /* + Check occlusion cache first. + */ + if (m_blocks_occ.find(p) != m_blocks_occ.end()) + continue; + if (m_occ_cull && !block_not_found && env->getMap().isBlockOccluded(block, cam_pos_nodes)) { + m_blocks_occ.insert(p); continue; } } @@ -395,8 +402,11 @@ queue_full_break: } } - if (new_nearest_unsent_d != -1) + if (new_nearest_unsent_d != -1 && m_nearest_unsent_d != new_nearest_unsent_d) { m_nearest_unsent_d = new_nearest_unsent_d; + // if the distance has changed, clear the occlusion cache + m_blocks_occ.clear(); + } } void RemoteClient::GotBlock(v3s16 p) |