]> git.lizzy.rs Git - minetest.git/blob - src/mapgen.h
Camera: Higher frequency limit for view/hand bobbing and footsteps
[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 MAPGEN_DEFAULT MAPGEN_V6
30 #define MAPGEN_DEFAULT_NAME "v6"
31
32 /////////////////// Mapgen flags
33 #define MG_TREES       0x01  // Deprecated. Moved into mgv6 flags
34 #define MG_CAVES       0x02
35 #define MG_DUNGEONS    0x04
36 #define MG_FLAT        0x08  // Deprecated. Moved into mgv6 flags
37 #define MG_LIGHT       0x10
38 #define MG_DECORATIONS 0x20
39
40 typedef u8 biome_t;  // copy from mg_biome.h to avoid an unnecessary include
41
42 class Settings;
43 class MMVManip;
44 class INodeDefManager;
45
46 extern FlagDesc flagdesc_mapgen[];
47 extern FlagDesc flagdesc_gennotify[];
48
49 class Biome;
50 class BiomeGen;
51 struct BiomeParams;
52 class BiomeManager;
53 class EmergeManager;
54 class MapBlock;
55 class VoxelManipulator;
56 struct BlockMakeData;
57 class VoxelArea;
58 class Map;
59
60 enum MapgenObject {
61         MGOBJ_VMANIP,
62         MGOBJ_HEIGHTMAP,
63         MGOBJ_BIOMEMAP,
64         MGOBJ_HEATMAP,
65         MGOBJ_HUMIDMAP,
66         MGOBJ_GENNOTIFY
67 };
68
69 enum GenNotifyType {
70         GENNOTIFY_DUNGEON,
71         GENNOTIFY_TEMPLE,
72         GENNOTIFY_CAVE_BEGIN,
73         GENNOTIFY_CAVE_END,
74         GENNOTIFY_LARGECAVE_BEGIN,
75         GENNOTIFY_LARGECAVE_END,
76         GENNOTIFY_DECORATION,
77         NUM_GENNOTIFY_TYPES
78 };
79
80 // TODO(hmmmm/paramat): make stone type selection dynamic
81 enum MgStoneType {
82         MGSTONE_STONE,
83         MGSTONE_DESERT_STONE,
84         MGSTONE_SANDSTONE,
85 };
86
87 struct GenNotifyEvent {
88         GenNotifyType type;
89         v3s16 pos;
90         u32 id;
91 };
92
93 class GenerateNotifier {
94 public:
95         GenerateNotifier();
96         GenerateNotifier(u32 notify_on, std::set<u32> *notify_on_deco_ids);
97
98         void setNotifyOn(u32 notify_on);
99         void setNotifyOnDecoIds(std::set<u32> *notify_on_deco_ids);
100
101         bool addEvent(GenNotifyType type, v3s16 pos, u32 id=0);
102         void getEvents(std::map<std::string, std::vector<v3s16> > &event_map,
103                 bool peek_events=false);
104
105 private:
106         u32 m_notify_on;
107         std::set<u32> *m_notify_on_deco_ids;
108         std::list<GenNotifyEvent> m_notify_events;
109 };
110
111 enum MapgenType {
112         MAPGEN_V5,
113         MAPGEN_V6,
114         MAPGEN_V7,
115         MAPGEN_FLAT,
116         MAPGEN_FRACTAL,
117         MAPGEN_VALLEYS,
118         MAPGEN_SINGLENODE,
119         MAPGEN_INVALID,
120 };
121
122 struct MapgenParams {
123         MapgenType mgtype;
124         s16 chunksize;
125         u64 seed;
126         s16 water_level;
127         u32 flags;
128
129         BiomeParams *bparams;
130
131         MapgenParams() :
132                 mgtype(MAPGEN_DEFAULT),
133                 chunksize(5),
134                 seed(0),
135                 water_level(1),
136                 flags(MG_CAVES | MG_LIGHT | MG_DECORATIONS),
137                 bparams(NULL)
138         {
139         }
140
141         virtual ~MapgenParams();
142
143         virtual void readParams(const Settings *settings);
144         virtual void writeParams(Settings *settings) const;
145 };
146
147
148 /*
149         Generic interface for map generators.  All mapgens must inherit this class.
150         If a feature exposed by a public member pointer is not supported by a
151         certain mapgen, it must be set to NULL.
152
153         Apart from makeChunk, getGroundLevelAtPoint, and getSpawnLevelAtPoint, all
154         methods can be used by constructing a Mapgen base class and setting the
155         appropriate public members (e.g. vm, ndef, and so on).
156 */
157 class Mapgen {
158 public:
159         s32 seed;
160         int water_level;
161         u32 flags;
162         bool generating;
163         int id;
164
165         MMVManip *vm;
166         INodeDefManager *ndef;
167
168         u32 blockseed;
169         s16 *heightmap;
170         biome_t *biomemap;
171         v3s16 csize;
172
173         BiomeGen *biomegen;
174         GenerateNotifier gennotify;
175
176         Mapgen();
177         Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
178         virtual ~Mapgen();
179
180         virtual MapgenType getType() const { return MAPGEN_INVALID; }
181
182         static u32 getBlockSeed(v3s16 p, s32 seed);
183         static u32 getBlockSeed2(v3s16 p, s32 seed);
184         s16 findGroundLevelFull(v2s16 p2d);
185         s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
186         s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
187         void updateHeightmap(v3s16 nmin, v3s16 nmax);
188         void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
189
190         void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
191         void lightSpread(VoxelArea &a, v3s16 p, u8 light);
192         void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax,
193                 bool propagate_shadow = true);
194         void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow);
195         void spreadLight(v3s16 nmin, v3s16 nmax);
196
197         virtual void makeChunk(BlockMakeData *data) {}
198         virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
199
200         // getSpawnLevelAtPoint() is a function within each mapgen that returns a
201         // suitable y co-ordinate for player spawn ('suitable' usually meaning
202         // within 16 nodes of water_level). If a suitable spawn level cannot be
203         // found at the specified (X, Z) 'MAX_MAP_GENERATION_LIMIT' is returned to
204         // signify this and to cause Server::findSpawnPos() to try another (X, Z).
205         virtual int getSpawnLevelAtPoint(v2s16 p) { return 0; }
206
207         // Mapgen management functions
208         static MapgenType getMapgenType(const std::string &mgname);
209         static const char *getMapgenName(MapgenType mgtype);
210         static Mapgen *createMapgen(MapgenType mgtype, int mgid,
211                 MapgenParams *params, EmergeManager *emerge);
212         static MapgenParams *createMapgenParams(MapgenType mgtype);
213         static void getMapgenNames(std::vector<const char *> *mgnames, bool include_hidden);
214
215 private:
216         // isLiquidHorizontallyFlowable() is a helper function for updateLiquid()
217         // that checks whether there are floodable nodes without liquid beneath
218         // the node at index vi.
219         inline bool isLiquidHorizontallyFlowable(u32 vi, v3s16 em);
220         DISABLE_CLASS_COPY(Mapgen);
221 };
222
223 /*
224         MapgenBasic is a Mapgen implementation that handles basic functionality
225         the majority of conventional mapgens will probably want to use, but isn't
226         generic enough to be included as part of the base Mapgen class (such as
227         generating biome terrain over terrain node skeletons, generating caves,
228         dungeons, etc.)
229
230         Inherit MapgenBasic instead of Mapgen to add this basic functionality to
231         your mapgen without having to reimplement it.  Feel free to override any of
232         these methods if you desire different or more advanced behavior.
233
234         Note that you must still create your own generateTerrain implementation when
235         inheriting MapgenBasic.
236 */
237 class MapgenBasic : public Mapgen {
238 public:
239         MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emerge);
240         virtual ~MapgenBasic();
241
242         virtual void generateCaves(s16 max_stone_y, s16 large_cave_depth);
243         virtual void generateDungeons(s16 max_stone_y, MgStoneType stone_type);
244         virtual MgStoneType generateBiomes();
245         virtual void dustTopNodes();
246
247 protected:
248         EmergeManager *m_emerge;
249         BiomeManager *m_bmgr;
250
251         Noise *noise_filler_depth;
252
253         v3s16 node_min;
254         v3s16 node_max;
255         v3s16 full_node_min;
256         v3s16 full_node_max;
257
258         // Content required for generateBiomes
259         content_t c_stone;
260         content_t c_water_source;
261         content_t c_river_water_source;
262         content_t c_desert_stone;
263         content_t c_sandstone;
264
265         // Content required for generateDungeons
266         content_t c_cobble;
267         content_t c_stair_cobble;
268         content_t c_mossycobble;
269         content_t c_sandstonebrick;
270         content_t c_stair_sandstonebrick;
271
272         int ystride;
273         int zstride;
274         int zstride_1d;
275         int zstride_1u1d;
276
277         u32 spflags;
278
279         NoiseParams np_cave1;
280         NoiseParams np_cave2;
281         float cave_width;
282 };
283
284 #endif