summaryrefslogtreecommitdiff
path: root/src/voxelalgorithms.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-01-27 13:24:06 +0200
committerPerttu Ahola <celeron55@gmail.com>2012-03-27 19:01:51 +0300
commit0f3c2f65414f332fad510fb8651dd59d506aad2e (patch)
treedda3c34cf10d3e3458830cb53820866f4d535c3a /src/voxelalgorithms.cpp
parent56496ad5d8a7662b0ae5c9f25d1348cb7b677b65 (diff)
downloadminetest-0f3c2f65414f332fad510fb8651dd59d506aad2e.tar.gz
minetest-0f3c2f65414f332fad510fb8651dd59d506aad2e.tar.bz2
minetest-0f3c2f65414f332fad510fb8651dd59d506aad2e.zip
voxalgo::clearLightAndCollectSources
Diffstat (limited to 'src/voxelalgorithms.cpp')
-rw-r--r--src/voxelalgorithms.cpp41
1 files changed, 36 insertions, 5 deletions
diff --git a/src/voxelalgorithms.cpp b/src/voxelalgorithms.cpp
index ae609e96a..ab6cbdfa2 100644
--- a/src/voxelalgorithms.cpp
+++ b/src/voxelalgorithms.cpp
@@ -37,6 +37,42 @@ void setLight(VoxelManipulator &v, VoxelArea a, u8 light,
}
}
+void clearLightAndCollectSources(VoxelManipulator &v, VoxelArea a,
+ enum LightBank bank, INodeDefManager *ndef,
+ core::map<v3s16, bool> & light_sources,
+ core::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.emerge(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[p] = true;
+
+ // 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.insert(p, oldlight);
+ }
+ }
+}
+
SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
bool inexistent_top_provides_sunlight,
core::map<v3s16, bool> & light_sources,
@@ -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--)