]> git.lizzy.rs Git - minetest.git/blobdiff - src/mapblock_mesh.cpp
Fix mod store rating
[minetest.git] / src / mapblock_mesh.cpp
index 318be14d69d2ffd68876378aefad6a0672b3dd08..ab4b63f864aa06beffce28946dd35b2406a0f759 100644 (file)
@@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "light.h"
 #include "mapblock.h"
 #include "map.h"
-#include "main.h" // for g_profiler
 #include "profiler.h"
 #include "nodedef.h"
 #include "gamedef.h"
@@ -248,7 +247,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 +437,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 +587,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 +605,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 +745,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 +760,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;
@@ -1029,7 +1035,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
        m_last_daynight_ratio((u32) -1),
        m_daynight_diffs()
 {
-       m_enable_shaders = g_settings->getBool("enable_shaders");
+       m_enable_shaders = data->m_use_shaders;
        m_enable_highlighting = g_settings->getBool("enable_node_highlighting");
 
        // 4-21ms for MAP_BLOCKSIZE=16  (NOTE: probably outdated)
@@ -1037,6 +1043,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.
@@ -1122,7 +1129,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
                        os<<":"<<(u32)p.tile.animation_frame_count<<":";
                        m_crack_materials.insert(std::make_pair(i, os.str()));
                        // Replace tile texture with the cracked one
-                       p.tile.texture = tsrc->getTexture(
+                       p.tile.texture = tsrc->getTextureForMesh(
                                        os.str()+"0",
                                        &p.tile.texture_id);
                }
@@ -1196,9 +1203,9 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
                                p.tile.applyMaterialOptionsWithShaders(material);
                                if (p.tile.normal_texture) {
                                        material.setTexture(1, p.tile.normal_texture);
-                                       material.setTexture(2, tsrc->getTexture("enable_img.png"));
+                                       material.setTexture(2, tsrc->getTextureForMesh("enable_img.png"));
                                } else {
-                                       material.setTexture(2, tsrc->getTexture("disable_img.png"));
+                                       material.setTexture(2, tsrc->getTextureForMesh("disable_img.png"));
                                }
                        } else {
                                p.tile.applyMaterialOptions(material);
@@ -1290,7 +1297,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
                        os<<basename<<crack;
                        u32 new_texture_id = 0;
                        video::ITexture *new_texture =
-                               tsrc->getTexture(os.str(), &new_texture_id);
+                               tsrc->getTextureForMesh(os.str(), &new_texture_id);
                        buf->getMaterial().setTexture(0, new_texture);
 
                        // If the current material is also animated,
@@ -1333,9 +1340,9 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
                if (m_enable_shaders) {
                        if (animation_frame.normal_texture) {
                                buf->getMaterial().setTexture(1, animation_frame.normal_texture);
-                               buf->getMaterial().setTexture(2, tsrc->getTexture("enable_img.png"));
+                               buf->getMaterial().setTexture(2, tsrc->getTextureForMesh("enable_img.png"));
                        } else {
-                               buf->getMaterial().setTexture(2, tsrc->getTexture("disable_img.png"));
+                               buf->getMaterial().setTexture(2, tsrc->getTextureForMesh("disable_img.png"));
                        }
                }
        }