From c0ce918d77ed7e23c5e8da480d4ca99f213beb3c Mon Sep 17 00:00:00 2001 From: Desour Date: Tue, 7 Jan 2025 15:36:45 +0100 Subject: [PATCH] Meshgen: Handle enable_water_reflections like smooth_lighting --- src/client/content_mapblock.cpp | 7 +++---- src/client/content_mapblock.h | 1 - src/client/mapblock_mesh.cpp | 5 ----- src/client/mapblock_mesh.h | 6 +----- src/client/mesh_generator_thread.cpp | 4 +++- src/client/mesh_generator_thread.h | 3 ++- src/client/wieldmesh.cpp | 3 ++- src/unittest/test_content_mapblock.cpp | 3 ++- 8 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index f1e268866971..56d0bd4985c6 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -63,8 +63,7 @@ MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector data(input), collector(output), nodedef(data->nodedef), - blockpos_nodes(data->m_blockpos * MAP_BLOCKSIZE), - smooth_liquids(g_settings->getBool("enable_water_reflections")) + blockpos_nodes(data->m_blockpos * MAP_BLOCKSIZE) { } @@ -733,7 +732,7 @@ void MapblockMeshGenerator::drawLiquidTop() int u = corner_resolve[i][0]; int w = corner_resolve[i][1]; - if (smooth_liquids) { + if (data->m_enable_water_reflections) { int x = vertices[i].Pos.X > 0; int z = vertices[i].Pos.Z > 0; @@ -785,7 +784,7 @@ void MapblockMeshGenerator::drawLiquidTop() vertex.TCoords += tcoord_translate; - if (!smooth_liquids) { + if (!data->m_enable_water_reflections) { vertex.Normal = v3f(dx, 1., dz).normalize(); } } diff --git a/src/client/content_mapblock.h b/src/client/content_mapblock.h index 8302cd2a7468..2bfbbdc61448 100644 --- a/src/client/content_mapblock.h +++ b/src/client/content_mapblock.h @@ -112,7 +112,6 @@ class MapblockMeshGenerator f32 corner_levels[2][2]; }; LiquidData cur_liquid; - bool smooth_liquids = false; void prepareLiquidNodeDrawing(); void getLiquidNeighborhood(); diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index d26457996d78..b879de0475b9 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -58,11 +58,6 @@ void MeshMakeData::setCrack(int crack_level, v3s16 crack_pos) m_crack_pos_relative = crack_pos - m_blockpos*MAP_BLOCKSIZE; } -void MeshMakeData::setSmoothLighting(bool smooth_lighting) -{ - m_smooth_lighting = smooth_lighting; -} - /* Light and vertex color functions */ diff --git a/src/client/mapblock_mesh.h b/src/client/mapblock_mesh.h index 0b9b437dba20..c4380432fff2 100644 --- a/src/client/mapblock_mesh.h +++ b/src/client/mapblock_mesh.h @@ -39,6 +39,7 @@ struct MeshMakeData v3s16 m_blockpos = v3s16(-1337,-1337,-1337); v3s16 m_crack_pos_relative = v3s16(-1337,-1337,-1337); bool m_smooth_lighting = false; + bool m_enable_water_reflections = false; u16 side_length; const NodeDefManager *nodedef; @@ -55,11 +56,6 @@ struct MeshMakeData Set the (node) position of a crack */ void setCrack(int crack_level, v3s16 crack_pos); - - /* - Enable or disable smooth lighting - */ - void setSmoothLighting(bool smooth_lighting); }; // represents a triangle as indexes into the vertex buffer in SMeshBuffer diff --git a/src/client/mesh_generator_thread.cpp b/src/client/mesh_generator_thread.cpp index 3d80f8e67c25..0b85a1bc96d6 100644 --- a/src/client/mesh_generator_thread.cpp +++ b/src/client/mesh_generator_thread.cpp @@ -40,6 +40,7 @@ MeshUpdateQueue::MeshUpdateQueue(Client *client): m_client(client) { m_cache_smooth_lighting = g_settings->getBool("smooth_lighting"); + m_cache_enable_water_reflections = g_settings->getBool("enable_water_reflections"); } MeshUpdateQueue::~MeshUpdateQueue() @@ -191,7 +192,8 @@ void MeshUpdateQueue::fillDataFromMapBlocks(QueuedMeshUpdate *q) } data->setCrack(q->crack_level, q->crack_pos); - data->setSmoothLighting(m_cache_smooth_lighting); + data->m_smooth_lighting = m_cache_smooth_lighting; + data->m_enable_water_reflections = m_cache_enable_water_reflections; } /* diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h index fb9b5ae9e32c..72e4c7bed7e4 100644 --- a/src/client/mesh_generator_thread.h +++ b/src/client/mesh_generator_thread.h @@ -69,8 +69,9 @@ class MeshUpdateQueue std::unordered_set m_inflight_blocks; std::mutex m_mutex; - // TODO: Add callback to update these when g_settings changes + // TODO: Add callback to update these when g_settings changes, and update all meshes bool m_cache_smooth_lighting; + bool m_cache_enable_water_reflections; void fillDataFromMapBlocks(QueuedMeshUpdate *q); }; diff --git a/src/client/wieldmesh.cpp b/src/client/wieldmesh.cpp index 3ba18711ec75..a557fc2a2a84 100644 --- a/src/client/wieldmesh.cpp +++ b/src/client/wieldmesh.cpp @@ -311,7 +311,8 @@ static scene::SMesh *createSpecialNodeMesh(Client *client, MapNode n, { MeshMakeData mesh_make_data(client->ndef(), 1); MeshCollector collector(v3f(0.0f * BS), v3f()); - mesh_make_data.setSmoothLighting(false); + mesh_make_data.m_smooth_lighting = false; + mesh_make_data.m_enable_water_reflections = false; MapblockMeshGenerator gen(&mesh_make_data, &collector); if (n.getParam2()) { diff --git a/src/unittest/test_content_mapblock.cpp b/src/unittest/test_content_mapblock.cpp index c357c5ea767e..e7148a69f673 100644 --- a/src/unittest/test_content_mapblock.cpp +++ b/src/unittest/test_content_mapblock.cpp @@ -39,7 +39,8 @@ class MockGameDef : public DummyGameDef { MeshMakeData makeSingleNodeMMD(bool smooth_lighting = true) { MeshMakeData data{ndef(), 1}; - data.setSmoothLighting(smooth_lighting); + data.m_smooth_lighting = smooth_lighting; + data.m_enable_water_reflections = false; data.m_blockpos = {0, 0, 0}; for (s16 x = -1; x <= 1; x++) for (s16 y = -1; y <= 1; y++)