Skip to content

Commit d5de0cb

Browse files
sapiersapier
sapier
authored and
sapier
committed
Minor fix in check order
1 parent fcfd53a commit d5de0cb

File tree

1 file changed

+51
-49
lines changed

1 file changed

+51
-49
lines changed

src/mapblock_mesh.cpp

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void MeshMakeData::fill(MapBlock *block)
5959
m_blockpos = block->getPos();
6060

6161
v3s16 blockpos_nodes = m_blockpos*MAP_BLOCKSIZE;
62-
62+
6363
/*
6464
Copy data
6565
*/
@@ -84,7 +84,7 @@ void MeshMakeData::fill(MapBlock *block)
8484
Copy neighbors. This is lightning fast.
8585
Copying only the borders would be *very* slow.
8686
*/
87-
87+
8888
// Get map
8989
Map *map = block->getParent();
9090

@@ -102,7 +102,7 @@ void MeshMakeData::fill(MapBlock *block)
102102
void MeshMakeData::fillSingleNode(MapNode *node)
103103
{
104104
m_blockpos = v3s16(0,0,0);
105-
105+
106106
v3s16 blockpos_nodes = v3s16(0,0,0);
107107
VoxelArea area(blockpos_nodes-v3s16(1,1,1)*MAP_BLOCKSIZE,
108108
blockpos_nodes+v3s16(1,1,1)*MAP_BLOCKSIZE*2-v3s16(1,1,1));
@@ -257,6 +257,12 @@ static u8 getSmoothLight(enum LightBank bank, v3s16 p, MeshMakeData *data)
257257
for(u32 i=0; i<8; i++)
258258
{
259259
MapNode n = data->m_vmanip.getNodeNoEx(p - dirs8[i]);
260+
261+
if (n.getContent() == CONTENT_IGNORE) {
262+
ambient_occlusion++;
263+
continue;
264+
}
265+
260266
const ContentFeatures &f = ndef->get(n);
261267
if(f.light_source > light_source_max)
262268
light_source_max = f.light_source;
@@ -267,15 +273,11 @@ static u8 getSmoothLight(enum LightBank bank, v3s16 p, MeshMakeData *data)
267273
light += decode_light(n.getLight(bank, ndef));
268274
light_count++;
269275
}
270-
else if(n.getContent() != CONTENT_IGNORE)
271-
{
272-
ambient_occlusion++;
273-
}
274276
}
275277

276278
if(light_count == 0)
277279
return 255;
278-
280+
279281
light /= light_count;
280282

281283
// Boost brightness around light sources
@@ -323,7 +325,7 @@ u16 getSmoothLight(v3s16 p, v3s16 corner, MeshMakeData *data)
323325
else assert(corner.Y == -1);
324326
if(corner.Z == 1) p.Z += 1;
325327
else assert(corner.Z == -1);
326-
328+
327329
return getSmoothLight(p, data);
328330
}
329331

