]> git.lizzy.rs Git - minetest.git/blobdiff - src/voxelalgorithms.cpp
Set acceleration only once in falling node
[minetest.git] / src / voxelalgorithms.cpp
index ae609e96ad93e95f26ef63761d7b7c04314d653b..f067a221ac1504484bc5ff4cd9e6beb6618a022d 100644 (file)
@@ -1,18 +1,18 @@
 /*
-Minetest-c55
-Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+GNU Lesser General Public License for more details.
 
-You should have received a copy of the GNU General Public License along
+You should have received a copy of the GNU Lesser General Public License along
 with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
@@ -37,9 +37,45 @@ void setLight(VoxelManipulator &v, VoxelArea a, u8 light,
        }
 }
 
+void clearLightAndCollectSources(VoxelManipulator &v, VoxelArea a,
+               enum LightBank bank, INodeDefManager *ndef,
+               std::set<v3s16> & light_sources,
+               std::map<v3s16, u8> & unlight_from)
+{
+       // The full area we shall touch
+       VoxelArea required_a = a;
+       required_a.pad(v3s16(0,0,0));
+       // Make sure we have access to it
+       v.addArea(a);
+
+       for(s32 x=a.MinEdge.X; x<=a.MaxEdge.X; x++)
+       for(s32 z=a.MinEdge.Z; z<=a.MaxEdge.Z; z++)
+       for(s32 y=a.MinEdge.Y; y<=a.MaxEdge.Y; y++)
+       {
+               v3s16 p(x,y,z);
+               MapNode &n = v.getNodeRefUnsafe(p);
+               u8 oldlight = n.getLight(bank, ndef);
+               n.setLight(bank, 0, ndef);
+
+               // If node sources light, add to list
+               u8 source = ndef->get(n).light_source;
+               if(source != 0)
+                       light_sources.insert(p);
+
+               // Collect borders for unlighting
+               if((x==a.MinEdge.X || x == a.MaxEdge.X
+               || y==a.MinEdge.Y || y == a.MaxEdge.Y
+               || z==a.MinEdge.Z || z == a.MaxEdge.Z)
+               && oldlight != 0)
+               {
+                       unlight_from[p] = oldlight;
+               }
+       }
+}
+
 SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
                bool inexistent_top_provides_sunlight,
-               core::map<v3s16, bool> & light_sources,
+               std::set<v3s16> & light_sources,
                INodeDefManager *ndef)
 {
        // Return values
@@ -49,11 +85,11 @@ SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
        VoxelArea required_a = a;
        required_a.pad(v3s16(0,1,0));
        // Make sure we have access to it
-       v.emerge(a);
-       
+       v.addArea(a);
+
        s16 max_y = a.MaxEdge.Y;
        s16 min_y = a.MinEdge.Y;
-       
+
        for(s32 x=a.MinEdge.X; x<=a.MaxEdge.X; x++)
        for(s32 z=a.MinEdge.Z; z<=a.MaxEdge.Z; z++)
        {
@@ -69,11 +105,6 @@ SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
                        overtop_has_sunlight = (v.getNodeRefUnsafe(p_overtop).getLight(
                                        LIGHTBANK_DAY, ndef) == LIGHT_SUN);
 
-               dstream<<"inexistent_top_provides_sunlight="
-                               <<inexistent_top_provides_sunlight<<std::endl;
-               dstream<<"v.exists(p_overtop)="
-                               <<v.exists(p_overtop)<<std::endl;
-
                // Copy overtop's sunlight all over the place
                u8 incoming_light = overtop_has_sunlight ? LIGHT_SUN : 0;
                for(s32 y=max_y; y>=min_y; y--)
@@ -94,11 +125,11 @@ SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
 
                        if(incoming_light > old_light)
                                n.setLight(LIGHTBANK_DAY, incoming_light, ndef);
-                       
+
                        if(diminish_light(incoming_light) != 0)
-                               light_sources.insert(p, true);
+                               light_sources.insert(p);
                }
-               
+
                // Check validity of sunlight at top of block below if it
                // hasn't already been proven invalid
                if(bottom_sunlight_valid)