]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen/mg_biome.h
Lua_api.txt: Improve bullet point indentation consistency
[dragonfireclient.git] / src / mapgen / mg_biome.h
1 /*
2 Minetest
3 Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2014-2017 paramat
5
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.
10
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.
15
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.
19 */
20
21 #pragma once
22
23 #include "objdef.h"
24 #include "nodedef.h"
25 #include "noise.h"
26
27 class Server;
28 class Settings;
29 class BiomeManager;
30
31 ////
32 //// Biome
33 ////
34
35 typedef u8 biome_t;
36
37 #define BIOME_NONE ((biome_t)0)
38
39 // TODO(hmmmm): Decide whether this is obsolete or will be used in the future
40 enum BiomeType {
41         BIOMETYPE_NORMAL,
42         BIOMETYPE_LIQUID,
43         BIOMETYPE_NETHER,
44         BIOMETYPE_AETHER,
45         BIOMETYPE_FLAT,
46 };
47
48 class Biome : public ObjDef, public NodeResolver {
49 public:
50         u32 flags;
51
52         content_t c_top;
53         content_t c_filler;
54         content_t c_stone;
55         content_t c_water_top;
56         content_t c_water;
57         content_t c_river_water;
58         content_t c_riverbed;
59         content_t c_dust;
60
61         s16 depth_top;
62         s16 depth_filler;
63         s16 depth_water_top;
64         s16 depth_riverbed;
65
66         s16 y_min;
67         s16 y_max;
68         float heat_point;
69         float humidity_point;
70         s16 vertical_blend;
71
72         virtual void resolveNodeNames();
73 };
74
75
76 ////
77 //// BiomeGen
78 ////
79
80 enum BiomeGenType {
81         BIOMEGEN_ORIGINAL,
82 };
83
84 struct BiomeParams {
85         virtual void readParams(const Settings *settings) = 0;
86         virtual void writeParams(Settings *settings) const = 0;
87         virtual ~BiomeParams() = default;
88
89         s32 seed;
90 };
91
92 class BiomeGen {
93 public:
94         virtual ~BiomeGen() = default;
95
96         virtual BiomeGenType getType() const = 0;
97
98         // Calculates the biome at the exact position provided.  This function can
99         // be called at any time, but may be less efficient than the latter methods,
100         // depending on implementation.
101         virtual Biome *calcBiomeAtPoint(v3s16 pos) const = 0;
102
103         // Computes any intermediate results needed for biome generation.  Must be
104         // called before using any of: getBiomes, getBiomeAtPoint, or getBiomeAtIndex.
105         // Calling this invalidates the previous results stored in biomemap.
106         virtual void calcBiomeNoise(v3s16 pmin) = 0;
107
108         // Gets all biomes in current chunk using each corresponding element of
109         // heightmap as the y position, then stores the results by biome index in
110         // biomemap (also returned)
111         virtual biome_t *getBiomes(s16 *heightmap) = 0;
112
113         // Gets a single biome at the specified position, which must be contained
114         // in the region formed by m_pmin and (m_pmin + m_csize - 1).
115         virtual Biome *getBiomeAtPoint(v3s16 pos) const = 0;
116
117         // Same as above, but uses a raw numeric index correlating to the (x,z) position.
118         virtual Biome *getBiomeAtIndex(size_t index, s16 y) const = 0;
119
120         // Result of calcBiomes bulk computation.
121         biome_t *biomemap = nullptr;
122
123 protected:
124         BiomeManager *m_bmgr = nullptr;
125         v3s16 m_pmin;
126         v3s16 m_csize;
127 };
128
129
130 ////
131 //// BiomeGen implementations
132 ////
133
134 //
135 // Original biome algorithm (Whittaker's classification + surface height)
136 //
137
138 struct BiomeParamsOriginal : public BiomeParams {
139         BiomeParamsOriginal() :
140                 np_heat(50, 50, v3f(1000.0, 1000.0, 1000.0), 5349, 3, 0.5, 2.0),
141                 np_humidity(50, 50, v3f(1000.0, 1000.0, 1000.0), 842, 3, 0.5, 2.0),
142                 np_heat_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 13, 2, 1.0, 2.0),
143                 np_humidity_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 90003, 2, 1.0, 2.0)
144         {
145         }
146
147         virtual void readParams(const Settings *settings);
148         virtual void writeParams(Settings *settings) const;
149
150         NoiseParams np_heat;
151         NoiseParams np_humidity;
152         NoiseParams np_heat_blend;
153         NoiseParams np_humidity_blend;
154 };
155
156 class BiomeGenOriginal : public BiomeGen {
157 public:
158         BiomeGenOriginal(BiomeManager *biomemgr,
159                 BiomeParamsOriginal *params, v3s16 chunksize);
160         virtual ~BiomeGenOriginal();
161
162         BiomeGenType getType() const { return BIOMEGEN_ORIGINAL; }
163
164         Biome *calcBiomeAtPoint(v3s16 pos) const;
165         void calcBiomeNoise(v3s16 pmin);
166
167         biome_t *getBiomes(s16 *heightmap);
168         Biome *getBiomeAtPoint(v3s16 pos) const;
169         Biome *getBiomeAtIndex(size_t index, s16 y) const;
170
171         Biome *calcBiomeFromNoise(float heat, float humidity, s16 y) const;
172
173         float *heatmap;
174         float *humidmap;
175
176 private:
177         BiomeParamsOriginal *m_params;
178
179         Noise *noise_heat;
180         Noise *noise_humidity;
181         Noise *noise_heat_blend;
182         Noise *noise_humidity_blend;
183 };
184
185
186 ////
187 //// BiomeManager
188 ////
189
190 class BiomeManager : public ObjDefManager {
191 public:
192         BiomeManager(Server *server);
193         virtual ~BiomeManager() = default;
194
195         const char *getObjectTitle() const
196         {
197                 return "biome";
198         }
199
200         static Biome *create(BiomeType type)
201         {
202                 return new Biome;
203         }
204
205         BiomeGen *createBiomeGen(BiomeGenType type, BiomeParams *params, v3s16 chunksize)
206         {
207                 switch (type) {
208                 case BIOMEGEN_ORIGINAL:
209                         return new BiomeGenOriginal(this,
210                                 (BiomeParamsOriginal *)params, chunksize);
211                 default:
212                         return NULL;
213                 }
214         }
215
216         static BiomeParams *createBiomeParams(BiomeGenType type)
217         {
218                 switch (type) {
219                 case BIOMEGEN_ORIGINAL:
220                         return new BiomeParamsOriginal;
221                 default:
222                         return NULL;
223                 }
224         }
225
226         virtual void clear();
227
228 private:
229         Server *m_server;
230
231 };