summaryrefslogtreecommitdiff
path: root/src/mapblock_mesh.cpp
diff options
context:
space:
mode:
authorgregorycu <gregory.currie@gmail.com>2015-02-23 23:20:06 +1000
committerCraig Robbins <kde.psych@gmail.com>2015-02-23 23:20:31 +1000
commit577701cabd6382bb97dc05e9c9244b5ce8202ca3 (patch)
treedb20283fff1b8563fe4c5f11f16ddbe30702b0d1 /src/mapblock_mesh.cpp
parent3b6480c5b0c968ad9f5a7cfb7ca494989be03629 (diff)
downloadminetest-577701cabd6382bb97dc05e9c9244b5ce8202ca3.tar.gz
minetest-577701cabd6382bb97dc05e9c9244b5ce8202ca3.tar.bz2
minetest-577701cabd6382bb97dc05e9c9244b5ce8202ca3.zip
Optimise MapBlockMesh related functions
Directely or indirectly optimises the following functions: * MapBlockMesh::MapBlockMesh * MapBlockMesh::getTileInfo * MapBlockMesh::makeFastFace * MapBlockMesh::getSmoothLightCombined
Diffstat (limited to 'src/mapblock_mesh.cpp')
-rw-r--r--src/mapblock_mesh.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp
index b3a1a73d7..d95b8d286 100644
--- a/src/mapblock_mesh.cpp
+++ b/src/mapblock_mesh.cpp
@@ -248,7 +248,7 @@ static u16 getSmoothLightCombined(v3s16 p, MeshMakeData *data)
for (u32 i = 0; i < 8; i++)
{
- MapNode n = data->m_vmanip.getNodeNoEx(p - dirs8[i]);
+ const MapNode &n = data->m_vmanip.getNodeRefUnsafeCheckFlags(p - dirs8[i]);
// if it's CONTENT_IGNORE we can't do any light calculations
if (n.getContent() == CONTENT_IGNORE) {
@@ -438,8 +438,6 @@ struct FastFace
static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
v3f p, v3s16 dir, v3f scale, u8 light_source, std::vector<FastFace> &dest)
{
- FastFace face;
-
// Position is at the center of the cube.
v3f pos = p * BS;
@@ -590,6 +588,10 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
u8 alpha = tile.alpha;
+ dest.push_back(FastFace());
+
+ FastFace& face = *dest.rbegin();
+
face.vertices[0] = video::S3DVertex(vertex_pos[0], normal,
MapBlock_LightColor(alpha, li0, light_source),
core::vector2d<f32>(x0+w*abs_scale, y0+h));
@@ -604,7 +606,6 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
core::vector2d<f32>(x0+w*abs_scale, y0));
face.tile = tile;
- dest.push_back(face);
}
/*
@@ -745,8 +746,8 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 dir, MeshMakeData *data)
static void getTileInfo(
// Input:
MeshMakeData *data,
- v3s16 p,
- v3s16 face_dir,
+ const v3s16 &p,
+ const v3s16 &face_dir,
// Output:
bool &makes_face,
v3s16 &p_corrected,
@@ -760,14 +761,20 @@ static void getTileInfo(
INodeDefManager *ndef = data->m_gamedef->ndef();
v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
- MapNode n0 = vmanip.getNodeNoEx(blockpos_nodes + p);
+ MapNode &n0 = vmanip.getNodeRefUnsafe(blockpos_nodes + p);
// Don't even try to get n1 if n0 is already CONTENT_IGNORE
- if (n0.getContent() == CONTENT_IGNORE ) {
+ if (n0.getContent() == CONTENT_IGNORE) {
+ makes_face = false;
+ return;
+ }
+
+ const MapNode &n1 = vmanip.getNodeRefUnsafeCheckFlags(blockpos_nodes + p + face_dir);
+
+ if (n1.getContent() == CONTENT_IGNORE) {
makes_face = false;
return;
}
- MapNode n1 = vmanip.getNodeNoEx(blockpos_nodes + p + face_dir);
// This is hackish
bool equivalent = false;
@@ -1037,6 +1044,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
//TimeTaker timer1("MapBlockMesh()");
std::vector<FastFace> fastfaces_new;
+ fastfaces_new.reserve(512);
/*
We are including the faces of the trailing edges of the block.