]> 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 bff366addc2e4bee975b40d39b1feecdd0ced727..d489ec8ac11d47137c7ddc60e93bec895d5e464f 100644 (file)
@@ -255,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;
@@ -661,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.
@@ -736,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++)
                {
@@ -837,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
@@ -1081,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};
@@ -1120,7 +1105,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                        //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
                                        s32 j = corner_resolve[i];
                                        vertices[i].Pos.Y += corner_levels[j];
-                                       vertices[i].Pos += intToFloat(p + getPosRelative());
+                                       vertices[i].Pos += intToFloat(p + getPosRelative(), BS);
                                }
 
                                u16 indices[] = {0,1,2,2,3,0};
@@ -1157,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};
@@ -1182,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++)
@@ -1236,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};
@@ -1610,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);
                                }
                        }
@@ -1770,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;
@@ -1894,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);