@@ -165,6 +165,9 @@ void ClientMap::updateDrawList()
165
165
v3s16 p_blocks_max;
166
166
getBlocksInViewRange (cam_pos_nodes, &p_blocks_min, &p_blocks_max);
167
167
168
+ // Read the vision range, unless unlimited range is enabled.
169
+ float range = m_control.range_all ? 1e7 : m_control.wanted_range ;
170
+
168
171
// Number of blocks currently loaded by the client
169
172
u32 blocks_loaded = 0 ;
170
173
// Number of blocks with mesh in rendering range
@@ -182,6 +185,7 @@ void ClientMap::updateDrawList()
182
185
occlusion_culling_enabled = false ;
183
186
}
184
187
188
+
185
189
// Uncomment to debug occluded blocks in the wireframe mode
186
190
// TODO: Include this as a flag for an extended debugging setting
187
191
// if (occlusion_culling_enabled && m_control.show_wireframe)
@@ -218,32 +222,34 @@ void ClientMap::updateDrawList()
218
222
continue ;
219
223
}
220
224
221
- float range = 100000 * BS;
222
- if (!m_control.range_all )
223
- range = m_control.wanted_range * BS;
225
+ v3s16 block_coord = block->getPos ();
226
+ v3s16 block_position = block->getPosRelative () + MAP_BLOCKSIZE / 2 ;
224
227
225
- float d = 0.0 ;
226
- if (!isBlockInSight (block-> getPos (), camera_position,
227
- camera_direction, camera_fov, range, &d) )
228
- continue ;
228
+ // First, perform a simple distance check, with a padding of one extra block.
229
+ if (!m_control. range_all &&
230
+ block_position. getDistanceFrom (cam_pos_nodes) > range + MAP_BLOCKSIZE )
231
+ continue ; // Out of range, skip.
229
232
233
+ // Keep the block alive as long as it is in range.
234
+ block->resetUsageTimer ();
230
235
blocks_in_range_with_mesh++;
231
236
232
- /*
233
- Occlusion culling
234
- */
237
+ // Frustum culling
238
+ float d = 0.0 ;
239
+ if (!isBlockInSight (block_coord, camera_position,
240
+ camera_direction, camera_fov, range * BS, &d))
241
+ continue ;
242
+
243
+ // Occlusion culling
235
244
if ((!m_control.range_all && d > m_control.wanted_range * BS) ||
236
245
(occlusion_culling_enabled && isBlockOccluded (block, cam_pos_nodes))) {
237
246
blocks_occlusion_culled++;
238
247
continue ;
239
248
}
240
249
241
- // This block is in range. Reset usage timer.
242
- block->resetUsageTimer ();
243
-
244
250
// Add to set
245
251
block->refGrab ();
246
- m_drawlist[block-> getPos () ] = block;
252
+ m_drawlist[block_coord ] = block;
247
253
248
254
sector_blocks_drawn++;
249
255
} // foreach sectorblocks
@@ -282,8 +288,6 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
282
288
const u32 daynight_ratio = m_client->getEnv ().getDayNightRatio ();
283
289
284
290
const v3f camera_position = m_camera_position;
285
- const v3f camera_direction = m_camera_direction;
286
- const f32 camera_fov = m_camera_fov;
287
291
288
292
/*
289
293
Get all blocks and draw all visible ones
@@ -310,11 +314,10 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
310
314
if (!block->mesh )
311
315
continue ;
312
316
313
- float d = 0.0 ;
314
- if (!isBlockInSight (block->getPos (), camera_position,
315
- camera_direction, camera_fov, 100000 * BS, &d))
316
- continue ;
317
-
317
+ v3f block_pos_r = intToFloat (block->getPosRelative () + MAP_BLOCKSIZE / 2 , BS);
318
+ float d = camera_position.getDistanceFrom (block_pos_r);
319
+ d = MYMAX (0 ,d - BLOCK_MAX_RADIUS);
320
+
318
321
// Mesh animation
319
322
if (pass == scene::ESNRP_SOLID) {
320
323
// MutexAutoLock lock(block->mesh_mutex);
0 commit comments