Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
mg_biome.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2014-2020 paramat
4Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation; either version 2.1 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License along
17with this program; if not, write to the Free Software Foundation, Inc.,
1851 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20
21#pragma once
22
23#include "objdef.h"
24#include "nodedef.h"
25#include "noise.h"
26
27class Server;
28class Settings;
29class BiomeManager;
30
34
35typedef u16 biome_t;
36
37#define BIOME_NONE ((biome_t)0)
38
41};
42
43class Biome : public ObjDef, public NodeResolver {
44public:
45 ObjDef *clone() const;
46
47 u32 flags;
48
57 std::vector<content_t> c_cave_liquid;
61
66
72
73 virtual void resolveNodeNames();
74};
75
76
80
83};
84
86 virtual void readParams(const Settings *settings) = 0;
87 virtual void writeParams(Settings *settings) const = 0;
88 virtual ~BiomeParams() = default;
89
90 s32 seed;
91};
92
93// WARNING: this class is not thread-safe
94class BiomeGen {
95public:
96 virtual ~BiomeGen() = default;
97
98 virtual BiomeGenType getType() const = 0;
99
100 // Clone this BiomeGen and set a the new BiomeManager to be used by the copy
101 virtual BiomeGen *clone(BiomeManager *biomemgr) const = 0;
102
103 // Check that the internal chunk size is what the mapgen expects, just to be sure.
104 inline void assertChunkSize(v3s16 expect) const
105 {
106 FATAL_ERROR_IF(m_csize != expect, "Chunk size mismatches");
107 }
108
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;
113
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;
118
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;
123
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;
127
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;
130
131 virtual s16 *getBiomeTransitions() const = 0;
132
133 // Result of calcBiomes bulk computation.
134 biome_t *biomemap = nullptr;
135 s16 *biome_transitions = nullptr;
136
137protected:
141};
142
143
147
148//
149// Original biome algorithm (Whittaker's classification + surface height)
150//
151
154 np_heat(50, 50, v3f(1000.0, 1000.0, 1000.0), 5349, 3, 0.5, 2.0),
155 np_humidity(50, 50, v3f(1000.0, 1000.0, 1000.0), 842, 3, 0.5, 2.0),
156 np_heat_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 13, 2, 1.0, 2.0),
157 np_humidity_blend(0, 1.5, v3f(8.0, 8.0, 8.0), 90003, 2, 1.0, 2.0)
158 {
159 }
160
161 virtual void readParams(const Settings *settings);
162 virtual void writeParams(Settings *settings) const;
163
168};
169
171public:
173 const BiomeParamsOriginal *params, v3s16 chunksize);
174 virtual ~BiomeGenOriginal();
175
177
178 BiomeGen *clone(BiomeManager *biomemgr) const;
179
180 // Slower, meant for Script API use
181 float calcHeatAtPoint(v3s16 pos) const;
182 float calcHumidityAtPoint(v3s16 pos) const;
183 Biome *calcBiomeAtPoint(v3s16 pos) const;
184
185 void calcBiomeNoise(v3s16 pmin);
186
187 biome_t *getBiomes(s16 *heightmap, v3s16 pmin);
188 Biome *getBiomeAtPoint(v3s16 pos) const;
189 Biome *getBiomeAtIndex(size_t index, v3s16 pos) const;
190
191 Biome *calcBiomeFromNoise(float heat, float humidity, v3s16 pos) const;
192 s16 *getBiomeTransitions() const;
193
194 float *heatmap;
195 float *humidmap;
196
197private:
199
204};
205
206
210
212public:
214 virtual ~BiomeManager() = default;
215
216 BiomeManager *clone() const;
217
218 const char *getObjectTitle() const
219 {
220 return "biome";
221 }
222
223 static Biome *create(BiomeType type)
224 {
225 return new Biome;
226 }
227
229 {
230 switch (type) {
232 return new BiomeGenOriginal(this,
233 (BiomeParamsOriginal *)params, chunksize);
234 default:
235 return NULL;
236 }
237 }
238
240 {
241 switch (type) {
243 return new BiomeParamsOriginal;
244 default:
245 return NULL;
246 }
247 }
248
249 virtual void clear();
250
251private:
253
255
256};
u16 biome_t
Definition: cavegen.h:25
Definition: mg_biome.h:170
Biome * calcBiomeAtPoint(v3s16 pos) const
Definition: mg_biome.cpp:211
Noise * noise_heat_blend
Definition: mg_biome.h:202
virtual ~BiomeGenOriginal()
Definition: mg_biome.cpp:178
float * humidmap
Definition: mg_biome.h:195
Noise * noise_humidity
Definition: mg_biome.h:201
BiomeGen * clone(BiomeManager *biomemgr) const
Definition: mg_biome.cpp:194
Biome * getBiomeAtIndex(size_t index, v3s16 pos) const
Definition: mg_biome.cpp:258
float calcHeatAtPoint(v3s16 pos) const
Definition: mg_biome.cpp:199
Biome * calcBiomeFromNoise(float heat, float humidity, v3s16 pos) const
Definition: mg_biome.cpp:267
Noise * noise_humidity_blend
Definition: mg_biome.h:203
float * heatmap
Definition: mg_biome.h:194
const BiomeParamsOriginal * m_params
Definition: mg_biome.h:198
biome_t * getBiomes(s16 *heightmap, v3s16 pmin)
Definition: mg_biome.cpp:233
float calcHumidityAtPoint(v3s16 pos) const
Definition: mg_biome.cpp:205
BiomeGenType getType() const
Definition: mg_biome.h:176
Noise * noise_heat
Definition: mg_biome.h:200
Biome * getBiomeAtPoint(v3s16 pos) const
Definition: mg_biome.cpp:250
void calcBiomeNoise(v3s16 pmin)
Definition: mg_biome.cpp:217
s16 * getBiomeTransitions() const
Definition: mg_biome.cpp:189
Definition: mg_biome.h:94
biome_t * biomemap
Definition: mg_biome.h:134
v3s16 m_csize
Definition: mg_biome.h:140
virtual BiomeGen * clone(BiomeManager *biomemgr) const =0
virtual Biome * calcBiomeAtPoint(v3s16 pos) const =0
virtual s16 * getBiomeTransitions() const =0
void assertChunkSize(v3s16 expect) const
Definition: mg_biome.h:104
virtual biome_t * getBiomes(s16 *heightmap, v3s16 pmin)=0
virtual BiomeGenType getType() const =0
s16 * biome_transitions
Definition: mg_biome.h:135
virtual ~BiomeGen()=default
BiomeManager * m_bmgr
Definition: mg_biome.h:138
virtual void calcBiomeNoise(v3s16 pmin)=0
v3s16 m_pmin
Definition: mg_biome.h:139
virtual Biome * getBiomeAtIndex(size_t index, v3s16 pos) const =0
virtual Biome * getBiomeAtPoint(v3s16 pos) const =0
Definition: mg_biome.h:211
virtual ~BiomeManager()=default
BiomeManager * clone() const
Definition: mg_biome.cpp:95
BiomeManager()
Definition: mg_biome.h:252
Server * m_server
Definition: mg_biome.h:254
static BiomeParams * createBiomeParams(BiomeGenType type)
Definition: mg_biome.h:239
BiomeGen * createBiomeGen(BiomeGenType type, BiomeParams *params, v3s16 chunksize)
Definition: mg_biome.h:228
static Biome * create(BiomeType type)
Definition: mg_biome.h:223
virtual void clear()
Definition: mg_biome.cpp:76
const char * getObjectTitle() const
Definition: mg_biome.h:218
Definition: mg_biome.h:43
content_t c_dungeon
Definition: mg_biome.h:58
float heat_point
Definition: mg_biome.h:69
ObjDef * clone() const
Definition: mg_biome.cpp:318
s16 depth_filler
Definition: mg_biome.h:63
u32 flags
Definition: mg_biome.h:47
s16 depth_top
Definition: mg_biome.h:62
content_t c_top
Definition: mg_biome.h:49
std::vector< content_t > c_cave_liquid
Definition: mg_biome.h:57
virtual void resolveNodeNames()
Definition: mg_biome.cpp:353
content_t c_filler
Definition: mg_biome.h:50
content_t c_water_top
Definition: mg_biome.h:52
s16 depth_riverbed
Definition: mg_biome.h:65
v3s16 min_pos
Definition: mg_biome.h:67
content_t c_dungeon_stair
Definition: mg_biome.h:60
content_t c_stone
Definition: mg_biome.h:51
s16 depth_water_top
Definition: mg_biome.h:64
content_t c_riverbed
Definition: mg_biome.h:55
content_t c_water
Definition: mg_biome.h:53
v3s16 max_pos
Definition: mg_biome.h:68
content_t c_dust
Definition: mg_biome.h:56
s16 vertical_blend
Definition: mg_biome.h:71
float humidity_point
Definition: mg_biome.h:70
content_t c_river_water
Definition: mg_biome.h:54
content_t c_dungeon_alt
Definition: mg_biome.h:59
Definition: nodedef.h:853
Definition: noise.h:146
Definition: objdef.h:70
Definition: objdef.h:44
Definition: server.h:146
Definition: settings.h:124
#define FATAL_ERROR_IF(expr, msg)
Definition: debug.h:51
core::vector3d< s16 > v3s16
Definition: irr_v3d.h:28
core::vector3df v3f
Definition: irr_v3d.h:26
static LightingParams params
Definition: light.cpp:40
u16 content_t
Definition: mapnode.h:37
BiomeGenType
Definition: mg_biome.h:81
@ BIOMEGEN_ORIGINAL
Definition: mg_biome.h:82
BiomeType
Definition: mg_biome.h:39
@ BIOMETYPE_NORMAL
Definition: mg_biome.h:40
u16 biome_t
Definition: mg_biome.h:35
Definition: activeobjectmgr.cpp:26
Definition: mg_biome.h:152
NoiseParams np_heat
Definition: mg_biome.h:164
NoiseParams np_humidity
Definition: mg_biome.h:165
NoiseParams np_humidity_blend
Definition: mg_biome.h:167
virtual void readParams(const Settings *settings)
Definition: mg_biome.cpp:106
BiomeParamsOriginal()
Definition: mg_biome.h:153
NoiseParams np_heat_blend
Definition: mg_biome.h:166
virtual void writeParams(Settings *settings) const
Definition: mg_biome.cpp:115
Definition: mg_biome.h:85
virtual void readParams(const Settings *settings)=0
s32 seed
Definition: mg_biome.h:90
virtual ~BiomeParams()=default
virtual void writeParams(Settings *settings) const =0
Definition: noise.h:119