Add more neighbors on mesh update (#6765)

This commit is contained in:
Vitaliy 2021-12-30 00:59:53 +03:00 committed by GitHub
parent 481bb90eac
commit 9b650b9efb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 68 deletions

@ -475,6 +475,10 @@ connected_glass (Connect glass) bool false
# Disable for speed or for different looks. # Disable for speed or for different looks.
smooth_lighting (Smooth lighting) bool true 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. # Clouds are a client side effect.
enable_clouds (Clouds) bool true enable_clouds (Clouds) bool true

@ -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) void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server, bool urgent)
{ {
try{ m_mesh_update_thread.updateBlock(&m_env.getMap(), blockpos, ack_to_server, urgent, true);
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){}
}
} }
void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool urgent) void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool urgent)
@ -1638,36 +1625,14 @@ void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool ur
v3s16 blockpos = getNodeBlockPos(nodepos); v3s16 blockpos = getNodeBlockPos(nodepos);
v3s16 blockpos_relative = blockpos * MAP_BLOCKSIZE; v3s16 blockpos_relative = blockpos * MAP_BLOCKSIZE;
m_mesh_update_thread.updateBlock(&m_env.getMap(), blockpos, ack_to_server, urgent, false);
try{
addUpdateMeshTask(blockpos, ack_to_server, urgent);
}
catch(InvalidPositionException &e) {}
// Leading edge // Leading edge
if(nodepos.X == blockpos_relative.X){ if (nodepos.X == blockpos_relative.X)
try{ addUpdateMeshTask(blockpos + v3s16(-1, 0, 0), false, urgent);
v3s16 p = blockpos + v3s16(-1,0,0); if (nodepos.Y == blockpos_relative.Y)
addUpdateMeshTask(p, false, urgent); addUpdateMeshTask(blockpos + v3s16(0, -1, 0), false, urgent);
} if (nodepos.Z == blockpos_relative.Z)
catch(InvalidPositionException &e){} addUpdateMeshTask(blockpos + v3s16(0, 0, -1), false, urgent);
}
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){}
}
} }
ClientEvent *Client::getClientEvent() ClientEvent *Client::getClientEvent()

@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client.h" #include "client.h"
#include "mapblock.h" #include "mapblock.h"
#include "map.h" #include "map.h"
#include "util/directiontables.h"
/* /*
CachedMapBlockData 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); 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; std::vector<CachedMapBlockData*> cached_blocks;
size_t cache_hit_counter = 0; 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); 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 [%]", g_profiler->avg("MeshUpdateQueue: MapBlocks from cache [%]",
100.0f * cache_hit_counter / cached_blocks.size()); 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->ack_block_to_server = true;
q->crack_level = m_client->getCrackLevel(); q->crack_level = m_client->getCrackLevel();
q->crack_pos = m_client->getCrackPos(); 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) { for (CachedMapBlockData *cached_block : cached_blocks) {
cached_block->refcount_from_queue++; cached_block->refcount_from_queue++;
} }
return true;
} }
// Returned pointer must be deleted // Returned pointer must be deleted
@ -212,10 +209,7 @@ void MeshUpdateQueue::fillDataFromMapBlockCache(QueuedMeshUpdate *q)
std::time_t t_now = std::time(0); std::time_t t_now = std::time(0);
// Collect data for 3*3*3 blocks from cache // Collect data for 3*3*3 blocks from cache
v3s16 dp; for (v3s16 dp : g_27dirs) {
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 p = q->p + dp; v3s16 p = q->p + dp;
CachedMapBlockData *cached_block = getCachedBlock(p); CachedMapBlockData *cached_block = getCachedBlock(p);
if (cached_block) { if (cached_block) {
@ -272,10 +266,25 @@ MeshUpdateThread::MeshUpdateThread(Client *client):
} }
void MeshUpdateThread::updateBlock(Map *map, v3s16 p, bool ack_block_to_server, 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 static thread_local const bool many_neighbors =
m_queue_in.addBlock(map, p, ack_block_to_server, urgent); 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(); deferUpdate();
} }

@ -66,7 +66,7 @@ public:
// Caches the block at p and its neighbors (if needed) and queues a mesh // Caches the block at p and its neighbors (if needed) and queues a mesh
// update for the block at p // 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 // Returned pointer must be deleted
// Returns NULL if queue is empty // 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 // Caches the block at p and its neighbors (if needed) and queues a mesh
// update for the block at p // 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; v3s16 m_camera_offset;
MutexedQueue<MeshUpdateResult> m_queue_out; MutexedQueue<MeshUpdateResult> m_queue_out;

@ -184,6 +184,7 @@ void set_default_settings()
settings->setDefault("leaves_style", "fancy"); settings->setDefault("leaves_style", "fancy");
settings->setDefault("connected_glass", "false"); settings->setDefault("connected_glass", "false");
settings->setDefault("smooth_lighting", "true"); settings->setDefault("smooth_lighting", "true");
settings->setDefault("performance_tradeoffs", "false");
settings->setDefault("lighting_alpha", "0.0"); settings->setDefault("lighting_alpha", "0.0");
settings->setDefault("lighting_beta", "1.5"); settings->setDefault("lighting_beta", "1.5");
settings->setDefault("display_gamma", "1.0"); settings->setDefault("display_gamma", "1.0");
@ -477,6 +478,7 @@ void set_default_settings()
settings->setDefault("screen_h", "0"); settings->setDefault("screen_h", "0");
settings->setDefault("fullscreen", "true"); settings->setDefault("fullscreen", "true");
settings->setDefault("smooth_lighting", "false"); settings->setDefault("smooth_lighting", "false");
settings->setDefault("performance_tradeoffs", "true");
settings->setDefault("max_simultaneous_block_sends_per_client", "10"); settings->setDefault("max_simultaneous_block_sends_per_client", "10");
settings->setDefault("emergequeue_limit_diskonly", "16"); settings->setDefault("emergequeue_limit_diskonly", "16");
settings->setDefault("emergequeue_limit_generate", "16"); settings->setDefault("emergequeue_limit_generate", "16");