]> git.lizzy.rs Git - minetest.git/blobdiff - src/mapblock_mesh.cpp
Use numeric indices and raw table access with LUA_REGISTRYINDEX
[minetest.git] / src / mapblock_mesh.cpp
index 79e3e81baea6b3ebb8ed173c95378c82008a98d6..6ae9dec14bf040c934887910e7b6a21cba2c061a 100644 (file)
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "nodedef.h"
 #include "gamedef.h"
 #include "mesh.h"
+#include "minimap.h"
 #include "content_mapblock.h"
 #include "noise.h"
 #include "shader.h"
@@ -1028,6 +1029,7 @@ static void updateAllFastFaceRows(MeshMakeData *data,
 
 MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
        m_mesh(new scene::SMesh()),
+       m_minimap_mapblock(NULL),
        m_gamedef(data->m_gamedef),
        m_tsrc(m_gamedef->getTextureSource()),
        m_shdrsrc(m_gamedef->getShaderSource()),
@@ -1041,6 +1043,12 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
        m_enable_shaders = data->m_use_shaders;
        m_enable_highlighting = g_settings->getBool("enable_node_highlighting");
 
+       if (g_settings->getBool("enable_minimap")) {
+               m_minimap_mapblock = new MinimapMapblock;
+               m_minimap_mapblock->getMinimapNodes(
+                       &data->m_vmanip, data->m_blockpos * MAP_BLOCKSIZE);
+       }
+
        // 4-21ms for MAP_BLOCKSIZE=16  (NOTE: probably outdated)
        // 24-155ms for MAP_BLOCKSIZE=32  (NOTE: probably outdated)
        //TimeTaker timer1("MapBlockMesh()");
@@ -1155,7 +1163,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
                }
 
                if(m_enable_highlighting && p.tile.material_flags & MATERIAL_FLAG_HIGHLIGHTED)
-                       m_highlighted_materials.push_back(i);   
+                       m_highlighted_materials.push_back(i);
 
                for(u32 j = 0; j < p.vertices.size(); j++)
                {
@@ -1205,10 +1213,8 @@ 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, m_tsrc->getTextureForMesh("enable_img.png"));
-                               } else {
-                                       material.setTexture(2, m_tsrc->getTextureForMesh("disable_img.png"));
                                }
+                               material.setTexture(2, p.tile.flags_texture);
                        } else {
                                p.tile.applyMaterialOptions(material);
                        }
@@ -1272,6 +1278,7 @@ MapBlockMesh::~MapBlockMesh()
 {
        m_mesh->drop();
        m_mesh = NULL;
+       delete m_minimap_mapblock;
 }
 
 bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_ratio)
@@ -1289,7 +1296,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
        {
                for(std::map<u32, std::string>::iterator
                                i = m_crack_materials.begin();
-                               i != m_crack_materials.end(); i++)
+                               i != m_crack_materials.end(); ++i)
                {
                        scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
                        std::string basename = i->second;
@@ -1321,7 +1328,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
        // Texture animation
        for(std::map<u32, TileSpec>::iterator
                        i = m_animation_tiles.begin();
-                       i != m_animation_tiles.end(); i++)
+                       i != m_animation_tiles.end(); ++i)
        {
                const TileSpec &tile = i->second;
                // Figure out current frame
@@ -1341,10 +1348,8 @@ 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, m_tsrc->getTextureForMesh("enable_img.png"));
-                       } else {
-                               buf->getMaterial().setTexture(2, m_tsrc->getTextureForMesh("disable_img.png"));
                        }
+                       buf->getMaterial().setTexture(2, animation_frame.flags_texture);
                }
        }
 
@@ -1353,13 +1358,13 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
        {
                for(std::map<u32, std::map<u32, std::pair<u8, u8> > >::iterator
                                i = m_daynight_diffs.begin();
-                               i != m_daynight_diffs.end(); i++)
+                               i != m_daynight_diffs.end(); ++i)
                {
                        scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
                        video::S3DVertexTangents *vertices = (video::S3DVertexTangents *)buf->getVertices();
                        for(std::map<u32, std::pair<u8, u8 > >::iterator
                                        j = i->second.begin();
-                                       j != i->second.end(); j++)
+                                       j != i->second.end(); ++j)
                        {
                                u8 day = j->second.first;
                                u8 night = j->second.second;
@@ -1372,7 +1377,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
        // Node highlighting
        if (m_enable_highlighting) {
                u8 day = m_highlight_mesh_color.getRed();
-               u8 night = m_highlight_mesh_color.getGreen();   
+               u8 night = m_highlight_mesh_color.getGreen();
                video::SColor hc;
                finalColorBlend(hc, day, night, daynight_ratio);
                float sin_r = 0.07 * sin(1.5 * time);
@@ -1384,7 +1389,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
 
                for(std::list<u32>::iterator
                        i = m_highlighted_materials.begin();
-                       i != m_highlighted_materials.end(); i++)
+                       i != m_highlighted_materials.end(); ++i)
                {
                        scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(*i);
                        video::S3DVertexTangents *vertices = (video::S3DVertexTangents*)buf->getVertices();