]> git.lizzy.rs Git - dragonfireclient.git/blob - src/cavegen.h
Cavegen: Merge instances of repetitive surface level-finding code
[dragonfireclient.git] / src / cavegen.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef CAVEGEN_HEADER
21 #define CAVEGEN_HEADER
22
23 #define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
24 #define DEFAULT_LAVA_DEPTH (-256)
25
26 class GenerateNotifier;
27
28 class CavesRandomWalk {
29 public:
30         Mapgen *mg;
31         MMVManip *vm;
32         INodeDefManager *ndef;
33         s16 *heightmap;
34
35         // variables
36         int lava_depth;
37         NoiseParams *np_caveliquids;
38
39         s16 min_tunnel_diameter;
40         s16 max_tunnel_diameter;
41         u16 tunnel_routepoints;
42         int dswitchint;
43         int part_max_length_rs;
44
45         bool large_cave_is_flat;
46         bool flooded;
47
48         s16 max_stone_y;
49         v3s16 node_min;
50         v3s16 node_max;
51
52         v3f orp;  // starting point, relative to caved space
53         v3s16 of; // absolute coordinates of caved space
54         v3s16 ar; // allowed route area
55         s16 rs;   // tunnel radius size
56         v3f main_direction;
57
58         s16 route_y_min;
59         s16 route_y_max;
60
61         PseudoRandom *ps;
62
63         content_t c_water_source;
64         content_t c_lava_source;
65         content_t c_ice;
66
67         int water_level;
68         u16 ystride;
69
70         CavesRandomWalk(Mapgen *mg, PseudoRandom *ps);
71         void makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height);
72         void makeTunnel(bool dirswitch);
73         void carveRoute(v3f vec, float f, bool randomize_xz);
74
75 private:
76         inline bool isPosAboveSurface(v3s16 p);
77 };
78
79 /*
80         CavesV6 is the original version of caves used with Mapgen V6.
81
82         Though it uses the same fundamental algorithm as CavesRandomWalk, it is made
83         separate to preserve the exact sequence of PseudoRandom calls - any change
84         to this ordering results in the output being radically different.
85         Because caves in Mapgen V6 are responsible for a large portion of the basic
86         terrain shape, modifying this will break our contract of reverse
87         compatibility for a 'stable' mapgen such as V6.
88
89         tl;dr,
90         *** DO NOT TOUCH THIS CLASS UNLESS YOU KNOW WHAT YOU ARE DOING ***
91 */
92 class CavesV6 {
93 public:
94         MMVManip *vm;
95         INodeDefManager *ndef;
96         GenerateNotifier *gennotify;
97         PseudoRandom *ps;
98         PseudoRandom *ps2;
99
100         s16 *heightmap;
101         content_t c_water_source;
102         content_t c_lava_source;
103         int water_level;
104
105         u16 ystride;
106
107         s16 min_tunnel_diameter;
108         s16 max_tunnel_diameter;
109         u16 tunnel_routepoints;
110         int dswitchint;
111         int part_max_length_rs;
112
113         bool large_cave;
114         bool large_cave_is_flat;
115
116         v3s16 node_min;
117         v3s16 node_max;
118
119         v3f orp;  // starting point, relative to caved space
120         v3s16 of; // absolute coordinates of caved space
121         v3s16 ar; // allowed route area
122         s16 rs;   // tunnel radius size
123         v3f main_direction;
124
125         s16 route_y_min;
126         s16 route_y_max;
127
128         // ndef is a mandatory parameter.
129         // If gennotify is NULL, generation events are not logged.
130         CavesV6(INodeDefManager *ndef,
131                 GenerateNotifier *gennotify = NULL,
132                 int water_level = 1,
133                 content_t water_source = CONTENT_IGNORE,
134                 content_t lava_source = CONTENT_IGNORE);
135
136         // vm, ps, and ps2 are mandatory parameters.
137         // If heightmap is NULL, the surface level at all points is assumed to
138         // be water_level.
139         void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax,
140                 PseudoRandom *ps, PseudoRandom *ps2,
141                 bool is_large_cave, int max_stone_height, s16 *heightmap = NULL);
142
143 private:
144         void makeTunnel(bool dirswitch);
145         void carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground);
146
147         inline s16 getSurfaceFromHeightmap(v3s16 p);
148 };
149
150 #endif