Skip to content

Commit

Permalink
Meshgen: Handle enable_water_reflections like smooth_lighting
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour committed Jan 11, 2025
1 parent 9a60b83 commit c0ce918
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/client/content_mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}
Expand Down
1 change: 0 additions & 1 deletion src/client/content_mapblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ class MapblockMeshGenerator
f32 corner_levels[2][2];
};
LiquidData cur_liquid;
bool smooth_liquids = false;

void prepareLiquidNodeDrawing();
void getLiquidNeighborhood();
Expand Down
5 changes: 0 additions & 5 deletions src/client/mapblock_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
6 changes: 1 addition & 5 deletions src/client/mapblock_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/client/mesh_generator_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}

/*
Expand Down
3 changes: 2 additions & 1 deletion src/client/mesh_generator_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class MeshUpdateQueue
std::unordered_set<v3s16> 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);
};
Expand Down
3 changes: 2 additions & 1 deletion src/client/wieldmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion src/unittest/test_content_mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down

0 comments on commit c0ce918

Please sign in to comment.