@@ -630,16 +632,16 @@ static u8 face_contents(content_t m1, content_t m2, bool *equivalent,
630632

631633
if(m1 == CONTENT_IGNORE || m2 == CONTENT_IGNORE)
632634
return 0;
633-
635+
634636
bool contents_differ = (m1 != m2);
635-
637+
636638
const ContentFeatures &f1 = ndef->get(m1);
637639
const ContentFeatures &f2 = ndef->get(m2);
638640

639641
// Contents don't differ for different forms of same liquid
640642
if(f1.sameLiquid(f2))
641643
contents_differ = false;
642-
644+
643645
u8 c1 = f1.solidness;
644646
u8 c2 = f2.solidness;
645647

@@ -648,12 +650,12 @@ static u8 face_contents(content_t m1, content_t m2, bool *equivalent,
648650

649651
if(makes_face == false)
650652
return 0;
651-
653+
652654
if(c1 == 0)
653655
c1 = f1.visual_solidness;
654656
if(c2 == 0)
655657
c2 = f2.visual_solidness;
656-
658+
657659
if(c1 == c2){
658660
*equivalent = true;
659661
// If same solidness, liquid takes precense
@@ -662,7 +664,7 @@ static u8 face_contents(content_t m1, content_t m2, bool *equivalent,
662664
if(f2.isLiquid())
663665
return 2;
664666
}
665-
667+
666668
if(c1 > c2)
667669
return 1;
668670
else
@@ -712,7 +714,7 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 dir, MeshMakeData *data)
712714
facedir = 0;
713715
static const u16 dir_to_tile[24 * 16] =
714716
{
715-
// 0 +X +Y +Z -Z -Y -X -> value=tile,rotation
717+
// 0 +X +Y +Z -Z -Y -X -> value=tile,rotation
716718
0,0, 2,0 , 0,0 , 4,0 , 0,0, 5,0 , 1,0 , 3,0 , // rotate around y+ 0 - 3
717719
0,0, 4,0 , 0,3 , 3,0 , 0,0, 2,0 , 1,1 , 5,0 ,
718720
0,0, 3,0 , 0,2 , 5,0 , 0,0, 4,0 , 1,2 , 2,0 ,
@@ -733,15 +735,15 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 dir, MeshMakeData *data)
733735
0,0, 0,1 , 2,3 , 5,1 , 0,0, 4,3 , 3,3 , 1,1 ,
734736
0,0, 0,0 , 4,3 , 2,1 , 0,0, 3,3 , 5,3 , 1,2 ,
735737

736-
0,0, 1,1 , 2,1 , 4,3 , 0,0, 5,1 , 3,1 , 0,1 , // rotate around x- 16 - 19
738+
0,0, 1,1 , 2,1 , 4,3 , 0,0, 5,1 , 3,1 , 0,1 , // rotate around x- 16 - 19
737739
0,0, 1,2 , 4,1 , 3,3 , 0,0, 2,1 , 5,1 , 0,0 ,
738-
0,0, 1,3 , 3,1 , 5,3 , 0,0, 4,1 , 2,1 , 0,3 ,
739-
0,0, 1,0 , 5,1 , 2,3 , 0,0, 3,1 , 4,1 , 0,2 ,
740+
0,0, 1,3 , 3,1 , 5,3 , 0,0, 4,1 , 2,1 , 0,3 ,
741+
0,0, 1,0 , 5,1 , 2,3 , 0,0, 3,1 , 4,1 , 0,2 ,
740742

741743
0,0, 3,2 , 1,2 , 4,2 , 0,0, 5,2 , 0,2 , 2,2 , // rotate around y- 20 - 23
742-
0,0, 5,2 , 1,3 , 3,2 , 0,0, 2,2 , 0,1 , 4,2 ,
743-
0,0, 2,2 , 1,0 , 5,2 , 0,0, 4,2 , 0,0 , 3,2 ,
744-
0,0, 4,2 , 1,1 , 2,2 , 0,0, 3,2 , 0,3 , 5,2
744+
0,0, 5,2 , 1,3 , 3,2 , 0,0, 2,2 , 0,1 , 4,2 ,
745+
0,0, 2,2 , 1,0 , 5,2 , 0,0, 4,2 , 0,0 , 3,2 ,
746+
0,0, 4,2 , 1,1 , 2,2 , 0,0, 3,2 , 0,3 , 5,2
745747

746748
};
747749
u16 tile_index=facedir*16 + dir_i;
@@ -770,14 +772,14 @@ static void getTileInfo(
770772
v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
771773

772774
MapNode n0 = vmanip.getNodeNoEx(blockpos_nodes + p);
773-
775+
774776
// Don't even try to get n1 if n0 is already CONTENT_IGNORE
775777
if (n0.getContent() == CONTENT_IGNORE ) {
776778
makes_face = false;
777779
return;
778780
}
779781
MapNode n1 = vmanip.getNodeNoEx(blockpos_nodes + p + face_dir);
780-
782+
781783
// This is hackish
782784
bool equivalent = false;
783785
u8 mf = face_contents(n0.getContent(), n1.getContent(),
@@ -790,7 +792,7 @@ static void getTileInfo(
790792
}
791793

792794
makes_face = true;
793-
795+
794796
if(mf == 1)
795797
{
796798
tile = getNodeTile(n0, p, face_dir, data);
@@ -805,7 +807,7 @@ static void getTileInfo(
805807
face_dir_corrected = -face_dir;
806808
light_source = ndef->get(n1).light_source;
807809
}
808-
810+
809811
// eg. water and glass
810812
if(equivalent)
811813
tile.material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
@@ -826,7 +828,7 @@ static void getTileInfo(
826828
vertex_dirs[i], data);
827829
}
828830
}
829-
831+
830832
return;
831833
}
832834

@@ -845,44 +847,44 @@ static void updateFastFaceRow(
845847
std::vector<FastFace> &dest)
846848
{
847849
v3s16 p = startpos;
848-
850+
849851
u16 continuous_tiles_count = 0;
850-
852+
851853
bool makes_face = false;
852854
v3s16 p_corrected;
853855
v3s16 face_dir_corrected;
854856
u16 lights[4] = {0,0,0,0};
855857
TileSpec tile;
856858
u8 light_source = 0;
857-
getTileInfo(data, p, face_dir,
859+
getTileInfo(data, p, face_dir,
858860
makes_face, p_corrected, face_dir_corrected,
859861
lights, tile, light_source);
860862

861863
for(u16 j=0; j<MAP_BLOCKSIZE; j++)
862864
{
863865
// If tiling can be done, this is set to false in the next step
864866
bool next_is_different = true;
865-
867+
866868
v3s16 p_next;
867-
869+
868870
bool next_makes_face = false;
869871
v3s16 next_p_corrected;
870872
v3s16 next_face_dir_corrected;
871873
u16 next_lights[4] = {0,0,0,0};
872874
TileSpec next_tile;
873875
u8 next_light_source = 0;
874-
876+
875877
// If at last position, there is nothing to compare to and
876878
// the face must be drawn anyway
877879
if(j != MAP_BLOCKSIZE - 1)
878880
{
879881
p_next = p + translate_dir;
880-
882+
881883
getTileInfo(data, p_next, face_dir,
882884
next_makes_face, next_p_corrected,
883885
next_face_dir_corrected, next_lights,
884886
next_tile, next_light_source);
885-
887+
886888
if(next_makes_face == makes_face
887889
&& next_p_corrected == p_corrected + translate_dir
888890
&& next_face_dir_corrected == face_dir_corrected
@@ -922,7 +924,7 @@ static void updateFastFaceRow(
922924
}
923925

924926
continuous_tiles_count++;
925-
927+
926928
if(next_is_different)
927929
{
928930
/*
@@ -950,19 +952,19 @@ static void updateFastFaceRow(
950952
{
951953
scale.Z = continuous_tiles_count;
952954
}
953-
955+
954956
makeFastFace(tile, lights[0], lights[1], lights[2], lights[3],
955957
sp, face_dir_corrected, scale, light_source,
956958
dest);
957-
959+
958960
g_profiler->avg("Meshgen: faces drawn by tiling", 0);
959961
for(int i=1; i<continuous_tiles_count; i++){
960962
g_profiler->avg("Meshgen: faces drawn by tiling", 1);
961963
}
962964
}
963965

964966
continuous_tiles_count = 0;
965-
967+
966968
makes_face = next_makes_face;
967969
p_corrected = next_p_corrected;
968970
face_dir_corrected = next_face_dir_corrected;
@@ -973,7 +975,7 @@ static void updateFastFaceRow(
973975
tile = next_tile;
974976
light_source = next_light_source;
975977
}
976-
978+
977979
p = p_next;
978980
}
979981
}
@@ -1077,12 +1079,12 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
10771079

10781080
const u16 indices[] = {0,1,2,2,3,0};
10791081
const u16 indices_alternate[] = {0,1,3,2,3,1};
1080-
1082+
10811083
if(f.tile.texture == NULL)
10821084
continue;
10831085

10841086
const u16 *indices_p = indices;
1085-
1087+
10861088
/*
10871089
Revert triangles for nicer looking gradient if vertices
10881090
1 and 3 have same color or 0 and 2 have different color.
@@ -1091,7 +1093,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
10911093
if(f.vertices[0].Color.getRed() != f.vertices[2].Color.getRed()
10921094
|| f.vertices[1].Color.getRed() == f.vertices[3].Color.getRed())
10931095
indices_p = indices_alternate;
1094-
1096+
10951097
collector.append(f.tile, f.vertices, 4, indices_p, 6);
10961098
}
10971099
}
@@ -1105,7 +1107,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
11051107
*/
11061108

11071109
mapblock_mesh_generate_special(data, collector);
1108-
1110+
11091111

11101112
/*
11111113
Convert MeshCollector to SMesh
@@ -1198,7 +1200,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
11981200

11991201
if (enable_shaders) {
12001202
material.MaterialType = shdrsrc->getShaderInfo(p.tile.shader_id).material;
1201-
p.tile.applyMaterialOptionsWithShaders(material);
1203+
p.tile.applyMaterialOptionsWithShaders(material);
12021204
material.setTexture(2, tsrc->getTexture("disable_img.png"));
12031205
if (enable_bumpmapping || enable_parallax_occlusion) {
12041206
if (tsrc->isKnownSourceImage("override_normal.png")){
@@ -1211,7 +1213,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
12111213
std::string fname_normal = fname_base.substr(0, pos) + normal_ext;
12121214

12131215
if (tsrc->isKnownSourceImage(fname_normal)) {
1214-
// look for image extension and replace it
1216+
// look for image extension and replace it
12151217
size_t i = 0;
12161218
while ((i = fname_base.find(".", i)) != std::string::npos) {
12171219
fname_base.replace(i, 4, normal_ext);
@@ -1241,7 +1243,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
12411243
}
12421244

12431245
m_camera_offset = camera_offset;
1244-
1246+
12451247
/*
12461248
Do some stuff to the mesh
12471249
*/
@@ -1267,7 +1269,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
12671269
the hardware buffer and then delete the mesh
12681270
*/
12691271
}
1270-
1272+
12711273
//std::cout<<"added "<<fastfaces.getSize()<<" faces."<<std::endl;
12721274

12731275
// Check if animation is required for this mesh
@@ -1331,7 +1333,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
13311333

13321334
m_last_crack = crack;
13331335
}
1334-
1336+
13351337
// Texture animation
13361338
for(std::map<u32, TileSpec>::iterator
13371339
i = m_animation_tiles.begin();

0 commit comments

Comments
 (0)