Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
mapgen.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2010-2020 celeron55, Perttu Ahola <celeron55@gmail.com>
4Copyright (C) 2015-2020 paramat
5Copyright (C) 2013-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU Lesser General Public License as published by
9the Free Software Foundation; either version 2.1 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along
18with this program; if not, write to the Free Software Foundation, Inc.,
1951 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20*/
21
22#pragma once
23
24#include "noise.h"
25#include "nodedef.h"
26#include "util/string.h"
27#include "util/container.h"
28#include <utility>
29
30#define MAPGEN_DEFAULT MAPGEN_V7
31#define MAPGEN_DEFAULT_NAME "v7"
32
34#define MG_CAVES 0x02
35#define MG_DUNGEONS 0x04
36#define MG_LIGHT 0x10
37#define MG_DECORATIONS 0x20
38#define MG_BIOMES 0x40
39#define MG_ORES 0x80
40
41typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
42
43class Settings;
44class MMVManip;
45class NodeDefManager;
46
49
50class Biome;
51class BiomeGen;
52struct BiomeParams;
53class BiomeManager;
54class EmergeParams;
55class EmergeManager;
56class MapBlock;
58struct BlockMakeData;
59class VoxelArea;
60class Map;
61
69};
70
79 GENNOTIFY_CUSTOM, // user-defined data
81};
82
84public:
88 u32 id; // for GENNOTIFY_DECORATION
89 };
90
91 // Use only for temporary Mapgen objects with no map generation!
92 GenerateNotifier() = default;
93 // normal constructor
94 GenerateNotifier(u32 notify_on, const std::set<u32> *notify_on_deco_ids,
95 const std::set<std::string> *notify_on_custom);
96
97 bool addEvent(GenNotifyType type, v3s16 pos);
98 bool addDecorationEvent(v3s16 pos, u32 deco_id);
99 bool setCustom(const std::string &key, const std::string &value);
100 void getEvents(std::map<std::string, std::vector<v3s16>> &map) const;
101 const StringMap &getCustomData() const { return m_notify_custom; }
102 void clearEvents();
103
104private:
105 u32 m_notify_on = 0;
106 const std::set<u32> *m_notify_on_deco_ids = nullptr;
107 const std::set<std::string> *m_notify_on_custom = nullptr;
108 std::list<GenNotifyEvent> m_notify_events;
110
111 inline bool shouldNotifyOn(GenNotifyType type) const {
112 return m_notify_on & (1 << type);
113 }
114};
115
116// Order must match the order of 'static MapgenDesc g_reg_mapgens[]' in mapgen.cpp
127};
128
130 MapgenParams() = default;
131 virtual ~MapgenParams();
132
134 s16 chunksize = 5;
135 u64 seed = 0;
136 s16 water_level = 1;
138 // Flags set in readParams
139 u32 flags = 0;
140 u32 spflags = 0;
141
143
146
147 virtual void readParams(const Settings *settings);
148 virtual void writeParams(Settings *settings) const;
149 // Default settings for g_settings such as flags
150 virtual void setDefaultSettings(Settings *settings) {};
151
152 s32 getSpawnRangeMax();
153
154private:
156};
157
158
159/*
160 Generic interface for map generators. All mapgens must inherit this class.
161 If a feature exposed by a public member pointer is not supported by a
162 certain mapgen, it must be set to NULL.
163
164 Apart from makeChunk, getGroundLevelAtPoint, and getSpawnLevelAtPoint, all
165 methods can be used by constructing a Mapgen base class and setting the
166 appropriate public members (e.g. vm, ndef, and so on).
167*/
168class Mapgen {
169public:
170 s32 seed = 0;
171 int water_level = 0;
173 u32 flags = 0;
174 bool generating = false;
175 int id = -1;
176
177 MMVManip *vm = nullptr;
178 // Note that this contains various things the mapgens *can* use, so biomegen
179 // might be NULL while m_emerge->biomegen is not.
181 const NodeDefManager *ndef = nullptr;
182
184 s16 *heightmap = nullptr;
185 biome_t *biomemap = nullptr;
187
188 BiomeGen *biomegen = nullptr;
190
191 Mapgen() = default;
192 Mapgen(int mapgenid, MapgenParams *params, EmergeParams *emerge);
193 virtual ~Mapgen();
195
196 virtual MapgenType getType() const { return MAPGEN_INVALID; }
197
198 static u32 getBlockSeed(v3s16 p, s32 seed);
199 static u32 getBlockSeed2(v3s16 p, s32 seed);
200 s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
201 s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
202 void updateHeightmap(v3s16 nmin, v3s16 nmax);
203 void getSurfaces(v2s16 p2d, s16 ymin, s16 ymax,
204 std::vector<s16> &floors, std::vector<s16> &ceilings);
205
206 void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
207
214 void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
223 void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax,
224 bool propagate_shadow = true);
233 void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow);
240 void spreadLight(const v3s16 &nmin, const v3s16 &nmax);
241
242 virtual void makeChunk(BlockMakeData *data) {}
243 virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
244
245 // getSpawnLevelAtPoint() is a function within each mapgen that returns a
246 // suitable y co-ordinate for player spawn ('suitable' usually meaning
247 // within 16 nodes of water_level). If a suitable spawn level cannot be
248 // found at the specified (X, Z) 'MAX_MAP_GENERATION_LIMIT' is returned to
249 // signify this and to cause Server::findSpawnPos() to try another (X, Z).
250 virtual int getSpawnLevelAtPoint(v2s16 p) { return 0; }
251
252 // Mapgen management functions
253 static MapgenType getMapgenType(const std::string &mgname);
254 static const char *getMapgenName(MapgenType mgtype);
256 EmergeParams *emerge);
258 static void getMapgenNames(std::vector<const char *> *mgnames, bool include_hidden);
259 static void setDefaultSettings(Settings *settings);
260
261private:
271 void lightSpread(VoxelArea &a, std::queue<std::pair<v3s16, u8>> &queue,
272 const v3s16 &p, u8 light);
273
274 // isLiquidHorizontallyFlowable() is a helper function for updateLiquid()
275 // that checks whether there are floodable nodes without liquid beneath
276 // the node at index vi.
277 inline bool isLiquidHorizontallyFlowable(u32 vi, v3s16 em);
278};
279
280/*
281 MapgenBasic is a Mapgen implementation that handles basic functionality
282 the majority of conventional mapgens will probably want to use, but isn't
283 generic enough to be included as part of the base Mapgen class (such as
284 generating biome terrain over terrain node skeletons, generating caves,
285 dungeons, etc.)
286
287 Inherit MapgenBasic instead of Mapgen to add this basic functionality to
288 your mapgen without having to reimplement it. Feel free to override any of
289 these methods if you desire different or more advanced behavior.
290
291 Note that you must still create your own generateTerrain implementation when
292 inheriting MapgenBasic.
293*/
294class MapgenBasic : public Mapgen {
295public:
296 MapgenBasic(int mapgenid, MapgenParams *params, EmergeParams *emerge);
297 virtual ~MapgenBasic();
298
299 virtual void generateBiomes();
300 virtual void dustTopNodes();
301 virtual void generateCavesNoiseIntersection(s16 max_stone_y);
302 virtual void generateCavesRandomWalk(s16 max_stone_y, s16 large_cave_ymax);
303 virtual bool generateCavernsNoise(s16 max_stone_y);
304 virtual void generateDungeons(s16 max_stone_y);
305
306protected:
308
310
315
321
326
328
345};
346
347// Calculate exact edges of the outermost mapchunks that are within the set
348// mapgen_limit. Returns the minimum and maximum edges in nodes in that order.
349std::pair<s16, s16> get_mapgen_edges(s16 mapgen_limit, s16 chunksize);
Definition: mg_biome.h:94
Definition: mg_biome.h:211
Definition: mg_biome.h:43
Definition: emerge.h:130
Definition: emerge.h:98
Definition: mapgen.h:83
StringMap m_notify_custom
Definition: mapgen.h:109
bool addEvent(GenNotifyType type, v3s16 pos)
Definition: mapgen.cpp:993
GenerateNotifier()=default
void clearEvents()
Definition: mapgen.cpp:1054
const StringMap & getCustomData() const
Definition: mapgen.h:101
void getEvents(std::map< std::string, std::vector< v3s16 > > &map) const
Definition: mapgen.cpp:1039
bool shouldNotifyOn(GenNotifyType type) const
Definition: mapgen.h:111
std::list< GenNotifyEvent > m_notify_events
Definition: mapgen.h:108
const std::set< std::string > * m_notify_on_custom
Definition: mapgen.h:107
bool addDecorationEvent(v3s16 pos, u32 deco_id)
Definition: mapgen.cpp:1007
bool setCustom(const std::string &key, const std::string &value)
Definition: mapgen.cpp:1025
const std::set< u32 > * m_notify_on_deco_ids
Definition: mapgen.h:106
u32 m_notify_on
Definition: mapgen.h:105
Definition: map.h:320
Definition: mapblock.h:73
Definition: map.h:116
Definition: mapgen.h:294
int zstride_1u1d
Definition: mapgen.h:325
float cavern_limit
Definition: mapgen.h:334
content_t c_lava_source
Definition: mapgen.h:319
float cavern_taper
Definition: mapgen.h:335
int zstride_1d
Definition: mapgen.h:324
content_t c_stone
Definition: mapgen.h:316
virtual void dustTopNodes()
Definition: mapgen.cpp:792
Noise * noise_filler_depth
Definition: mapgen.h:309
virtual bool generateCavernsNoise(s16 max_stone_y)
Definition: mapgen.cpp:901
content_t c_water_source
Definition: mapgen.h:317
virtual void generateDungeons(s16 max_stone_y)
Definition: mapgen.cpp:913
v3s16 full_node_min
Definition: mapgen.h:313
NoiseParams np_cave1
Definition: mapgen.h:329
int ystride
Definition: mapgen.h:322
int zstride
Definition: mapgen.h:323
NoiseParams np_dungeons
Definition: mapgen.h:332
int large_cave_num_min
Definition: mapgen.h:339
virtual void generateCavesRandomWalk(s16 max_stone_y, s16 large_cave_ymax)
Definition: mapgen.cpp:870
s16 dungeon_ymin
Definition: mapgen.h:343
u32 spflags
Definition: mapgen.h:327
s16 dungeon_ymax
Definition: mapgen.h:344
virtual ~MapgenBasic()
Definition: mapgen.cpp:635
content_t c_river_water_source
Definition: mapgen.h:318
v3s16 node_min
Definition: mapgen.h:311
int large_cave_num_max
Definition: mapgen.h:340
BiomeManager * m_bmgr
Definition: mapgen.h:307
int small_cave_num_min
Definition: mapgen.h:337
float cave_width
Definition: mapgen.h:333
v3s16 full_node_max
Definition: mapgen.h:314
int small_cave_num_max
Definition: mapgen.h:338
v3s16 node_max
Definition: mapgen.h:312
float large_cave_flooded
Definition: mapgen.h:341
virtual void generateCavesNoiseIntersection(s16 max_stone_y)
Definition: mapgen.cpp:856
float cavern_threshold
Definition: mapgen.h:336
NoiseParams np_cave2
Definition: mapgen.h:330
content_t c_cobble
Definition: mapgen.h:320
s16 large_cave_depth
Definition: mapgen.h:342
NoiseParams np_cavern
Definition: mapgen.h:331
virtual void generateBiomes()
Definition: mapgen.cpp:641
Definition: mapgen.h:168
s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax)
Definition: mapgen.cpp:256
void getSurfaces(v2s16 p2d, s16 ymin, s16 ymax, std::vector< s16 > &floors, std::vector< s16 > &ceilings)
Definition: mapgen.cpp:311
virtual MapgenType getType() const
Definition: mapgen.h:196
void updateHeightmap(v3s16 nmin, v3s16 nmax)
Definition: mapgen.cpp:294
s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax)
Definition: mapgen.cpp:274
Mapgen()=default
void lightSpread(VoxelArea &a, std::queue< std::pair< v3s16, u8 > > &queue, const v3s16 &p, u8 light)
Spread light to the node at the given position, add to queue if changed.
Definition: mapgen.cpp:447
GenerateNotifier gennotify
Definition: mapgen.h:189
s16 * heightmap
Definition: mapgen.h:184
EmergeParams * m_emerge
Definition: mapgen.h:180
s32 seed
Definition: mapgen.h:170
virtual int getGroundLevelAtPoint(v2s16 p)
Definition: mapgen.h:243
virtual int getSpawnLevelAtPoint(v2s16 p)
Definition: mapgen.h:250
virtual void makeChunk(BlockMakeData *data)
Definition: mapgen.h:242
MMVManip * vm
Definition: mapgen.h:177
u32 flags
Definition: mapgen.h:173
int water_level
Definition: mapgen.h:171
void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax, bool propagate_shadow=true)
Run all lighting calculations.
Definition: mapgen.cpp:484
static MapgenType getMapgenType(const std::string &mgname)
Definition: mapgen.cpp:145
static u32 getBlockSeed(v3s16 p, s32 seed)
Definition: mapgen.cpp:237
DISABLE_CLASS_COPY(Mapgen)
virtual ~Mapgen()
Definition: mapgen.cpp:139
int mapgen_limit
Definition: mapgen.h:172
static void setDefaultSettings(Settings *settings)
Definition: mapgen.cpp:225
static Mapgen * createMapgen(MapgenType mgtype, MapgenParams *params, EmergeParams *emerge)
Definition: mapgen.cpp:166
void setLighting(u8 light, v3s16 nmin, v3s16 nmax)
Set light in entire area to fixed value.
Definition: mapgen.cpp:432
static u32 getBlockSeed2(v3s16 p, s32 seed)
Definition: mapgen.cpp:246
static void getMapgenNames(std::vector< const char * > *mgnames, bool include_hidden)
Definition: mapgen.cpp:217
biome_t * biomemap
Definition: mapgen.h:185
bool isLiquidHorizontallyFlowable(u32 vi, v3s16 em)
Definition: mapgen.cpp:338
static const char * getMapgenName(MapgenType mgtype)
Definition: mapgen.cpp:156
const NodeDefManager * ndef
Definition: mapgen.h:181
void spreadLight(const v3s16 &nmin, const v3s16 &nmax)
Spread light in the given area.
Definition: mapgen.cpp:530
static MapgenParams * createMapgenParams(MapgenType mgtype)
Definition: mapgen.cpp:192
u32 blockseed
Definition: mapgen.h:183
void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow)
Spread sunlight from the area above downwards.
Definition: mapgen.cpp:494
BiomeGen * biomegen
Definition: mapgen.h:188
bool generating
Definition: mapgen.h:174
void updateLiquid(UniqueQueue< v3s16 > *trans_liquid, v3s16 nmin, v3s16 nmax)
Definition: mapgen.cpp:371
v3s16 csize
Definition: mapgen.h:186
This class is for getting the actual properties of nodes from their content ID.
Definition: nodedef.h:556
Definition: noise.h:146
Definition: settings.h:124
Definition: container.h:41
Definition: voxel.h:59
Definition: voxel.h:381
#define MAX_MAP_GENERATION_LIMIT
Definition: constants.h:69
core::vector2d< s16 > v2s16
Definition: irr_v2d.h:27
core::vector3d< s16 > v3s16
Definition: irr_v3d.h:28
static LightingParams params
Definition: light.cpp:40
GenNotifyType
Definition: mapgen.h:71
@ GENNOTIFY_CUSTOM
Definition: mapgen.h:79
@ GENNOTIFY_LARGECAVE_END
Definition: mapgen.h:77
@ GENNOTIFY_DECORATION
Definition: mapgen.h:78
@ GENNOTIFY_LARGECAVE_BEGIN
Definition: mapgen.h:76
@ GENNOTIFY_CAVE_END
Definition: mapgen.h:75
@ NUM_GENNOTIFY_TYPES
Definition: mapgen.h:80
@ GENNOTIFY_TEMPLE
Definition: mapgen.h:73
@ GENNOTIFY_DUNGEON
Definition: mapgen.h:72
@ GENNOTIFY_CAVE_BEGIN
Definition: mapgen.h:74
MapgenType
Definition: mapgen.h:117
@ MAPGEN_V6
Definition: mapgen.h:125
@ MAPGEN_INVALID
Definition: mapgen.h:126
@ MAPGEN_FLAT
Definition: mapgen.h:122
@ MAPGEN_V5
Definition: mapgen.h:121
@ MAPGEN_CARPATHIAN
Definition: mapgen.h:120
@ MAPGEN_SINGLENODE
Definition: mapgen.h:124
@ MAPGEN_V7
Definition: mapgen.h:118
@ MAPGEN_VALLEYS
Definition: mapgen.h:119
@ MAPGEN_FRACTAL
Definition: mapgen.h:123
FlagDesc flagdesc_mapgen[]
Definition: mapgen.cpp:55
std::pair< s16, s16 > get_mapgen_edges(s16 mapgen_limit, s16 chunksize)
Definition: mapgen.cpp:1135
MapgenObject
Definition: mapgen.h:62
@ MGOBJ_HEATMAP
Definition: mapgen.h:66
@ MGOBJ_HUMIDMAP
Definition: mapgen.h:67
@ MGOBJ_GENNOTIFY
Definition: mapgen.h:68
@ MGOBJ_VMANIP
Definition: mapgen.h:63
@ MGOBJ_HEIGHTMAP
Definition: mapgen.h:64
@ MGOBJ_BIOMEMAP
Definition: mapgen.h:65
u16 biome_t
Definition: mapgen.h:41
#define MAPGEN_DEFAULT
Definition: mapgen.h:30
FlagDesc flagdesc_gennotify[]
Definition: mapgen.cpp:65
u16 content_t
Definition: mapnode.h:37
std::unordered_map< std::string, std::string > StringMap
Definition: string.h:78
Definition: mg_biome.h:85
Definition: emerge.h:51
Definition: string.h:80
Definition: mapgen.h:85
GenNotifyType type
Definition: mapgen.h:86
u32 id
Definition: mapgen.h:88
v3s16 pos
Definition: mapgen.h:87
Definition: mapgen.h:129
virtual ~MapgenParams()
Definition: mapgen.cpp:1066
BiomeParams * bparams
Definition: mapgen.h:142
virtual void setDefaultSettings(Settings *settings)
Definition: mapgen.h:150
u32 flags
Definition: mapgen.h:139
s16 mapgen_edge_max
Definition: mapgen.h:145
u64 seed
Definition: mapgen.h:135
s16 mapgen_edge_min
Definition: mapgen.h:144
s16 water_level
Definition: mapgen.h:136
virtual void writeParams(Settings *settings) const
Definition: mapgen.cpp:1108
s16 mapgen_limit
Definition: mapgen.h:137
MapgenType mgtype
Definition: mapgen.h:133
virtual void readParams(const Settings *settings)
Definition: mapgen.cpp:1072
bool m_mapgen_edges_calculated
Definition: mapgen.h:155
MapgenParams()=default
s32 getSpawnRangeMax()
Definition: mapgen.cpp:1122
s16 chunksize
Definition: mapgen.h:134
u32 spflags
Definition: mapgen.h:140
Definition: noise.h:119
static std::string p(std::string path)
Definition: test_filesys.cpp:64