Skip to content

Commit 9b650b9

Browse files
authoredDec 29, 2021
Add more neighbors on mesh update (#6765)
1 parent 481bb90 commit 9b650b9

File tree

5 files changed

+49
-68
lines changed

5 files changed

+49
-68
lines changed
 

‎builtin/settingtypes.txt

+4
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ connected_glass (Connect glass) bool false
475475
# Disable for speed or for different looks.
476476
smooth_lighting (Smooth lighting) bool true
477477

478+
# Enables tradeoffs that reduce CPU load or increase rendering performance
479+
# at the expense of minor visual glitches that do not impact game playability.
480+
performance_tradeoffs (Tradeoffs for performance) bool false
481+
478482
# Clouds are a client side effect.
479483
enable_clouds (Clouds) bool true
480484

‎src/client/client.cpp

+9-44
Original file line numberDiff line numberDiff line change
@@ -1611,20 +1611,7 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent)
16111611

16121612
void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server, bool urgent)
16131613
{
1614-
try{
1615-
addUpdateMeshTask(blockpos, ack_to_server, urgent);
1616-
}
1617-
catch(InvalidPositionException &e){}
1618-
1619-
// Leading edge
1620-
for (int i=0;i<6;i++)
1621-
{
1622-
try{
1623-
v3s16 p = blockpos + g_6dirs[i];
1624-
addUpdateMeshTask(p, false, urgent);
1625-
}
1626-
catch(InvalidPositionException &e){}
1627-
}
1614+
m_mesh_update_thread.updateBlock(&m_env.getMap(), blockpos, ack_to_server, urgent, true);
16281615
}
16291616

16301617
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
16361623
<<std::endl;
16371624
}
16381625

1639-
v3s16 blockpos = getNodeBlockPos(nodepos);
1626+
v3s16 blockpos = getNodeBlockPos(nodepos);
16401627
v3s16 blockpos_relative = blockpos * MAP_BLOCKSIZE;
1641-
1642-
try{
1643-
addUpdateMeshTask(blockpos, ack_to_server, urgent);
1644-
}
1645-
catch(InvalidPositionException &e) {}
1646-
1628+
m_mesh_update_thread.updateBlock(&m_env.getMap(), blockpos, ack_to_server, urgent, false);
16471629
// Leading edge
1648-
if(nodepos.X == blockpos_relative.X){
1649-
try{
1650-
v3s16 p = blockpos + v3s16(-1,0,0);
1651-
addUpdateMeshTask(p, false, urgent);
1652-
}
1653-
catch(InvalidPositionException &e){}
1654-
}
1655-
1656-
if(nodepos.Y == blockpos_relative.Y){
1657-
try{
1658-
v3s16 p = blockpos + v3s16(0,-1,0);
1659-
addUpdateMeshTask(p, false, urgent);
1660-
}
1661-
catch(InvalidPositionException &e){}
1662-
}
1663-
1664-
if(nodepos.Z == blockpos_relative.Z){
1665-
try{
1666-
v3s16 p = blockpos + v3s16(0,0,-1);
1667-
addUpdateMeshTask(p, false, urgent);
1668-
}
1669-
catch(InvalidPositionException &e){}
1670-
}
1630+
if (nodepos.X == blockpos_relative.X)
1631+
addUpdateMeshTask(blockpos + v3s16(-1, 0, 0), false, urgent);
1632+
if (nodepos.Y == blockpos_relative.Y)
1633+
addUpdateMeshTask(blockpos + v3s16(0, -1, 0), false, urgent);
1634+
if (nodepos.Z == blockpos_relative.Z)
1635+
addUpdateMeshTask(blockpos + v3s16(0, 0, -1), false, urgent);
16711636
}
16721637

16731638
ClientEvent *Client::getClientEvent()

‎src/client/mesh_generator_thread.cpp

+31-22
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include "client.h"
2424
#include "mapblock.h"
2525
#include "map.h"
26+
#include "util/directiontables.h"
2627

2728
/*
2829
CachedMapBlockData
@@ -69,7 +70,7 @@ MeshUpdateQueue::~MeshUpdateQueue()
6970
}
7071
}
7172

72-
void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent)
73+
bool MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent)
7374
{
7475
MutexAutoLock lock(m_mutex);
7576

@@ -81,20 +82,15 @@ void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool
8182
*/
8283
std::vector<CachedMapBlockData*> cached_blocks;
8384
size_t cache_hit_counter = 0;
85+
CachedMapBlockData *cached_block = cacheBlock(map, p, FORCE_UPDATE);
86+
if (!cached_block->data)
87+
return false; // nothing to update
8488
cached_blocks.reserve(3*3*3);
85-
v3s16 dp;
86-
for (dp.X = -1; dp.X <= 1; dp.X++)
87-
for (dp.Y = -1; dp.Y <= 1; dp.Y++)
88-
for (dp.Z = -1; dp.Z <= 1; dp.Z++) {
89-
v3s16 p1 = p + dp;
90-
CachedMapBlockData *cached_block;
91-
if (dp == v3s16(0, 0, 0))
92-
cached_block = cacheBlock(map, p1, FORCE_UPDATE);
93-
else
94-
cached_block = cacheBlock(map, p1, SKIP_UPDATE_IF_ALREADY_CACHED,
95-
&cache_hit_counter);
96-
cached_blocks.push_back(cached_block);
97-
}
89+
cached_blocks.push_back(cached_block);
90+
for (v3s16 dp : g_26dirs)
91+
cached_blocks.push_back(cacheBlock(map, p + dp,
92+
SKIP_UPDATE_IF_ALREADY_CACHED,
93+
&cache_hit_counter));
9894
g_profiler->avg("MeshUpdateQueue: MapBlocks from cache [%]",
9995
100.0f * cache_hit_counter / cached_blocks.size());
10096

