content_mapblock: Move static initialization out of functions

This commit is contained in:
sfan5 2020-05-15 15:42:33 +02:00
parent be38a44ffe
commit 52430d34d3

@ -512,8 +512,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 +520,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 +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;
@ -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,
@ -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 .
@ -1233,7 +1234,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 +1245,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 +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),
@ -1288,7 +1291,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 +1299,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;