]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mapblock.cpp
Fixed insufficient error handling in narrow_to_wide, which caused a crash if the...
[dragonfireclient.git] / src / mapblock.cpp
index e0b8965b43cacc5ac4d748149b2423e0354e8a16..d489ec8ac11d47137c7ddc60e93bec895d5e464f 100644 (file)
@@ -148,25 +148,6 @@ u8 MapBlock::getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
                v3s16 face_dir)
 {
        try{
-               // DEBUG
-               /*{
-                       if(n.d == CONTENT_WATER)
-                       {
-                               u8 l = n.param2*2;
-                               if(l > LIGHT_MAX)
-                                       l = LIGHT_MAX;
-                               return l;
-                       }
-                       if(n2.d == CONTENT_WATER)
-                       {
-                               u8 l = n2.param2*2;
-                               if(l > LIGHT_MAX)
-                                       l = LIGHT_MAX;
-                               return l;
-                       }
-               }*/
-
-
                u8 light;
                u8 l1 = n.getLightBlend(daynight_ratio);
                u8 l2 = n2.getLightBlend(daynight_ratio);
@@ -177,11 +158,13 @@ u8 MapBlock::getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
 
                // Make some nice difference to different sides
 
+               // This makes light come from a corner
                /*if(face_dir.X == 1 || face_dir.Z == 1 || face_dir.Y == -1)
                        light = diminish_light(diminish_light(light));
                else if(face_dir.X == -1 || face_dir.Z == -1)
                        light = diminish_light(light);*/
-
+               
+               // All neighboring faces have different shade (like in minecraft)
                if(face_dir.X == 1 || face_dir.X == -1 || face_dir.Y == -1)
                        light = diminish_light(diminish_light(light));
                else if(face_dir.Z == 1 || face_dir.Z == -1)
@@ -272,32 +255,18 @@ void MapBlock::makeFastFace(TileSpec tile, u8 light, v3f p,
 
        video::SColor c = video::SColor(alpha,li,li,li);
 
-       face.vertices[0] = video::S3DVertex(vertex_pos[0], zerovector, c,
-                       core::vector2d<f32>(abs_scale,1));
-       face.vertices[1] = video::S3DVertex(vertex_pos[1], zerovector, c,
-                       core::vector2d<f32>(0,1));
-       face.vertices[2] = video::S3DVertex(vertex_pos[2], zerovector, c,
-                       core::vector2d<f32>(0,0));
-       face.vertices[3] = video::S3DVertex(vertex_pos[3], zerovector, c,
-                       core::vector2d<f32>(abs_scale,0));
-       
-       /*float x0 = (float)tile.tx/256.0;
-       float y0 = (float)tile.ty/256.0;
-       float w = ((float)tile.tw + 1.0)/256.0;
-       float h = ((float)tile.th + 1.0)/256.0;*/
-
        float x0 = tile.texture.pos.X;
        float y0 = tile.texture.pos.Y;
        float w = tile.texture.size.X;
        float h = tile.texture.size.Y;
 
-       face.vertices[0] = video::S3DVertex(vertex_pos[0], zerovector, c,
+       face.vertices[0] = video::S3DVertex(vertex_pos[0], v3f(0,1,0), c,
                        core::vector2d<f32>(x0+w*abs_scale, y0+h));
-       face.vertices[1] = video::S3DVertex(vertex_pos[1], zerovector, c,
+       face.vertices[1] = video::S3DVertex(vertex_pos[1], v3f(0,1,0), c,
                        core::vector2d<f32>(x0, y0+h));
-       face.vertices[2] = video::S3DVertex(vertex_pos[2], zerovector, c,
+       face.vertices[2] = video::S3DVertex(vertex_pos[2], v3f(0,1,0), c,
                        core::vector2d<f32>(x0, y0));
-       face.vertices[3] = video::S3DVertex(vertex_pos[3], zerovector, c,
+       face.vertices[3] = video::S3DVertex(vertex_pos[3], v3f(0,1,0), c,
                        core::vector2d<f32>(x0+w*abs_scale, y0));
 
        face.tile = tile;
@@ -678,7 +647,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
        
        float node_water_level = 1.0;
        if(new_style_water)
-               node_water_level = 0.9;
+               node_water_level = 0.85;
        
        /*
                We are including the faces of the trailing edges of the block.
@@ -753,12 +722,11 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                //TimeTaker timer2("updateMesh() mesh building");
 
                video::SMaterial material;
-               material.Lighting = false;
-               material.BackfaceCulling = false;
+               material.setFlag(video::EMF_LIGHTING, false);
                material.setFlag(video::EMF_BILINEAR_FILTER, false);
+               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.setFlag(video::EMF_FOG_ENABLE, true);
 
                for(u32 i=0; i<fastfaces_new.size(); i++)
                {
@@ -791,7 +759,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
        // Flowing water material
        video::SMaterial material_water1;
        material_water1.setFlag(video::EMF_LIGHTING, false);
-       material_water1.setFlag(video::EMF_BACK_FACE_CULLING, false);
+       //material_water1.setFlag(video::EMF_BACK_FACE_CULLING, false);
        material_water1.setFlag(video::EMF_BILINEAR_FILTER, false);
        material_water1.setFlag(video::EMF_FOG_ENABLE, true);
        material_water1.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
@@ -854,7 +822,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                if(dir == v3s16(0,1,0))
                                        vertices[i].Pos.rotateXZBy(-45);
 
-                               vertices[i].Pos += intToFloat(p + getPosRelative());
+                               vertices[i].Pos += intToFloat(p + getPosRelative(), BS);
                        }
 
                        // Set material
@@ -1040,9 +1008,9 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                        video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
                                        video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
                                        video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
-                                       video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
+                                       video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
                                                        pa_water1.x0(), pa_water1.y1()),
-                                       video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
+                                       video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
                                                        pa_water1.x1(), pa_water1.y1()),
                                        video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
                                                        pa_water1.x1(), pa_water1.y0()),
@@ -1098,7 +1066,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                        if(dir == v3s16(1,0,-0))
                                                vertices[j].Pos.rotateXZBy(-90);
 
-                                       vertices[j].Pos += intToFloat(p + getPosRelative());
+                                       vertices[j].Pos += intToFloat(p + getPosRelative(), BS);
                                }
 
                                u16 indices[] = {0,1,2,2,3,0};
@@ -1118,22 +1086,26 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                        video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,1),
                                        video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
                                        video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
-                                       video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
+                                       video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
                                                        pa_water1.x0(), pa_water1.y1()),
-                                       video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
-                                                       pa_water1.x1(), pa_water1.y1()),
                                        video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
+                                                       pa_water1.x1(), pa_water1.y1()),
+                                       video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
                                                        pa_water1.x1(), pa_water1.y0()),
-                                       video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
+                                       video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
                                                        pa_water1.x0(), pa_water1.y0()),
                                };
+                               
+                               // This fixes a strange bug
+                               s32 corner_resolve[4] = {3,2,1,0};
 
                                for(s32 i=0; i<4; i++)
                                {
                                        //vertices[i].Pos.Y += water_level;
                                        //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
-                                       vertices[i].Pos.Y += corner_levels[i];
-                                       vertices[i].Pos += intToFloat(p + getPosRelative());
+                                       s32 j = corner_resolve[i];
+                                       vertices[i].Pos.Y += corner_levels[j];
+                                       vertices[i].Pos += intToFloat(p + getPosRelative(), BS);
                                }
 
                                u16 indices[] = {0,1,2,2,3,0};
@@ -1170,20 +1142,20 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,1),
                                video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
                                video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
-                               video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
+                               video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
                                                pa_water1.x0(), pa_water1.y1()),
-                               video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
-                                               pa_water1.x1(), pa_water1.y1()),
                                video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
+                                               pa_water1.x1(), pa_water1.y1()),
+                               video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
                                                pa_water1.x1(), pa_water1.y0()),
-                               video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
+                               video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
                                                pa_water1.x0(), pa_water1.y0()),
                        };
 
                        for(s32 i=0; i<4; i++)
                        {
                                vertices[i].Pos.Y += (-0.5+node_water_level)*BS;
-                               vertices[i].Pos += intToFloat(p + getPosRelative());
+                               vertices[i].Pos += intToFloat(p + getPosRelative(), BS);
                        }
 
                        u16 indices[] = {0,1,2,2,3,0};
@@ -1195,7 +1167,8 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                */
                else if(n.d == CONTENT_LEAVES && new_style_leaves)
                {
-                       u8 l = decode_light(n.getLightBlend(daynight_ratio));
+                       /*u8 l = decode_light(n.getLightBlend(daynight_ratio));*/
+                       u8 l = decode_light(undiminish_light(n.getLightBlend(daynight_ratio)));
                        video::SColor c(255,l,l,l);
 
                        for(u32 j=0; j<6; j++)
@@ -1249,7 +1222,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
 
                                for(u16 i=0; i<4; i++)
                                {
-                                       vertices[i].Pos += intToFloat(p + getPosRelative());
+                                       vertices[i].Pos += intToFloat(p + getPosRelative(), BS);
                                }
 
                                u16 indices[] = {0,1,2,2,3,0};
@@ -1623,7 +1596,7 @@ void MapBlock::stepObjects(float dtime, bool server, u32 daynight_ratio)
                                if(getNode(p).d == CONTENT_AIR
                                                && getNode(p).getLightBlend(daynight_ratio) <= 11)
                                {
-                                       RatObject *obj = new RatObject(NULL, -1, intToFloat(p));
+                                       RatObject *obj = new RatObject(NULL, -1, intToFloat(p, BS));
                                        addObject(obj);
                                }
                        }
@@ -1783,11 +1756,11 @@ void MapBlock::serialize(std::ostream &os, u8 version)
                // First byte
                u8 flags = 0;
                if(is_underground)
-                       flags |= 1;
+                       flags |= 0x01;
                if(m_day_night_differs)
-                       flags |= 2;
+                       flags |= 0x02;
                if(m_lighting_expired)
-                       flags |= 3;
+                       flags |= 0x04;
                os.write((char*)&flags, 1);
 
                u32 nodecount = MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE;
@@ -1907,9 +1880,9 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
 
                u8 flags;
                is.read((char*)&flags, 1);
-               is_underground = (flags & 1) ? true : false;
-               m_day_night_differs = (flags & 2) ? true : false;
-               m_lighting_expired = (flags & 3) ? true : false;
+               is_underground = (flags & 0x01) ? true : false;
+               m_day_night_differs = (flags & 0x02) ? true : false;
+               m_lighting_expired = (flags & 0x04) ? true : false;
 
                // Uncompress data
                std::ostringstream os(std::ios_base::binary);