3 Copyright (C) 2010-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2015-2018 paramat
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
25 class GenerateNotifier;
28 CavesNoiseIntersection is a cave digging algorithm that carves smooth,
29 web-like, continuous tunnels at points where the density of the intersection
30 between two separate 3d noises is above a certain value. This value,
31 cave_width, can be modified to set the effective width of these tunnels.
33 This algorithm is relatively heavyweight, taking ~80ms to generate an
34 80x80x80 chunk of map on a modern processor. Use sparingly!
36 TODO(hmmmm): Remove dependency on biomes
37 TODO(hmmmm): Find alternative to overgeneration as solution for sunlight issue
39 class CavesNoiseIntersection
42 CavesNoiseIntersection(const NodeDefManager *nodedef,
43 BiomeManager *biomemgr, v3s16 chunksize, NoiseParams *np_cave1,
44 NoiseParams *np_cave2, s32 seed, float cave_width);
45 ~CavesNoiseIntersection();
47 void generateCaves(MMVManip *vm, v3s16 nmin, v3s16 nmax, u8 *biomemap);
50 const NodeDefManager *m_ndef;
53 // configurable parameters
57 // intermediate state variables
66 CavernsNoise is a cave digging algorithm
71 CavernsNoise(const NodeDefManager *nodedef, v3s16 chunksize,
72 NoiseParams *np_cavern, s32 seed, float cavern_limit,
73 float cavern_taper, float cavern_threshold);
76 bool generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax);
79 const NodeDefManager *m_ndef;
81 // configurable parameters
85 float m_cavern_threshold;
87 // intermediate state variables
93 content_t c_water_source;
94 content_t c_lava_source;
98 CavesRandomWalk is an implementation of a cave-digging algorithm that
99 operates on the principle of a "random walk" to approximate the stochiastic
100 activity of cavern development.
102 In summary, this algorithm works by carving a randomly sized tunnel in a
103 random direction a random amount of times, randomly varying in width.
104 All randomness here is uniformly distributed; alternative distributions have
105 not yet been implemented.
107 This algorithm is very fast, executing in less than 1ms on average for an
108 80x80x80 chunk of map on a modern processor.
110 class CavesRandomWalk
114 const NodeDefManager *ndef;
115 GenerateNotifier *gennotify;
119 // configurable parameters
122 // TODO 'lava_depth' and 'np_caveliquids' are deprecated and should be removed.
123 // Cave liquids are now defined and located using biome definitions.
125 NoiseParams *np_caveliquids;
127 // intermediate state variables
130 s16 min_tunnel_diameter;
131 s16 max_tunnel_diameter;
132 u16 tunnel_routepoints;
133 int part_max_length_rs;
136 bool large_cave_is_flat;
138 bool use_biome_liquid;
143 v3f orp; // starting point, relative to caved space
144 v3s16 of; // absolute coordinates of caved space
145 v3s16 ar; // allowed route area
146 s16 rs; // tunnel radius size
154 content_t c_water_source;
155 content_t c_lava_source;
156 content_t c_biome_liquid;
158 // ndef is a mandatory parameter.
159 // If gennotify is NULL, generation events are not logged.
160 // If biomegen is NULL, cave liquids have classic behaviour.
161 CavesRandomWalk(const NodeDefManager *ndef, GenerateNotifier *gennotify =
162 NULL, s32 seed = 0, int water_level = 1, content_t water_source =
163 CONTENT_IGNORE, content_t lava_source = CONTENT_IGNORE,
164 int lava_depth = -256, BiomeGen *biomegen = NULL);
166 // vm and ps are mandatory parameters.
167 // If heightmap is NULL, the surface level at all points is assumed to
169 void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, PseudoRandom *ps,
170 bool is_large_cave, int max_stone_height, s16 *heightmap);
173 void makeTunnel(bool dirswitch);
174 void carveRoute(v3f vec, float f, bool randomize_xz);
176 inline bool isPosAboveSurface(v3s16 p);
180 CavesV6 is the original version of caves used with Mapgen V6.
182 Though it uses the same fundamental algorithm as CavesRandomWalk, it is made
183 separate to preserve the exact sequence of PseudoRandom calls - any change
184 to this ordering results in the output being radically different.
185 Because caves in Mapgen V6 are responsible for a large portion of the basic
186 terrain shape, modifying this will break our contract of reverse
187 compatibility for a 'stable' mapgen such as V6.
190 *** DO NOT TOUCH THIS CLASS UNLESS YOU KNOW WHAT YOU ARE DOING ***
196 const NodeDefManager *ndef;
197 GenerateNotifier *gennotify;
201 // configurable parameters
203 content_t c_water_source;
204 content_t c_lava_source;
207 // intermediate state variables
210 s16 min_tunnel_diameter;
211 s16 max_tunnel_diameter;
212 u16 tunnel_routepoints;
213 int part_max_length_rs;
216 bool large_cave_is_flat;
221 v3f orp; // starting point, relative to caved space
222 v3s16 of; // absolute coordinates of caved space
223 v3s16 ar; // allowed route area
224 s16 rs; // tunnel radius size
230 // ndef is a mandatory parameter.
231 // If gennotify is NULL, generation events are not logged.
232 CavesV6(const NodeDefManager *ndef, GenerateNotifier *gennotify = NULL,
233 int water_level = 1, content_t water_source = CONTENT_IGNORE,
234 content_t lava_source = CONTENT_IGNORE);
236 // vm, ps, and ps2 are mandatory parameters.
237 // If heightmap is NULL, the surface level at all points is assumed to
239 void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax, PseudoRandom *ps,
240 PseudoRandom *ps2, bool is_large_cave, int max_stone_height,
241 s16 *heightmap = NULL);
244 void makeTunnel(bool dirswitch);
245 void carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground);
247 inline s16 getSurfaceFromHeightmap(v3s16 p);