3 Copyright (C) 2014-2020 paramat
4 Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
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 {
45 ObjDef *clone() const;
52 content_t c_water_top;
54 content_t c_river_water;
57 std::vector<content_t> c_cave_liquid;
59 content_t c_dungeon_alt;
60 content_t c_dungeon_stair;
73 virtual void resolveNodeNames();
86 virtual void readParams(const Settings *settings) = 0;
87 virtual void writeParams(Settings *settings) const = 0;
88 virtual ~BiomeParams() = default;
93 // WARNING: this class is not thread-safe
96 virtual ~BiomeGen() = default;
98 virtual BiomeGenType getType() const = 0;
100 // Clone this BiomeGen and set a the new BiomeManager to be used by the copy
101 virtual BiomeGen *clone(BiomeManager *biomemgr) const = 0;
103 // Check that the internal chunk size is what the mapgen expects, just to be sure.
104 inline void assertChunkSize(v3s16 expect) const
106 FATAL_ERROR_IF(m_csize != expect, "Chunk size mismatches");
109 // Calculates the biome at the exact position provided. This function can
110 // be called at any time, but may be less efficient than the latter methods,
111 // depending on implementation.
112 virtual Biome *calcBiomeAtPoint(v3s16 pos) const = 0;
114 // Computes any intermediate results needed for biome generation. Must be
115 // called before using any of: getBiomes, getBiomeAtPoint, or getBiomeAtIndex.
116 // Calling this invalidates the previous results stored in biomemap.
117 virtual void calcBiomeNoise(v3s16 pmin) = 0;
119 // Gets all biomes in current chunk using each corresponding element of
120 // heightmap as the y position, then stores the results by biome index in
121 // biomemap (also returned)
122 virtual biome_t *getBiomes(s16 *heightmap, v3s16 pmin) = 0;
124 // Gets a single biome at the specified position, which must be contained
125 // in the region formed by m_pmin and (m_pmin + m_csize - 1).
126 virtual Biome *getBiomeAtPoint(v3s16 pos) const = 0;
128 // Same as above, but uses a raw numeric index correlating to the (x,z) position.
129 virtual Biome *getBiomeAtIndex(size_t index, v3s16 pos) const = 0;
131 // Result of calcBiomes bulk computation.
132 biome_t *biomemap = nullptr;
135 BiomeManager *m_bmgr = nullptr;
142 //// BiomeGen implementations
146 // Original biome algorithm (Whittaker's classification + surface height)
149 struct BiomeParamsOriginal : public BiomeParams {
150 BiomeParamsOriginal() :
151 np_heat(50, 50, v3f(1000.0, 1000.0, 1000.0), 5349, 3, 0.5, 2.0),
152 np_humidity(50, 50, v3f(1000.0, 1000.0, 1000.0), 842, 3, 0.5, 2.0),
153 np_heat_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 13, 2, 1.0, 2.0),
154 np_humidity_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 90003, 2, 1.0, 2.0)
158 virtual void readParams(const Settings *settings);
159 virtual void writeParams(Settings *settings) const;
162 NoiseParams np_humidity;
163 NoiseParams np_heat_blend;
164 NoiseParams np_humidity_blend;
167 class BiomeGenOriginal : public BiomeGen {
169 BiomeGenOriginal(BiomeManager *biomemgr,
170 const BiomeParamsOriginal *params, v3s16 chunksize);
171 virtual ~BiomeGenOriginal();
173 BiomeGenType getType() const { return BIOMEGEN_ORIGINAL; }
175 BiomeGen *clone(BiomeManager *biomemgr) const;
177 // Slower, meant for Script API use
178 float calcHeatAtPoint(v3s16 pos) const;
179 float calcHumidityAtPoint(v3s16 pos) const;
180 Biome *calcBiomeAtPoint(v3s16 pos) const;
182 void calcBiomeNoise(v3s16 pmin);
184 biome_t *getBiomes(s16 *heightmap, v3s16 pmin);
185 Biome *getBiomeAtPoint(v3s16 pos) const;
186 Biome *getBiomeAtIndex(size_t index, v3s16 pos) const;
188 Biome *calcBiomeFromNoise(float heat, float humidity, v3s16 pos) const;
194 const BiomeParamsOriginal *m_params;
197 Noise *noise_humidity;
198 Noise *noise_heat_blend;
199 Noise *noise_humidity_blend;
207 class BiomeManager : public ObjDefManager {
209 BiomeManager(Server *server);
210 virtual ~BiomeManager() = default;
212 BiomeManager *clone() const;
214 const char *getObjectTitle() const
219 static Biome *create(BiomeType type)
224 BiomeGen *createBiomeGen(BiomeGenType type, BiomeParams *params, v3s16 chunksize)
227 case BIOMEGEN_ORIGINAL:
228 return new BiomeGenOriginal(this,
229 (BiomeParamsOriginal *)params, chunksize);
235 static BiomeParams *createBiomeParams(BiomeGenType type)
238 case BIOMEGEN_ORIGINAL:
239 return new BiomeParamsOriginal;
245 virtual void clear();