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