Mapgen: Add propagate_shadow bool to calcLighting
[oweals/minetest.git] / src / mapgen.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MAPGEN_HEADER
21 #define MAPGEN_HEADER
22
23 #include "noise.h"
24 #include "nodedef.h"
25 #include "mapnode.h"
26 #include "util/string.h"
27 #include "util/container.h"
28
29 #define DEFAULT_MAPGEN "v6"
30
31 /////////////////// Mapgen flags
32 #define MG_TREES       0x01
33 #define MG_CAVES       0x02
34 #define MG_DUNGEONS    0x04
35 #define MG_FLAT        0x08
36 #define MG_LIGHT       0x10
37 #define MG_DECORATIONS 0x20
38
39 class Settings;
40 class MMVManip;
41 class INodeDefManager;
42
43 extern FlagDesc flagdesc_mapgen[];
44 extern FlagDesc flagdesc_gennotify[];
45
46 class Biome;
47 class EmergeManager;
48 class MapBlock;
49 class VoxelManipulator;
50 struct BlockMakeData;
51 class VoxelArea;
52 class Map;
53
54 enum MapgenObject {
55         MGOBJ_VMANIP,
56         MGOBJ_HEIGHTMAP,
57         MGOBJ_BIOMEMAP,
58         MGOBJ_HEATMAP,
59         MGOBJ_HUMIDMAP,
60         MGOBJ_GENNOTIFY
61 };
62
63 enum GenNotifyType {
64         GENNOTIFY_DUNGEON,
65         GENNOTIFY_TEMPLE,
66         GENNOTIFY_CAVE_BEGIN,
67         GENNOTIFY_CAVE_END,
68         GENNOTIFY_LARGECAVE_BEGIN,
69         GENNOTIFY_LARGECAVE_END,
70         GENNOTIFY_DECORATION,
71         NUM_GENNOTIFY_TYPES
72 };
73
74 // TODO(hmmmm/paramat): make stone type selection dynamic
75 enum MgStoneType {
76         STONE,
77         DESERT_STONE,
78         SANDSTONE,
79 };
80
81 struct GenNotifyEvent {
82         GenNotifyType type;
83         v3s16 pos;
84         u32 id;
85 };
86
87 class GenerateNotifier {
88 public:
89         GenerateNotifier();
90         GenerateNotifier(u32 notify_on, std::set<u32> *notify_on_deco_ids);
91
92         void setNotifyOn(u32 notify_on);
93         void setNotifyOnDecoIds(std::set<u32> *notify_on_deco_ids);
94
95         bool addEvent(GenNotifyType type, v3s16 pos, u32 id=0);
96         void getEvents(std::map<std::string, std::vector<v3s16> > &event_map,
97                 bool peek_events=false);
98
99 private:
100         u32 m_notify_on;
101         std::set<u32> *m_notify_on_deco_ids;
102         std::list<GenNotifyEvent> m_notify_events;
103 };
104
105 struct MapgenSpecificParams {
106         virtual void readParams(const Settings *settings) = 0;
107         virtual void writeParams(Settings *settings) const = 0;
108         virtual ~MapgenSpecificParams() {}
109 };
110
111 struct MapgenParams {
112         std::string mg_name;
113         s16 chunksize;
114         u64 seed;
115         s16 water_level;
116         u32 flags;
117
118         NoiseParams np_biome_heat;
119         NoiseParams np_biome_heat_blend;
120         NoiseParams np_biome_humidity;
121         NoiseParams np_biome_humidity_blend;
122
123         MapgenSpecificParams *sparams;
124
125         MapgenParams() :
126                 mg_name(DEFAULT_MAPGEN),
127                 chunksize(5),
128                 seed(0),
129                 water_level(1),
130                 flags(MG_CAVES | MG_LIGHT | MG_DECORATIONS),
131                 np_biome_heat(NoiseParams(50, 50, v3f(750.0, 750.0, 750.0), 5349, 3, 0.5, 2.0)),
132                 np_biome_heat_blend(NoiseParams(0, 1.5, v3f(8.0, 8.0, 8.0), 13, 2, 1.0, 2.0)),
133                 np_biome_humidity(NoiseParams(50, 50, v3f(750.0, 750.0, 750.0), 842, 3, 0.5, 2.0)),
134                 np_biome_humidity_blend(NoiseParams(0, 1.5, v3f(8.0, 8.0, 8.0), 90003, 2, 1.0, 2.0)),
135                 sparams(NULL)
136         {}
137
138         void load(const Settings &settings);
139         void save(Settings &settings) const;
140 };
141
142 class Mapgen {
143 public:
144         int seed;
145         int water_level;
146         u32 flags;
147         bool generating;
148         int id;
149
150         MMVManip *vm;
151         INodeDefManager *ndef;
152
153         u32 blockseed;
154         s16 *heightmap;
155         u8 *biomemap;
156         float *heatmap;
157         float *humidmap;
158         v3s16 csize;
159
160         GenerateNotifier gennotify;
161
162         Mapgen();
163         Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
164         virtual ~Mapgen();
165
166         static u32 getBlockSeed(v3s16 p, int seed);
167         static u32 getBlockSeed2(v3s16 p, int seed);
168         s16 findGroundLevelFull(v2s16 p2d);
169         s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
170         s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
171         void updateHeightmap(v3s16 nmin, v3s16 nmax);
172         void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
173
174         void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
175         void lightSpread(VoxelArea &a, v3s16 p, u8 light);
176         void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax,
177                 bool propagate_shadow = true);
178         void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow);
179         void spreadLight(v3s16 nmin, v3s16 nmax);
180
181         virtual void makeChunk(BlockMakeData *data) {}
182         virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
183
184 private:
185         DISABLE_CLASS_COPY(Mapgen);
186 };
187
188 struct MapgenFactory {
189         virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
190                 EmergeManager *emerge) = 0;
191         virtual MapgenSpecificParams *createMapgenParams() = 0;
192         virtual ~MapgenFactory() {}
193 };
194
195 #endif