aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/client.cpp43
-rw-r--r--src/client/clientmap.cpp37
-rw-r--r--src/client/clientmap.h2
-rw-r--r--src/client/content_mapblock.cpp6
-rw-r--r--src/client/mapblock_mesh.cpp124
-rw-r--r--src/client/mapblock_mesh.h22
-rw-r--r--src/client/mesh_generator_thread.cpp56
-rw-r--r--src/client/mesh_generator_thread.h7
-rw-r--r--src/client/meshgen/collector.cpp4
-rw-r--r--src/client/meshgen/collector.h5
-rw-r--r--src/client/wieldmesh.cpp2
-rw-r--r--src/map.cpp7
-rw-r--r--src/util/directiontables.cpp72
-rw-r--r--src/util/directiontables.h3
14 files changed, 269 insertions, 121 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp
index 9a7e1498f..66dee613f 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -41,6 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "filesys.h"
#include "mapblock_mesh.h"
#include "mapblock.h"
+#include "mapsector.h"
#include "minimap.h"
#include "modchannels.h"
#include "content/mods.h"
@@ -555,19 +556,27 @@ void Client::step(float dtime)
{
num_processed_meshes++;
- MinimapMapblock *minimap_mapblock = NULL;
+ std::vector<MinimapMapblock*> minimap_mapblocks;
bool do_mapper_update = true;
- MapBlock *block = m_env.getMap().getBlockNoCreateNoEx(r.p);
+ MapSector *sector = m_env.getMap().emergeSector(v2s16(r.p.X, r.p.Z));
+
+ MapBlock *block = sector->getBlockNoCreateNoEx(r.p.Y);
+
+ // The block in question is not visible (perhaps it is culled at the server),
+ // create a blank block just to hold the 2x2x2 mesh.
+ // If the block becomes visible later it will replace the blank block.
+ if (!block && r.mesh)
+ block = sector->createBlankBlock(r.p.Y);
+
if (block) {
// Delete the old mesh
delete block->mesh;
block->mesh = nullptr;
if (r.mesh) {
- block->solid_sides = r.solid_sides;
- minimap_mapblock = r.mesh->moveMinimapMapblock();
- if (minimap_mapblock == NULL)
+ minimap_mapblocks = r.mesh->moveMinimapMapblocks();
+ if (minimap_mapblocks.empty())
do_mapper_update = false;
bool is_empty = true;
@@ -588,16 +597,32 @@ void Client::step(float dtime)
delete r.mesh;
}
- if (m_minimap && do_mapper_update)
- m_minimap->addBlock(r.p, minimap_mapblock);
+ for (auto p : r.solid_sides) {
+ auto block = m_env.getMap().getBlockNoCreateNoEx(p.first);
+ if (block)
+ block->solid_sides = p.second;
+ }
+
+ if (m_minimap && do_mapper_update) {
+ v3s16 ofs;
+
+ // See also mapblock_mesh.cpp for the code that creates the array of minimap blocks.
+ for (ofs.Z = 0; ofs.Z <= 1; ofs.Z++)
+ for (ofs.Y = 0; ofs.Y <= 1; ofs.Y++)
+ for (ofs.X = 0; ofs.X <= 1; ofs.X++) {
+ size_t i = ofs.Z * 4 + ofs.Y * 2 + ofs.X;
+ if (i < minimap_mapblocks.size() && minimap_mapblocks[i])
+ m_minimap->addBlock(r.p + ofs, minimap_mapblocks[i]);
+ }
+ }
- if (r.ack_block_to_server) {
+ for (auto p : r.ack_list) {
if (blocks_to_ack.size() == 255) {
sendGotBlocks(blocks_to_ack);
blocks_to_ack.clear();
}
- blocks_to_ack.emplace_back(r.p);
+ blocks_to_ack.emplace_back(p);
}
for (auto block : r.map_blocks)
diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp
index 34d99e07d..146531d8b 100644
--- a/src/client/clientmap.cpp
+++ b/src/client/clientmap.cpp
@@ -298,6 +298,8 @@ void ClientMap::updateDrawList()
blocks_to_consider.push(camera_block);
blocks_seen.getChunk(camera_block).getBits(camera_block) = 0x07; // mark all sides as visible
+ std::set<v3s16> shortlist;
+
// Recursively walk the space and pick mapblocks for drawing
while (blocks_to_consider.size() > 0) {
@@ -369,11 +371,13 @@ void ClientMap::updateDrawList()
continue;
}
- // The block is visible, add to the draw list
- if (mesh) {
- // Add to set
+ // Block meshes are stored in blocks where all coordinates are even (lowest bit set to 0)
+ // Add them to the de-dup set.
+ shortlist.emplace(block_coord.X & ~1, block_coord.Y & ~1, block_coord.Z & ~1);
+ // All other blocks we can grab and add to the drawlist right away.
+ if (block && m_drawlist.emplace(block_coord, block).second) {
+ // only grab the ref if the block exists and was not in the list
block->refGrab();
- m_drawlist[block_coord] = block;
}
// Decide which sides to traverse next or to block away
@@ -474,6 +478,16 @@ void ClientMap::updateDrawList()
}
}
+ g_profiler->avg("MapBlocks shortlist [#]", shortlist.size());
+
+ for (auto pos : shortlist) {
+ MapBlock * block = getBlockNoCreateNoEx(pos);
+ if (block && m_drawlist.emplace(pos, block).second) {
+ // only grab the ref if the block exists and was not in the list
+ block->refGrab();
+ }
+ }
+
g_profiler->avg("MapBlocks occlusion culled [#]", blocks_occlusion_culled);
g_profiler->avg("MapBlocks sides skipped [#]", sides_skipped);
g_profiler->avg("MapBlocks examined [#]", blocks_visited);
@@ -597,7 +611,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
MapBlock *block = i.second;
MapBlockMesh *block_mesh = block->mesh;
- // If the mesh of the block happened to get deleted, ignore it
+ // Meshes are only stored every 8-th block (where all coordinates are even),
+ // but we keep all the visible blocks in the draw list to prevent client
+ // from dropping them.
+ // On top of that, in some cases block mesh can be removed
+ // before the block is removed from the draw list.
if (!block_mesh)
continue;
@@ -720,7 +738,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
material.TextureLayer[ShadowRenderer::TEXTURE_LAYER_SHADOW].Texture = nullptr;
}
- v3f block_wpos = intToFloat(descriptor.m_pos * MAP_BLOCKSIZE, BS);
+ v3f block_wpos = intToFloat(descriptor.m_pos / 8 * 8 * MAP_BLOCKSIZE, BS);
m.setTranslation(block_wpos - offset);
driver->setTransform(video::ETS_WORLD, m);
@@ -1046,7 +1064,7 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver,
++material_swaps;
}
- v3f block_wpos = intToFloat(descriptor.m_pos * MAP_BLOCKSIZE, BS);
+ v3f block_wpos = intToFloat(descriptor.m_pos / 8 * 8 * MAP_BLOCKSIZE, BS);
m.setTranslation(block_wpos - offset);
driver->setTransform(video::ETS_WORLD, m);
@@ -1133,6 +1151,11 @@ void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir,
g_profiler->avg("SHADOW MapBlocks loaded [#]", blocks_loaded);
}
+void ClientMap::reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks)
+{
+ g_profiler->avg("CM::reportMetrics loaded blocks [#]", all_blocks);
+}
+
void ClientMap::updateTransparentMeshBuffers()
{
ScopeProfiler sp(g_profiler, "CM::updateTransparentMeshBuffers", SPT_AVG);
diff --git a/src/client/clientmap.h b/src/client/clientmap.h
index cc68c1c15..41f281a8a 100644
--- a/src/client/clientmap.h
+++ b/src/client/clientmap.h
@@ -140,6 +140,8 @@ public:
void onSettingChanged(const std::string &name);
+protected:
+ void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override;
private:
// update the vertex order in transparent mesh buffers
diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp
index 1cd1f1441..4db72c75f 100644
--- a/src/client/content_mapblock.cpp
+++ b/src/client/content_mapblock.cpp
@@ -1619,9 +1619,9 @@ void MapblockMeshGenerator::drawNode()
*/
void MapblockMeshGenerator::generate()
{
- for (p.Z = 0; p.Z < MAP_BLOCKSIZE; p.Z++)
- for (p.Y = 0; p.Y < MAP_BLOCKSIZE; p.Y++)
- for (p.X = 0; p.X < MAP_BLOCKSIZE; p.X++) {
+ for (p.Z = 0; p.Z < data->side_length; p.Z++)
+ for (p.Y = 0; p.Y < data->side_length; p.Y++)
+ for (p.X = 0; p.X < data->side_length; p.X++) {
n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
f = &nodedef->get(n);
drawNode();
diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp
index 7eba29624..c0931a570 100644
--- a/src/client/mapblock_mesh.cpp
+++ b/src/client/mapblock_mesh.cpp
@@ -49,7 +49,7 @@ void MeshMakeData::fillBlockDataBegin(const v3s16 &blockpos)
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));
+ blockpos_nodes + v3s16(1,1,1) * (side_length + MAP_BLOCKSIZE /* extra layer of blocks around the mesh */) - v3s16(1,1,1));
m_vmanip.addArea(voxel_area);
}
@@ -63,23 +63,6 @@ void MeshMakeData::fillBlockData(const v3s16 &block_offset, MapNode *data)
m_vmanip.copyFrom(data, data_area, v3s16(0,0,0), blockpos_nodes, data_size);
}
-void MeshMakeData::fill(MapBlock *block)
-{
- fillBlockDataBegin(block->getPos());
-
- fillBlockData(v3s16(0,0,0), block->getData());
-
- // Get map for reading neighbor blocks
- Map *map = block->getParent();
-
- for (const v3s16 &dir : g_26dirs) {
- v3s16 bp = m_blockpos + dir;
- MapBlock *b = map->getBlockNoCreateNoEx(bp);
- if(b)
- fillBlockData(dir, b->getData());
- }
-}
-
void MeshMakeData::setCrack(int crack_level, v3s16 crack_pos)
{
if (crack_level >= 0)
@@ -883,7 +866,7 @@ static void updateFastFaceRow(
// Unroll this variable which has a significant build cost
TileSpec next_tile;
- for (u16 j = 0; j < MAP_BLOCKSIZE; j++) {
+ for (u16 j = 0; j < data->side_length; j++) {
// If tiling can be done, this is set to false in the next step
bool next_is_different = true;
@@ -894,7 +877,7 @@ static void updateFastFaceRow(
// If at last position, there is nothing to compare to and
// the face must be drawn anyway
- if (j != MAP_BLOCKSIZE - 1) {
+ if (j != data->side_length - 1) {
p += translate_dir;
getTileInfo(data, p, face_dir,
@@ -957,8 +940,8 @@ static void updateAllFastFaceRows(MeshMakeData *data,
/*
Go through every y,z and get top(y+) faces in rows of x+
*/
- for (s16 y = 0; y < MAP_BLOCKSIZE; y++)
- for (s16 z = 0; z < MAP_BLOCKSIZE; z++)
+ for (s16 y = 0; y < data->side_length; y++)
+ for (s16 z = 0; z < data->side_length; z++)
updateFastFaceRow(data,
v3s16(0, y, z),
v3s16(1, 0, 0), //dir
@@ -969,8 +952,8 @@ static void updateAllFastFaceRows(MeshMakeData *data,
/*
Go through every x,y and get right(x+) faces in rows of z+
*/
- for (s16 x = 0; x < MAP_BLOCKSIZE; x++)
- for (s16 y = 0; y < MAP_BLOCKSIZE; y++)
+ for (s16 x = 0; x < data->side_length; x++)
+ for (s16 y = 0; y < data->side_length; y++)
updateFastFaceRow(data,
v3s16(x, y, 0),
v3s16(0, 0, 1), //dir
@@ -981,8 +964,8 @@ static void updateAllFastFaceRows(MeshMakeData *data,
/*
Go through every y,z and get back(z+) faces in rows of x+
*/
- for (s16 z = 0; z < MAP_BLOCKSIZE; z++)
- for (s16 y = 0; y < MAP_BLOCKSIZE; y++)
+ for (s16 z = 0; z < data->side_length; z++)
+ for (s16 y = 0; y < data->side_length; y++)
updateFastFaceRow(data,
v3s16(0, y, z),
v3s16(1, 0, 0), //dir
@@ -1009,7 +992,7 @@ static void applyTileColor(PreMeshBuffer &pmb)
MapBlockBspTree
*/
-void MapBlockBspTree::buildTree(const std::vector<MeshTriangle> *triangles)
+void MapBlockBspTree::buildTree(const std::vector<MeshTriangle> *triangles, u16 side_length)
{
this->triangles = triangles;
@@ -1024,7 +1007,7 @@ void MapBlockBspTree::buildTree(const std::vector<MeshTriangle> *triangles)
if (!indexes.empty()) {
// Start in the center of the block with increment of one quarter in each direction
- root = buildTree(v3f(1, 0, 0), v3f((MAP_BLOCKSIZE + 1) * 0.5f * BS), MAP_BLOCKSIZE * 0.25f * BS, indexes, 0);
+ root = buildTree(v3f(1, 0, 0), v3f((side_length + 1) * 0.5f * BS), side_length * 0.25f * BS, indexes, 0);
} else {
root = -1;
}
@@ -1183,7 +1166,6 @@ void PartialMeshBuffer::afterDraw() const
*/
MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
- m_minimap_mapblock(NULL),
m_tsrc(data->m_client->getTextureSource()),
m_shdrsrc(data->m_client->getShaderSource()),
m_animation_force_timer(0), // force initial animation
@@ -1195,10 +1177,23 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
m_enable_shaders = data->m_use_shaders;
m_enable_vbo = g_settings->getBool("enable_vbo");
- if (data->m_client->getMinimap()) {
- m_minimap_mapblock = new MinimapMapblock;
- m_minimap_mapblock->getMinimapNodes(
- &data->m_vmanip, data->m_blockpos * MAP_BLOCKSIZE);
+ v3s16 bp = data->m_blockpos;
+ // Only generate minimap mapblocks at even coordinates.
+ if (((bp.X | bp.Y | bp.Z) & 1) == 0 && data->m_client->getMinimap()) {
+ m_minimap_mapblocks.resize(8, nullptr);
+ v3s16 ofs;
+
+ // See also client.cpp for the code that reads the array of minimap blocks.
+ for (ofs.Z = 0; ofs.Z <= 1; ofs.Z++)
+ for (ofs.Y = 0; ofs.Y <= 1; ofs.Y++)
+ for (ofs.X = 0; ofs.X <= 1; ofs.X++) {
+ v3s16 p = (bp + ofs) * MAP_BLOCKSIZE;
+ if (data->m_vmanip.getNodeNoEx(p).getContent() != CONTENT_IGNORE) {
+ MinimapMapblock *block = new MinimapMapblock;
+ m_minimap_mapblocks[ofs.Z * 4 + ofs.Y * 2 + ofs.X] = block;
+ block->getMinimapNodes(&data->m_vmanip, p);
+ }
+ }
}
// 4-21ms for MAP_BLOCKSIZE=16 (NOTE: probably outdated)
@@ -1226,7 +1221,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
Convert FastFaces to MeshCollector
*/
- MeshCollector collector(m_bounding_sphere_center);
+ v3f offset = intToFloat((data->m_blockpos - data->m_blockpos / 8 * 8) * MAP_BLOCKSIZE, BS);
+ MeshCollector collector(m_bounding_sphere_center, offset);
{
// avg 0ms (100ms spikes when loading textures the first time)
@@ -1386,7 +1382,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
}
//std::cout<<"added "<<fastfaces.getSize()<<" faces."<<std::endl;
- m_bsp_tree.buildTree(&m_transparent_triangles);
+ m_bsp_tree.buildTree(&m_transparent_triangles, data->side_length);
// Check if animation is required for this mesh
m_has_animation =
@@ -1408,7 +1404,8 @@ MapBlockMesh::~MapBlockMesh()
#endif
m->drop();
}
- delete m_minimap_mapblock;
+ for (MinimapMapblock *block : m_minimap_mapblocks)
+ delete block;
}
bool MapBlockMesh::animate(bool faraway, float time, int crack,
@@ -1583,30 +1580,39 @@ video::SColor encode_light(u16 light, u8 emissive_light)
return video::SColor(r, b, b, b);
}
-u8 get_solid_sides(MeshMakeData *data)
+std::unordered_map<v3s16, u8> get_solid_sides(MeshMakeData *data)
{
- v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
- const NodeDefManager *ndef = data->m_client->ndef();
-
- u8 result = 0x3F; // all sides solid;
-
- for (s16 i = 0; i < MAP_BLOCKSIZE && result != 0; i++)
- for (s16 j = 0; j < MAP_BLOCKSIZE && result != 0; j++) {
- v3s16 positions[6] = {
- v3s16(0, i, j),
- v3s16(MAP_BLOCKSIZE - 1, i, j),
- v3s16(i, 0, j),
- v3s16(i, MAP_BLOCKSIZE - 1, j),
- v3s16(i, j, 0),
- v3s16(i, j, MAP_BLOCKSIZE - 1)
- };
-
- for (u8 k = 0; k < 6; k++) {
- const MapNode &top = data->m_vmanip.getNodeRefUnsafe(blockpos_nodes + positions[k]);
- if (ndef->get(top).solidness != 2)
- result &= ~(1 << k);
+ std::unordered_map<v3s16, u8> results;
+ v3s16 ofs;
+
+ for (ofs.X = 0; ofs.X < 2; ofs.X++)
+ for (ofs.Y = 0; ofs.Y < 2; ofs.Y++)
+ for (ofs.Z = 0; ofs.Z < 2; ofs.Z++) {
+ v3s16 blockpos = data->m_blockpos + ofs;
+ v3s16 blockpos_nodes = blockpos * MAP_BLOCKSIZE;
+ const NodeDefManager *ndef = data->m_client->ndef();
+
+ u8 result = 0x3F; // all sides solid;
+
+ for (s16 i = 0; i < MAP_BLOCKSIZE && result != 0; i++)
+ for (s16 j = 0; j < MAP_BLOCKSIZE && result != 0; j++) {
+ v3s16 positions[6] = {
+ v3s16(0, i, j),
+ v3s16(MAP_BLOCKSIZE - 1, i, j),
+ v3s16(i, 0, j),
+ v3s16(i, MAP_BLOCKSIZE - 1, j),
+ v3s16(i, j, 0),
+ v3s16(i, j, MAP_BLOCKSIZE - 1)
+ };
+
+ for (u8 k = 0; k < 6; k++) {
+ const MapNode &top = data->m_vmanip.getNodeRefUnsafe(blockpos_nodes + positions[k]);
+ if (ndef->get(top).solidness != 2)
+ result &= ~(1 << k);
+ }
}
- }
- return result;
+ results[blockpos] = result;
+ }
+ return results;
}
diff --git a/src/client/mapblock_mesh.h b/src/client/mapblock_mesh.h
index 7f6185c3a..82e9a0f22 100644
--- a/src/client/mapblock_mesh.h
+++ b/src/client/mapblock_mesh.h
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "voxel.h"
#include <array>
#include <map>
+#include <unordered_map>
class Client;
class IShaderSource;
@@ -42,6 +43,7 @@ struct MeshMakeData
v3s16 m_blockpos = v3s16(-1337,-1337,-1337);
v3s16 m_crack_pos_relative = v3s16(-1337,-1337,-1337);
bool m_smooth_lighting = false;
+ u16 side_length = MAP_BLOCKSIZE;
Client *m_client;
bool m_use_shaders;
@@ -55,12 +57,6 @@ struct MeshMakeData
void fillBlockData(const v3s16 &block_offset, MapNode *data);
/*
- Copy central data directly from block, and other data from
- parent of block.
- */
- void fill(MapBlock *block);
-
- /*
Set the (node) position of a crack
*/
void setCrack(int crack_level, v3s16 crack_pos);
@@ -108,7 +104,7 @@ class MapBlockBspTree
public:
MapBlockBspTree() {}
- void buildTree(const std::vector<MeshTriangle> *triangles);
+ void buildTree(const std::vector<MeshTriangle> *triangles, u16 side_lingth);
void traverse(v3f viewpoint, std::vector<s32> &output) const
{
@@ -203,11 +199,11 @@ public:
return m_mesh[layer];
}
- MinimapMapblock *moveMinimapMapblock()
+ std::vector<MinimapMapblock*> moveMinimapMapblocks()
{
- MinimapMapblock *p = m_minimap_mapblock;
- m_minimap_mapblock = NULL;
- return p;
+ std::vector<MinimapMapblock*> minimap_mapblocks;
+ minimap_mapblocks.swap(m_minimap_mapblocks);
+ return minimap_mapblocks;
}
bool isAnimationForced() const
@@ -245,7 +241,7 @@ private:
};
scene::IMesh *m_mesh[MAX_TILE_LAYERS];
- MinimapMapblock *m_minimap_mapblock;
+ std::vector<MinimapMapblock*> m_minimap_mapblocks;
ITextureSource *m_tsrc;
IShaderSource *m_shdrsrc;
@@ -344,4 +340,4 @@ void getNodeTile(MapNode mn, const v3s16 &p, const v3s16 &dir, MeshMakeData *dat
/// Return bitset of the sides of the mapblock that consist of solid nodes only
/// Bits:
/// 0 0 -Z +Z -X +X -Y +Y
-u8 get_solid_sides(MeshMakeData *data);
+std::unordered_map<v3s16, u8> get_solid_sides(MeshMakeData *data);
diff --git a/src/client/mesh_generator_thread.cpp b/src/client/mesh_generator_thread.cpp
index adea057d6..6d1fe2bda 100644
--- a/src/client/mesh_generator_thread.cpp
+++ b/src/client/mesh_generator_thread.cpp
@@ -25,6 +25,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "map.h"
#include "util/directiontables.h"
+static class BlockPlaceholder {
+public:
+ MapNode data[MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE];
+
+ BlockPlaceholder()
+ {
+ for (std::size_t i = 0; i < MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE; i++)
+ data[i] = MapNode(CONTENT_IGNORE);
+ }
+
+} block_placeholder;
/*
QueuedMeshUpdate
*/
@@ -66,28 +77,31 @@ bool MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool
MutexAutoLock lock(m_mutex);
+ // Mesh is placed at even positions at all coordinates
+ // (every 8-th block) and will cover 8 blocks
+ v3s16 mesh_position(p.X & ~1, p.Y & ~1, p.Z & ~1);
/*
Mark the block as urgent if requested
*/
if (urgent)
- m_urgents.insert(p);
+ m_urgents.insert(mesh_position);
/*
Find if block is already in queue.
If it is, update the data and quit.
*/
for (QueuedMeshUpdate *q : m_queue) {
- if (q->p == p) {
+ if (q->p == mesh_position) {
// NOTE: We are not adding a new position to the queue, thus
// refcount_from_queue stays the same.
if(ack_block_to_server)
- q->ack_block_to_server = true;
+ q->ack_list.push_back(p);
q->crack_level = m_client->getCrackLevel();
q->crack_pos = m_client->getCrackPos();
q->urgent |= urgent;
- for (std::size_t i = 1; i < q->map_blocks.size(); i++) {
+ for (std::size_t i = 0; i < q->map_blocks.size(); i++) {
if (!q->map_blocks[i]) {
- MapBlock *block = map->getBlockNoCreateNoEx(q->p + g_26dirs[i - 1]);
+ MapBlock *block = map->getBlockNoCreateNoEx(q->p + g_64dirs[i]);
if (block) {
block->refGrab();
q->map_blocks[i] = block;
@@ -99,16 +113,13 @@ bool MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool
}
/*
- Cache the block data (force-update the center block, don't update the
- neighbors but get them if they aren't already cached)
+ Make a list of blocks necessary for mesh generation and lock the blocks in memory.
*/
- std::vector<MapBlock *> cached_blocks;
- cached_blocks.reserve(3*3*3);
- cached_blocks.push_back(main_block);
- main_block->refGrab();
- for (v3s16 dp : g_26dirs) {
- MapBlock *block = map->getBlockNoCreateNoEx(p + dp);
- cached_blocks.push_back(block);
+ std::vector<MapBlock *> map_blocks;
+ map_blocks.reserve(4*4*4);
+ for (v3s16 dp : g_64dirs) {
+ MapBlock *block = map->getBlockNoCreateNoEx(mesh_position + dp);
+ map_blocks.push_back(block);
if (block)
block->refGrab();
}
@@ -117,12 +128,13 @@ bool MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool
Add the block
*/
QueuedMeshUpdate *q = new QueuedMeshUpdate;
- q->p = p;
- q->ack_block_to_server = ack_block_to_server;
+ q->p = mesh_position;
+ if(ack_block_to_server)
+ q->ack_list.push_back(p);
q->crack_level = m_client->getCrackLevel();
q->crack_pos = m_client->getCrackPos();
q->urgent = urgent;
- q->map_blocks = std::move(cached_blocks);
+ q->map_blocks = std::move(map_blocks);
m_queue.push_back(q);
return true;
@@ -170,12 +182,14 @@ void MeshUpdateQueue::fillDataFromMapBlocks(QueuedMeshUpdate *q)
{
MeshMakeData *data = new MeshMakeData(m_client, m_cache_enable_shaders);
q->data = data;
+ data->side_length = 2 * MAP_BLOCKSIZE;
data->fillBlockDataBegin(q->p);
- for (MapBlock *block : q->map_blocks)
- if (block)
- data->fillBlockData(block->getPos() - q->p, block->getData());
+ for (std::size_t i = 0; i < 64; i++) {
+ MapBlock *block = q->map_blocks[i];
+ data->fillBlockData(g_64dirs[i], block ? block->getData() : block_placeholder.data);
+ }
data->setCrack(q->crack_level, q->crack_pos);
data->setSmoothLighting(m_cache_smooth_lighting);
@@ -208,7 +222,7 @@ void MeshUpdateWorkerThread::doUpdate()
r.p = q->p;
r.mesh = mesh_new;
r.solid_sides = get_solid_sides(q->data);
- r.ack_block_to_server = q->ack_block_to_server;
+ r.ack_list = std::move(q->ack_list);
r.urgent = q->urgent;
r.map_blocks = q->map_blocks;
diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h
index cfcb1df09..3097f3704 100644
--- a/src/client/mesh_generator_thread.h
+++ b/src/client/mesh_generator_thread.h
@@ -28,11 +28,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/thread.h"
#include <vector>
#include <memory>
+#include <unordered_map>
struct QueuedMeshUpdate
{
v3s16 p = v3s16(-1337, -1337, -1337);
- bool ack_block_to_server = false;
+ std::vector<v3s16> ack_list;
int crack_level = -1;
v3s16 crack_pos;
MeshMakeData *data = nullptr; // This is generated in MeshUpdateQueue::pop()
@@ -96,8 +97,8 @@ struct MeshUpdateResult
{
v3s16 p = v3s16(-1338, -1338, -1338);
MapBlockMesh *mesh = nullptr;
- u8 solid_sides = 0;
- bool ack_block_to_server = false;
+ std::unordered_map<v3s16, u8> solid_sides;
+ std::vector<v3s16> ack_list;
bool urgent = false;
std::vector<MapBlock *> map_blocks;
diff --git a/src/client/meshgen/collector.cpp b/src/client/meshgen/collector.cpp
index c5f4eb976..86c188c3f 100644
--- a/src/client/meshgen/collector.cpp
+++ b/src/client/meshgen/collector.cpp
@@ -46,7 +46,7 @@ void MeshCollector::append(const TileLayer &layer, const video::S3DVertex *verti
u32 vertex_count = p.vertices.size();
for (u32 i = 0; i < numVertices; i++) {
- p.vertices.emplace_back(vertices[i].Pos, vertices[i].Normal,
+ p.vertices.emplace_back(vertices[i].Pos + offset, vertices[i].Normal,
vertices[i].Color, scale * vertices[i].TCoords);
m_bounding_radius_sq = std::max(m_bounding_radius_sq,
(vertices[i].Pos - m_center_pos).getLengthSQ());
@@ -84,7 +84,7 @@ void MeshCollector::append(const TileLayer &layer, const video::S3DVertex *verti
video::SColor color = c;
if (!light_source)
applyFacesShading(color, vertices[i].Normal);
- auto vpos = vertices[i].Pos + pos;
+ auto vpos = vertices[i].Pos + pos + offset;
p.vertices.emplace_back(vpos, vertices[i].Normal, color,
scale * vertices[i].TCoords);
m_bounding_radius_sq = std::max(m_bounding_radius_sq,
diff --git a/src/client/meshgen/collector.h b/src/client/meshgen/collector.h
index c390c53e7..9b49ce72e 100644
--- a/src/client/meshgen/collector.h
+++ b/src/client/meshgen/collector.h
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <array>
#include <vector>
#include "irrlichttypes.h"
+#include "irr_v3d.h"
#include <S3DVertex.h>
#include "client/tile.h"
@@ -40,9 +41,11 @@ struct MeshCollector
// bounding sphere radius and center
f32 m_bounding_radius_sq = 0.0f;
v3f m_center_pos;
+ v3f offset;
// center_pos: pos to use for bounding-sphere, in BS-space
- MeshCollector(const v3f center_pos) : m_center_pos(center_pos) {}
+ // offset: offset added to vertices
+ MeshCollector(const v3f center_pos, v3f offset = v3f()) : m_center_pos(center_pos), offset(offset) {}
// clang-format off
void append(const TileSpec &material,
diff --git a/src/client/wieldmesh.cpp b/src/client/wieldmesh.cpp
index 155b5ecc4..5030ea575 100644
--- a/src/client/wieldmesh.cpp
+++ b/src/client/wieldmesh.cpp
@@ -318,7 +318,7 @@ static scene::SMesh *createSpecialNodeMesh(Client *client, MapNode n,
std::vector<ItemPartColor> *colors, const ContentFeatures &f)
{
MeshMakeData mesh_make_data(client, false);
- MeshCollector collector(v3f(0.0f * BS));
+ MeshCollector collector(v3f(0.0f * BS), v3f());
mesh_make_data.setSmoothLighting(false);
MapblockMeshGenerator gen(&mesh_make_data, &collector,
client->getSceneManager()->getMeshManipulator());
diff --git a/src/map.cpp b/src/map.cpp
index cfe5f126d..59d1a925d 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -325,6 +325,7 @@ void Map::timerUpdate(float dtime, float unload_timeout, s32 max_loaded_blocks,
u32 deleted_blocks_count = 0;
u32 saved_blocks_count = 0;
u32 block_count_all = 0;
+ u32 locked_blocks = 0;
const auto start_time = porting::getTimeUs();
beginSave();
@@ -396,8 +397,10 @@ void Map::timerUpdate(float dtime, float unload_timeout, s32 max_loaded_blocks,
MapBlock *block = b.block;
- if (block->refGet() != 0)
+ if (block->refGet() != 0) {
+ locked_blocks++;
continue;
+ }
v3s16 p = block->getPos();
@@ -442,7 +445,7 @@ void Map::timerUpdate(float dtime, float unload_timeout, s32 max_loaded_blocks,
<<" blocks from memory";
if(save_before_unloading)
infostream<<", of which "<<saved_blocks_count<<" were written";
- infostream<<", "<<block_count_all<<" blocks in memory";
+ infostream<<", "<<block_count_all<<" blocks in memory, " << locked_blocks << " locked";
infostream<<"."<<std::endl;
if(saved_blocks_count != 0){
PrintInfo(infostream); // ServerMap/ClientMap:
diff --git a/src/util/directiontables.cpp b/src/util/directiontables.cpp
index 297058c9c..86ea6a45f 100644
--- a/src/util/directiontables.cpp
+++ b/src/util/directiontables.cpp
@@ -110,6 +110,78 @@ const v3s16 g_27dirs[27] =
v3s16(0,0,0),
};
+const v3s16 g_64dirs[64] =
+{
+ // +right, +top, +back
+ v3s16( -1, -1, -1),
+ v3s16( -1, 0, -1),
+ v3s16( -1, 1, -1),
+ v3s16( -1, 2, -1),
+ v3s16( -1, -1, 0),
+ v3s16( -1, 0, 0),
+ v3s16( -1, 1, 0),
+ v3s16( -1, 2, 0),
+ v3s16( -1, -1, 1),
+ v3s16( -1, 0, 1),
+ v3s16( -1, 1, 1),
+ v3s16( -1, 2, 1),
+ v3s16( -1, -1, 2),
+ v3s16( -1, 0, 2),
+ v3s16( -1, 1, 2),
+ v3s16( -1, 2, 2),
+
+ v3s16( 0, -1, -1),
+ v3s16( 0, 0, -1),
+ v3s16( 0, 1, -1),
+ v3s16( 0, 2, -1),
+ v3s16( 0, -1, 0),
+ v3s16( 0, 0, 0),
+ v3s16( 0, 1, 0),
+ v3s16( 0, 2, 0),
+ v3s16( 0, -1, 1),
+ v3s16( 0, 0, 1),
+ v3s16( 0, 1, 1),
+ v3s16( 0, 2, 1),
+ v3s16( 0, -1, 2),
+ v3s16( 0, 0, 2),
+ v3s16( 0, 1, 2),
+ v3s16( 0, 2, 2),
+
+ v3s16( 1, -1, -1),
+ v3s16( 1, 0, -1),
+ v3s16( 1, 1, -1),
+ v3s16( 1, 2, -1),
+ v3s16( 1, -1, 0),
+ v3s16( 1, 0, 0),
+ v3s16( 1, 1, 0),
+ v3s16( 1, 2, 0),
+ v3s16( 1, -1, 1),
+ v3s16( 1, 0, 1),
+ v3s16( 1, 1, 1),
+ v3s16( 1, 2, 1),
+ v3s16( 1, -1, 2),
+ v3s16( 1, 0, 2),
+ v3s16( 1, 1, 2),
+ v3s16( 1, 2, 2),
+
+ v3s16( 2, -1, -1),
+ v3s16( 2, 0, -1),
+ v3s16( 2, 1, -1),
+ v3s16( 2, 2, -1),
+ v3s16( 2, -1, 0),
+ v3s16( 2, 0, 0),
+ v3s16( 2, 1, 0),
+ v3s16( 2, 2, 0),
+ v3s16( 2, -1, 1),
+ v3s16( 2, 0, 1),
+ v3s16( 2, 1, 1),
+ v3s16( 2, 2, 1),
+ v3s16( 2, -1, 2),
+ v3s16( 2, 0, 2),
+ v3s16( 2, 1, 2),
+ v3s16( 2, 2, 2),
+};
+
const u8 wallmounted_to_facedir[6] = {
20,
0,
diff --git a/src/util/directiontables.h b/src/util/directiontables.h
index 3883a6e37..7cdcebaa4 100644
--- a/src/util/directiontables.h
+++ b/src/util/directiontables.h
@@ -31,6 +31,9 @@ extern const v3s16 g_26dirs[26];
// 26th is (0,0,0)
extern const v3s16 g_27dirs[27];
+// all positions around an octablock in sector-first order
+extern const v3s16 g_64dirs[64];
+
extern const u8 wallmounted_to_facedir[6];
extern const v3s16 wallmounted_dirs[8];