aboutsummaryrefslogtreecommitdiff
path: root/src/client/content_mapblock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/content_mapblock.cpp')
-rw-r--r--src/client/content_mapblock.cpp70
1 files changed, 43 insertions, 27 deletions
diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp
index 9b4fd221e..3d06584c4 100644
--- a/src/client/content_mapblock.cpp
+++ b/src/client/content_mapblock.cpp
@@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <cmath>
#include "content_mapblock.h"
#include "util/numeric.h"
#include "util/directiontables.h"
@@ -366,6 +367,7 @@ void MapblockMeshGenerator::generateCuboidTextureCoords(const aabb3f &box, f32 *
void MapblockMeshGenerator::drawAutoLightedCuboid(aabb3f box, const f32 *txc,
TileSpec *tiles, int tile_count)
{
+ bool scale = std::fabs(f->visual_scale - 1.0f) > 1e-3f;
f32 texture_coord_buf[24];
f32 dx1 = box.MinEdge.X;
f32 dy1 = box.MinEdge.Y;
@@ -373,6 +375,14 @@ void MapblockMeshGenerator::drawAutoLightedCuboid(aabb3f box, const f32 *txc,
f32 dx2 = box.MaxEdge.X;
f32 dy2 = box.MaxEdge.Y;
f32 dz2 = box.MaxEdge.Z;
+ if (scale) {
+ if (!txc) { // generate texture coords before scaling
+ generateCuboidTextureCoords(box, texture_coord_buf);
+ txc = texture_coord_buf;
+ }
+ box.MinEdge *= f->visual_scale;
+ box.MaxEdge *= f->visual_scale;
+ }
box.MinEdge += origin;
box.MaxEdge += origin;
if (!txc) {
@@ -405,8 +415,8 @@ void MapblockMeshGenerator::prepareLiquidNodeDrawing()
MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(p.X, p.Y + 1, p.Z));
MapNode nbottom = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(p.X, p.Y - 1, p.Z));
- c_flowing = nodedef->getId(f->liquid_alternative_flowing);
- c_source = nodedef->getId(f->liquid_alternative_source);
+ c_flowing = f->liquid_alternative_flowing_id;
+ c_source = f->liquid_alternative_source_id;
top_is_same_liquid = (ntop.getContent() == c_flowing) || (ntop.getContent() == c_source);
draw_liquid_bottom = (nbottom.getContent() != c_flowing) && (nbottom.getContent() != c_source);
if (draw_liquid_bottom) {
@@ -512,8 +522,7 @@ f32 MapblockMeshGenerator::getCornerLevel(int i, int k)
return 0;
}
-void MapblockMeshGenerator::drawLiquidSides()
-{
+namespace {
struct LiquidFaceDesc {
v3s16 dir; // XZ
v3s16 p[2]; // XZ only; 1 means +, 0 means -
@@ -521,20 +530,23 @@ void MapblockMeshGenerator::drawLiquidSides()
struct UV {
int u, v;
};
- static const LiquidFaceDesc base_faces[4] = {
+ static const LiquidFaceDesc liquid_base_faces[4] = {
{v3s16( 1, 0, 0), {v3s16(1, 0, 1), v3s16(1, 0, 0)}},
{v3s16(-1, 0, 0), {v3s16(0, 0, 0), v3s16(0, 0, 1)}},
{v3s16( 0, 0, 1), {v3s16(0, 0, 1), v3s16(1, 0, 1)}},
{v3s16( 0, 0, -1), {v3s16(1, 0, 0), v3s16(0, 0, 0)}},
};
- static const UV base_vertices[4] = {
+ static const UV liquid_base_vertices[4] = {
{0, 1},
{1, 1},
{1, 0},
{0, 0}
};
+}
- for (const auto &face : base_faces) {
+void MapblockMeshGenerator::drawLiquidSides()
+{
+ for (const auto &face : liquid_base_faces) {
const NeighborData &neighbor = liquid_neighbors[face.dir.Z + 1][face.dir.X + 1];
// No face between nodes of the same liquid, unless there is node
@@ -554,7 +566,7 @@ void MapblockMeshGenerator::drawLiquidSides()
video::S3DVertex vertices[4];
for (int j = 0; j < 4; j++) {
- const UV &vertex = base_vertices[j];
+ const UV &vertex = liquid_base_vertices[j];
const v3s16 &base = face.p[vertex.u];
float v = vertex.v;
@@ -1193,15 +1205,14 @@ bool MapblockMeshGenerator::isSameRail(v3s16 dir)
(def2.getGroup(raillike_groupname) == raillike_group));
}
-void MapblockMeshGenerator::drawRaillikeNode()
-{
- static const v3s16 direction[4] = {
+namespace {
+ static const v3s16 rail_direction[4] = {
v3s16( 0, 0, 1),
v3s16( 0, 0, -1),
v3s16(-1, 0, 0),
v3s16( 1, 0, 0),
};
- static const int slope_angle[4] = {0, 180, 90, -90};
+ static const int rail_slope_angle[4] = {0, 180, 90, -90};
enum RailTile {
straight,
@@ -1214,8 +1225,8 @@ void MapblockMeshGenerator::drawRaillikeNode()
int angle;
};
static const RailDesc rail_kinds[16] = {
- // +x -x -z +z
- //-------------
+ // +x -x -z +z
+ //-------------
{straight, 0}, // . . . .
{straight, 0}, // . . . +Z
{straight, 0}, // . . -Z .
@@ -1233,7 +1244,10 @@ void MapblockMeshGenerator::drawRaillikeNode()
{junction, 270}, // +X -X -Z .
{ cross, 0}, // +X -X -Z +Z
};
+}
+void MapblockMeshGenerator::drawRaillikeNode()
+{
raillike_group = nodedef->get(n).getGroup(raillike_groupname);
int code = 0;
@@ -1241,14 +1255,14 @@ void MapblockMeshGenerator::drawRaillikeNode()
int tile_index;
bool sloped = false;
for (int dir = 0; dir < 4; dir++) {
- bool rail_above = isSameRail(direction[dir] + v3s16(0, 1, 0));
+ bool rail_above = isSameRail(rail_direction[dir] + v3s16(0, 1, 0));
if (rail_above) {
sloped = true;
- angle = slope_angle[dir];
+ angle = rail_slope_angle[dir];
}
if (rail_above ||
- isSameRail(direction[dir]) ||
- isSameRail(direction[dir] + v3s16(0, -1, 0)))
+ isSameRail(rail_direction[dir]) ||
+ isSameRail(rail_direction[dir] + v3s16(0, -1, 0)))
code |= 1 << dir;
}
@@ -1276,9 +1290,8 @@ void MapblockMeshGenerator::drawRaillikeNode()
drawQuad(vertices);
}
-void MapblockMeshGenerator::drawNodeboxNode()
-{
- static const v3s16 tile_dirs[6] = {
+namespace {
+ static const v3s16 nodebox_tile_dirs[6] = {
v3s16(0, 1, 0),
v3s16(0, -1, 0),
v3s16(1, 0, 0),
@@ -1288,7 +1301,7 @@ void MapblockMeshGenerator::drawNodeboxNode()
};
// we have this order for some reason...
- static const v3s16 connection_dirs[6] = {
+ static const v3s16 nodebox_connection_dirs[6] = {
v3s16( 0, 1, 0), // top
v3s16( 0, -1, 0), // bottom
v3s16( 0, 0, -1), // front
@@ -1296,19 +1309,22 @@ void MapblockMeshGenerator::drawNodeboxNode()
v3s16( 0, 0, 1), // back
v3s16( 1, 0, 0), // right
};
+}
+void MapblockMeshGenerator::drawNodeboxNode()
+{
TileSpec tiles[6];
for (int face = 0; face < 6; face++) {
// Handles facedir rotation for textures
- getTile(tile_dirs[face], &tiles[face]);
+ getTile(nodebox_tile_dirs[face], &tiles[face]);
}
// locate possible neighboring nodes to connect to
- int neighbors_set = 0;
+ u8 neighbors_set = 0;
if (f->node_box.type == NODEBOX_CONNECTED) {
for (int dir = 0; dir != 6; dir++) {
- int flag = 1 << dir;
- v3s16 p2 = blockpos_nodes + p + connection_dirs[dir];
+ u8 flag = 1 << dir;
+ v3s16 p2 = blockpos_nodes + p + nodebox_connection_dirs[dir];
MapNode n2 = data->m_vmanip.getNodeNoEx(p2);
if (nodedef->nodeboxConnects(n, n2, flag))
neighbors_set |= flag;
@@ -1317,7 +1333,7 @@ void MapblockMeshGenerator::drawNodeboxNode()
std::vector<aabb3f> boxes;
n.getNodeBoxes(nodedef, &boxes, neighbors_set);
- for (const auto &box : boxes)
+ for (auto &box : boxes)
drawAutoLightedCuboid(box, nullptr, tiles, 6);
}