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