summaryrefslogtreecommitdiff
path: root/src/mapblock.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-01-15 13:50:13 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-01-15 13:50:13 +0200
commita176f9eb36033196040443991a0723c39886b8a2 (patch)
tree9951d81ea02d1355d15ccefd09379a2737efaf44 /src/mapblock.cpp
parent83e083a667d8423ea27555ed58cc90a5f57d103f (diff)
downloadminetest-a176f9eb36033196040443991a0723c39886b8a2.tar.gz
minetest-a176f9eb36033196040443991a0723c39886b8a2.tar.bz2
minetest-a176f9eb36033196040443991a0723c39886b8a2.zip
generate-time lighting optimization
Diffstat (limited to 'src/mapblock.cpp')
-rw-r--r--src/mapblock.cpp87
1 files changed, 47 insertions, 40 deletions
diff --git a/src/mapblock.cpp b/src/mapblock.cpp
index 68b296154..252f123ac 100644
--- a/src/mapblock.cpp
+++ b/src/mapblock.cpp
@@ -934,61 +934,68 @@ bool MapBlock::propagateSunlight(core::map<v3s16, bool> & light_sources,
s16 y = MAP_BLOCKSIZE-1;
- if(no_sunlight == false)
+ // This makes difference to diminishing in water.
+ bool stopped_to_solid_object = false;
+
+ u8 current_light = no_sunlight ? 0 : LIGHT_SUN;
+
+ for(; y >= 0; y--)
{
- // Continue spreading sunlight downwards through transparent
- // nodes
- for(; y >= 0; y--)
+ v3s16 pos(x, y, z);
+ MapNode &n = getNodeRef(pos);
+
+ if(current_light == 0)
{
- v3s16 pos(x, y, z);
-
- MapNode &n = getNodeRef(pos);
-
- if(n.sunlight_propagates())
- {
- n.setLight(LIGHTBANK_DAY, LIGHT_SUN);
-
- light_sources.insert(pos_relative + pos, true);
- }
- else
+ // Do nothing
+ }
+ else if(current_light == LIGHT_SUN && n.sunlight_propagates())
+ {
+ // Do nothing: Sunlight is continued
+ }
+ else if(n.light_propagates() == false)
+ {
+ // Turn mud into grass
+ if(n.d == CONTENT_MUD && current_light == LIGHT_SUN)
{
- // Turn mud into grass
- if(n.d == CONTENT_MUD)
- {
- n.d = CONTENT_GRASS;
- }
-
- // Sunlight goes no further
- break;
+ n.d = CONTENT_GRASS;
}
+
+ // A solid object is on the way.
+ stopped_to_solid_object = true;
+
+ // Light stops.
+ current_light = 0;
+ }
+ else
+ {
+ // Diminish light
+ current_light = diminish_light(current_light);
}
- }
- bool sunlight_should_go_down = (y==-1);
-
- /*
- Check rest through to the bottom of the block
- */
- for(; y >= 0; y--)
- {
- v3s16 pos(x, y, z);
- MapNode &n = getNodeRef(pos);
+ u8 old_light = n.getLight(LIGHTBANK_DAY);
- if(n.light_propagates())
+ if(current_light > old_light || remove_light)
+ {
+ n.setLight(LIGHTBANK_DAY, current_light);
+ }
+
+ if(diminish_light(current_light) != 0)
+ {
+ light_sources.insert(pos_relative + pos, true);
+ }
+
+ if(current_light == 0 && stopped_to_solid_object)
{
if(black_air_left)
{
*black_air_left = true;
}
-
- if(remove_light)
- {
- // Fill transparent nodes with black
- n.setLight(LIGHTBANK_DAY, 0);
- }
}
}
+ // Whether or not the block below should see LIGHT_SUN
+ bool sunlight_should_go_down = (current_light == LIGHT_SUN);
+
/*
If the block below hasn't already been marked invalid: