Skip to content

Commit 556bdc2

Browse files
sapiersapier
sapier
authored and
sapier
committedApr 6, 2014
Pass pointer to nodedef directly to avoid recalculation in quite often called function
1 parent 2885449 commit 556bdc2

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed
 

‎src/content_mapblock.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
219219
if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
220220
top_is_same_liquid = true;
221221

222-
u16 l = getInteriorLight(n, 0, data);
222+
u16 l = getInteriorLight(n, 0, nodedef);
223223
video::SColor c = MapBlock_LightColor(f.alpha, l, decode_light(f.light_source));
224224

225225
/*
@@ -389,10 +389,10 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
389389
}
390390
// Use the light of the node on top if possible
391391
else if(nodedef->get(ntop).param_type == CPT_LIGHT)
392-
l = getInteriorLight(ntop, 0, data);
392+
l = getInteriorLight(ntop, 0, nodedef);
393393
// Otherwise use the light of this node (the liquid)
394394
else
395-
l = getInteriorLight(n, 0, data);
395+
l = getInteriorLight(n, 0, nodedef);
396396
video::SColor c = MapBlock_LightColor(f.alpha, l, decode_light(f.light_source));
397397

398398
u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8);
@@ -696,7 +696,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
696696
{
697697
TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
698698

699-
u16 l = getInteriorLight(n, 1, data);
699+
u16 l = getInteriorLight(n, 1, nodedef);
700700
video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
701701

702702
for(u32 j=0; j<6; j++)
@@ -758,7 +758,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
758758
TileSpec tiles[2];
759759
tiles[0] = getNodeTile(n, p, dirs[0], data);
760760
tiles[1] = getNodeTile(n, p, dirs[1], data);
761-
u16 l = getInteriorLight(n, 1, data);
761+
u16 l = getInteriorLight(n, 1, nodedef);
762762
video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
763763
v3f pos = intToFloat(p, BS);
764764
static const float a=BS/2;
@@ -876,7 +876,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
876876
TileSpec tile_leaves = getNodeTile(n, p,
877877
v3s16(0,0,0), data);
878878

879-
u16 l = getInteriorLight(n, 1, data);
879+
u16 l = getInteriorLight(n, 1, nodedef);
880880
video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
881881

882882
v3f pos = intToFloat(p, BS);
@@ -909,7 +909,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
909909
tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
910910
tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
911911

912-
u16 l = getInteriorLight(n, 1, data);
912+
u16 l = getInteriorLight(n, 1, nodedef);
913913
video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
914914

915915
float s = BS/2*f.visual_scale;
@@ -950,7 +950,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
950950
tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
951951
tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
952952

953-
u16 l = getInteriorLight(n, 0, data);
953+
u16 l = getInteriorLight(n, 0, nodedef);
954954
video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
955955

956956
float d = (float)BS/16;
@@ -993,7 +993,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
993993
TileSpec tile = getNodeTileN(n, p, 0, data);
994994
tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
995995

996-
u16 l = getInteriorLight(n, 1, data);
996+
u16 l = getInteriorLight(n, 1, nodedef);
997997
video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
998998

999999
float s = BS/2*f.visual_scale;
@@ -1045,7 +1045,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
10451045
texturestring_rot,
10461046
&tile_rot.texture_id);
10471047

1048-
u16 l = getInteriorLight(n, 1, data);
1048+
u16 l = getInteriorLight(n, 1, nodedef);
10491049
video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
10501050

10511051
const f32 post_rad=(f32)BS/8;
@@ -1294,7 +1294,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
12941294
tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
12951295
tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
12961296

1297-
u16 l = getInteriorLight(n, 0, data);
1297+
u16 l = getInteriorLight(n, 0, nodedef);
12981298
video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
12991299

13001300
float d = (float)BS/64;
@@ -1333,7 +1333,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
13331333
};
13341334
TileSpec tiles[6];
13351335

1336-
u16 l = getInteriorLight(n, 0, data);
1336+
u16 l = getInteriorLight(n, 0, nodedef);
13371337
video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
13381338

13391339
v3f pos = intToFloat(p, BS);

‎src/mapblock_mesh.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ void MeshMakeData::setSmoothLighting(bool smooth_lighting)
150150
Single light bank.
151151
*/
152152
static u8 getInteriorLight(enum LightBank bank, MapNode n, s32 increment,
153-
MeshMakeData *data)
153+
INodeDefManager *ndef)
154154
{
155-
INodeDefManager *ndef = data->m_gamedef->ndef();
156155
u8 light = n.getLight(bank, ndef);
157156

158157
while(increment > 0)
@@ -173,10 +172,10 @@ static u8 getInteriorLight(enum LightBank bank, MapNode n, s32 increment,
173172
Calculate non-smooth lighting at interior of node.
174173
Both light banks.
175174
*/
176-
u16 getInteriorLight(MapNode n, s32 increment, MeshMakeData *data)
175+
u16 getInteriorLight(MapNode n, s32 increment, INodeDefManager *ndef)
177176
{
178-
u16 day = getInteriorLight(LIGHTBANK_DAY, n, increment, data);
179-
u16 night = getInteriorLight(LIGHTBANK_NIGHT, n, increment, data);
177+
u16 day = getInteriorLight(LIGHTBANK_DAY, n, increment, ndef);
178+
u16 night = getInteriorLight(LIGHTBANK_NIGHT, n, increment, ndef);
180179
return day | (night << 8);
181180
}
182181

@@ -185,10 +184,8 @@ u16 getInteriorLight(MapNode n, s32 increment, MeshMakeData *data)
185184
Single light bank.
186185
*/
187186
static u8 getFaceLight(enum LightBank bank, MapNode n, MapNode n2,
188-
v3s16 face_dir, MeshMakeData *data)
187+
v3s16 face_dir, INodeDefManager *ndef)
189188
{
190-
INodeDefManager *ndef = data->m_gamedef->ndef();
191-
192189
u8 light;
193190
u8 l1 = n.getLight(bank, ndef);
194191
u8 l2 = n2.getLight(bank, ndef);
@@ -227,10 +224,10 @@ static u8 getFaceLight(enum LightBank bank, MapNode n, MapNode n2,
227224
Calculate non-smooth lighting at face of node.
228225
Both light banks.
229226
*/
230-
u16 getFaceLight(MapNode n, MapNode n2, v3s16 face_dir, MeshMakeData *data)
227+
u16 getFaceLight(MapNode n, MapNode n2, v3s16 face_dir, INodeDefManager *ndef)
231228
{
232-
u16 day = getFaceLight(LIGHTBANK_DAY, n, n2, face_dir, data);
233-
u16 night = getFaceLight(LIGHTBANK_NIGHT, n, n2, face_dir, data);
229+
u16 day = getFaceLight(LIGHTBANK_DAY, n, n2, face_dir, ndef);
230+
u16 night = getFaceLight(LIGHTBANK_NIGHT, n, n2, face_dir, ndef);
234231
return day | (night << 8);
235232
}
236233

@@ -812,7 +809,7 @@ static void getTileInfo(
812809
if(data->m_smooth_lighting == false)
813810
{
814811
lights[0] = lights[1] = lights[2] = lights[3] =
815-
getFaceLight(n0, n1, face_dir, data);
812+
getFaceLight(n0, n1, face_dir, ndef);
816813
}
817814
else
818815
{

‎src/mapblock_mesh.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ inline video::SColor MapBlock_LightColor(u8 alpha, u16 light, u8 light_source=0)
172172
}
173173

174174
// Compute light at node
175-
u16 getInteriorLight(MapNode n, s32 increment, MeshMakeData *data);
176-
u16 getFaceLight(MapNode n, MapNode n2, v3s16 face_dir, MeshMakeData *data);
175+
u16 getInteriorLight(MapNode n, s32 increment, INodeDefManager *ndef);
176+
u16 getFaceLight(MapNode n, MapNode n2, v3s16 face_dir, INodeDefManager *ndef);
177177
u16 getSmoothLight(v3s16 p, v3s16 corner, MeshMakeData *data);
178178

179179
// Retrieves the TileSpec of a face of a node

0 commit comments

Comments
 (0)
Please sign in to comment.