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