@@ -116,7 +112,7 @@ void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool
116112
q->ack_block_to_server = true;
117113
q->crack_level = m_client->getCrackLevel();
118114
q->crack_pos = m_client->getCrackPos();
119-
return;
115+
return true;
120116
}
121117
}
122118

@@ -134,6 +130,7 @@ void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool
134130
for (CachedMapBlockData *cached_block : cached_blocks) {
135131
cached_block->refcount_from_queue++;
136132
}
133+
return true;
137134
}
138135

139136
// Returned pointer must be deleted
@@ -212,10 +209,7 @@ void MeshUpdateQueue::fillDataFromMapBlockCache(QueuedMeshUpdate *q)
212209
std::time_t t_now = std::time(0);
213210

214211
// Collect data for 3*3*3 blocks from cache
215-
v3s16 dp;
216-
for (dp.X = -1; dp.X <= 1; dp.X++)
217-
for (dp.Y = -1; dp.Y <= 1; dp.Y++)
218-
for (dp.Z = -1; dp.Z <= 1; dp.Z++) {
212+
for (v3s16 dp : g_27dirs) {
219213
v3s16 p = q->p + dp;
220214
CachedMapBlockData *cached_block = getCachedBlock(p);
221215
if (cached_block) {
@@ -272,10 +266,25 @@ MeshUpdateThread::MeshUpdateThread(Client *client):
272266
}
273267

274268
void MeshUpdateThread::updateBlock(Map *map, v3s16 p, bool ack_block_to_server,
275-
bool urgent)
269+
bool urgent, bool update_neighbors)
276270
{
277-
// Allow the MeshUpdateQueue to do whatever it wants
278-
m_queue_in.addBlock(map, p, ack_block_to_server, urgent);
271+
static thread_local const bool many_neighbors =
272+
g_settings->getBool("smooth_lighting")
273+
&& !g_settings->getFlag("performance_tradeoffs");
274+
if (!m_queue_in.addBlock(map, p, ack_block_to_server, urgent)) {
275+
warningstream << "Update requested for non-existent block at ("
276+
<< p.X << ", " << p.Y << ", " << p.Z << ")" << std::endl;
277+
return;
278+
}
279+
if (update_neighbors) {
280+
if (many_neighbors) {
281+
for (v3s16 dp : g_26dirs)
282+
m_queue_in.addBlock(map, p + dp, false, urgent);
283+
} else {
284+
for (v3s16 dp : g_6dirs)
285+
m_queue_in.addBlock(map, p + dp, false, urgent);
286+
}
287+
}
279288
deferUpdate();
280289
}
281290

‎src/client/mesh_generator_thread.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class MeshUpdateQueue
6666

6767
// Caches the block at p and its neighbors (if needed) and queues a mesh
6868
// update for the block at p
69-
void addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent);
69+
bool addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent);
7070

7171
// Returned pointer must be deleted
7272
// Returns NULL if queue is empty
@@ -113,7 +113,8 @@ class MeshUpdateThread : public UpdateThread
113113

114114
// Caches the block at p and its neighbors (if needed) and queues a mesh
115115
// update for the block at p
116-
void updateBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent);
116+
void updateBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent,
117+
bool update_neighbors = false);
117118

118119
v3s16 m_camera_offset;
119120
MutexedQueue<MeshUpdateResult> m_queue_out;

‎src/defaultsettings.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ void set_default_settings()
184184
settings->setDefault("leaves_style", "fancy");
185185
settings->setDefault("connected_glass", "false");
186186
settings->setDefault("smooth_lighting", "true");
187+
settings->setDefault("performance_tradeoffs", "false");
187188
settings->setDefault("lighting_alpha", "0.0");
188189
settings->setDefault("lighting_beta", "1.5");
189190
settings->setDefault("display_gamma", "1.0");
@@ -477,6 +478,7 @@ void set_default_settings()
477478
settings->setDefault("screen_h", "0");
478479
settings->setDefault("fullscreen", "true");
479480
settings->setDefault("smooth_lighting", "false");
481+
settings->setDefault("performance_tradeoffs", "true");
480482
settings->setDefault("max_simultaneous_block_sends_per_client", "10");
481483
settings->setDefault("emergequeue_limit_diskonly", "16");
482484
settings->setDefault("emergequeue_limit_generate", "16");

0 commit comments

Comments
 (0)
Please sign in to comment.