]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Add more neighbors on mesh update (#6765)
authorVitaliy <numzer0@yandex.ru>
Wed, 29 Dec 2021 21:59:53 +0000 (00:59 +0300)
committerGitHub <noreply@github.com>
Wed, 29 Dec 2021 21:59:53 +0000 (22:59 +0100)
builtin/settingtypes.txt
src/client/client.cpp
src/client/mesh_generator_thread.cpp
src/client/mesh_generator_thread.h
src/defaultsettings.cpp

index 81ebef67d1c59c0a62460c2e7b6569e7331ef957..1bc5e79824e50aa276fbed2f04f3f2cdad4d98a9 100644 (file)
@@ -475,6 +475,10 @@ connected_glass (Connect glass) bool false
 #    Disable for speed or for different looks.
 smooth_lighting (Smooth lighting) bool true
 
+#    Enables tradeoffs that reduce CPU load or increase rendering performance
+#    at the expense of minor visual glitches that do not impact game playability.
+performance_tradeoffs (Tradeoffs for performance) bool false
+
 #    Clouds are a client side effect.
 enable_clouds (Clouds) bool true
 
index 3ee1298ff182646909539621dab0a90917aa506a..6e4a90a79095cddccfbbf4d5413e623afe81494f 100644 (file)
@@ -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()
index c8d1cba2654fb7c3ef04f843c6d989f6cf412e5e..5c3f4180bb32d7136955ab8b8b6e2e352ffb701e 100644 (file)
@@ -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();
 }
 
index 4371b839099e1693710738dde2eadcc53c95a031..1b734bc0614e35c5e3de747c098dd4f26b84c4b1 100644 (file)
@@ -66,7 +66,7 @@ class MeshUpdateQueue
 
        // 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 @@ class MeshUpdateThread : public UpdateThread
 
        // 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;
index d705552d6908c105e9a7d684496fe83669445151..635ec22577f6c81ab1c1b24b150443c1192dee04 100644 (file)
@@ -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");