adspartan : liquid updates

b656636a78
This commit is contained in:
T1ti
2024-08-31 00:05:48 +02:00
parent 47e4ab4f80
commit 01958a7d89
5 changed files with 49 additions and 4 deletions

View File

@@ -173,6 +173,14 @@ void ChunkWater::autoGen(MapChunk *chunk, float factor)
update_layers();
}
void ChunkWater::update_underground_vertices_depth(MapChunk* chunk)
{
for (liquid_layer& layer : _layers)
{
layer.update_underground_vertices_depth(chunk);
}
}
void ChunkWater::CropWater(MapChunk* chunkTerrain)
{
@@ -282,11 +290,13 @@ void ChunkWater::update_layers()
_water_tile->tagExtents(true);
vcenter = (vmin + vmax) * 0.5f;
_layer_count = _layers.size();
}
bool ChunkWater::hasData(size_t layer) const
{
return _layers.size() > layer;
return _layer_count > layer;
}

View File

@@ -40,6 +40,7 @@ public:
) const;
void autoGen(MapChunk* chunk, float factor);
void update_underground_vertices_depth(MapChunk* chunk);
void CropWater(MapChunk* chunkTerrain);
void setType(int type, size_t layer);
@@ -91,6 +92,8 @@ private:
void update_attributes();
std::vector<liquid_layer> _layers;
int _layer_count = 0;
MapChunk* _chunk;
TileWater* _water_tile;

View File

@@ -57,6 +57,8 @@ public:
void autoGen(float factor);
void update_underground_vertices_depth();
void setType(int type, size_t layer);
int getType(size_t layer);

View File

@@ -34,6 +34,7 @@ liquid_layer::liquid_layer(ChunkWater* chunk, glm::vec3 const& base, float heigh
changeLiquidID(_liquid_id);
update_min_max();
}
liquid_layer::liquid_layer(ChunkWater* chunk, glm::vec3 const& base, mclq& liquid, int liquid_id)
@@ -85,7 +86,7 @@ liquid_layer::liquid_layer(ChunkWater* chunk, glm::vec3 const& base, mclq& liqui
_vertices[v_index] = lv;
}
}
update_min_max();
}
liquid_layer::liquid_layer(ChunkWater* chunk
@@ -170,8 +171,7 @@ liquid_layer::liquid_layer(ChunkWater* chunk
changeLiquidID(_liquid_id); // to update the liquid type
if (check_fatigue())
_fatigue_enabled = true;
update_min_max();
}
liquid_layer::liquid_layer(liquid_layer&& other)
@@ -456,6 +456,35 @@ void liquid_layer::update_opacity(MapChunk* chunk, float factor)
}
}
void liquid_layer::update_underground_vertices_depth(MapChunk* chunk)
{
// set depth = 0 to liquid verts under ground. This is for LODs.
{
for (int z = 0; z < 9; ++z)
{
for (int x = 0; x < 9; ++x)
{
float diff = _vertices[z * 9 + x].position.y - chunk->mVertices[z * 17 + x].y;
if (diff < 0.f)
{
_vertices[z * 9 + x].depth = 0.f;
}
else
{
if (x < 8 && z < 8 && !hasSubchunk(x, z))
{
_vertices[z * 9 + x].depth = 0.f;
_vertices[z * 9 + x + 1].depth = 0.f;
_vertices[(z + 1) * 9 + x].depth = 0.f;
_vertices[(z + 1) * 9 + (x + 1)].depth = 0.f;
}
}
}
}
}
}
bool liquid_layer::hasSubchunk(int x, int z, int size) const
{
for (int pz = z; pz < z + size; ++pz)

View File

@@ -66,6 +66,7 @@ public:
void crop(MapChunk* chunk);
void update_opacity(MapChunk* chunk, float factor);
void update_underground_vertices_depth(MapChunk* chunk);
std::array<liquid_vertex, 9 * 9>& getVertices() { return _vertices; };
// std::array<float, 9 * 9>& getDepth() { return _depth; };