Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
mapgen.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2020 celeron55, Perttu Ahola <celeron55@gmail.com>
4// Copyright (C) 2015-2020 paramat
5// Copyright (C) 2013-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
6
7#pragma once
8
9#include "noise.h"
10#include "nodedef.h"
11#include "util/string.h"
12#include "util/container.h"
13#include <utility>
14
15#define MAPGEN_DEFAULT MAPGEN_V7
16#define MAPGEN_DEFAULT_NAME "v7"
17
19#define MG_CAVES 0x02
20#define MG_DUNGEONS 0x04
21#define MG_LIGHT 0x10
22#define MG_DECORATIONS 0x20
23#define MG_BIOMES 0x40
24#define MG_ORES 0x80
25
26typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
27
28class Settings;
29class MMVManip;
30class NodeDefManager;
31
34
35class Biome;
36class BiomeGen;
37struct BiomeParams;
38class BiomeManager;
39class EmergeParams;
40class EmergeManager;
41class MapBlock;
43struct BlockMakeData;
44class VoxelArea;
45class Map;
46
55
67
69public:
73 u32 id; // for GENNOTIFY_DECORATION
74 };
75
76 // Use only for temporary Mapgen objects with no map generation!
77 GenerateNotifier() = default;
78 // normal constructor
79 GenerateNotifier(u32 notify_on, const std::set<u32> *notify_on_deco_ids,
80 const std::set<std::string> *notify_on_custom);
81
82 bool addEvent(GenNotifyType type, v3s16 pos);
83 bool addDecorationEvent(v3s16 pos, u32 deco_id);
84 bool setCustom(const std::string &key, const std::string &value);
85 void getEvents(std::map<std::string, std::vector<v3s16>> &map) const;
86 const StringMap &getCustomData() const { return m_notify_custom; }
87 void clearEvents();
88
89private:
90 u32 m_notify_on = 0;
91 const std::set<u32> *m_notify_on_deco_ids = nullptr;
92 const std::set<std::string> *m_notify_on_custom = nullptr;
93 std::list<GenNotifyEvent> m_notify_events;
95
96 inline bool shouldNotifyOn(GenNotifyType type) const {
97 return m_notify_on & (1 << type);
98 }
99};
100
101// Order must match the order of 'static MapgenDesc g_reg_mapgens[]' in mapgen.cpp
113
115 MapgenParams() = default;
116 virtual ~MapgenParams();
117
119 s16 chunksize = 5;
120 u64 seed = 0;
121 s16 water_level = 1;
123 // Flags set in readParams
124 u32 flags = 0;
125 u32 spflags = 0;
126
128
131
132 virtual void readParams(const Settings *settings);
133 virtual void writeParams(Settings *settings) const;
134 // Default settings for g_settings such as flags
136
137 s32 getSpawnRangeMax();
138
139private:
141};
142
143
144/*
145 Generic interface for map generators. All mapgens must inherit this class.
146 If a feature exposed by a public member pointer is not supported by a
147 certain mapgen, it must be set to NULL.
148
149 Apart from makeChunk, getGroundLevelAtPoint, and getSpawnLevelAtPoint, all
150 methods can be used by constructing a Mapgen base class and setting the
151 appropriate public members (e.g. vm, ndef, and so on).
152*/
153class Mapgen {
154public:
155 // Seed used for noises (truncated from the map seed)
156 s32 seed = 0;
157 int water_level = 0;
159 u32 flags = 0;
160 bool generating = false;
161 int id = -1;
162
163 MMVManip *vm = nullptr;
164 // Note that this contains various things the mapgens *can* use, so biomegen
165 // might be NULL while m_emerge->biomegen is not.
167 const NodeDefManager *ndef = nullptr;
168
169 // Chunk-specific seed used to place ores and decorations
171 s16 *heightmap = nullptr;
172 biome_t *biomemap = nullptr;
174
175 BiomeGen *biomegen = nullptr;
177
178 Mapgen() = default;
179 Mapgen(int mapgenid, MapgenParams *params, EmergeParams *emerge);
180 virtual ~Mapgen();
182
183 virtual MapgenType getType() const { return MAPGEN_INVALID; }
184
185 static u32 getBlockSeed(v3s16 p, s32 seed);
186 static u32 getBlockSeed2(v3s16 p, s32 seed);
187 s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
188 s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
189 void updateHeightmap(v3s16 nmin, v3s16 nmax);
190 void getSurfaces(v2s16 p2d, s16 ymin, s16 ymax,
191 std::vector<s16> &floors, std::vector<s16> &ceilings);
192
193 void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
194
201 void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
210 void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax,
211 bool propagate_shadow = true);
220 void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow);
227 void spreadLight(const v3s16 &nmin, const v3s16 &nmax);
228
229 virtual void makeChunk(BlockMakeData *data) {}
230 virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
231
232 // getSpawnLevelAtPoint() is a function within each mapgen that returns a
233 // suitable y co-ordinate for player spawn ('suitable' usually meaning
234 // within 16 nodes of water_level). If a suitable spawn level cannot be
235 // found at the specified (X, Z) 'MAX_MAP_GENERATION_LIMIT' is returned to
236 // signify this and to cause Server::findSpawnPos() to try another (X, Z).
237 virtual int getSpawnLevelAtPoint(v2s16 p) { return 0; }
238
239 // Mapgen management functions
240 static MapgenType getMapgenType(const std::string &mgname);
241 static const char *getMapgenName(MapgenType mgtype);
242 static Mapgen *createMapgen(MapgenType mgtype, MapgenParams *params,
243 EmergeParams *emerge);
245 static void getMapgenNames(std::vector<const char *> *mgnames, bool include_hidden);
247
248private:
258 void lightSpread(VoxelArea &a, std::queue<std::pair<v3s16, u8>> &queue,
259 const v3s16 &p, u8 light);
260
261 // isLiquidHorizontallyFlowable() is a helper function for updateLiquid()
262 // that checks whether there are floodable nodes without liquid beneath
263 // the node at index vi.
264 inline bool isLiquidHorizontallyFlowable(u32 vi, v3s16 em);
265};
266
267/*
268 MapgenBasic is a Mapgen implementation that handles basic functionality
269 the majority of conventional mapgens will probably want to use, but isn't
270 generic enough to be included as part of the base Mapgen class (such as
271 generating biome terrain over terrain node skeletons, generating caves,
272 dungeons, etc.)
273
274 Inherit MapgenBasic instead of Mapgen to add this basic functionality to
275 your mapgen without having to reimplement it. Feel free to override any of
276 these methods if you desire different or more advanced behavior.
277
278 Note that you must still create your own generateTerrain implementation when
279 inheriting MapgenBasic.
280*/
333
334// Calculate exact edges of the outermost mapchunks that are within the set
335// mapgen_limit. Returns the minimum and maximum edges in nodes in that order.
336std::pair<s16, s16> get_mapgen_edges(s16 mapgen_limit, s16 chunksize);
Definition mg_biome.h:79
Definition mg_biome.h:202
Definition mg_biome.h:28
Definition emerge.h:117
Definition emerge.h:85
Definition mapgen.h:68
StringMap m_notify_custom
Definition mapgen.h:94
bool addEvent(GenNotifyType type, v3s16 pos)
Definition mapgen.cpp:967
GenerateNotifier()=default
void clearEvents()
Definition mapgen.cpp:1028
const StringMap & getCustomData() const
Definition mapgen.h:86
void getEvents(std::map< std::string, std::vector< v3s16 > > &map) const
Definition mapgen.cpp:1013
bool shouldNotifyOn(GenNotifyType type) const
Definition mapgen.h:96
std::list< GenNotifyEvent > m_notify_events
Definition mapgen.h:93
const std::set< std::string > * m_notify_on_custom
Definition mapgen.h:92
bool addDecorationEvent(v3s16 pos, u32 deco_id)
Definition mapgen.cpp:981
bool setCustom(const std::string &key, const std::string &value)
Definition mapgen.cpp:999
const std::set< u32 > * m_notify_on_deco_ids
Definition mapgen.h:91
u32 m_notify_on
Definition mapgen.h:90
Definition map.h:305
Definition mapblock.h:58
Definition map.h:101
Definition mapgen.h:281
MapgenBasic(int mapgenid, MapgenParams *params, EmergeParams *emerge)
Definition mapgen.cpp:567
int zstride_1u1d
Definition mapgen.h:312
float cavern_limit
Definition mapgen.h:321
content_t c_lava_source
Definition mapgen.h:306
float cavern_taper
Definition mapgen.h:322
int zstride_1d
Definition mapgen.h:311
content_t c_stone
Definition mapgen.h:303
virtual void dustTopNodes()
Definition mapgen.cpp:766
Noise * noise_filler_depth
Definition mapgen.h:296
virtual bool generateCavernsNoise(s16 max_stone_y)
Definition mapgen.cpp:875
content_t c_water_source
Definition mapgen.h:304
virtual void generateDungeons(s16 max_stone_y)
Definition mapgen.cpp:887
v3s16 full_node_min
Definition mapgen.h:300
NoiseParams np_cave1
Definition mapgen.h:316
int ystride
Definition mapgen.h:309
int zstride
Definition mapgen.h:310
NoiseParams np_dungeons
Definition mapgen.h:319
int large_cave_num_min
Definition mapgen.h:326
virtual void generateCavesRandomWalk(s16 max_stone_y, s16 large_cave_ymax)
Definition mapgen.cpp:844
s16 dungeon_ymin
Definition mapgen.h:330
u32 spflags
Definition mapgen.h:314
s16 dungeon_ymax
Definition mapgen.h:331
virtual ~MapgenBasic()
Definition mapgen.cpp:620
content_t c_river_water_source
Definition mapgen.h:305
v3s16 node_min
Definition mapgen.h:298
int large_cave_num_max
Definition mapgen.h:327
BiomeManager * m_bmgr
Definition mapgen.h:294
int small_cave_num_min
Definition mapgen.h:324
float cave_width
Definition mapgen.h:320
v3s16 full_node_max
Definition mapgen.h:301
int small_cave_num_max
Definition mapgen.h:325
v3s16 node_max
Definition mapgen.h:299
float large_cave_flooded
Definition mapgen.h:328
virtual void generateCavesNoiseIntersection(s16 max_stone_y)
Definition mapgen.cpp:830
float cavern_threshold
Definition mapgen.h:323
NoiseParams np_cave2
Definition mapgen.h:317
content_t c_cobble
Definition mapgen.h:307
s16 large_cave_depth
Definition mapgen.h:329
NoiseParams np_cavern
Definition mapgen.h:318
virtual void generateBiomes()
Definition mapgen.cpp:626
Definition mapgen.h:153
s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax)
Definition mapgen.cpp:241
void getSurfaces(v2s16 p2d, s16 ymin, s16 ymax, std::vector< s16 > &floors, std::vector< s16 > &ceilings)
Definition mapgen.cpp:296
virtual MapgenType getType() const
Definition mapgen.h:183
void updateHeightmap(v3s16 nmin, v3s16 nmax)
Definition mapgen.cpp:279
s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax)
Definition mapgen.cpp:259
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:432
GenerateNotifier gennotify
Definition mapgen.h:176
s16 * heightmap
Definition mapgen.h:171
EmergeParams * m_emerge
Definition mapgen.h:166
s32 seed
Definition mapgen.h:156
virtual int getGroundLevelAtPoint(v2s16 p)
Definition mapgen.h:230
virtual int getSpawnLevelAtPoint(v2s16 p)
Definition mapgen.h:237
virtual void makeChunk(BlockMakeData *data)
Definition mapgen.h:229
MMVManip * vm
Definition mapgen.h:163
u32 flags
Definition mapgen.h:159
int water_level
Definition mapgen.h:157
void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax, bool propagate_shadow=true)
Run all lighting calculations.
Definition mapgen.cpp:469
static MapgenType getMapgenType(const std::string &mgname)
Definition mapgen.cpp:130
static u32 getBlockSeed(v3s16 p, s32 seed)
Definition mapgen.cpp:222
DISABLE_CLASS_COPY(Mapgen)
virtual ~Mapgen()
Definition mapgen.cpp:124
int mapgen_limit
Definition mapgen.h:158
static void setDefaultSettings(Settings *settings)
Definition mapgen.cpp:210
static Mapgen * createMapgen(MapgenType mgtype, MapgenParams *params, EmergeParams *emerge)
Definition mapgen.cpp:151
void setLighting(u8 light, v3s16 nmin, v3s16 nmax)
Set light in entire area to fixed value.
Definition mapgen.cpp:417
static u32 getBlockSeed2(v3s16 p, s32 seed)
Definition mapgen.cpp:231
static void getMapgenNames(std::vector< const char * > *mgnames, bool include_hidden)
Definition mapgen.cpp:202
biome_t * biomemap
Definition mapgen.h:172
bool isLiquidHorizontallyFlowable(u32 vi, v3s16 em)
Definition mapgen.cpp:323
static const char * getMapgenName(MapgenType mgtype)
Definition mapgen.cpp:141
const NodeDefManager * ndef
Definition mapgen.h:167
void spreadLight(const v3s16 &nmin, const v3s16 &nmax)
Spread light in the given area.
Definition mapgen.cpp:515
static MapgenParams * createMapgenParams(MapgenType mgtype)
Definition mapgen.cpp:177
u32 blockseed
Definition mapgen.h:170
void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow)
Spread sunlight from the area above downwards.
Definition mapgen.cpp:479
BiomeGen * biomegen
Definition mapgen.h:175
bool generating
Definition mapgen.h:160
void updateLiquid(UniqueQueue< v3s16 > *trans_liquid, v3s16 nmin, v3s16 nmax)
Definition mapgen.cpp:356
v3s16 csize
Definition mapgen.h:173
This class is for getting the actual properties of nodes from their content ID.
Definition nodedef.h:541
Definition noise.h:146
Definition settings.h:109
Definition container.h:26
Definition voxel.h:44
Definition voxel.h:360
#define MAX_MAP_GENERATION_LIMIT
Definition constants.h:54
static const char * settings[]
Definition fontengine.cpp:27
core::vector2d< s16 > v2s16
Definition irr_v2d.h:12
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
GenNotifyType
Definition mapgen.h:56
@ GENNOTIFY_CUSTOM
Definition mapgen.h:64
@ GENNOTIFY_LARGECAVE_END
Definition mapgen.h:62
@ GENNOTIFY_DECORATION
Definition mapgen.h:63
@ GENNOTIFY_LARGECAVE_BEGIN
Definition mapgen.h:61
@ GENNOTIFY_CAVE_END
Definition mapgen.h:60
@ NUM_GENNOTIFY_TYPES
Definition mapgen.h:65
@ GENNOTIFY_TEMPLE
Definition mapgen.h:58
@ GENNOTIFY_DUNGEON
Definition mapgen.h:57
@ GENNOTIFY_CAVE_BEGIN
Definition mapgen.h:59
MapgenType
Definition mapgen.h:102
@ MAPGEN_V6
Definition mapgen.h:110
@ MAPGEN_INVALID
Definition mapgen.h:111
@ MAPGEN_FLAT
Definition mapgen.h:107
@ MAPGEN_V5
Definition mapgen.h:106
@ MAPGEN_CARPATHIAN
Definition mapgen.h:105
@ MAPGEN_SINGLENODE
Definition mapgen.h:109
@ MAPGEN_V7
Definition mapgen.h:103
@ MAPGEN_VALLEYS
Definition mapgen.h:104
@ MAPGEN_FRACTAL
Definition mapgen.h:108
FlagDesc flagdesc_mapgen[]
Definition mapgen.cpp:40
std::pair< s16, s16 > get_mapgen_edges(s16 mapgen_limit, s16 chunksize)
Definition mapgen.cpp:1109
MapgenObject
Definition mapgen.h:47
@ MGOBJ_HEATMAP
Definition mapgen.h:51
@ MGOBJ_HUMIDMAP
Definition mapgen.h:52
@ MGOBJ_GENNOTIFY
Definition mapgen.h:53
@ MGOBJ_VMANIP
Definition mapgen.h:48
@ MGOBJ_HEIGHTMAP
Definition mapgen.h:49
@ MGOBJ_BIOMEMAP
Definition mapgen.h:50
u16 biome_t
Definition mapgen.h:26
#define MAPGEN_DEFAULT
Definition mapgen.h:15
FlagDesc flagdesc_gennotify[]
Definition mapgen.cpp:50
u16 content_t
Definition mapnode.h:22
std::unordered_map< std::string, std::string > StringMap
Definition string.h:65
Definition mg_biome.h:70
Definition emerge.h:37
Definition string.h:67
Definition mapgen.h:70
GenNotifyType type
Definition mapgen.h:71
u32 id
Definition mapgen.h:73
v3s16 pos
Definition mapgen.h:72
Definition mapgen.h:114
virtual ~MapgenParams()
Definition mapgen.cpp:1040
BiomeParams * bparams
Definition mapgen.h:127
virtual void setDefaultSettings(Settings *settings)
Definition mapgen.h:135
u32 flags
Definition mapgen.h:124
s16 mapgen_edge_max
Definition mapgen.h:130
u64 seed
Definition mapgen.h:120
s16 mapgen_edge_min
Definition mapgen.h:129
s16 water_level
Definition mapgen.h:121
virtual void writeParams(Settings *settings) const
Definition mapgen.cpp:1082
s16 mapgen_limit
Definition mapgen.h:122
MapgenType mgtype
Definition mapgen.h:118
virtual void readParams(const Settings *settings)
Definition mapgen.cpp:1046
bool m_mapgen_edges_calculated
Definition mapgen.h:140
MapgenParams()=default
s32 getSpawnRangeMax()
Definition mapgen.cpp:1096
s16 chunksize
Definition mapgen.h:119
u32 spflags
Definition mapgen.h:125
Definition noise.h:119
static std::string p(std::string path)
Definition test_filesys.cpp:53