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
36 #define BIOME_NONE ((biome_t)0)
38 // TODO(hmmmm): Decide whether this is obsolete or will be used in the future
47 class Biome : public ObjDef, public NodeResolver {
54 content_t c_water_top;
56 content_t c_river_water;
70 virtual void resolveNodeNames();
83 virtual void readParams(const Settings *settings) = 0;
84 virtual void writeParams(Settings *settings) const = 0;
85 virtual ~BiomeParams() {}
92 virtual ~BiomeGen() {}
93 virtual BiomeGenType getType() const = 0;
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;
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;
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;
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;
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;
117 // Result of calcBiomes bulk computation.
121 BiomeManager *m_bmgr;
128 //// BiomeGen implementations
132 // Original biome algorithm (Whittaker's classification + surface height)
135 struct BiomeParamsOriginal : public BiomeParams {
136 BiomeParamsOriginal() :
137 np_heat(50, 50, v3f(1000.0, 1000.0, 1000.0), 5349, 3, 0.5, 2.0),
138 np_humidity(50, 50, v3f(1000.0, 1000.0, 1000.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)
144 virtual void readParams(const Settings *settings);
145 virtual void writeParams(Settings *settings) const;
148 NoiseParams np_humidity;
149 NoiseParams np_heat_blend;
150 NoiseParams np_humidity_blend;
153 class BiomeGenOriginal : public BiomeGen {
155 BiomeGenOriginal(BiomeManager *biomemgr,
156 BiomeParamsOriginal *params, v3s16 chunksize);
157 virtual ~BiomeGenOriginal();
159 BiomeGenType getType() const { return BIOMEGEN_ORIGINAL; }
161 Biome *calcBiomeAtPoint(v3s16 pos) const;
162 void calcBiomeNoise(v3s16 pmin);
164 biome_t *getBiomes(s16 *heightmap);
165 Biome *getBiomeAtPoint(v3s16 pos) const;
166 Biome *getBiomeAtIndex(size_t index, s16 y) const;
168 Biome *calcBiomeFromNoise(float heat, float humidity, s16 y) const;
174 BiomeParamsOriginal *m_params;
177 Noise *noise_humidity;
178 Noise *noise_heat_blend;
179 Noise *noise_humidity_blend;
187 class BiomeManager : public ObjDefManager {
189 BiomeManager(IGameDef *gamedef);
190 virtual ~BiomeManager();
192 const char *getObjectTitle() const
197 static Biome *create(BiomeType type)
202 BiomeGen *createBiomeGen(BiomeGenType type, BiomeParams *params, v3s16 chunksize)
205 case BIOMEGEN_ORIGINAL:
206 return new BiomeGenOriginal(this,
207 (BiomeParamsOriginal *)params, chunksize);
213 static BiomeParams *createBiomeParams(BiomeGenType type)
216 case BIOMEGEN_ORIGINAL:
217 return new BiomeParamsOriginal;
223 virtual void clear();