Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
mg_biome.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2014-2020 paramat
4// Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
5
6#pragma once
7
8#include "objdef.h"
9#include "nodedef.h"
10#include "noise.h"
11
12class Server;
13class Settings;
14class BiomeManager;
15
19
20typedef u16 biome_t;
21
26);
27
28#define BIOME_NONE ((biome_t)0)
29
33
67
68
72
76
78 virtual void readParams(const Settings *settings) = 0;
79 virtual void writeParams(Settings *settings) const = 0;
80 virtual ~BiomeParams() = default;
81
82 s32 seed;
83};
84
85// WARNING: this class is not thread-safe
86class BiomeGen {
87public:
88 virtual ~BiomeGen() = default;
89
90 virtual BiomeGenType getType() const = 0;
91
92 // Clone this BiomeGen and set a the new BiomeManager to be used by the copy
93 virtual BiomeGen *clone(BiomeManager *biomemgr) const = 0;
94
95 // Check that the internal chunk size is what the mapgen expects, just to be sure.
96 inline void assertChunkSize(v3s16 expect) const
97 {
98 FATAL_ERROR_IF(m_csize != expect, "Chunk size mismatches");
99 }
100
101 // Calculates the biome at the exact position provided. This function can
102 // be called at any time, but may be less efficient than the latter methods,
103 // depending on implementation.
104 virtual Biome *calcBiomeAtPoint(v3s16 pos) const = 0;
105
106 // Computes any intermediate results needed for biome generation. Must be
107 // called before using any of: getBiomes, getBiomeAtPoint, or getBiomeAtIndex.
108 // Calling this invalidates the previous results stored in biomemap.
109 virtual void calcBiomeNoise(v3s16 pmin) = 0;
110
111 // Gets all biomes in current chunk using each corresponding element of
112 // heightmap as the y position, then stores the results by biome index in
113 // biomemap (also returned)
114 virtual biome_t *getBiomes(s16 *heightmap, v3s16 pmin) = 0;
115
116 // Gets a single biome at the specified position, which must be contained
117 // in the region formed by m_pmin and (m_pmin + m_csize - 1).
118 virtual Biome *getBiomeAtPoint(v3s16 pos) const = 0;
119
120 // Same as above, but uses a raw numeric index correlating to the (x,z) position.
121 virtual Biome *getBiomeAtIndex(size_t index, v3s16 pos) const = 0;
122
123 // Returns the next lower y position at which the biome could change.
124 // You can use this to optimize calls to getBiomeAtIndex().
125 virtual s16 getNextTransitionY(s16 y) const {
126 return y == S16_MIN ? y : (y - 1);
127 };
128
129 // Result of calcBiomes bulk computation.
130 biome_t *biomemap = nullptr;
131
132protected:
136};
137
138
142
143//
144// Original biome algorithm (Whittaker's classification + surface height)
145//
146
149 np_heat(50, 50, v3f(1000.0, 1000.0, 1000.0), 5349, 3, 0.5, 2.0),
150 np_humidity(50, 50, v3f(1000.0, 1000.0, 1000.0), 842, 3, 0.5, 2.0),
151 np_heat_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 13, 2, 1.0, 2.0),
152 np_humidity_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 90003, 2, 1.0, 2.0)
153 {
154 }
155
156 virtual void readParams(const Settings *settings);
157 virtual void writeParams(Settings *settings) const;
158
163};
164
165class BiomeGenOriginal final : public BiomeGen {
166public:
168 const BiomeParamsOriginal *params, v3s16 chunksize);
169 virtual ~BiomeGenOriginal();
170
172
173 BiomeGen *clone(BiomeManager *biomemgr) const;
174
175 // Slower, meant for Script API use
176 float calcHeatAtPoint(v3s16 pos) const;
177 float calcHumidityAtPoint(v3s16 pos) const;
178 Biome *calcBiomeAtPoint(v3s16 pos) const;
179
180 void calcBiomeNoise(v3s16 pmin);
181
182 biome_t *getBiomes(s16 *heightmap, v3s16 pmin);
183 Biome *getBiomeAtPoint(v3s16 pos) const;
184 Biome *getBiomeAtIndex(size_t index, v3s16 pos) const;
185
186 Biome *calcBiomeFromNoise(float heat, float humidity, v3s16 pos) const;
187 s16 getNextTransitionY(s16 y) const;
188
189 float *heatmap;
190 float *humidmap;
191
192private:
194
199
202 std::vector<s16> m_transitions_y;
203};
204
205
209
211public:
213 virtual ~BiomeManager() = default;
214
215 BiomeManager *clone() const;
216
217 const char *getObjectTitle() const
218 {
219 return "biome";
220 }
221
222 static Biome *create(BiomeType type)
223 {
224 return new Biome;
225 }
226
228 {
229 switch (type) {
231 return new BiomeGenOriginal(this,
232 (BiomeParamsOriginal *)params, chunksize);
233 default:
234 return NULL;
235 }
236 }
237
239 {
240 switch (type) {
242 return new BiomeParamsOriginal;
243 default:
244 return NULL;
245 }
246 }
247
248 virtual void clear();
249
250private:
252
254
255};
u16 biome_t
Definition cavegen.h:10
Definition mg_biome.h:165
Biome * calcBiomeAtPoint(v3s16 pos) const
Definition mg_biome.cpp:178
Noise * noise_heat_blend
Definition mg_biome.h:197
virtual ~BiomeGenOriginal()
Definition mg_biome.cpp:144
BiomeGenOriginal(BiomeManager *biomemgr, const BiomeParamsOriginal *params, v3s16 chunksize)
Definition mg_biome.cpp:101
float * humidmap
Definition mg_biome.h:190
s16 getNextTransitionY(s16 y) const
Definition mg_biome.cpp:154
Noise * noise_humidity
Definition mg_biome.h:196
BiomeGen * clone(BiomeManager *biomemgr) const
Definition mg_biome.cpp:161
Biome * getBiomeAtIndex(size_t index, v3s16 pos) const
Definition mg_biome.cpp:225
float calcHeatAtPoint(v3s16 pos) const
Definition mg_biome.cpp:166
Biome * calcBiomeFromNoise(float heat, float humidity, v3s16 pos) const
Definition mg_biome.cpp:234
Noise * noise_humidity_blend
Definition mg_biome.h:198
float * heatmap
Definition mg_biome.h:189
const BiomeParamsOriginal * m_params
Definition mg_biome.h:193
biome_t * getBiomes(s16 *heightmap, v3s16 pmin)
Definition mg_biome.cpp:200
float calcHumidityAtPoint(v3s16 pos) const
Definition mg_biome.cpp:172
std::vector< s16 > m_transitions_y
Y values at which biomes may transition.
Definition mg_biome.h:202
BiomeGenType getType() const
Definition mg_biome.h:171
Noise * noise_heat
Definition mg_biome.h:195
Biome * getBiomeAtPoint(v3s16 pos) const
Definition mg_biome.cpp:217
void calcBiomeNoise(v3s16 pmin)
Definition mg_biome.cpp:184
Definition mg_biome.h:86
biome_t * biomemap
Definition mg_biome.h:130
v3s16 m_csize
Definition mg_biome.h:135
virtual BiomeGen * clone(BiomeManager *biomemgr) const =0
virtual Biome * calcBiomeAtPoint(v3s16 pos) const =0
void assertChunkSize(v3s16 expect) const
Definition mg_biome.h:96
virtual biome_t * getBiomes(s16 *heightmap, v3s16 pmin)=0
virtual BiomeGenType getType() const =0
virtual s16 getNextTransitionY(s16 y) const
Definition mg_biome.h:125
virtual ~BiomeGen()=default
BiomeManager * m_bmgr
Definition mg_biome.h:133
virtual void calcBiomeNoise(v3s16 pmin)=0
v3s16 m_pmin
Definition mg_biome.h:134
virtual Biome * getBiomeAtIndex(size_t index, v3s16 pos) const =0
virtual Biome * getBiomeAtPoint(v3s16 pos) const =0
Definition mg_biome.h:210
virtual ~BiomeManager()=default
BiomeManager * clone() const
Definition mg_biome.cpp:70
BiomeManager()
Definition mg_biome.h:251
Server * m_server
Definition mg_biome.h:253
static BiomeParams * createBiomeParams(BiomeGenType type)
Definition mg_biome.h:238
BiomeGen * createBiomeGen(BiomeGenType type, BiomeParams *params, v3s16 chunksize)
Definition mg_biome.h:227
static Biome * create(BiomeType type)
Definition mg_biome.h:222
virtual void clear()
Definition mg_biome.cpp:49
const char * getObjectTitle() const
Definition mg_biome.h:217
Definition mg_biome.h:34
float weight
Definition mg_biome.h:63
content_t c_dungeon
Definition mg_biome.h:49
float heat_point
Definition mg_biome.h:60
ObjDef * clone() const
Definition mg_biome.cpp:287
s16 depth_filler
Definition mg_biome.h:54
s16 depth_top
Definition mg_biome.h:53
content_t c_top
Definition mg_biome.h:39
std::vector< content_t > c_cave_liquid
Definition mg_biome.h:47
virtual void resolveNodeNames()
Definition mg_biome.cpp:321
content_t c_filler
Definition mg_biome.h:40
content_t c_water_top
Definition mg_biome.h:42
s16 depth_riverbed
Definition mg_biome.h:56
v3s16 min_pos
Definition mg_biome.h:58
content_t c_dungeon_stair
Definition mg_biome.h:51
content_t c_stone
Definition mg_biome.h:41
s16 depth_water_top
Definition mg_biome.h:55
content_t c_riverbed
Definition mg_biome.h:45
content_t c_water
Definition mg_biome.h:43
v3s16 max_pos
Definition mg_biome.h:59
content_t c_dust
Definition mg_biome.h:46
s16 vertical_blend
Definition mg_biome.h:62
float humidity_point
Definition mg_biome.h:61
content_t c_river_water
Definition mg_biome.h:44
content_t c_dungeon_alt
Definition mg_biome.h:50
Definition nodedef.h:842
Definition noise.h:146
Definition objdef.h:56
Definition objdef.h:30
Definition server.h:166
Definition settings.h:109
#define MAX_MAP_GENERATION_LIMIT
Definition constants.h:54
#define FATAL_ERROR_IF(expr, msg)
Definition debug.h:36
static const char * settings[]
Definition fontengine.cpp:27
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
core::vector3df v3f
Definition irr_v3d.h:11
#define S16_MIN
Definition irrlichttypes.h:18
#define CONTENT_IGNORE
Definition mapnode.h:58
u16 content_t
Definition mapnode.h:22
BiomeGenType
Definition mg_biome.h:73
@ BIOMEGEN_ORIGINAL
Definition mg_biome.h:74
BiomeType
Definition mg_biome.h:30
@ BIOMETYPE_NORMAL
Definition mg_biome.h:31
u16 biome_t
Definition mg_biome.h:20
constexpr v3s16 MAX_MAP_GENERATION_LIMIT_V3(MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT)
Definition activeobjectmgr.cpp:11
Definition mg_biome.h:147
NoiseParams np_heat
Definition mg_biome.h:159
NoiseParams np_humidity
Definition mg_biome.h:160
NoiseParams np_humidity_blend
Definition mg_biome.h:162
virtual void readParams(const Settings *settings)
Definition mg_biome.cpp:81
BiomeParamsOriginal()
Definition mg_biome.h:148
NoiseParams np_heat_blend
Definition mg_biome.h:161
virtual void writeParams(Settings *settings) const
Definition mg_biome.cpp:90
Definition mg_biome.h:77
virtual void readParams(const Settings *settings)=0
s32 seed
Definition mg_biome.h:82
virtual ~BiomeParams()=default
virtual void writeParams(Settings *settings) const =0
Definition noise.h:119
constexpr v3f y
Definition test_irr_matrix4.cpp:16