Apply review feedback.

This commit is contained in:
SFENCE 2024-03-24 18:41:39 +01:00
parent b3ed9af532
commit 8109f07a43
5 changed files with 35 additions and 39 deletions

View File

@ -159,7 +159,10 @@ void ClientMap::updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SCo
if (previous_node != current_node)
m_needs_update_transparent_meshes = true;
// regenerate mapblocks meshes if neccessary
/* update liquid hideable sides materials if neccessary
* This is used to hide specific liquid sides on a liquid-glass boundary
* if the player is in the specific liquid.
*/
if (prev_pos != curr_pos) {
MapNode prev_node = getNode(prev_pos);
MapNode curr_node = getNode(curr_pos);
@ -173,7 +176,7 @@ void ClientMap::updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SCo
m_camera_liquid_source_id = curr_f.liquid_alternative_source_id;
m_camera_liquid_flowing_id = curr_f.liquid_alternative_flowing_id;
for (auto &i : m_drawlist) {
i.second->mesh->updateHiddable(m_camera_liquid_source_id, m_camera_liquid_flowing_id);
i.second->mesh->updateHideable(m_camera_liquid_source_id, m_camera_liquid_flowing_id);
}
}
}
@ -181,7 +184,7 @@ void ClientMap::updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SCo
void ClientMap::updateMesh(MapBlockMesh *mesh)
{
mesh->updateHiddable(m_camera_liquid_source_id, m_camera_liquid_flowing_id);
mesh->updateHideable(m_camera_liquid_source_id, m_camera_liquid_flowing_id);
}
MapSector * ClientMap::emergeSector(v2s16 p2d)
@ -289,6 +292,13 @@ private:
v3s16 volume;
};
void ClientMap::addBlockToDrawList(v3s16 pos, MapBlock *block)
{
block->refGrab();
block->mesh->updateHideable(m_camera_liquid_source_id, m_camera_liquid_flowing_id);
m_drawlist.emplace(pos, block);
}
void ClientMap::updateDrawList()
{
ScopeProfiler sp(g_profiler, "CM::updateDrawList()", SPT_AVG);
@ -424,9 +434,7 @@ void ClientMap::updateDrawList()
block->refGrab();
} else if (mesh) {
// without mesh chunking we can add the block to the drawlist
block->refGrab();
block->mesh->updateHiddable(m_camera_liquid_source_id, m_camera_liquid_flowing_id);
m_drawlist.emplace(block->getPos(), block);
addBlockToDrawList(block->getPos(), block);
}
}
}
@ -533,9 +541,7 @@ void ClientMap::updateDrawList()
}
} else if (mesh) {
// without mesh chunking we can add the block to the drawlist
block->refGrab();
block->mesh->updateHiddable(m_camera_liquid_source_id, m_camera_liquid_flowing_id);
m_drawlist.emplace(block_coord, block);
addBlockToDrawList(block_coord, block);
}
// Decide which sides to traverse next or to block away
@ -646,9 +652,7 @@ void ClientMap::updateDrawList()
for (auto pos : shortlist) {
MapBlock *block = getBlockNoCreateNoEx(pos);
if (block) {
block->refGrab();
block->mesh->updateHiddable(m_camera_liquid_source_id, m_camera_liquid_flowing_id);
m_drawlist.emplace(pos, block);
addBlockToDrawList(pos, block);
}
}

View File

@ -126,6 +126,8 @@ private:
// update the vertex order in transparent mesh buffers
void updateTransparentMeshBuffers();
// help method for updateDrawList
void addBlockToDrawList(v3s16 pos, MapBlock *block);
// Orders blocks by distance to the camera
class MapBlockComparer

View File

