3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
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.
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.
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.
20 #ifndef MG_BIOME_HEADER
21 #define MG_BIOME_HEADER
34 #define BIOME_NONE ((u8)0)
45 class Biome : public ObjDef, public NodeResolver {
52 content_t c_water_top;
54 content_t c_river_water;
66 virtual void resolveNodeNames();
79 virtual void readParams(const Settings *settings) = 0;
80 virtual void writeParams(Settings *settings) const = 0;
81 virtual ~BiomeParams() {}
88 virtual ~BiomeGen() {}
89 virtual BiomeGenType getType() const = 0;
91 // Calculates the biome at the exact position provided. This function can
92 // be called at any time, but may be less efficient than the latter methods,
93 // depending on implementation.
94 virtual Biome *calcBiomeAtPoint(v3s16 pos) const = 0;
96 // Computes any intermediate results needed for biome generation. Must be
97 // called before using any of: getBiomes, getBiomeAtPoint, or getBiomeAtIndex.
98 // Calling this invalidates the previous results stored in biomemap.
99 virtual void calcBiomeNoise(v3s16 pmin) = 0;
101 // Gets all biomes in current chunk using each corresponding element of
102 // heightmap as the y position, then stores the results by biome index in
103 // biomemap (also returned)
104 virtual u8 *getBiomes(s16 *heightmap) = 0;
106 // Gets a single biome at the specified position, which must be contained
107 // in the region formed by m_pmin and (m_pmin + m_csize - 1).
108 virtual Biome *getBiomeAtPoint(v3s16 pos) const = 0;
110 // Same as above, but uses a raw numeric index correlating to the (x,z) position.
111 virtual Biome *getBiomeAtIndex(size_t index, s16 y) const = 0;
113 // Result of calcBiomes bulk computation.
117 BiomeManager *m_bmgr;
124 //// BiomeGen implementations
128 // Original biome algorithm (Whittaker's classification + surface height)
131 struct BiomeParamsOriginal : public BiomeParams {
132 BiomeParamsOriginal() :
133 np_heat(50, 50, v3f(750.0, 750.0, 750.0), 5349, 3, 0.5, 2.0),
134 np_humidity(50, 50, v3f(750.0, 750.0, 750.0), 842, 3, 0.5, 2.0),
135 np_heat_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 13, 2, 1.0, 2.0),
136 np_humidity_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 90003, 2, 1.0, 2.0)
140 virtual void readParams(const Settings *settings);
141 virtual void writeParams(Settings *settings) const;
144 NoiseParams np_humidity;
145 NoiseParams np_heat_blend;
146 NoiseParams np_humidity_blend;
149 class BiomeGenOriginal : public BiomeGen {
151 BiomeGenOriginal(BiomeManager *biomemgr,
152 BiomeParamsOriginal *params, v3s16 chunksize);
153 virtual ~BiomeGenOriginal();
155 BiomeGenType getType() const { return BIOMEGEN_ORIGINAL; }
157 Biome *calcBiomeAtPoint(v3s16 pos) const;
158 void calcBiomeNoise(v3s16 pmin);
160 u8 *getBiomes(s16 *heightmap);
161 Biome *getBiomeAtPoint(v3s16 pos) const;
162 Biome *getBiomeAtIndex(size_t index, s16 y) const;
164 Biome *calcBiomeFromNoise(float heat, float humidity, s16 y) const;
170 BiomeParamsOriginal *m_params;
173 Noise *noise_humidity;
174 Noise *noise_heat_blend;
175 Noise *noise_humidity_blend;
183 class BiomeManager : public ObjDefManager {
185 BiomeManager(IGameDef *gamedef);
186 virtual ~BiomeManager();
188 const char *getObjectTitle() const
193 static Biome *create(BiomeType type)
198 BiomeGen *createBiomeGen(BiomeGenType type, BiomeParams *params, v3s16 chunksize)
201 case BIOMEGEN_ORIGINAL:
202 return new BiomeGenOriginal(this,
203 (BiomeParamsOriginal *)params, chunksize);
209 static BiomeParams *createBiomeParams(BiomeGenType type)
212 case BIOMEGEN_ORIGINAL:
213 return new BiomeParamsOriginal;
219 virtual void clear();
221 // Looks for pos in the biome cache, and if non-existent, looks up by noise
222 u8 getBiomeAtPoint(v3s16 pos);