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
37 #define BIOME_NONE ((biome_t)0)
39 // TODO(hmmmm): Decide whether this is obsolete or will be used in the future
48 class Biome : public ObjDef, public NodeResolver {
55 content_t c_water_top;
57 content_t c_river_water;
71 virtual void resolveNodeNames();
84 virtual void readParams(const Settings *settings) = 0;
85 virtual void writeParams(Settings *settings) const = 0;
86 virtual ~BiomeParams() {}
93 virtual ~BiomeGen() {}
94 virtual BiomeGenType getType() const = 0;
96 // Calculates the biome at the exact position provided. This function can
97 // be called at any time, but may be less efficient than the latter methods,
98 // depending on implementation.
99 virtual Biome *calcBiomeAtPoint(v3s16 pos) const = 0;
101 // Computes any intermediate results needed for biome generation. Must be
102 // called before using any of: getBiomes, getBiomeAtPoint, or getBiomeAtIndex.
103 // Calling this invalidates the previous results stored in biomemap.
104 virtual void calcBiomeNoise(v3s16 pmin) = 0;
106 // Gets all biomes in current chunk using each corresponding element of
107 // heightmap as the y position, then stores the results by biome index in
108 // biomemap (also returned)
109 virtual biome_t *getBiomes(s16 *heightmap) = 0;
111 // Gets a single biome at the specified position, which must be contained
112 // in the region formed by m_pmin and (m_pmin + m_csize - 1).
113 virtual Biome *getBiomeAtPoint(v3s16 pos) const = 0;
115 // Same as above, but uses a raw numeric index correlating to the (x,z) position.
116 virtual Biome *getBiomeAtIndex(size_t index, s16 y) const = 0;
118 // Result of calcBiomes bulk computation.
122 BiomeManager *m_bmgr;
129 //// BiomeGen implementations
133 // Original biome algorithm (Whittaker's classification + surface height)
136 struct BiomeParamsOriginal : public BiomeParams {
137 BiomeParamsOriginal() :
138 np_heat(50, 50, v3f(1000.0, 1000.0, 1000.0), 5349, 3, 0.5, 2.0),
139 np_humidity(50, 50, v3f(1000.0, 1000.0, 1000.0), 842, 3, 0.5, 2.0),
140 np_heat_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 13, 2, 1.0, 2.0),
141 np_humidity_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 90003, 2, 1.0, 2.0)
145 virtual void readParams(const Settings *settings);
146 virtual void writeParams(Settings *settings) const;
149 NoiseParams np_humidity;
150 NoiseParams np_heat_blend;
151 NoiseParams np_humidity_blend;
154 class BiomeGenOriginal : public BiomeGen {
156 BiomeGenOriginal(BiomeManager *biomemgr,
157 BiomeParamsOriginal *params, v3s16 chunksize);
158 virtual ~BiomeGenOriginal();
160 BiomeGenType getType() const { return BIOMEGEN_ORIGINAL; }
162 Biome *calcBiomeAtPoint(v3s16 pos) const;
163 void calcBiomeNoise(v3s16 pmin);
165 biome_t *getBiomes(s16 *heightmap);
166 Biome *getBiomeAtPoint(v3s16 pos) const;
167 Biome *getBiomeAtIndex(size_t index, s16 y) const;
169 Biome *calcBiomeFromNoise(float heat, float humidity, s16 y) const;
175 BiomeParamsOriginal *m_params;
178 Noise *noise_humidity;
179 Noise *noise_heat_blend;
180 Noise *noise_humidity_blend;
188 class BiomeManager : public ObjDefManager {
190 BiomeManager(Server *server);
191 virtual ~BiomeManager();
193 const char *getObjectTitle() const
198 static Biome *create(BiomeType type)
203 BiomeGen *createBiomeGen(BiomeGenType type, BiomeParams *params, v3s16 chunksize)
206 case BIOMEGEN_ORIGINAL:
207 return new BiomeGenOriginal(this,
208 (BiomeParamsOriginal *)params, chunksize);
214 static BiomeParams *createBiomeParams(BiomeGenType type)
217 case BIOMEGEN_ORIGINAL:
218 return new BiomeParamsOriginal;
224 virtual void clear();