1 /************************************************************************
3 * Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
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
24 ************************************************************************/
29 #include "common_irrlicht.h"
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.
49 // Light is stored as 4 bits, thus 15 is the maximum.
50 // This brightness is reserved for sunlight
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
)
61 if(light
>= LIGHT_MAX
)
67 inline u8
diminish_light(u8 light
, u8 distance
)
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.
80 if(light
== LIGHT_MAX
)
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
];
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
)
105 u32 l
= ((daylight_factor
* lightday
+ (c
-daylight_factor
) * lightnight
))/c
;