Skip to content

Commit

Permalink
content_mapblock: Move static initialization out of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed May 17, 2020
1 parent be38a44 commit 52430d3
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions src/client/content_mapblock.cpp
Expand Up @@ -512,29 +512,31 @@ 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 -
};
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
Expand All @@ -554,7 +556,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;

Expand Down Expand Up @@ -1193,15 +1195,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,
Expand All @@ -1214,8 +1215,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 .
Expand All @@ -1233,22 +1234,25 @@ 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;
int angle;
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;
}

Expand Down Expand Up @@ -1276,9 +1280,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),
Expand All @@ -1288,27 +1291,30 @@ 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
v3s16(-1, 0, 0), // left
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;
Expand Down

0 comments on commit 52430d3

Please sign in to comment.