1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

MeshUpdateQueue: Add a MapBlock cache that minimizes the amount of MapBlock copying done in the main thread

Cache size is configurable by the meshgen_block_cache_size (default 20 MB).

New profiler stats:
- MeshUpdateQueue MapBlock cache hit %
- MeshUpdateQueue MapBlock cache size kB

Removes one type of stutter that was seen on the client when received MapBlocks
were being handled. (the "MeshMakeData::fill" stutter)

Kind of related to at least #5239

Originally preceded by these commits, now includes them:
- Move the mesh generator thread into src/mesh_generator_thread.{cpp,h}
- mesh_generator_thread.cpp: Update code style
- MeshUpdateThread: Modify interface to house a different implementation: Actual functionality will be changed by next commits.
- MeshMakeData: Add fillBlockData() interface (so that caller can fill in stuff from eg. a MapBlock cache)
This commit is contained in:
Perttu Ahola 2017-04-15 10:55:52 +03:00 committed by celeron55
parent 4323ad163f
commit 04cc9de8f2
12 changed files with 526 additions and 278 deletions

View file

@ -48,49 +48,43 @@ MeshMakeData::MeshMakeData(Client *client, bool use_shaders,
m_use_tangent_vertices(use_tangent_vertices)
{}
void MeshMakeData::fill(MapBlock *block)
void MeshMakeData::fillBlockDataBegin(const v3s16 &blockpos)
{
m_blockpos = block->getPos();
m_blockpos = blockpos;
v3s16 blockpos_nodes = m_blockpos*MAP_BLOCKSIZE;
/*
Copy data
*/
// Allocate this block + neighbors
m_vmanip.clear();
VoxelArea voxel_area(blockpos_nodes - v3s16(1,1,1) * MAP_BLOCKSIZE,
blockpos_nodes + v3s16(1,1,1) * MAP_BLOCKSIZE*2-v3s16(1,1,1));
m_vmanip.addArea(voxel_area);
}
{
//TimeTaker timer("copy central block data");
// 0ms
void MeshMakeData::fillBlockData(const v3s16 &block_offset, MapNode *data)
{
v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
VoxelArea data_area(v3s16(0,0,0), data_size - v3s16(1,1,1));
// Copy our data
block->copyTo(m_vmanip);
}
{
//TimeTaker timer("copy neighbor block data");
// 0ms
v3s16 bp = m_blockpos + block_offset;
v3s16 blockpos_nodes = bp * MAP_BLOCKSIZE;
m_vmanip.copyFrom(data, data_area, v3s16(0,0,0), blockpos_nodes, data_size);
}
/*
Copy neighbors. This is lightning fast.
Copying only the borders would be *very* slow.
*/
void MeshMakeData::fill(MapBlock *block)
{
fillBlockDataBegin(block->getPos());
// Get map
Map *map = block->getParent();
fillBlockData(v3s16(0,0,0), block->getData());
for(u16 i=0; i<26; i++)
{
const v3s16 &dir = g_26dirs[i];
v3s16 bp = m_blockpos + dir;
MapBlock *b = map->getBlockNoCreateNoEx(bp);
if(b)
b->copyTo(m_vmanip);
}
// Get map for reading neigbhor blocks
Map *map = block->getParent();
for (u16 i=0; i<26; i++) {
const v3s16 &dir = g_26dirs[i];
v3s16 bp = m_blockpos + dir;
MapBlock *b = map->getBlockNoCreateNoEx(bp);
if(b)
fillBlockData(dir, b->getData());
}
}