@@ -165,6 +165,9 @@ void ClientMap::updateDrawList()
165165 v3s16 p_blocks_max;
166166 getBlocksInViewRange (cam_pos_nodes, &p_blocks_min, &p_blocks_max);
167167
168+ // Read the vision range, unless unlimited range is enabled.
169+ float range = m_control.range_all ? 1e7 : m_control.wanted_range ;
170+
168171 // Number of blocks currently loaded by the client
169172 u32 blocks_loaded = 0 ;
170173 // Number of blocks with mesh in rendering range
@@ -182,6 +185,7 @@ void ClientMap::updateDrawList()
182185 occlusion_culling_enabled = false ;
183186 }
184187
188+
185189 // Uncomment to debug occluded blocks in the wireframe mode
186190 // TODO: Include this as a flag for an extended debugging setting
187191 // if (occlusion_culling_enabled && m_control.show_wireframe)
@@ -218,32 +222,34 @@ void ClientMap::updateDrawList()
218222 continue ;
219223 }
220224
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 ;
224227
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.
229232
233+ // Keep the block alive as long as it is in range.
234+ block->resetUsageTimer ();
230235 blocks_in_range_with_mesh++;
231236
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
235244 if ((!m_control.range_all && d > m_control.wanted_range * BS) ||
236245 (occlusion_culling_enabled && isBlockOccluded (block, cam_pos_nodes))) {
237246 blocks_occlusion_culled++;
238247 continue ;
239248 }
240249
241- // This block is in range. Reset usage timer.
242- block->resetUsageTimer ();
243-
244250 // Add to set
245251 block->refGrab ();
246- m_drawlist[block-> getPos () ] = block;
252+ m_drawlist[block_coord ] = block;
247253
248254 sector_blocks_drawn++;
249255 } // foreach sectorblocks
@@ -282,8 +288,6 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
282288 const u32 daynight_ratio = m_client->getEnv ().getDayNightRatio ();
283289
284290 const v3f camera_position = m_camera_position;
285- const v3f camera_direction = m_camera_direction;
286- const f32 camera_fov = m_camera_fov;
287291
288292 /*
289293 Get all blocks and draw all visible ones
@@ -310,11 +314,10 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
310314 if (!block->mesh )
311315 continue ;
312316
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+
318321 // Mesh animation
319322 if (pass == scene::ESNRP_SOLID) {
320323 // MutexAutoLock lock(block->mesh_mutex);
0 commit comments