mirror of
https://github.com/minetest/minetest.git
synced 2024-11-30 03:23:45 +01:00
Keep mapblocks in memory if they're in range (#10714)
Some other minor parts of clientmap.cpp have been cleaned up along the way
This commit is contained in:
parent
3edb1ddb81
commit
225e69063f
@ -165,6 +165,9 @@ void ClientMap::updateDrawList()
|
|||||||
v3s16 p_blocks_max;
|
v3s16 p_blocks_max;
|
||||||
getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max);
|
getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max);
|
||||||
|
|
||||||
|
// Read the vision range, unless unlimited range is enabled.
|
||||||
|
float range = m_control.range_all ? 1e7 : m_control.wanted_range;
|
||||||
|
|
||||||
// Number of blocks currently loaded by the client
|
// Number of blocks currently loaded by the client
|
||||||
u32 blocks_loaded = 0;
|
u32 blocks_loaded = 0;
|
||||||
// Number of blocks with mesh in rendering range
|
// Number of blocks with mesh in rendering range
|
||||||
@ -182,6 +185,7 @@ void ClientMap::updateDrawList()
|
|||||||
occlusion_culling_enabled = false;
|
occlusion_culling_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Uncomment to debug occluded blocks in the wireframe mode
|
// Uncomment to debug occluded blocks in the wireframe mode
|
||||||
// TODO: Include this as a flag for an extended debugging setting
|
// TODO: Include this as a flag for an extended debugging setting
|
||||||
//if (occlusion_culling_enabled && m_control.show_wireframe)
|
//if (occlusion_culling_enabled && m_control.show_wireframe)
|
||||||
@ -218,32 +222,34 @@ void ClientMap::updateDrawList()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float range = 100000 * BS;
|
v3s16 block_coord = block->getPos();
|
||||||
if (!m_control.range_all)
|
v3s16 block_position = block->getPosRelative() + MAP_BLOCKSIZE / 2;
|
||||||
range = m_control.wanted_range * BS;
|
|
||||||
|
|
||||||
float d = 0.0;
|
// First, perform a simple distance check, with a padding of one extra block.
|
||||||
if (!isBlockInSight(block->getPos(), camera_position,
|
if (!m_control.range_all &&
|
||||||
camera_direction, camera_fov, range, &d))
|
block_position.getDistanceFrom(cam_pos_nodes) > range + MAP_BLOCKSIZE)
|
||||||
continue;
|
continue; // Out of range, skip.
|
||||||
|
|
||||||
|
// Keep the block alive as long as it is in range.
|
||||||
|
block->resetUsageTimer();
|
||||||
blocks_in_range_with_mesh++;
|
blocks_in_range_with_mesh++;
|
||||||
|
|
||||||
/*
|
// Frustum culling
|
||||||
Occlusion culling
|
float d = 0.0;
|
||||||
*/
|
if (!isBlockInSight(block_coord, camera_position,
|
||||||
|
camera_direction, camera_fov, range * BS, &d))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Occlusion culling
|
||||||
if ((!m_control.range_all && d > m_control.wanted_range * BS) ||
|
if ((!m_control.range_all && d > m_control.wanted_range * BS) ||
|
||||||
(occlusion_culling_enabled && isBlockOccluded(block, cam_pos_nodes))) {
|
(occlusion_culling_enabled && isBlockOccluded(block, cam_pos_nodes))) {
|
||||||
blocks_occlusion_culled++;
|
blocks_occlusion_culled++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This block is in range. Reset usage timer.
|
|
||||||
block->resetUsageTimer();
|
|
||||||
|
|
||||||
// Add to set
|
// Add to set
|
||||||
block->refGrab();
|
block->refGrab();
|
||||||
m_drawlist[block->getPos()] = block;
|
m_drawlist[block_coord] = block;
|
||||||
|
|
||||||
sector_blocks_drawn++;
|
sector_blocks_drawn++;
|
||||||
} // foreach sectorblocks
|
} // foreach sectorblocks
|
||||||
@ -282,8 +288,6 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||||||
const u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
|
const u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
|
||||||
|
|
||||||
const v3f camera_position = m_camera_position;
|
const v3f camera_position = m_camera_position;
|
||||||
const v3f camera_direction = m_camera_direction;
|
|
||||||
const f32 camera_fov = m_camera_fov;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Get all blocks and draw all visible ones
|
Get all blocks and draw all visible ones
|
||||||
@ -310,10 +314,9 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||||||
if (!block->mesh)
|
if (!block->mesh)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
float d = 0.0;
|
v3f block_pos_r = intToFloat(block->getPosRelative() + MAP_BLOCKSIZE / 2, BS);
|
||||||
if (!isBlockInSight(block->getPos(), camera_position,
|
float d = camera_position.getDistanceFrom(block_pos_r);
|
||||||
camera_direction, camera_fov, 100000 * BS, &d))
|
d = MYMAX(0,d - BLOCK_MAX_RADIUS);
|
||||||
continue;
|
|
||||||
|
|
||||||
// Mesh animation
|
// Mesh animation
|
||||||
if (pass == scene::ESNRP_SOLID) {
|
if (pass == scene::ESNRP_SOLID) {
|
||||||
|
@ -106,10 +106,6 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed)
|
|||||||
bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
|
bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
|
||||||
f32 camera_fov, f32 range, f32 *distance_ptr)
|
f32 camera_fov, f32 range, f32 *distance_ptr)
|
||||||
{
|
{
|
||||||
// Maximum radius of a block. The magic number is
|
|
||||||
// sqrt(3.0) / 2.0 in literal form.
|
|
||||||
static constexpr const f32 block_max_radius = 0.866025403784f * MAP_BLOCKSIZE * BS;
|
|
||||||
|
|
||||||
v3s16 blockpos_nodes = blockpos_b * MAP_BLOCKSIZE;
|
v3s16 blockpos_nodes = blockpos_b * MAP_BLOCKSIZE;
|
||||||
|
|
||||||
// Block center position
|
// Block center position
|
||||||
@ -123,7 +119,7 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
|
|||||||
v3f blockpos_relative = blockpos - camera_pos;
|
v3f blockpos_relative = blockpos - camera_pos;
|
||||||
|
|
||||||
// Total distance
|
// Total distance
|
||||||
f32 d = MYMAX(0, blockpos_relative.getLength() - block_max_radius);
|
f32 d = MYMAX(0, blockpos_relative.getLength() - BLOCK_MAX_RADIUS);
|
||||||
|
|
||||||
if (distance_ptr)
|
if (distance_ptr)
|
||||||
*distance_ptr = d;
|
*distance_ptr = d;
|
||||||
@ -141,7 +137,7 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
|
|||||||
// such that a block that has any portion visible with the
|
// such that a block that has any portion visible with the
|
||||||
// current camera position will have the center visible at the
|
// current camera position will have the center visible at the
|
||||||
// adjusted postion
|
// adjusted postion
|
||||||
f32 adjdist = block_max_radius / cos((M_PI - camera_fov) / 2);
|
f32 adjdist = BLOCK_MAX_RADIUS / cos((M_PI - camera_fov) / 2);
|
||||||
|
|
||||||
// Block position relative to adjusted camera
|
// Block position relative to adjusted camera
|
||||||
v3f blockpos_adj = blockpos - (camera_pos - camera_dir * adjdist);
|
v3f blockpos_adj = blockpos - (camera_pos - camera_dir * adjdist);
|
||||||
|
@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "basic_macros.h"
|
#include "basic_macros.h"
|
||||||
|
#include "constants.h"
|
||||||
#include "irrlichttypes.h"
|
#include "irrlichttypes.h"
|
||||||
#include "irr_v2d.h"
|
#include "irr_v2d.h"
|
||||||
#include "irr_v3d.h"
|
#include "irr_v3d.h"
|
||||||
@ -36,6 +37,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
y = temp; \
|
y = temp; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
// Maximum radius of a block. The magic number is
|
||||||
|
// sqrt(3.0) / 2.0 in literal form.
|
||||||
|
static constexpr const f32 BLOCK_MAX_RADIUS = 0.866025403784f * MAP_BLOCKSIZE * BS;
|
||||||
|
|
||||||
inline s16 getContainerPos(s16 p, s16 d)
|
inline s16 getContainerPos(s16 p, s16 d)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user