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 {
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;
95 virtual ~BiomeGen() = default;
97 virtual BiomeGenType getType() const = 0;
99 // Calculates the biome at the exact position provided. This function can
100 // be called at any time, but may be less efficient than the latter methods,
101 // depending on implementation.
102 virtual Biome *calcBiomeAtPoint(v3s16 pos) const = 0;
104 // Computes any intermediate results needed for biome generation. Must be
105 // called before using any of: getBiomes, getBiomeAtPoint, or getBiomeAtIndex.
106 // Calling this invalidates the previous results stored in biomemap.
107 virtual void calcBiomeNoise(v3s16 pmin) = 0;
109 // Gets all biomes in current chunk using each corresponding element of
110 // heightmap as the y position, then stores the results by biome index in
111 // biomemap (also returned)
112 virtual biome_t *getBiomes(s16 *heightmap, v3s16 pmin) = 0;
114 // Gets a single biome at the specified position, which must be contained
115 // in the region formed by m_pmin and (m_pmin + m_csize - 1).
116 virtual Biome *getBiomeAtPoint(v3s16 pos) const = 0;
118 // Same as above, but uses a raw numeric index correlating to the (x,z) position.
119 virtual Biome *getBiomeAtIndex(size_t index, v3s16 pos) const = 0;
121 // Result of calcBiomes bulk computation.
122 biome_t *biomemap = nullptr;
125 BiomeManager *m_bmgr = nullptr;
132 //// BiomeGen implementations
136 // Original biome algorithm (Whittaker's classification + surface height)
139 struct BiomeParamsOriginal : public BiomeParams {
140 BiomeParamsOriginal() :
141 np_heat(50, 50, v3f(1000.0, 1000.0, 1000.0), 5349, 3, 0.5, 2.0),
142 np_humidity(50, 50, v3f(1000.0, 1000.0, 1000.0), 842, 3, 0.5, 2.0),
143 np_heat_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 13, 2, 1.0, 2.0),
144 np_humidity_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 90003, 2, 1.0, 2.0)
148 virtual void readParams(const Settings *settings);
149 virtual void writeParams(Settings *settings) const;
152 NoiseParams np_humidity;
153 NoiseParams np_heat_blend;
154 NoiseParams np_humidity_blend;
157 class BiomeGenOriginal : public BiomeGen {
159 BiomeGenOriginal(BiomeManager *biomemgr,
160 BiomeParamsOriginal *params, v3s16 chunksize);
161 virtual ~BiomeGenOriginal();
163 BiomeGenType getType() const { return BIOMEGEN_ORIGINAL; }
165 Biome *calcBiomeAtPoint(v3s16 pos) const;
166 void calcBiomeNoise(v3s16 pmin);
168 biome_t *getBiomes(s16 *heightmap, v3s16 pmin);
169 Biome *getBiomeAtPoint(v3s16 pos) const;
170 Biome *getBiomeAtIndex(size_t index, v3s16 pos) const;
172 Biome *calcBiomeFromNoise(float heat, float humidity, v3s16 pos) const;
178 BiomeParamsOriginal *m_params;
181 Noise *noise_humidity;
182 Noise *noise_heat_blend;
183 Noise *noise_humidity_blend;
191 class BiomeManager : public ObjDefManager {
193 BiomeManager(Server *server);
194 virtual ~BiomeManager() = default;
196 BiomeManager *clone() const;
198 const char *getObjectTitle() const
203 static Biome *create(BiomeType type)
208 BiomeGen *createBiomeGen(BiomeGenType type, BiomeParams *params, v3s16 chunksize)
211 case BIOMEGEN_ORIGINAL:
212 return new BiomeGenOriginal(this,
213 (BiomeParamsOriginal *)params, chunksize);
219 static BiomeParams *createBiomeParams(BiomeGenType type)
222 case BIOMEGEN_ORIGINAL:
223 return new BiomeParamsOriginal;
229 virtual void clear();
231 // For BiomeGen type 'BiomeGenOriginal'
232 float getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat,
233 NoiseParams &np_heat_blend, u64 seed) const;
234 float getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity,
235 NoiseParams &np_humidity_blend, u64 seed) const;
236 Biome *getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos) const;