@ -426,7 +426,7 @@ void MapblockMeshGenerator::drawSolidNode()
MapNode neighbor = data->m_vmanip.getNodeNoEx(p2);
content_t n2 = neighbor.getContent();
bool backface_culling = cur_node.f->drawtype == NDT_NORMAL;
bool is_hiddable = false;
bool is_hideable = false;
if (n2 == n1)
continue;
if (n2 == CONTENT_IGNORE)
@ -439,7 +439,7 @@ void MapblockMeshGenerator::drawSolidNode()
if (cur_node.f->sameLiquidRender(f2))
continue;
if (f2.drawtype == NDT_GLASSLIKE) {
is_hiddable = true;
is_hideable = true;
}
backface_culling = f2.solidness || f2.visual_solidness;
}
@ -451,7 +451,7 @@ void MapblockMeshGenerator::drawSolidNode()
layer.material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
layer.material_flags |= MATERIAL_FLAG_TILEABLE_HORIZONTAL;
layer.material_flags |= MATERIAL_FLAG_TILEABLE_VERTICAL;
if (is_hiddable) {
if (is_hideable) {
layer.material_flags |= MATERIAL_FLAG_HIDDABLE;
layer.liquid_source_id = cur_node.f->liquid_alternative_source_id;
layer.liquid_flowing_id = cur_node.f->liquid_alternative_flowing_id;

View File

@ -751,10 +751,10 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs
p.layer.texture = (*p.layer.frames)[0].texture;
}
// - Texture hiddable
// - Texture hideable
if (p.layer.material_flags & MATERIAL_FLAG_HIDDABLE) {
// Add to MapBlockMesh to hiddable
auto &info = m_hiddable_info[{layer, i}];
// Add to MapBlockMesh to hideable
auto &info = m_hideable_info[{layer, i}];
info.hidden = false;
info.liquid_source_id = p.layer.liquid_source_id;
info.liquid_flowing_id = p.layer.liquid_flowing_id;
@ -936,10 +936,10 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack,
return true;
}
void MapBlockMesh::updateHiddable(content_t liquid_source_id, content_t liquid_flowing_id)
void MapBlockMesh::updateHideable(content_t liquid_source_id, content_t liquid_flowing_id)
{
// Texture animation
for (auto &it : m_hiddable_info) {
for (auto &it : m_hideable_info) {
const TileLayer &tile = it.second.tile;
scene::IMeshBuffer *buf = m_mesh[it.first.first]->getMeshBuffer(it.first.second);
@ -947,21 +947,11 @@ void MapBlockMesh::updateHiddable(content_t liquid_source_id, content_t liquid_f
bool hide = (it.second.liquid_source_id == liquid_source_id) &&
(it.second.liquid_flowing_id == liquid_flowing_id);
if (it.second.hidden != hide) {
if (hide) {
buf->getMaterial().setTexture(0, m_texture_blank);
if (m_enable_shaders) {
if (tile.normal_texture)
buf->getMaterial().setTexture(1, m_texture_blank);
buf->getMaterial().setTexture(2, m_texture_blank);
}
}
else {
buf->getMaterial().setTexture(0, tile.texture);
if (m_enable_shaders) {
if (tile.normal_texture)
buf->getMaterial().setTexture(1, tile.normal_texture);
buf->getMaterial().setTexture(2, tile.flags_texture);
}
buf->getMaterial().setTexture(0, hide ? m_texture_blank : tile.texture);
if (m_enable_shaders) {
if (tile.normal_texture)
buf->getMaterial().setTexture(1, hide ? m_texture_blank : tile.normal_texture);
buf->getMaterial().setTexture(2, hide ? m_texture_blank : tile.flags_texture);
}
it.second.hidden = hide;
}

View File

@ -194,7 +194,7 @@ public:
// Returns true if anything has been changed.
bool animate(bool faraway, float time, int crack, u32 daynight_ratio);
void updateHiddable(content_t liquid_source_id, content_t liquid_flowing_id);
void updateHideable(content_t liquid_source_id, content_t liquid_flowing_id);
scene::IMesh *getMesh()
{
@ -246,7 +246,7 @@ private:
int frame_offset;
TileLayer tile;
};
struct HiddableInfo {
struct HideableInfo {
bool hidden;
content_t liquid_source_id;
content_t liquid_flowing_id;
@ -280,9 +280,9 @@ private:
// Keys are pairs of (mesh index, buffer index in the mesh)
std::map<std::pair<u8, u32>, AnimationInfo> m_animation_info;
// Hiddable info: hiddable textures
// Hideable info: hideable textures
// Used for better rendering under liquids
std::map<std::pair<u8, u32>, HiddableInfo> m_hiddable_info;
std::map<std::pair<u8, u32>, HideableInfo> m_hideable_info;
// Animation info: day/night transitions
// Last daynight_ratio value passed to animate()