3 Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2014-2018 paramat
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.
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.
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.
37 #define BIOME_NONE ((biome_t)0)
43 class Biome : public ObjDef, public NodeResolver {
50 content_t c_water_top;
52 content_t c_river_water;
67 virtual void resolveNodeNames();
80 virtual void readParams(const Settings *settings) = 0;
81 virtual void writeParams(Settings *settings) const = 0;
82 virtual ~BiomeParams() = default;
89 virtual ~BiomeGen() = default;
91 virtual BiomeGenType getType() const = 0;
93 // Calculates the biome at the exact position provided. This function can
94 // be called at any time, but may be less efficient than the latter methods,
95 // depending on implementation.
96 virtual Biome *calcBiomeAtPoint(v3s16 pos) const = 0;
98 // Computes any intermediate results needed for biome generation. Must be
99 // called before using any of: getBiomes, getBiomeAtPoint, or getBiomeAtIndex.
100 // Calling this invalidates the previous results stored in biomemap.
101 virtual void calcBiomeNoise(v3s16 pmin) = 0;
103 // Gets all biomes in current chunk using each corresponding element of
104 // heightmap as the y position, then stores the results by biome index in
105 // biomemap (also returned)
106 virtual biome_t *getBiomes(s16 *heightmap, v3s16 pmin) = 0;
108 // Gets a single biome at the specified position, which must be contained
109 // in the region formed by m_pmin and (m_pmin + m_csize - 1).
110 virtual Biome *getBiomeAtPoint(v3s16 pos) const = 0;
112 // Same as above, but uses a raw numeric index correlating to the (x,z) position.
113 virtual Biome *getBiomeAtIndex(size_t index, v3s16 pos) const = 0;
115 // Result of calcBiomes bulk computation.
116 biome_t *biomemap = nullptr;
119 BiomeManager *m_bmgr = nullptr;
126 //// BiomeGen implementations
130 // Original biome algorithm (Whittaker's classification + surface height)
133 struct BiomeParamsOriginal : public BiomeParams {
134 BiomeParamsOriginal() :
135 np_heat(50, 50, v3f(1000.0, 1000.0, 1000.0), 5349, 3, 0.5, 2.0),
136 np_humidity(50, 50, v3f(1000.0, 1000.0, 1000.0), 842, 3, 0.5, 2.0),
137 np_heat_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 13, 2, 1.0, 2.0),
138 np_humidity_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 90003, 2, 1.0, 2.0)
142 virtual void readParams(const Settings *settings);
143 virtual void writeParams(Settings *settings) const;
146 NoiseParams np_humidity;
147 NoiseParams np_heat_blend;
148 NoiseParams np_humidity_blend;
151 class BiomeGenOriginal : public BiomeGen {
153 BiomeGenOriginal(BiomeManager *biomemgr,
154 BiomeParamsOriginal *params, v3s16 chunksize);
155 virtual ~BiomeGenOriginal();
157 BiomeGenType getType() const { return BIOMEGEN_ORIGINAL; }
159 Biome *calcBiomeAtPoint(v3s16 pos) const;
160 void calcBiomeNoise(v3s16 pmin);
162 biome_t *getBiomes(s16 *heightmap, v3s16 pmin);
163 Biome *getBiomeAtPoint(v3s16 pos) const;
164 Biome *getBiomeAtIndex(size_t index, v3s16 pos) const;
166 Biome *calcBiomeFromNoise(float heat, float humidity, v3s16 pos) const;
172 BiomeParamsOriginal *m_params;
175 Noise *noise_humidity;
176 Noise *noise_heat_blend;
177 Noise *noise_humidity_blend;
185 class BiomeManager : public ObjDefManager {
187 BiomeManager(Server *server);
188 virtual ~BiomeManager() = default;
190 const char *getObjectTitle() const
195 static Biome *create(BiomeType type)
200 BiomeGen *createBiomeGen(BiomeGenType type, BiomeParams *params, v3s16 chunksize)
203 case BIOMEGEN_ORIGINAL:
204 return new BiomeGenOriginal(this,
205 (BiomeParamsOriginal *)params, chunksize);
211 static BiomeParams *createBiomeParams(BiomeGenType type)
214 case BIOMEGEN_ORIGINAL:
215 return new BiomeParamsOriginal;
221 virtual void clear();
223 // For BiomeGen type 'BiomeGenOriginal'
224 float getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat,
225 NoiseParams &np_heat_blend, u64 seed);
226 float getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity,
227 NoiseParams &np_humidity_blend, u64 seed);
228 Biome *getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos);