]> git.lizzy.rs Git - minetest.git/blobdiff - src/mapblock_mesh.cpp
Warnings fix
[minetest.git] / src / mapblock_mesh.cpp
index 5e4d713b0107e4f676198e2607e43680717c9d75..40158e1ad388355be49ee1f02af323e0a067290c 100644 (file)
@@ -448,7 +448,7 @@ 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;
 
@@ -460,7 +460,9 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
        v3f vertex_pos[4];
        v3s16 vertex_dirs[4];
        getNodeVertexDirs(dir, vertex_dirs);
+
        v3s16 t;
+       u16 t1;
        switch (tile.rotation)
        {
        case 0:
@@ -471,6 +473,11 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
                vertex_dirs[3] = vertex_dirs[2];
                vertex_dirs[2] = vertex_dirs[1];
                vertex_dirs[1] = t;
+               t1=li0;
+               li0=li3;
+               li3=li2;
+               li2=li1;
+               li1=t1;
                break;
        case 2: //R180
                t = vertex_dirs[0];
@@ -479,6 +486,12 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
                t = vertex_dirs[1];
                vertex_dirs[1] = vertex_dirs[3];
                vertex_dirs[3] = t;
+               t1  = li0;
+               li0 = li2;
+               li2 = t1;
+               t1  = li1;
+               li1 = li3;
+               li3 = t1;
                break;
        case 3: //R270
                t = vertex_dirs[0];
@@ -486,6 +499,11 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
                vertex_dirs[1] = vertex_dirs[2];
                vertex_dirs[2] = vertex_dirs[3];
                vertex_dirs[3] = t;
+               t1  = li0;
+               li0 = li1;
+               li1 = li2;
+               li2 = li3;
+               li3 = t1;
                break;
        case 4: //FXR90
                t = vertex_dirs[0];
@@ -493,6 +511,11 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
                vertex_dirs[3] = vertex_dirs[2];
                vertex_dirs[2] = vertex_dirs[1];
                vertex_dirs[1] = t;
+               t1  = li0;
+               li0 = li3;
+               li3 = li2;
+               li2 = li1;
+               li1 = t1;
                y0 += h;
                h *= -1;
                break;
@@ -502,6 +525,11 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
                vertex_dirs[1] = vertex_dirs[2];
                vertex_dirs[2] = vertex_dirs[3];
                vertex_dirs[3] = t;
+               t1  = li0;
+               li0 = li1;
+               li1 = li2;
+               li2 = li3;
+               li3 = t1;
                y0 += h;
                h *= -1;
                break;
@@ -511,6 +539,11 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
                vertex_dirs[3] = vertex_dirs[2];
                vertex_dirs[2] = vertex_dirs[1];
                vertex_dirs[1] = t;
+               t1  = li0;
+               li0 = li3;
+               li3 = li2;
+               li2 = li1;
+               li1 = t1;
                x0 += w;
                w *= -1;
                break;
@@ -520,6 +553,11 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
                vertex_dirs[1] = vertex_dirs[2];
                vertex_dirs[2] = vertex_dirs[3];
                vertex_dirs[3] = t;
+               t1  = li0;
+               li0 = li1;
+               li1 = li2;
+               li2 = li3;
+               li3 = t1;
                x0 += w;
                w *= -1;
                break;
@@ -534,6 +572,7 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
        default:
                break;
        }
+
        for(u16 i=0; i<4; i++)
        {
                vertex_pos[i] = v3f(
@@ -551,7 +590,7 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
                vertex_pos[i] += pos;
        }
 
-       f32 abs_scale = 1.;
+       f32 abs_scale = 1.0;
        if     (scale.X < 0.999 || scale.X > 1.001) abs_scale = scale.X;
        else if(scale.Y < 0.999 || scale.Y > 1.001) abs_scale = scale.Y;
        else if(scale.Z < 0.999 || scale.Z > 1.001) abs_scale = scale.Z;
@@ -574,7 +613,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);
 }
 
@@ -1069,10 +1107,9 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
 
        /*
                Convert MeshCollector to SMesh
-               Also store animation info
        */
-       bool enable_shaders = (g_settings->getS32("enable_shaders") > 0);
        bool enable_bumpmapping = g_settings->getBool("enable_bumpmapping");
+       bool enable_shaders = g_settings->getBool("enable_shaders");
        video::E_MATERIAL_TYPE shadermat1 = m_gamedef->getShaderSource()->
                        getShader("test_shader_1").material;
        video::E_MATERIAL_TYPE shadermat2 = m_gamedef->getShaderSource()->
@@ -1157,38 +1194,41 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
                material.setFlag(video::EMF_FOG_ENABLE, true);
                //material.setFlag(video::EMF_ANTI_ALIASING, video::EAAM_OFF);
                //material.setFlag(video::EMF_ANTI_ALIASING, video::EAAM_SIMPLE);
-               material.MaterialType
-                               = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+               material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
                material.setTexture(0, p.tile.texture);
-               if (enable_shaders)
-                       {
-                               if (enable_bumpmapping)
-                                       {
-                                               ITextureSource *tsrc = data->m_gamedef->tsrc();
-                                               std::string basename,normal,replace;
-                                               replace = "_normal.png";
-                                               basename = tsrc->getTextureName(p.tile.texture_id);
-                                               unsigned pos = basename.find(".");
-                                               normal = basename.substr (0, pos) + replace;
-                                               if (tsrc->isKnownSourceImage(normal))
-                                                       {
-                                                               // look for image extension and replace it 
-                                                               for(std::string::size_type i = 0; (i = basename.find(".", i)) != std::string::npos;)
-                                                                       {
-                                                                               basename.replace(i, 4, replace);
-                                                                               i += replace.length();
-                                                                       }
-                                                               material.setTexture(1, tsrc->getTexture(basename));             
-                                                               p.tile.applyMaterialOptionsWithShaders(material, bumpmaps1,bumpmaps2, shadermat3);
-                                                       }
-                                               else 
-                                                       p.tile.applyMaterialOptionsWithShaders(material, shadermat1, shadermat2, shadermat3);
+       
+               if (enable_shaders) {
+                       video::E_MATERIAL_TYPE smat1 = shadermat1;
+                       video::E_MATERIAL_TYPE smat2 = shadermat2;
+                       video::E_MATERIAL_TYPE smat3 = shadermat3;
+                       
+                       if (enable_bumpmapping) {
+                               ITextureSource *tsrc = data->m_gamedef->tsrc();
+                               std::string fname_base = tsrc->getTextureName(p.tile.texture_id);
+
+                               std::string normal_ext = "_normal.png";
+                               size_t pos = fname_base.find(".");
+                               std::string fname_normal = fname_base.substr(0, pos) + normal_ext;
+                               
+                               if (tsrc->isKnownSourceImage(fname_normal)) {
+                                       // look for image extension and replace it 
+                                       size_t i = 0;
+                                       while ((i = fname_base.find(".", i)) != std::string::npos) {
+                                               fname_base.replace(i, 4, normal_ext);
+                                               i += normal_ext.length();
                                        }
-                               else            
-                                               p.tile.applyMaterialOptionsWithShaders(material, shadermat1, shadermat2, shadermat3);   
+                                       
+                                       material.setTexture(1, tsrc->getTexture(fname_base));
+                                       
+                                       smat1 = bumpmaps1;
+                                       smat2 = bumpmaps2;
+                               }
                        }
-               else
+                       
+                       p.tile.applyMaterialOptionsWithShaders(material, smat1, smat2, smat3);
+               } else {
                        p.tile.applyMaterialOptions(material);
+               }
 
                // Create meshbuffer