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