diff options
author | Vitaliy <numzer0@yandex.ru> | 2021-12-30 00:59:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-29 22:59:53 +0100 |
commit | 9b650b9efb1d4617c97e86639ff115067a73e83a (patch) | |
tree | e0cec7fda984c54deb66ab56249a528ead2c613e /src | |
parent | 481bb90eac45651ba6f71860ed669341fcbef6f1 (diff) | |
download | minetest-9b650b9efb1d4617c97e86639ff115067a73e83a.tar.gz minetest-9b650b9efb1d4617c97e86639ff115067a73e83a.tar.bz2 minetest-9b650b9efb1d4617c97e86639ff115067a73e83a.zip |
Add more neighbors on mesh update (#6765)
Diffstat (limited to 'src')
-rw-r--r-- | src/client/client.cpp | 53 | ||||
-rw-r--r-- | src/client/mesh_generator_thread.cpp | 53 | ||||
-rw-r--r-- | src/client/mesh_generator_thread.h | 5 | ||||
-rw-r--r-- | src/defaultsettings.cpp | 2 |
4 files changed, 45 insertions, 68 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp index 3ee1298ff..6e4a90a79 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1611,20 +1611,7 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent) void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server, bool urgent) { - try{ - addUpdateMeshTask(blockpos, ack_to_server, urgent); - } - catch(InvalidPositionException &e){} - - // Leading edge - for (int i=0;i<6;i++) - { - try{ - v3s16 p = blockpos + g_6dirs[i]; - addUpdateMeshTask(p, false, urgent); - } - catch(InvalidPositionException &e){} - } + m_mesh_update_thread.updateBlock(&m_env.getMap(), blockpos, ack_to_server, urgent, true); } void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool urgent) @@ -1636,38 +1623,16 @@ void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool ur <<std::endl; } - v3s16 blockpos = getNodeBlockPos(nodepos); + v3s16 blockpos = getNodeBlockPos(nodepos); v3s16 blockpos_relative = blockpos * MAP_BLOCKSIZE; - - try{ - addUpdateMeshTask(blockpos, ack_to_server, urgent); - } - catch(InvalidPositionException &e) {} - + m_mesh_update_thread.updateBlock(&m_env.getMap(), blockpos, ack_to_server, urgent, false); // Leading edge - if(nodepos.X == blockpos_relative.X){ - try{ - v3s16 p = blockpos + v3s16(-1,0,0); - addUpdateMeshTask(p, false, urgent); - } - catch(InvalidPositionException &e){} - } - - if(nodepos.Y == blockpos_relative.Y){ - try{ - v3s16 p = blockpos + v3s16(0,-1,0); - addUpdateMeshTask(p, false, urgent); - } - catch(InvalidPositionException &e){} - } - - if(nodepos.Z == blockpos_relative.Z){ - try{ - v3s16 p = blockpos + v3s16(0,0,-1); - addUpdateMeshTask(p, false, urgent); - } - catch(InvalidPositionException &e){} - } + if (nodepos.X == blockpos_relative.X) + addUpdateMeshTask(blockpos + v3s16(-1, 0, 0), false, urgent); + if (nodepos.Y == blockpos_relative.Y) + addUpdateMeshTask(blockpos + v3s16(0, -1, 0), false, urgent); + if (nodepos.Z == blockpos_relative.Z) + addUpdateMeshTask(blockpos + v3s16(0, 0, -1), false, urgent); } ClientEvent *Client::getClientEvent() 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(); } diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h index 4371b8390..1b734bc06 100644 --- a/src/client/mesh_generator_thread.h +++ b/src/client/mesh_generator_thread.h @@ -66,7 +66,7 @@ public: // Caches the block at p and its neighbors (if needed) and queues a mesh // update for the block at p - void addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent); + bool addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent); // Returned pointer must be deleted // Returns NULL if queue is empty @@ -113,7 +113,8 @@ public: // Caches the block at p and its neighbors (if needed) and queues a mesh // update for the block at p - void updateBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent); + void updateBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent, + bool update_neighbors = false); v3s16 m_camera_offset; MutexedQueue<MeshUpdateResult> m_queue_out; diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index d705552d6..635ec2257 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -184,6 +184,7 @@ void set_default_settings() settings->setDefault("leaves_style", "fancy"); settings->setDefault("connected_glass", "false"); settings->setDefault("smooth_lighting", "true"); + settings->setDefault("performance_tradeoffs", "false"); settings->setDefault("lighting_alpha", "0.0"); settings->setDefault("lighting_beta", "1.5"); settings->setDefault("display_gamma", "1.0"); @@ -477,6 +478,7 @@ void set_default_settings() settings->setDefault("screen_h", "0"); settings->setDefault("fullscreen", "true"); settings->setDefault("smooth_lighting", "false"); + settings->setDefault("performance_tradeoffs", "true"); settings->setDefault("max_simultaneous_block_sends_per_client", "10"); settings->setDefault("emergequeue_limit_diskonly", "16"); settings->setDefault("emergequeue_limit_generate", "16"); |