]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mapblock.cpp
comments
[dragonfireclient.git] / src / mapblock.cpp
index 8de81b7741c418cf4b761de8ae13e3b4a717d061..15f3ad9a67591748161185b4b17b1d70c86d1e5e 100644 (file)
@@ -141,6 +141,8 @@ MapNode MapBlock::getNodeParentNoEx(v3s16 p)
                n: getNodeParent(p)
                n2: getNodeParent(p + face_dir)
                face_dir: axis oriented unit vector from p to p2
+       
+       returns encoded light value.
 */
 u8 MapBlock::getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
                v3s16 face_dir)
@@ -262,12 +264,10 @@ void MapBlock::makeFastFace(TileSpec tile, u8 light, v3f p,
        //u8 li = decode_light(light);
        u8 li = light;
 
-       u8 alpha = 255;
-
+       u8 alpha = tile.alpha;
+       /*u8 alpha = 255;
        if(tile.id == TILE_WATER)
-       {
-               alpha = 128;
-       }
+               alpha = WATER_ALPHA;*/
 
        video::SColor c = video::SColor(alpha,li,li,li);
 
@@ -295,17 +295,8 @@ void MapBlock::makeFastFace(TileSpec tile, u8 light, v3f p,
 TileSpec MapBlock::getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir)
 {
        TileSpec spec;
-
-       /*//DEBUG
-       {
-               spec.id = TILE_STONE;
-               return spec;
-       }*/
-
-       spec.feature = TILEFEAT_NONE;
-       //spec.id = TILE_STONE;
-       spec.id = mn.getTile(face_dir);
-
+       spec = mn.getTile(face_dir);
+       
        /*
                Check temporary modifications on this node
        */
@@ -318,12 +309,15 @@ TileSpec MapBlock::getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir)
                struct NodeMod mod = n->getValue();
                if(mod.type == NODEMOD_CHANGECONTENT)
                {
-                       spec.id = content_tile(mod.param, face_dir);
+                       //spec = content_tile(mod.param, face_dir);
+                       MapNode mn2(mod.param);
+                       spec = mn2.getTile(face_dir);
                }
                if(mod.type == NODEMOD_CRACK)
                {
-                       spec.feature = TILEFEAT_CRACK;
-                       spec.param.crack.progression = mod.param;
+                       std::ostringstream os;
+                       os<<"[[mod:crack"<<mod.param;
+                       spec.name += os.str();
                }
        }
        
