Minetest 5.10.0-dev
 
Loading...
Searching...
No Matches
cavegen.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2015-2020 paramat
4Copyright (C) 2010-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation; either version 2.1 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License along
17with this program; if not, write to the Free Software Foundation, Inc.,
1851 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20
21#pragma once
22
23#define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
24
25typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
26
28
29class BiomeGen;
30
31/*
32 CavesNoiseIntersection is a cave digging algorithm that carves smooth,
33 web-like, continuous tunnels at points where the density of the intersection
34 between two separate 3d noises is above a certain value. This value,
35 cave_width, can be modified to set the effective width of these tunnels.
36
37 This algorithm is relatively heavyweight, taking ~80ms to generate an
38 80x80x80 chunk of map on a modern processor. Use sparingly!
39
40 TODO(hmmmm): Remove dependency on biomes
41 TODO(hmmmm): Find alternative to overgeneration as solution for sunlight issue
42*/
44{
45public:
47 BiomeManager *biomemgr, BiomeGen *biomegen, v3s16 chunksize, NoiseParams *np_cave1,
48 NoiseParams *np_cave2, s32 seed, float cave_width);
50
51 void generateCaves(MMVManip *vm, v3s16 nmin, v3s16 nmax, biome_t *biomemap);
52
53private:
56
58
59 // configurable parameters
62
63 // intermediate state variables
66
69};
70
71/*
72 CavernsNoise is a cave digging algorithm
73*/
75{
76public:
77 CavernsNoise(const NodeDefManager *nodedef, v3s16 chunksize,
78 NoiseParams *np_cavern, s32 seed, float cavern_limit,
79 float cavern_taper, float cavern_threshold);
81
82 bool generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax);
83
84private:
86
87 // configurable parameters
92
93 // intermediate state variables
96
98
101};
102
103/*
104 CavesRandomWalk is an implementation of a cave-digging algorithm that
105 operates on the principle of a "random walk" to approximate the stochiastic
106 activity of cavern development.
107
108 In summary, this algorithm works by carving a randomly sized tunnel in a
109 random direction a random amount of times, randomly varying in width.
110 All randomness here is uniformly distributed; alternative distributions have
111 not yet been implemented.
112
113 This algorithm is very fast, executing in less than 1ms on average for an
114 80x80x80 chunk of map on a modern processor.
115*/
117{
118public:
124
125 s32 seed;
128 // TODO 'np_caveliquids' is deprecated and should eventually be removed.
129 // Cave liquids are now defined and located using biome definitions.
131
133
138
143
146
147 v3f orp; // starting point, relative to caved space
148 v3s16 of; // absolute coordinates of caved space
149 v3s16 ar; // allowed route area
150 s16 rs; // tunnel radius size
152
155
157
161
162 // ndef is a mandatory parameter.
163 // If gennotify is NULL, generation events are not logged.
164 // If biomegen is NULL, cave liquids have classic behavior.
166 NULL, s32 seed = 0, int water_level = 1, content_t water_source =
168 float large_cave_flooded = 0.5f, BiomeGen *biomegen = NULL);
169
170 // vm and ps are mandatory parameters.
171 // If heightmap is NULL, the surface level at all points is assumed to
172 // be water_level.
173 void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, PseudoRandom *ps,
174 bool is_large_cave, int max_stone_height, s16 *heightmap);
175
176private:
177 void makeTunnel(bool dirswitch);
178 void carveRoute(v3f vec, float f, bool randomize_xz);
179
180 inline bool isPosAboveSurface(v3s16 p);
181};
182
183/*
184 CavesV6 is the original version of caves used with Mapgen V6.
185
186 Though it uses the same fundamental algorithm as CavesRandomWalk, it is made
187 separate to preserve the exact sequence of PseudoRandom calls - any change
188 to this ordering results in the output being radically different.
189 Because caves in Mapgen V6 are responsible for a large portion of the basic
190 terrain shape, modifying this will break our contract of reverse
191 compatibility for a 'stable' mapgen such as V6.
192
193 tl;dr,
194 *** DO NOT TOUCH THIS CLASS UNLESS YOU KNOW WHAT YOU ARE DOING ***
195*/
197{
198public:
204
205 // configurable parameters
210
211 // intermediate state variables
213
218
221
224
225 v3f orp; // starting point, relative to caved space
226 v3s16 of; // absolute coordinates of caved space
227 v3s16 ar; // allowed route area
228 s16 rs; // tunnel radius size
230
233
234 // ndef is a mandatory parameter.
235 // If gennotify is NULL, generation events are not logged.
237 int water_level = 1, content_t water_source = CONTENT_IGNORE,
238 content_t lava_source = CONTENT_IGNORE);
239
240 // vm, ps, and ps2 are mandatory parameters.
241 // If heightmap is NULL, the surface level at all points is assumed to
242 // be water_level.
243 void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, PseudoRandom *ps,
244 PseudoRandom *ps2, bool is_large_cave, int max_stone_height,
245 s16 *heightmap = NULL);
246
247private:
248 void makeTunnel(bool dirswitch);
249 void carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground);
250
251 inline s16 getSurfaceFromHeightmap(v3s16 p);
252};
u16 biome_t
Definition cavegen.h:25
Definition mg_biome.h:94
Definition mg_biome.h:217
Definition cavegen.h:75
u16 m_zstride_1d
Definition cavegen.h:95
float m_cavern_threshold
Definition cavegen.h:91
bool generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax)
Definition cavegen.cpp:231
v3s16 m_csize
Definition cavegen.h:88
u16 m_ystride
Definition cavegen.h:94
content_t c_lava_source
Definition cavegen.h:100
content_t c_water_source
Definition cavegen.h:99
~CavernsNoise()
Definition cavegen.cpp:225
const NodeDefManager * m_ndef
Definition cavegen.h:85
float m_cavern_limit
Definition cavegen.h:89
Noise * noise_cavern
Definition cavegen.h:97
float m_cavern_taper
Definition cavegen.h:90
CavernsNoise(const NodeDefManager *nodedef, v3s16 chunksize, NoiseParams *np_cavern, s32 seed, float cavern_limit, float cavern_taper, float cavern_threshold)
Definition cavegen.cpp:194
Definition cavegen.h:44
float m_cave_width
Definition cavegen.h:61
BiomeGen * m_bmgn
Definition cavegen.h:57
Noise * noise_cave2
Definition cavegen.h:68
BiomeManager * m_bmgr
Definition cavegen.h:55
CavesNoiseIntersection(const NodeDefManager *nodedef, BiomeManager *biomemgr, BiomeGen *biomegen, v3s16 chunksize, NoiseParams *np_cave1, NoiseParams *np_cave2, s32 seed, float cave_width)
Definition cavegen.cpp:40
~CavesNoiseIntersection()
Definition cavegen.cpp:66
void generateCaves(MMVManip *vm, v3s16 nmin, v3s16 nmax, biome_t *biomemap)
Definition cavegen.cpp:73
const NodeDefManager * m_ndef
Definition cavegen.h:54
u16 m_ystride
Definition cavegen.h:64
v3s16 m_csize
Definition cavegen.h:60
u16 m_zstride_1d
Definition cavegen.h:65
Noise * noise_cave1
Definition cavegen.h:67
Definition cavegen.h:117
bool large_cave
Definition cavegen.h:139
bool large_cave_is_flat
Definition cavegen.h:140
MMVManip * vm
Definition cavegen.h:119
BiomeGen * bmgn
Definition cavegen.h:123
int water_level
Definition cavegen.h:126
v3f orp
Definition cavegen.h:147
v3s16 ar
Definition cavegen.h:149
s16 * heightmap
Definition cavegen.h:122
PseudoRandom * ps
Definition cavegen.h:156
content_t c_biome_liquid
Definition cavegen.h:160
s32 seed
Definition cavegen.h:125
u16 ystride
Definition cavegen.h:132
GenerateNotifier * gennotify
Definition cavegen.h:121
v3f main_direction
Definition cavegen.h:151
u16 tunnel_routepoints
Definition cavegen.h:136
const NodeDefManager * ndef
Definition cavegen.h:120
bool isPosAboveSurface(v3s16 p)
Definition cavegen.cpp:615
s16 route_y_max
Definition cavegen.h:154
void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, PseudoRandom *ps, bool is_large_cave, int max_stone_height, s16 *heightmap)
Definition cavegen.cpp:326
s16 route_y_min
Definition cavegen.h:153
content_t c_water_source
Definition cavegen.h:158
content_t c_lava_source
Definition cavegen.h:159
v3s16 node_max
Definition cavegen.h:145
v3s16 node_min
Definition cavegen.h:144
CavesRandomWalk(const NodeDefManager *ndef, GenerateNotifier *gennotify=NULL, s32 seed=0, int water_level=1, content_t water_source=CONTENT_IGNORE, content_t lava_source=CONTENT_IGNORE, float large_cave_flooded=0.5f, BiomeGen *biomegen=NULL)
Definition cavegen.cpp:292
NoiseParams * np_caveliquids
Definition cavegen.h:130
v3s16 of
Definition cavegen.h:148
s16 min_tunnel_diameter
Definition cavegen.h:134
void carveRoute(v3f vec, float f, bool randomize_xz)
Definition cavegen.cpp:526
void makeTunnel(bool dirswitch)
Definition cavegen.cpp:441
s16 max_tunnel_diameter
Definition cavegen.h:135
int part_max_length_rs
Definition cavegen.h:137
bool use_biome_liquid
Definition cavegen.h:142
s16 rs
Definition cavegen.h:150
bool flooded
Definition cavegen.h:141
float large_cave_flooded
Definition cavegen.h:127
Definition cavegen.h:197
bool large_cave_is_flat
Definition cavegen.h:220
MMVManip * vm
Definition cavegen.h:199
u16 tunnel_routepoints
Definition cavegen.h:216
GenerateNotifier * gennotify
Definition cavegen.h:201
v3s16 of
Definition cavegen.h:226
CavesV6(const NodeDefManager *ndef, GenerateNotifier *gennotify=NULL, int water_level=1, content_t water_source=CONTENT_IGNORE, content_t lava_source=CONTENT_IGNORE)
Definition cavegen.cpp:635
v3s16 node_min
Definition cavegen.h:222
s16 route_y_max
Definition cavegen.h:232
void carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground)
Definition cavegen.cpp:848
bool large_cave
Definition cavegen.h:219
v3s16 node_max
Definition cavegen.h:223
const NodeDefManager * ndef
Definition cavegen.h:200
s16 rs
Definition cavegen.h:228
PseudoRandom * ps
Definition cavegen.h:202
u16 ystride
Definition cavegen.h:212
void makeTunnel(bool dirswitch)
Definition cavegen.cpp:756
v3f main_direction
Definition cavegen.h:229
s16 max_tunnel_diameter
Definition cavegen.h:215
v3s16 ar
Definition cavegen.h:227
int part_max_length_rs
Definition cavegen.h:217
void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, PseudoRandom *ps, PseudoRandom *ps2, bool is_large_cave, int max_stone_height, s16 *heightmap=NULL)
Definition cavegen.cpp:658
PseudoRandom * ps2
Definition cavegen.h:203
s16 min_tunnel_diameter
Definition cavegen.h:214
content_t c_lava_source
Definition cavegen.h:208
v3f orp
Definition cavegen.h:225
s16 route_y_min
Definition cavegen.h:231
content_t c_water_source
Definition cavegen.h:207
s16 * heightmap
Definition cavegen.h:206
s16 getSurfaceFromHeightmap(v3s16 p)
Definition cavegen.cpp:920
int water_level
Definition cavegen.h:209
Definition mapgen.h:83
Definition map.h:320
This class is for getting the actual properties of nodes from their content ID.
Definition nodedef.h:556
Definition noise.h:146
Definition noise.h:43
core::vector3d< s16 > v3s16
Definition irr_v3d.h:28
core::vector3df v3f
Definition irr_v3d.h:26
#define CONTENT_IGNORE
Definition mapnode.h:73
u16 content_t
Definition mapnode.h:37
Definition noise.h:119
static std::string p(std::string path)
Definition test_filesys.cpp:66