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
22#define BIOME_NONE ((biome_t)0)
23
27
61
62
66
70
72 virtual void readParams(const Settings *settings) = 0;
73 virtual void writeParams(Settings *settings) const = 0;
74 virtual ~BiomeParams() = default;
75
76 s32 seed;
77};
78
79// WARNING: this class is not thread-safe
80class BiomeGen {
81public:
82 virtual ~BiomeGen() = default;
83
84 virtual BiomeGenType getType() const = 0;
85
86 // Clone this BiomeGen and set a the new BiomeManager to be used by the copy
87 virtual BiomeGen *clone(BiomeManager *biomemgr) const = 0;
88
89 // Check that the internal chunk size is what the mapgen expects, just to be sure.
90 inline void assertChunkSize(v3s16 expect) const
91 {
92 FATAL_ERROR_IF(m_csize != expect, "Chunk size mismatches");
93 }
94
95 // Calculates the biome at the exact position provided. This function can
96 // be called at any time, but may be less efficient than the latter methods,
97 // depending on implementation.
98 virtual Biome *calcBiomeAtPoint(v3s16 pos) const = 0;
99
100 // Computes any intermediate results needed for biome generation. Must be
101 // called before using any of: getBiomes, getBiomeAtPoint, or getBiomeAtIndex.
102 // Calling this invalidates the previous results stored in biomemap.
103 virtual void calcBiomeNoise(v3s16 pmin) = 0;
104
105 // Gets all biomes in current chunk using each corresponding element of
106 // heightmap as the y position, then stores the results by biome index in
107 // biomemap (also returned)
108 virtual biome_t *getBiomes(s16 *heightmap, v3s16 pmin) = 0;
109
110 // Gets a single biome at the specified position, which must be contained
111 // in the region formed by m_pmin and (m_pmin + m_csize - 1).
112 virtual Biome *getBiomeAtPoint(v3s16 pos) const = 0;
113
114 // Same as above, but uses a raw numeric index correlating to the (x,z) position.
115 virtual Biome *getBiomeAtIndex(size_t index, v3s16 pos) const = 0;
116
117 // Returns the next lower y position at which the biome could change.
118 // You can use this to optimize calls to getBiomeAtIndex().
119 virtual s16 getNextTransitionY(s16 y) const {
120 return y == S16_MIN ? y : (y - 1);
121 };
122
123 // Result of calcBiomes bulk computation.
124 biome_t *biomemap = nullptr;
125
126protected:
130};
131
132
136
137//
138// Original biome algorithm (Whittaker's classification + surface height)
139//
140
143 np_heat(50, 50, v3f(1000.0, 1000.0, 1000.0), 5349, 3, 0.5, 2.0),
144 np_humidity(50, 50, v3f(1000.0, 1000.0, 1000.0), 842, 3, 0.5, 2.0),
145 np_heat_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 13, 2, 1.0, 2.0),
146 np_humidity_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 90003, 2, 1.0, 2.0)
147 {
148 }
149
150 virtual void readParams(const Settings *settings);
151 virtual void writeParams(Settings *settings) const;
152
157};
158
159class BiomeGenOriginal final : public BiomeGen {
160public:
162 const BiomeParamsOriginal *params, v3s16 chunksize);
163 virtual ~BiomeGenOriginal();
164
166
167 BiomeGen *clone(BiomeManager *biomemgr) const;
168
169 // Slower, meant for Script API use
170 float calcHeatAtPoint(v3s16 pos) const;
171 float calcHumidityAtPoint(v3s16 pos) const;
172 Biome *calcBiomeAtPoint(v3s16 pos) const;
173
174 void calcBiomeNoise(v3s16 pmin);
175
176 biome_t *getBiomes(s16 *heightmap, v3s16 pmin);
177 Biome *getBiomeAtPoint(v3s16 pos) const;
178 Biome *getBiomeAtIndex(size_t index, v3s16 pos) const;
179
180 Biome *calcBiomeFromNoise(float heat, float humidity, v3s16 pos) const;
181 s16 getNextTransitionY(s16 y) const;
182
183 float *heatmap;
184 float *humidmap;
185
186private:
188
193
194 // ordered descending
195 std::vector<s16> m_transitions_y;
196};
197
198
202
204public:
206 virtual ~BiomeManager() = default;
207
208 BiomeManager *clone() const;
209
210 const char *getObjectTitle() const
211 {
212 return "biome";
213 }
214
215 static Biome *create(BiomeType type)
216 {
217 return new Biome;
218 }
219
221 {
222 switch (type) {
224 return new BiomeGenOriginal(this,
225 (BiomeParamsOriginal *)params, chunksize);
226 default:
227 return NULL;
228 }
229 }
230
232 {
233 switch (type) {
235 return new BiomeParamsOriginal;
236 default:
237 return NULL;
238 }
239 }
240
241 virtual void clear();
242
243private:
245
247
248};
u16 biome_t
Definition cavegen.h:10
Definition mg_biome.h:159
Biome * calcBiomeAtPoint(v3s16 pos) const
Definition mg_biome.cpp:187
Noise * noise_heat_blend
Definition mg_biome.h:191
virtual ~BiomeGenOriginal()
Definition mg_biome.cpp:153
BiomeGenOriginal(BiomeManager *biomemgr, const BiomeParamsOriginal *params, v3s16 chunksize)
Definition mg_biome.cpp:113
float * humidmap
Definition mg_biome.h:184
s16 getNextTransitionY(s16 y) const
Definition mg_biome.cpp:163
Noise * noise_humidity
Definition mg_biome.h:190
BiomeGen * clone(BiomeManager *biomemgr) const
Definition mg_biome.cpp:170
Biome * getBiomeAtIndex(size_t index, v3s16 pos) const
Definition mg_biome.cpp:234
float calcHeatAtPoint(v3s16 pos) const
Definition mg_biome.cpp:175
Biome * calcBiomeFromNoise(float heat, float humidity, v3s16 pos) const
Definition mg_biome.cpp:243
Noise * noise_humidity_blend
Definition mg_biome.h:192
float * heatmap
Definition mg_biome.h:183
const BiomeParamsOriginal * m_params
Definition mg_biome.h:187
biome_t * getBiomes(s16 *heightmap, v3s16 pmin)
Definition mg_biome.cpp:209
float calcHumidityAtPoint(v3s16 pos) const
Definition mg_biome.cpp:181
std::vector< s16 > m_transitions_y
Definition mg_biome.h:195
BiomeGenType getType() const
Definition mg_biome.h:165
Noise * noise_heat
Definition mg_biome.h:189
Biome * getBiomeAtPoint(v3s16 pos) const
Definition mg_biome.cpp:226
void calcBiomeNoise(v3s16 pmin)
Definition mg_biome.cpp:193
Definition mg_biome.h:80
biome_t * biomemap
Definition mg_biome.h:124
v3s16 m_csize
Definition mg_biome.h:129
virtual BiomeGen * clone(BiomeManager *biomemgr) const =0
virtual Biome * calcBiomeAtPoint(v3s16 pos) const =0
void assertChunkSize(v3s16 expect) const
Definition mg_biome.h:90
virtual biome_t * getBiomes(s16 *heightmap, v3s16 pmin)=0
virtual BiomeGenType getType() const =0
virtual s16 getNextTransitionY(s16 y) const
Definition mg_biome.h:119
virtual ~BiomeGen()=default
BiomeManager * m_bmgr
Definition mg_biome.h:127
virtual void calcBiomeNoise(v3s16 pmin)=0
v3s16 m_pmin
Definition mg_biome.h:128
virtual Biome * getBiomeAtIndex(size_t index, v3s16 pos) const =0
virtual Biome * getBiomeAtPoint(v3s16 pos) const =0
Definition mg_biome.h:203
virtual ~BiomeManager()=default
BiomeManager * clone() const
Definition mg_biome.cpp:82
BiomeManager()
Definition mg_biome.h:244
Server * m_server
Definition mg_biome.h:246
static BiomeParams * createBiomeParams(BiomeGenType type)
Definition mg_biome.h:231
BiomeGen * createBiomeGen(BiomeGenType type, BiomeParams *params, v3s16 chunksize)
Definition mg_biome.h:220
static Biome * create(BiomeType type)
Definition mg_biome.h:215
virtual void clear()
Definition mg_biome.cpp:63
const char * getObjectTitle() const
Definition mg_biome.h:210
Definition mg_biome.h:28
float weight
Definition mg_biome.h:57
content_t c_dungeon
Definition mg_biome.h:43
float heat_point
Definition mg_biome.h:54
ObjDef * clone() const
Definition mg_biome.cpp:296
s16 depth_filler
Definition mg_biome.h:48
u32 flags
Definition mg_biome.h:32
s16 depth_top
Definition mg_biome.h:47
content_t c_top
Definition mg_biome.h:34
std::vector< content_t > c_cave_liquid
Definition mg_biome.h:42
virtual void resolveNodeNames()
Definition mg_biome.cpp:332
content_t c_filler
Definition mg_biome.h:35
content_t c_water_top
Definition mg_biome.h:37
s16 depth_riverbed
Definition mg_biome.h:50
v3s16 min_pos
Definition mg_biome.h:52
content_t c_dungeon_stair
Definition mg_biome.h:45
content_t c_stone
Definition mg_biome.h:36
s16 depth_water_top
Definition mg_biome.h:49
content_t c_riverbed
Definition mg_biome.h:40
content_t c_water
Definition mg_biome.h:38
v3s16 max_pos
Definition mg_biome.h:53
content_t c_dust
Definition mg_biome.h:41
s16 vertical_blend
Definition mg_biome.h:56
float humidity_point
Definition mg_biome.h:55
content_t c_river_water
Definition mg_biome.h:39
content_t c_dungeon_alt
Definition mg_biome.h:44
Definition nodedef.h:837
Definition noise.h:146
Definition objdef.h:56
Definition objdef.h:30
Definition server.h:166
Definition settings.h:109
#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
u16 content_t
Definition mapnode.h:22
BiomeGenType
Definition mg_biome.h:67
@ BIOMEGEN_ORIGINAL
Definition mg_biome.h:68
BiomeType
Definition mg_biome.h:24
@ BIOMETYPE_NORMAL
Definition mg_biome.h:25
u16 biome_t
Definition mg_biome.h:20
Definition activeobjectmgr.cpp:11
Definition mg_biome.h:141
NoiseParams np_heat
Definition mg_biome.h:153
NoiseParams np_humidity
Definition mg_biome.h:154
NoiseParams np_humidity_blend
Definition mg_biome.h:156
virtual void readParams(const Settings *settings)
Definition mg_biome.cpp:93
BiomeParamsOriginal()
Definition mg_biome.h:142
NoiseParams np_heat_blend
Definition mg_biome.h:155
virtual void writeParams(Settings *settings) const
Definition mg_biome.cpp:102
Definition mg_biome.h:71
virtual void readParams(const Settings *settings)=0
s32 seed
Definition mg_biome.h:76
virtual ~BiomeParams()=default
virtual void writeParams(Settings *settings) const =0
Definition noise.h:119