Skip to content

Commit 549cfd9

Browse files
paramatnerzhul
authored andcommittedJan 4, 2018
Biomes: Add vertical biome blend (#6853)
Add 'vertical blend' parameter to biome registration that defines how many nodes above the biome's 'y max' limit the blend will extend.
1 parent ff2ceed commit 549cfd9

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed
 

Diff for: ‎doc/lua_api.txt

+9-9
Original file line numberDiff line numberDiff line change
@@ -4989,18 +4989,18 @@ Definition tables
49894989
y_min = 1,
49904990
y_max = 31000,
49914991
-- ^ Lower and upper limits for biome.
4992+
vertical_blend = 8,
4993+
-- ^ Vertical distance in nodes above 'y_max' over which the biome will
4994+
-- ^ blend with the biome above.
4995+
-- ^ Set to 0 for no vertical blend. Defaults to 0.
49924996
heat_point = 0,
49934997
humidity_point = 50,
4994-
-- ^ Characteristic average temperature and humidity for the biome.
4995-
-- ^ These values create 'biome points' on a voronoi diagram that has heat
4996-
-- ^ and humidity as axes. The resulting voronoi cells determine which
4997-
-- ^ heat/humidity points belong to which biome, and therefore determine
4998-
-- ^ the area and location of each biome in the world.
4999-
-- ^ The biome points need to be carefully and evenly spaced on the voronoi
5000-
-- ^ diagram to result in roughly equal size biomes.
4998+
-- ^ Characteristic temperature and humidity for the biome.
4999+
-- ^ These values create 'biome points' on a voronoi diagram with heat and
5000+
-- ^ humidity as axes. The resulting voronoi cells determine the
5001+
-- ^ distribution of the biomes.
50015002
-- ^ Heat and humidity have average values of 50, vary mostly between
5002-
-- ^ 0 and 100 but also often exceed these values.
5003-
-- ^ Heat is not in degrees Celsius, both values are abstract.
5003+
-- ^ 0 and 100 but can exceed these values.
50045004
}
50055005

50065006
### Decoration definition (`register_decoration`)

Diff for: ‎src/mapgen/mg_biome.cpp

+27-10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ BiomeManager::BiomeManager(Server *server) :
5050
b->y_max = MAX_MAP_GENERATION_LIMIT;
5151
b->heat_point = 0.0;
5252
b->humidity_point = 0.0;
53+
b->vertical_blend = 0;
5354

5455
b->m_nodenames.emplace_back("mapgen_stone");
5556
b->m_nodenames.emplace_back("mapgen_stone");
@@ -201,25 +202,41 @@ Biome *BiomeGenOriginal::getBiomeAtIndex(size_t index, s16 y) const
201202

202203
Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, s16 y) const
203204
{
204-
Biome *b, *biome_closest = NULL;
205+
Biome *biome_closest = nullptr;
206+
Biome *biome_closest_blend = nullptr;
205207
float dist_min = FLT_MAX;
208+
float dist_min_blend = FLT_MAX;
206209

207210
for (size_t i = 1; i < m_bmgr->getNumObjects(); i++) {
208-
b = (Biome *)m_bmgr->getRaw(i);
209-
if (!b || y > b->y_max || y < b->y_min)
211+
Biome *b = (Biome *)m_bmgr->getRaw(i);
212+
if (!b || y > b->y_max + b->vertical_blend || y < b->y_min)
210213
continue;
211214

212-
float d_heat = heat - b->heat_point;
215+
float d_heat = heat - b->heat_point;
213216
float d_humidity = humidity - b->humidity_point;
214-
float dist = (d_heat * d_heat) +
215-
(d_humidity * d_humidity);
216-
if (dist < dist_min) {
217-
dist_min = dist;
218-
biome_closest = b;
217+
float dist = (d_heat * d_heat) + (d_humidity * d_humidity);
218+
219+
if (y <= b->y_max) { // Within y limits of biome b
220+
if (dist < dist_min) {
221+
dist_min = dist;
222+
biome_closest = b;
223+
}
224+
} else if (dist < dist_min_blend) { // Blend area above biome b
225+
dist_min_blend = dist;
226+
biome_closest_blend = b;
219227
}
220228
}
221229

222-
return biome_closest ? biome_closest : (Biome *)m_bmgr->getRaw(BIOME_NONE);
230+
// Carefully tune pseudorandom seed variation to avoid single node dither
231+
// and create larger scale blending patterns.
232+
mysrand(y + (heat - humidity) * 2);
233+
234+
if (biome_closest_blend &&
235+
myrand_range(0, biome_closest_blend->vertical_blend) >=
236+
y - biome_closest_blend->y_max)
237+
return biome_closest_blend;
238+
239+
return (biome_closest) ? biome_closest : (Biome *)m_bmgr->getRaw(BIOME_NONE);
223240
}
224241

225242

Diff for: ‎src/mapgen/mg_biome.h

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Biome : public ObjDef, public NodeResolver {
6767
s16 y_max;
6868
float heat_point;
6969
float humidity_point;
70+
s16 vertical_blend;
7071

7172
virtual void resolveNodeNames();
7273
};

Diff for: ‎src/script/lua_api/l_mapgen.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ Biome *read_biome_def(lua_State *L, int index, INodeDefManager *ndef)
392392
b->y_max = getintfield_default(L, index, "y_max", 31000);
393393
b->heat_point = getfloatfield_default(L, index, "heat_point", 0.f);
394394
b->humidity_point = getfloatfield_default(L, index, "humidity_point", 0.f);
395+
b->vertical_blend = getintfield_default(L, index, "vertical_blend", 0);
395396
b->flags = 0; //reserved
396397

397398
std::vector<std::string> &nn = b->m_nodenames;

0 commit comments

Comments
 (0)
Please sign in to comment.