]> git.lizzy.rs Git - minetest.git/blobdiff - src/mapblock_mesh.cpp
Fix logic of checkbox formspec element validity checking
[minetest.git] / src / mapblock_mesh.cpp
index 3324dd2b68a6de812844f562970233918f69a619..f4a44a25692b4363e942fc0a3472e61bae0aa12a 100644 (file)
@@ -65,8 +65,9 @@ void MeshMakeData::fill(MapBlock *block)
 
        // Allocate this block + neighbors
        m_vmanip.clear();
-       m_vmanip.addArea(VoxelArea(blockpos_nodes-v3s16(1,1,1)*MAP_BLOCKSIZE,
-                       blockpos_nodes+v3s16(1,1,1)*MAP_BLOCKSIZE*2-v3s16(1,1,1)));
+       VoxelArea voxel_area(blockpos_nodes - v3s16(1,1,1) * MAP_BLOCKSIZE,
+                       blockpos_nodes + v3s16(1,1,1) * MAP_BLOCKSIZE*2-v3s16(1,1,1));
+       m_vmanip.addArea(voxel_area);
 
        {
                //TimeTaker timer("copy central block data");
@@ -244,7 +245,7 @@ static u16 getSmoothLightCombined(v3s16 p, MeshMakeData *data)
        u16 light_day = 0;
        u16 light_night = 0;
 
-       for(u32 i = 0; i < 8; i++)
+       for (u32 i = 0; i < 8; i++)
        {
                MapNode n = data->m_vmanip.getNodeNoEx(p - dirs8[i]);
 
@@ -254,13 +255,12 @@ static u16 getSmoothLightCombined(v3s16 p, MeshMakeData *data)
                }
 
                const ContentFeatures &f = ndef->get(n);
-               if(f.light_source > light_source_max)
+               if (f.light_source > light_source_max)
                        light_source_max = f.light_source;
-               // Check f.solidness because fast-style leaves look
-               // better this way
+               // Check f.solidness because fast-style leaves look better this way
                if (f.param_type == CPT_LIGHT && f.solidness != 2) {
-                       light_day += decode_light(n.getLight(LIGHTBANK_DAY, ndef));
-                       light_night += decode_light(n.getLight(LIGHTBANK_NIGHT, ndef));
+                       light_day += decode_light(n.getLightNoChecks(LIGHTBANK_DAY, &f));
+                       light_night += decode_light(n.getLightNoChecks(LIGHTBANK_NIGHT, &f));
                        light_count++;
                } else {
                        ambient_occlusion++;
@@ -274,25 +274,31 @@ static u16 getSmoothLightCombined(v3s16 p, MeshMakeData *data)
        light_night /= light_count;
 
        // Boost brightness around light sources
-       bool skip_ambient_occlusion = false;
+       bool skip_ambient_occlusion_day = false;
        if(decode_light(light_source_max) >= light_day) {
                light_day = decode_light(light_source_max);
-               skip_ambient_occlusion = true;
+               skip_ambient_occlusion_day = true;
        }
+
+       bool skip_ambient_occlusion_night = false;
        if(decode_light(light_source_max) >= light_night) {
                light_night = decode_light(light_source_max);
-               skip_ambient_occlusion = true;
+               skip_ambient_occlusion_night = true;
        }
 
-       if(ambient_occlusion > 4 && !skip_ambient_occlusion)
+       if (ambient_occlusion > 4)
        {
-               //calculate table index for gamma space multiplier
-               ambient_occlusion -= 5;
                //table of precalculated gamma space multiply factors
                //light^2.2 * factor (0.75, 0.5, 0.25, 0.0), so table holds factor ^ (1 / 2.2)
-               static const float light_amount[4] = {0.877424315, 0.729740053, 0.532520545, 0.0};
-               light_day = rangelim(core::round32(light_day*light_amount[ambient_occlusion]), 0, 255);
-               light_night = rangelim(core::round32(light_night*light_amount[ambient_occlusion]), 0, 255);
+               static const float light_amount[4] = { 0.877424315, 0.729740053, 0.532520545, 0.0 };
+
+               //calculate table index for gamma space multiplier
+               ambient_occlusion -= 5;
+
+               if (!skip_ambient_occlusion_day)
+                       light_day = rangelim(core::round32(light_day*light_amount[ambient_occlusion]), 0, 255);
+               if (!skip_ambient_occlusion_night)
+                       light_night = rangelim(core::round32(light_night*light_amount[ambient_occlusion]), 0, 255);
        }
 
        return light_day | (light_night << 8);
@@ -1130,7 +1136,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
                                m_animation_frame_offsets[i] = 0;
                        }
                        // Replace tile texture with the first animation frame
-                       FrameSpec animation_frame = p.tile.frames.find(0)->second;
+                       FrameSpec animation_frame = p.tile.frames[0];
                        p.tile.texture = animation_frame.texture;
                }
 
@@ -1156,12 +1162,16 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
                                        applyFacesShading (vc, 0.836660);
                                }
                        }
-                       // - Classic lighting
-                       // Set initial real color and store for later updates
-                       u8 day = vc.getRed();
-                       u8 night = vc.getGreen();
-                       finalColorBlend(vc, day, night, 1000);
-                       m_daynight_diffs[i][j] = std::make_pair(day, night);
+                       if(!m_enable_shaders)
+                       {
+                               // - Classic lighting (shaders handle this by themselves)
+                               // Set initial real color and store for later updates
+                               u8 day = vc.getRed();
+                               u8 night = vc.getGreen();
+                               finalColorBlend(vc, day, night, 1000);
+                               if(day != night)
+                                       m_daynight_diffs[i][j] = std::make_pair(day, night);
+                       }
                }
 
                // Create material
@@ -1312,7 +1322,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
                scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
                ITextureSource *tsrc = m_gamedef->getTextureSource();
 
-               FrameSpec animation_frame = tile.frames.find(frame)->second;
+               FrameSpec animation_frame = tile.frames[frame];
                buf->getMaterial().setTexture(0, animation_frame.texture);
                if (m_enable_shaders) {
                        if (animation_frame.normal_texture) {
@@ -1325,7 +1335,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
        }
 
        // Day-night transition
-       if(daynight_ratio != m_last_daynight_ratio)
+       if(!m_enable_shaders && (daynight_ratio != m_last_daynight_ratio))
        {
                for(std::map<u32, std::map<u32, std::pair<u8, u8> > >::iterator
                                i = m_daynight_diffs.begin();