Skip to content

Commit 577701c

Browse files
gregorycuZeno-
authored andcommittedFeb 23, 2015
Optimise MapBlockMesh related functions
Directely or indirectly optimises the following functions: * MapBlockMesh::MapBlockMesh * MapBlockMesh::getTileInfo * MapBlockMesh::makeFastFace * MapBlockMesh::getSmoothLightCombined
1 parent 3b6480c commit 577701c

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed
 

Diff for: ‎src/mapblock_mesh.cpp

+17-9
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static u16 getSmoothLightCombined(v3s16 p, MeshMakeData *data)
248248

249249
for (u32 i = 0; i < 8; i++)
250250
{
251-
MapNode n = data->m_vmanip.getNodeNoEx(p - dirs8[i]);
251+
const MapNode &n = data->m_vmanip.getNodeRefUnsafeCheckFlags(p - dirs8[i]);
252252

253253
// if it's CONTENT_IGNORE we can't do any light calculations
254254
if (n.getContent() == CONTENT_IGNORE) {
@@ -438,8 +438,6 @@ struct FastFace
438438
static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
439439
v3f p, v3s16 dir, v3f scale, u8 light_source, std::vector<FastFace> &dest)
440440
{
441-
FastFace face;
442-
443441
// Position is at the center of the cube.
444442
v3f pos = p * BS;
445443

@@ -590,6 +588,10 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
590588

591589
u8 alpha = tile.alpha;
592590

591+
dest.push_back(FastFace());
592+
593+
FastFace& face = *dest.rbegin();
594+
593595
face.vertices[0] = video::S3DVertex(vertex_pos[0], normal,
594596
MapBlock_LightColor(alpha, li0, light_source),
595597
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,
604606
core::vector2d<f32>(x0+w*abs_scale, y0));
605607

606608
face.tile = tile;
607-
dest.push_back(face);
608609
}
609610

610611
/*
@@ -745,8 +746,8 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 dir, MeshMakeData *data)
745746
static void getTileInfo(
746747
// Input:
747748
MeshMakeData *data,
748-
v3s16 p,
749-
v3s16 face_dir,
749+
const v3s16 &p,
750+
const v3s16 &face_dir,
750751
// Output:
751752
bool &makes_face,
752753
v3s16 &p_corrected,
@@ -760,14 +761,20 @@ static void getTileInfo(
760761
INodeDefManager *ndef = data->m_gamedef->ndef();
761762
v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
762763

763-
MapNode n0 = vmanip.getNodeNoEx(blockpos_nodes + p);
764+
MapNode &n0 = vmanip.getNodeRefUnsafe(blockpos_nodes + p);
764765

765766
// Don't even try to get n1 if n0 is already CONTENT_IGNORE
766-
if (n0.getContent() == CONTENT_IGNORE ) {
767+
if (n0.getContent() == CONTENT_IGNORE) {
768+
makes_face = false;
769+
return;
770+
}
771+
772+
const MapNode &n1 = vmanip.getNodeRefUnsafeCheckFlags(blockpos_nodes + p + face_dir);
773+
774+
if (n1.getContent() == CONTENT_IGNORE) {
767775
makes_face = false;
768776
return;
769777
}
770-
MapNode n1 = vmanip.getNodeNoEx(blockpos_nodes + p + face_dir);
771778

772779
// This is hackish
773780
bool equivalent = false;
@@ -1037,6 +1044,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
10371044
//TimeTaker timer1("MapBlockMesh()");
10381045

10391046
std::vector<FastFace> fastfaces_new;
1047+
fastfaces_new.reserve(512);
10401048

10411049
/*
10421050
We are including the faces of the trailing edges of the block.

Diff for: ‎src/mapnode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ u8 MapNode::getLight(enum LightBank bank, INodeDefManager *nodemgr) const
104104
return MYMAX(f.light_source, light);
105105
}
106106

107-
u8 MapNode::getLightNoChecks(enum LightBank bank, const ContentFeatures *f)
107+
u8 MapNode::getLightNoChecks(enum LightBank bank, const ContentFeatures *f) const
108108
{
109109
return MYMAX(f->light_source,
110110
bank == LIGHTBANK_DAY ? param1 & 0x0f : (param1 >> 4) & 0x0f);

Diff for: ‎src/mapnode.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ struct MapNode
217217
* @pre f != NULL
218218
* @pre f->param_type == CPT_LIGHT
219219
*/
220-
u8 getLightNoChecks(LightBank bank, const ContentFeatures *f);
220+
u8 getLightNoChecks(LightBank bank, const ContentFeatures *f) const;
221221

222222
bool getLightBanks(u8 &lightday, u8 &lightnight, INodeDefManager *nodemgr) const;
223223

Diff for: ‎src/voxel.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ void VoxelManipulator::spreadLight(enum LightBank bank,
621621
}
622622
#endif
623623

624+
const MapNode VoxelManipulator::ContentIgnoreNode = MapNode(CONTENT_IGNORE);
625+
624626
#if 1
625627
/*
626628
Lights neighbors of from_nodes, collects all them and then

Diff for: ‎src/voxel.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,21 @@ class VoxelManipulator /*: public NodeContainer*/
413413
}
414414
// Stuff explodes if non-emerged area is touched with this.
415415
// Emerge first, and check VOXELFLAG_NO_DATA if appropriate.
416-
MapNode & getNodeRefUnsafe(v3s16 p)
416+
MapNode & getNodeRefUnsafe(const v3s16 &p)
417417
{
418418
return m_data[m_area.index(p)];
419419
}
420+
421+
const MapNode & getNodeRefUnsafeCheckFlags(const v3s16 &p)
422+
{
423+
s32 index = m_area.index(p);
424+
425+
if (m_flags[index] & VOXELFLAG_NO_DATA)
426+
return ContentIgnoreNode;
427+
428+
return m_data[index];
429+
}
430+
420431
u8 & getFlagsRefUnsafe(v3s16 p)
421432
{
422433
return m_flags[m_area.index(p)];
@@ -569,6 +580,8 @@ class VoxelManipulator /*: public NodeContainer*/
569580
*/
570581
u8 *m_flags;
571582

583+
static const MapNode ContentIgnoreNode;
584+
572585
//TODO: Use these or remove them
573586
//TODO: Would these make any speed improvement?
574587
//bool m_pressure_route_valid;

0 commit comments

Comments
 (0)
Please sign in to comment.