1604.00
[voxelands.git] / src / light.h
blobeeea7d2fc255c3aa7aa8358b7149cc9d642a437e
1 /************************************************************************
2 * Minetest-c55
3 * Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
5 * light.h
6 * voxelands - 3d voxel world sandbox game
7 * Copyright (C) Lisa 'darkrose' Milne 2014 <lisa@ltmnet.com>
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>
22 * License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
23 * for Voxelands.
24 ************************************************************************/
26 #ifndef LIGHT_HEADER
27 #define LIGHT_HEADER
29 #include "common_irrlicht.h"
30 #include "debug.h"
33 Day/night cache:
34 Meshes are cached for different day-to-night transition values
37 /*#define DAYNIGHT_CACHE_COUNT 3
38 // First one is day, last one is night.
39 extern u32 daynight_cache_ratios[DAYNIGHT_CACHE_COUNT];*/
42 Lower level lighting stuff
45 // This directly sets the range of light.
46 // Actually this is not the real maximum, and this is not the
47 // brightest. The brightest is LIGHT_SUN.
48 #define LIGHT_MAX 14
49 // Light is stored as 4 bits, thus 15 is the maximum.
50 // This brightness is reserved for sunlight
51 #define LIGHT_SUN 15
53 // these are used in mob spawning
54 #define LIGHT_SPAWN_BRIGHT 10
55 #define LIGHT_SPAWN_DARK 4
57 inline u8 diminish_light(u8 light)
59 if(light == 0)
60 return 0;
61 if(light >= LIGHT_MAX)
62 return LIGHT_MAX - 1;
64 return light - 1;
67 inline u8 diminish_light(u8 light, u8 distance)
69 if(distance >= light)
70 return 0;
71 return light - distance;
74 inline u8 undiminish_light(u8 light)
76 // We don't know if light should undiminish from this particular 0.
77 // Thus, keep it at 0.
78 if(light == 0)
79 return 0;
80 if(light == LIGHT_MAX)
81 return light;
83 return light + 1;
86 extern u8 light_decode_table[LIGHT_MAX+1];
88 inline u8 decode_light(u8 light)
90 if(light == LIGHT_SUN)
91 return light_decode_table[LIGHT_MAX];
93 if(light > LIGHT_MAX)
94 light = LIGHT_MAX;
96 return light_decode_table[light];
99 // 0 <= daylight_factor <= 1000
100 // 0 <= lightday, lightnight <= LIGHT_SUN
101 // 0 <= return value <= LIGHT_SUN
102 inline u8 blend_light(u32 daylight_factor, u8 lightday, u8 lightnight)
104 u32 c = 1000;
105 u32 l = ((daylight_factor * lightday + (c-daylight_factor) * lightnight))/c;
106 if(l > LIGHT_SUN)
107 l = LIGHT_SUN;
108 return l;
111 #endif