@@ -607,6 +601,8 @@ void MapBlock::updateMesh(u32 daynight_ratio)
        */
        
        {
+               //TimeTaker timer2("updateMesh() collect");
+
                // Lock this, as m_temp_mods will be used directly
                JMutexAutoLock lock(m_temp_mods_mutex);
 
@@ -668,41 +664,27 @@ void MapBlock::updateMesh(u32 daynight_ratio)
 
        if(fastfaces_new.size() > 0)
        {
+               // avg 0ms (100ms spikes when loading textures the first time)
+               //TimeTaker timer2("updateMesh() mesh building");
+
                for(u32 i=0; i<fastfaces_new.size(); i++)
                {
                        FastFace &f = fastfaces_new[i];
 
                        const u16 indices[] = {0,1,2,2,3,0};
-                       
-                       if(f.tile.feature == TILEFEAT_NONE)
-                       {
-                               collector.append(tile_material_get(f.tile.id), f.vertices, 4,
-                                               indices, 6);
-                       }
-                       else if(f.tile.feature == TILEFEAT_CRACK)
-                       {
-                               const char *path = tile_texture_path_get(f.tile.id);
-
-                               u16 progression = f.tile.param.crack.progression;
-
-                               std::string name = (std::string)path + "_cracked_"
-                                               + (char)('0' + progression);
-
-                               TextureMod *mod = new CrackTextureMod(progression);
 
-                               video::ITexture *texture = g_irrlicht->getTexture(
-                                               TextureSpec(name, path, mod));
-
-                               video::SMaterial material = tile_material_get(f.tile.id);
-                               material.setTexture(0, texture);
-
-                               collector.append(material, f.vertices, 4, indices, 6);
-                       }
-                       else
-                       {
-                               // No such feature
-                               assert(0);
-                       }
+                       video::ITexture *texture = g_irrlicht->getTexture(f.tile.name);
+                       video::SMaterial material;
+                       material.Lighting = false;
+                       material.BackfaceCulling = false;
+                       material.setFlag(video::EMF_BILINEAR_FILTER, false);
+                       material.setFlag(video::EMF_ANTI_ALIASING, video::EAAM_OFF);
+                       material.setFlag(video::EMF_FOG_ENABLE, true);
+                       material.setTexture(0, texture);
+                       if(f.tile.alpha != 255)
+                               material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
+                       
+                       collector.append(material, f.vertices, 4, indices, 6);
                }
        }
 
@@ -713,6 +695,9 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                TODO: Optimize by using same meshbuffer for same textures
        */
 
+       // 0ms
+       //TimeTaker timer2("updateMesh() adding special stuff");
+
        for(s16 z=0; z<MAP_BLOCKSIZE; z++)
        for(s16 y=0; y<MAP_BLOCKSIZE; y++)
        for(s16 x=0; x<MAP_BLOCKSIZE; x++)
@@ -721,6 +706,9 @@ void MapBlock::updateMesh(u32 daynight_ratio)
 
                MapNode &n = getNodeRef(x,y,z);
                
+               /*
+                       Add torches to mesh
+               */
                if(n.d == CONTENT_TORCH)
                {
                        video::SColor c(255,255,255,255);
@@ -779,6 +767,9 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                        // Add to mesh collector
                        collector.append(material, vertices, 4, indices, 6);
                }
+               /*
+                       Add flowing water to mesh
+               */
                else if(n.d == CONTENT_WATER)
                {
                        bool top_is_water = false;
@@ -787,8 +778,9 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                if(n.d == CONTENT_WATER || n.d == CONTENT_WATERSOURCE)
                                        top_is_water = true;
                        }catch(InvalidPositionException &e){}
-
-                       video::SColor c(128,255,255,255);
+                       
+                       u8 l = decode_light(n.getLightBlend(daynight_ratio));
+                       video::SColor c(WATER_ALPHA,l,l,l);
                        
                        // Neighbor water levels (key = relative position)
                        // Includes current node
@@ -960,6 +952,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                material.setFlag(video::EMF_LIGHTING, false);
                                material.setFlag(video::EMF_BACK_FACE_CULLING, false);
                                material.setFlag(video::EMF_BILINEAR_FILTER, false);
+                               material.setFlag(video::EMF_FOG_ENABLE, true);
                                material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
                                material.setTexture(0,
                                                g_irrlicht->getTexture(porting::getDataPath("water.png").c_str()));
@@ -996,6 +989,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                material.setFlag(video::EMF_LIGHTING, false);
                                material.setFlag(video::EMF_BACK_FACE_CULLING, false);
                                material.setFlag(video::EMF_BILINEAR_FILTER, false);
+                               material.setFlag(video::EMF_FOG_ENABLE, true);
                                material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
                                material.setTexture(0,
                                                g_irrlicht->getTexture(porting::getDataPath("water.png").c_str()));
@@ -1416,7 +1410,8 @@ s16 MapBlock::getGroundLevel(v2s16 p2d)
                s16 y = MAP_BLOCKSIZE-1;
                for(; y>=0; y--)
                {
-                       if(is_ground_content(getNodeRef(p2d.X, y, p2d.Y).d))
+                       //if(is_ground_content(getNodeRef(p2d.X, y, p2d.Y).d))
+                       if(content_features(getNodeRef(p2d.X, y, p2d.Y).d).walkable)
                        {
                                if(y == MAP_BLOCKSIZE-1)
                                        return -2;
@@ -1493,13 +1488,13 @@ void MapBlock::serialize(std::ostream &os, u8 version)
                
                if(version >= 10)
                {
-                       // Get and compress pressure
-                       SharedBuffer<u8> pressuredata(nodecount);
+                       // Get and compress param2
+                       SharedBuffer<u8> param2data(nodecount);
                        for(u32 i=0; i<nodecount; i++)
                        {
-                               pressuredata[i] = data[i].pressure;
+                               param2data[i] = data[i].param2;
                        }
-                       compress(pressuredata, os, version);
+                       compress(param2data, os, version);
                }
        }
        // All other versions (newest)
@@ -1533,10 +1528,10 @@ void MapBlock::serialize(std::ostream &os, u8 version)
                        databuf[i+nodecount] = data[i].param;
                }
 
-               // Get pressure
+               // Get param2
                for(u32 i=0; i<nodecount; i++)
                {
-                       databuf[i+nodecount*2] = data[i].pressure;
+                       databuf[i+nodecount*2] = data[i].param2;
                }
 
                /*
@@ -1610,7 +1605,7 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
        
                if(version >= 10)
                {
-                       // Uncompress and set pressure data
+                       // Uncompress and set param2 data
                        std::ostringstream os(std::ios_base::binary);
                        decompress(is, os, version);
                        std::string s = os.str();
@@ -1619,7 +1614,7 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
                                                ("MapBlock::deSerialize: invalid format");
                        for(u32 i=0; i<s.size(); i++)
                        {
-                               data[i].pressure = s[i];
+                               data[i].param2 = s[i];
                        }
                }
        }
@@ -1651,10 +1646,10 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
                {
                        data[i].param = s[i+nodecount];
                }
-               // Set pressure
+               // Set param2
                for(u32 i=0; i<nodecount; i++)
                {
-                       data[i].pressure = s[i+nodecount*2];
+                       data[i].param2 = s[i+nodecount*2];
                }
        }
 }