76ae73c527c6ea10da9a187736b5a44e4a9f74db
[oweals/minetest.git] / src / mapgen.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
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 MAPGEN_HEADER
21 #define MAPGEN_HEADER
22
23 #include "irrlichttypes_extrabloated.h"
24 #include "util/container.h" // UniqueQueue
25 #include "gamedef.h"
26 #include "mapnode.h"
27 #include "noise.h"
28
29 class BiomeDefManager;
30 class Biome;
31
32 //struct BlockMakeData;
33 class MapBlock;
34 class ManualMapVoxelManipulator;
35 class VoxelManipulator;
36 class INodeDefManager;
37
38
39 enum BiomeType
40 {
41         BT_NORMAL,
42         BT_DESERT
43 };
44
45
46 struct BlockMakeData {
47         bool no_op;
48         ManualMapVoxelManipulator *vmanip;
49         u64 seed;
50         v3s16 blockpos_min;
51         v3s16 blockpos_max;
52         v3s16 blockpos_requested;
53         UniqueQueue<v3s16> transforming_liquid;
54         INodeDefManager *nodedef;
55
56         BlockMakeData();
57         ~BlockMakeData();
58 };
59
60
61 class Mapgen {
62 public:
63
64         int seed;
65         int water_level;
66
67         bool generating;
68         int id;
69
70
71         //virtual Mapgen(BiomeDefManager *biomedef, int mapgenid=0, u64 seed=0);
72         //virtual ~Mapgen();
73         virtual void makeChunk(BlockMakeData *data) {};
74
75         //Legacy functions for Farmesh (pending removal)
76         static bool get_have_beach(u64 seed, v2s16 p2d);
77         static double tree_amount_2d(u64 seed, v2s16 p);
78         static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
79 };
80
81
82 class MapgenV6 : public Mapgen {
83 public:
84         //ManualMapVoxelManipulator &vmanip;
85
86         int ystride;
87         v3s16 csize;
88
89         v3s16 node_min;
90         v3s16 node_max;
91
92         Noise *noise_terrain_base;
93         Noise *noise_terrain_higher;
94         Noise *noise_steepness;
95         Noise *noise_height_select;
96         Noise *noise_trees;
97         Noise *noise_mud;
98         Noise *noise_beach;
99         Noise *noise_biome;
100         Noise *noise_cave;
101
102         float *map_terrain_base;
103         float *map_terrain_higher;
104         float *map_steepness;
105         float *map_height_select;
106         float *map_trees;
107         float *map_mud;
108         float *map_beach;
109         float *map_biome;
110         float *map_cave;
111
112         bool use_smooth_biome_trans;
113
114         MapgenV6(int mapgenid=0, u64 seed=0);
115         ~MapgenV6();
116
117         void makeChunk(BlockMakeData *data);
118
119
120         static s16 find_ground_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
121         static s16 find_stone_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
122         void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, bool is_apple_tree, INodeDefManager *ndef);
123         double tree_amount_2d(u64 seed, v2s16 p);
124         bool block_is_underground(u64 seed, v3s16 blockpos);
125         double base_rock_level_2d(u64 seed, v2s16 p);
126         s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
127         double get_mud_add_amount(u64 seed, v2s16 p);
128         bool get_have_beach(u64 seed, v2s16 p2d);
129         BiomeType get_biome(u64 seed, v2s16 p2d);
130         u32 get_blockseed(u64 seed, v3s16 p);
131 };
132
133
134 class MapgenV7 : public Mapgen {
135 public:
136         BlockMakeData *data;
137         ManualMapVoxelManipulator *vmanip;
138         INodeDefManager *ndef;
139         BiomeDefManager *biomedef;
140
141         int ystride;
142         int zstride;
143
144         v3s16 csize;
145         //int seed;
146         //int water_level;
147
148         Noise *noise_terrain;
149         Noise *noise_bgroup;
150         Noise *noise_heat;
151         Noise *noise_humidity;
152
153         v3s16 node_min;
154         v3s16 node_max;
155
156         float *map_terrain;
157         float *map_bgroup;
158         float *map_heat;
159         float *map_humidity;
160
161         bool generating;
162         int id;
163
164         NoiseParams *np_terrain;
165         NoiseParams *np_bgroup;
166         NoiseParams *np_heat;
167         NoiseParams *np_humidity;
168
169         //should these be broken off into a "commonly used nodes" class?
170         MapNode n_air;
171         MapNode n_water;
172         MapNode n_lava;
173
174         MapgenV7(BiomeDefManager *biomedef, int mapgenid=0, u64 seed=0);
175         MapgenV7(BiomeDefManager *biomedef, int mapgenid, u64 seed,
176                    NoiseParams *np_terrain, NoiseParams *np_bgroup,
177                    NoiseParams *np_heat,    NoiseParams *np_humidity);
178         void init(BiomeDefManager *biomedef, int mapgenid, u64 seed,
179                            NoiseParams *np_terrain, NoiseParams *np_bgroup,
180                            NoiseParams *np_heat,    NoiseParams *np_humidity);
181         ~MapgenV7();
182
183         void makeChunk(BlockMakeData *data);
184         void updateLiquid(v3s16 node_min, v3s16 node_max);
185         void updateLighting(v3s16 node_min, v3s16 node_max);
186
187         //Legacy functions for Farmesh (pending removal)
188 //      static bool get_have_beach(u64 seed, v2s16 p2d);
189 //      static double tree_amount_2d(u64 seed, v2s16 p);
190 //      static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
191 };
192
193 class EmergeManager {
194 public:
195         //settings
196         u64 seed;
197         int water_level;
198         NoiseParams *np_terrain;
199         NoiseParams *np_bgroup;
200         NoiseParams *np_heat;
201         NoiseParams *np_humidity;
202
203         //biome manager
204         BiomeDefManager *biomedef;
205
206         //mapgen objects here
207
208         EmergeManager(IGameDef *gamedef);
209         ~EmergeManager();
210         void addBlockToQueue();
211
212
213
214         //mapgen helper methods
215         Biome *getBiomeAtPoint(v3s16 p);
216         int getGroundLevelAtPoint(v2s16 p);
217         bool isBlockUnderground(v3s16 blockpos);
218         u32 getBlockSeed(v3s16 p);
219 };
220
221
222 /*
223 namespace mapgen
224 {
225         // Finds precise ground level at any position
226         s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
227
228         // Find out if block is completely underground
229         bool block_is_underground(u64 seed, v3s16 blockpos);
230
231         // Get a pseudorandom seed for a position on the map
232         u32 get_blockseed(u64 seed, v3s16 p);
233
234         // Main map generation routine
235         void make_block(BlockMakeData *data);
236
237
238         //These are used by FarMesh
239         bool get_have_beach(u64 seed, v2s16 p2d);
240         double tree_amount_2d(u64 seed, v2s16 p);
241
242         struct BlockMakeData
243         {
244                 bool no_op;
245                 ManualMapVoxelManipulator *vmanip; // Destructor deletes
246                 u64 seed;
247                 v3s16 blockpos_min;
248                 v3s16 blockpos_max;
249                 v3s16 blockpos_requested;
250                 UniqueQueue<v3s16> transforming_liquid;
251                 INodeDefManager *nodedef;
252
253                 BlockMakeData();
254                 ~BlockMakeData();
255         };
256
257 }; // namespace mapgen
258 */
259 #endif
260