Cleanup in content_mapblock (#5746)

NDT_LIQUID is being drawn by MapBlockMesh since a long time ago...
master
numberZero 2017-05-20 14:29:54 +04:00 committed by Loïc Blot
parent 1ff5ee0b69
commit 7779bac3a5
2 changed files with 37 additions and 60 deletions

View File

@ -376,10 +376,10 @@ static TileSpec getSpecialTile(const ContentFeatures &f,
return copy; return copy;
} }
void MapblockMeshGenerator::prepareLiquidNodeDrawing(bool flowing) void MapblockMeshGenerator::prepareLiquidNodeDrawing()
{ {
tile_liquid_top = getSpecialTile(*f, n, 0); tile_liquid_top = getSpecialTile(*f, n, 0);
tile_liquid = getSpecialTile(*f, n, flowing ? 1 : 0); tile_liquid = getSpecialTile(*f, n, 1);
MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(p.X, p.Y + 1, p.Z)); MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(p.X, p.Y + 1, p.Z));
c_flowing = nodedef->getId(f->liquid_alternative_flowing); c_flowing = nodedef->getId(f->liquid_alternative_flowing);
@ -403,16 +403,12 @@ void MapblockMeshGenerator::prepareLiquidNodeDrawing(bool flowing)
color = encode_light(light, f->light_source); color = encode_light(light, f->light_source);
} }
void MapblockMeshGenerator::getLiquidNeighborhood(bool flowing) void MapblockMeshGenerator::getLiquidNeighborhood()
{ {
u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8); u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8);
for (int w = -1; w <= 1; w++) for (int w = -1; w <= 1; w++)
for (int u = -1; u <= 1; u++) { for (int u = -1; u <= 1; u++) {
// Skip getting unneeded data
if (!flowing && u && w)
continue;
NeighborData &neighbor = liquid_neighbors[w + 1][u + 1]; NeighborData &neighbor = liquid_neighbors[w + 1][u + 1];
v3s16 p2 = p + v3s16(u, 0, w); v3s16 p2 = p + v3s16(u, 0, w);
MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2); MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
@ -447,13 +443,6 @@ void MapblockMeshGenerator::getLiquidNeighborhood(bool flowing)
} }
} }
void MapblockMeshGenerator::resetCornerLevels()
{
for (int k = 0; k < 2; k++)
for (int i = 0; i < 2; i++)
corner_levels[k][i] = 0.5 * BS;
}
void MapblockMeshGenerator::calculateCornerLevels() void MapblockMeshGenerator::calculateCornerLevels()
{ {
for (int k = 0; k < 2; k++) for (int k = 0; k < 2; k++)
@ -494,7 +483,7 @@ f32 MapblockMeshGenerator::getCornerLevel(int i, int k)
return 0; return 0;
} }
void MapblockMeshGenerator::drawLiquidSides(bool flowing) void MapblockMeshGenerator::drawLiquidSides()
{ {
struct LiquidFaceDesc { struct LiquidFaceDesc {
v3s16 dir; // XZ v3s16 dir; // XZ
@ -523,17 +512,12 @@ void MapblockMeshGenerator::drawLiquidSides(bool flowing)
// at the top to which it should be connected. Again, unless the face // at the top to which it should be connected. Again, unless the face
// there would be inside the liquid // there would be inside the liquid
if (neighbor.is_same_liquid) { if (neighbor.is_same_liquid) {
if (!flowing)
continue;
if (!top_is_same_liquid) if (!top_is_same_liquid)
continue; continue;
if (neighbor.top_is_same_liquid) if (neighbor.top_is_same_liquid)
continue; continue;
} }
if (!flowing && (neighbor.content == CONTENT_IGNORE))
continue;
const ContentFeatures &neighbor_features = nodedef->get(neighbor.content); const ContentFeatures &neighbor_features = nodedef->get(neighbor.content);
// Don't draw face if neighbor is blocking the view // Don't draw face if neighbor is blocking the view
if (neighbor_features.solidness == 2) if (neighbor_features.solidness == 2)
@ -559,7 +543,7 @@ void MapblockMeshGenerator::drawLiquidSides(bool flowing)
} }
} }
void MapblockMeshGenerator::drawLiquidTop(bool flowing) void MapblockMeshGenerator::drawLiquidTop()
{ {
// To get backface culling right, the vertices need to go // To get backface culling right, the vertices need to go
// clockwise around the front of the face. And we happened to // clockwise around the front of the face. And we happened to
@ -582,7 +566,6 @@ void MapblockMeshGenerator::drawLiquidTop(bool flowing)
vertices[i].Pos += origin; vertices[i].Pos += origin;
} }
if (flowing) {
// Default downwards-flowing texture animation goes from // Default downwards-flowing texture animation goes from
// -Z towards +Z, thus the direction is +Z. // -Z towards +Z, thus the direction is +Z.
// Rotate texture to make animation go in flow direction // Rotate texture to make animation go in flow direction
@ -605,22 +588,18 @@ void MapblockMeshGenerator::drawLiquidTop(bool flowing)
} }
std::swap(vertices[0].TCoords, vertices[2].TCoords); std::swap(vertices[0].TCoords, vertices[2].TCoords);
}
collector->append(tile_liquid_top, vertices, 4, quad_indices, 6); collector->append(tile_liquid_top, vertices, 4, quad_indices, 6);
} }
void MapblockMeshGenerator::drawLiquidNode(bool flowing) void MapblockMeshGenerator::drawLiquidNode()
{ {
prepareLiquidNodeDrawing(flowing); prepareLiquidNodeDrawing();
getLiquidNeighborhood(flowing); getLiquidNeighborhood();
if (flowing)
calculateCornerLevels(); calculateCornerLevels();
else drawLiquidSides();
resetCornerLevels();
drawLiquidSides(flowing);
if (!top_is_same_liquid) if (!top_is_same_liquid)
drawLiquidTop(flowing); drawLiquidTop();
} }
void MapblockMeshGenerator::drawGlasslikeNode() void MapblockMeshGenerator::drawGlasslikeNode()
@ -1291,8 +1270,7 @@ void MapblockMeshGenerator::drawNode()
else else
light = getInteriorLight(n, 1, nodedef); light = getInteriorLight(n, 1, nodedef);
switch (f->drawtype) { switch (f->drawtype) {
case NDT_LIQUID: drawLiquidNode(false); break; case NDT_FLOWINGLIQUID: drawLiquidNode(); break;
case NDT_FLOWINGLIQUID: drawLiquidNode(true); break;
case NDT_GLASSLIKE: drawGlasslikeNode(); break; case NDT_GLASSLIKE: drawGlasslikeNode(); break;
case NDT_GLASSLIKE_FRAMED: drawGlasslikeFramedNode(); break; case NDT_GLASSLIKE_FRAMED: drawGlasslikeFramedNode(); break;
case NDT_ALLFACES: drawAllfacesNode(); break; case NDT_ALLFACES: drawAllfacesNode(); break;

View File

@ -93,13 +93,12 @@ public:
NeighborData liquid_neighbors[3][3]; NeighborData liquid_neighbors[3][3];
f32 corner_levels[2][2]; f32 corner_levels[2][2];
void prepareLiquidNodeDrawing(bool flowing); void prepareLiquidNodeDrawing();
void getLiquidNeighborhood(bool flowing); void getLiquidNeighborhood();
void resetCornerLevels();
void calculateCornerLevels(); void calculateCornerLevels();
f32 getCornerLevel(int i, int k); f32 getCornerLevel(int i, int k);
void drawLiquidSides(bool flowing); void drawLiquidSides();
void drawLiquidTop(bool flowing); void drawLiquidTop();
// raillike-specific // raillike-specific
// name of the group that enables connecting to raillike nodes of different kind // name of the group that enables connecting to raillike nodes of different kind
@ -122,7 +121,7 @@ public:
float offset_h, float offset_v = 0.0); float offset_h, float offset_v = 0.0);
// drawtypes // drawtypes
void drawLiquidNode(bool flowing); void drawLiquidNode();
void drawGlasslikeNode(); void drawGlasslikeNode();
void drawGlasslikeFramedNode(); void drawGlasslikeFramedNode();
void drawAllfacesNode(); void drawAllfacesNode();