aboutsummaryrefslogtreecommitdiff
path: root/src/client/mesh_generator_thread.cpp
diff options
context:
space:
mode:
authorVitaliy <numzer0@yandex.ru>2021-12-30 00:59:53 +0300
committerGitHub <noreply@github.com>2021-12-29 22:59:53 +0100
commit9b650b9efb1d4617c97e86639ff115067a73e83a (patch)
treee0cec7fda984c54deb66ab56249a528ead2c613e /src/client/mesh_generator_thread.cpp
parent481bb90eac45651ba6f71860ed669341fcbef6f1 (diff)
downloadminetest-9b650b9efb1d4617c97e86639ff115067a73e83a.tar.gz
minetest-9b650b9efb1d4617c97e86639ff115067a73e83a.tar.bz2
minetest-9b650b9efb1d4617c97e86639ff115067a73e83a.zip
Add more neighbors on mesh update (#6765)
Diffstat (limited to 'src/client/mesh_generator_thread.cpp')
-rw-r--r--src/client/mesh_generator_thread.cpp53
1 files changed, 31 insertions, 22 deletions
diff --git a/src/client/mesh_generator_thread.cpp b/src/client/mesh_generator_thread.cpp
index c8d1cba26..5c3f4180b 100644
--- a/src/client/mesh_generator_thread.cpp
+++ b/src/client/mesh_generator_thread.cpp
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client.h"
#include "mapblock.h"
#include "map.h"
+#include "util/directiontables.h"
/*
CachedMapBlockData
@@ -69,7 +70,7 @@ MeshUpdateQueue::~MeshUpdateQueue()
}
}
-void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent)
+bool MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent)
{
MutexAutoLock lock(m_mutex);
@@ -81,20 +82,15 @@ void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool
*/
std::vector<CachedMapBlockData*> cached_blocks;
size_t cache_hit_counter = 0;
+ CachedMapBlockData *cached_block = cacheBlock(map, p, FORCE_UPDATE);
+ if (!cached_block->data)
+ return false; // nothing to update
cached_blocks.reserve(3*3*3);
- v3s16 dp;
- for (dp.X = -1; dp.X <= 1; dp.X++)
- for (dp.Y = -1; dp.Y <= 1; dp.Y++)
- for (dp.Z = -1; dp.Z <= 1; dp.Z++) {
- v3s16 p1 = p + dp;
- CachedMapBlockData *cached_block;
- if (dp == v3s16(0, 0, 0))
- cached_block = cacheBlock(map, p1, FORCE_UPDATE);
- else
- cached_block = cacheBlock(map, p1, SKIP_UPDATE_IF_ALREADY_CACHED,
- &cache_hit_counter);
- cached_blocks.push_back(cached_block);
- }
+ cached_blocks.push_back(cached_block);
+ for (v3s16 dp : g_26dirs)
+ cached_blocks.push_back(cacheBlock(map, p + dp,
+ SKIP_UPDATE_IF_ALREADY_CACHED,
+ &cache_hit_counter));
g_profiler->avg("MeshUpdateQueue: MapBlocks from cache [%]",
100.0f * cache_hit_counter / cached_blocks.size());
@@ -116,7 +112,7 @@ void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool
q->ack_block_to_server = true;
q->crack_level = m_client->getCrackLevel();
q->crack_pos = m_client->getCrackPos();
- return;
+ return true;
}
}
@@ -134,6 +130,7 @@ void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool
for (CachedMapBlockData *cached_block : cached_blocks) {
cached_block->refcount_from_queue++;
}
+ return true;
}
// Returned pointer must be deleted
@@ -212,10 +209,7 @@ void MeshUpdateQueue::fillDataFromMapBlockCache(QueuedMeshUpdate *q)
std::time_t t_now = std::time(0);
// Collect data for 3*3*3 blocks from cache
- v3s16 dp;
- for (dp.X = -1; dp.X <= 1; dp.X++)
- for (dp.Y = -1; dp.Y <= 1; dp.Y++)
- for (dp.Z = -1; dp.Z <= 1; dp.Z++) {
+ for (v3s16 dp : g_27dirs) {
v3s16 p = q->p + dp;
CachedMapBlockData *cached_block = getCachedBlock(p);
if (cached_block) {
@@ -272,10 +266,25 @@ MeshUpdateThread::MeshUpdateThread(Client *client):
}
void MeshUpdateThread::updateBlock(Map *map, v3s16 p, bool ack_block_to_server,
- bool urgent)
+ bool urgent, bool update_neighbors)
{
- // Allow the MeshUpdateQueue to do whatever it wants
- m_queue_in.addBlock(map, p, ack_block_to_server, urgent);
+ static thread_local const bool many_neighbors =
+ g_settings->getBool("smooth_lighting")
+ && !g_settings->getFlag("performance_tradeoffs");
+ if (!m_queue_in.addBlock(map, p, ack_block_to_server, urgent)) {
+ warningstream << "Update requested for non-existent block at ("
+ << p.X << ", " << p.Y << ", " << p.Z << ")" << std::endl;
+ return;
+ }
+ if (update_neighbors) {
+ if (many_neighbors) {
+ for (v3s16 dp : g_26dirs)
+ m_queue_in.addBlock(map, p + dp, false, urgent);
+ } else {
+ for (v3s16 dp : g_6dirs)
+ m_queue_in.addBlock(map, p + dp, false, urgent);
+ }
+ }
deferUpdate();
}