Skip to content

Commit

Permalink
Biome API: Add noise defined biome blend
Browse files Browse the repository at this point in the history
  • Loading branch information
paramat committed Jun 18, 2015
1 parent 2da1503 commit e45ecad
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
4 changes: 3 additions & 1 deletion minetest.conf.example
Expand Up @@ -532,9 +532,11 @@
# Mgv5 uses eased noise for np_ground so this is shown in group format,
# other noise parameters are shown in positional format to save space.

# Noise parameters for biome API temperature and humidity
# Noise parameters for biome API temperature, humidity and biome blend
#mg_biome_np_heat = 50, 50, (750, 750, 750), 5349, 3, 0.5, 2.0
#mg_biome_np_heat_blend = 0, 1.5, (8, 8, 8), 13, 2, 1.0, 2.0
#mg_biome_np_humidity = 50, 50, (750, 750, 750), 842, 3, 0.5, 2.0
#mg_biome_np_humidity_blend = 0, 1.5, (8, 8, 8), 90003, 2, 1.0, 2.0

#mgv5_np_filler_depth = 0, 1, (150, 150, 150), 261, 4, 0.7, 2.0
#mgv5_np_factor = 0, 1, (250, 250, 250), 920381, 3, 0.45, 2.0
Expand Down
4 changes: 4 additions & 0 deletions src/mapgen.cpp
Expand Up @@ -445,7 +445,9 @@ void MapgenParams::load(const Settings &settings)
settings.getS16NoEx("chunksize", chunksize);
settings.getFlagStrNoEx("mg_flags", flags, flagdesc_mapgen);
settings.getNoiseParams("mg_biome_np_heat", np_biome_heat);
settings.getNoiseParams("mg_biome_np_heat_blend", np_biome_heat_blend);
settings.getNoiseParams("mg_biome_np_humidity", np_biome_humidity);
settings.getNoiseParams("mg_biome_np_humidity_blend", np_biome_humidity_blend);

delete sparams;
sparams = EmergeManager::createMapgenParams(mg_name);
Expand All @@ -462,7 +464,9 @@ void MapgenParams::save(Settings &settings) const
settings.setS16("chunksize", chunksize);
settings.setFlagStr("mg_flags", flags, flagdesc_mapgen, (u32)-1);
settings.setNoiseParams("mg_biome_np_heat", np_biome_heat);
settings.setNoiseParams("mg_biome_np_heat_blend", np_biome_heat_blend);
settings.setNoiseParams("mg_biome_np_humidity", np_biome_humidity);
settings.setNoiseParams("mg_biome_np_humidity_blend", np_biome_humidity_blend);

if (sparams)
sparams->writeParams(&settings);
Expand Down
4 changes: 4 additions & 0 deletions src/mapgen.h
Expand Up @@ -115,7 +115,9 @@ struct MapgenParams {
u32 flags;

NoiseParams np_biome_heat;
NoiseParams np_biome_heat_blend;
NoiseParams np_biome_humidity;
NoiseParams np_biome_humidity_blend;

MapgenSpecificParams *sparams;

Expand All @@ -126,7 +128,9 @@ struct MapgenParams {
water_level(1),
flags(MG_TREES | MG_CAVES | MG_LIGHT),
np_biome_heat(NoiseParams(50, 50, v3f(750.0, 750.0, 750.0), 5349, 3, 0.5, 2.0)),
np_biome_heat_blend(NoiseParams(0, 1.5, v3f(8.0, 8.0, 8.0), 13, 2, 1.0, 2.0)),
np_biome_humidity(NoiseParams(50, 50, v3f(750.0, 750.0, 750.0), 842, 3, 0.5, 2.0)),
np_biome_humidity_blend(NoiseParams(0, 1.5, v3f(8.0, 8.0, 8.0), 90003, 2, 1.0, 2.0)),
sparams(NULL)
{}

Expand Down
20 changes: 15 additions & 5 deletions src/mapgen_v5.cpp
Expand Up @@ -68,13 +68,15 @@ MapgenV5::MapgenV5(int mapgenid, MapgenParams *params, EmergeManager *emerge)
noise_height = new Noise(&sp->np_height, seed, csize.X, csize.Z);

// 3D terrain noise
noise_cave1 = new Noise(&sp->np_cave1, seed, csize.X, csize.Y + 2, csize.Z);
noise_cave2 = new Noise(&sp->np_cave2, seed, csize.X, csize.Y + 2, csize.Z);
noise_ground = new Noise(&sp->np_ground, seed, csize.X, csize.Y + 2, csize.Z);
noise_cave1 = new Noise(&sp->np_cave1, seed, csize.X, csize.Y + 2, csize.Z);
noise_cave2 = new Noise(&sp->np_cave2, seed, csize.X, csize.Y + 2, csize.Z);
noise_ground = new Noise(&sp->np_ground, seed, csize.X, csize.Y + 2, csize.Z);

// Biome noise
noise_heat = new Noise(&params->np_biome_heat, seed, csize.X, csize.Z);
noise_humidity = new Noise(&params->np_biome_humidity, seed, csize.X, csize.Z);
noise_heat = new Noise(&params->np_biome_heat, seed, csize.X, csize.Z);
noise_humidity = new Noise(&params->np_biome_humidity, seed, csize.X, csize.Z);
noise_heat_blend = new Noise(&params->np_biome_heat_blend, seed, csize.X, csize.Z);
noise_humidity_blend = new Noise(&params->np_biome_humidity_blend, seed, csize.X, csize.Z);

//// Resolve nodes to be used
INodeDefManager *ndef = emerge->ndef;
Expand Down Expand Up @@ -116,6 +118,8 @@ MapgenV5::~MapgenV5()

delete noise_heat;
delete noise_humidity;
delete noise_heat_blend;
delete noise_humidity_blend;

delete[] heightmap;
delete[] biomemap;
Expand Down Expand Up @@ -330,7 +334,13 @@ void MapgenV5::calculateNoise()
noise_filler_depth->perlinMap2D(x, z);
noise_heat->perlinMap2D(x, z);
noise_humidity->perlinMap2D(x, z);
noise_heat_blend->perlinMap2D(x, z);
noise_humidity_blend->perlinMap2D(x, z);

for (s32 i = 0; i < csize.X * csize.Z; i++) {
noise_heat->result[i] += noise_heat_blend->result[i];
noise_humidity->result[i] += noise_humidity_blend->result[i];
}
//printf("calculateNoise: %dus\n", t.stop());
}

Expand Down
3 changes: 3 additions & 0 deletions src/mapgen_v5.h
Expand Up @@ -69,8 +69,11 @@ class MapgenV5 : public Mapgen {
Noise *noise_cave1;
Noise *noise_cave2;
Noise *noise_ground;

Noise *noise_heat;
Noise *noise_humidity;
Noise *noise_heat_blend;
Noise *noise_humidity_blend;

content_t c_stone;
content_t c_water_source;
Expand Down
29 changes: 21 additions & 8 deletions src/mapgen_v7.cpp
Expand Up @@ -82,8 +82,10 @@ MapgenV7::MapgenV7(int mapgenid, MapgenParams *params, EmergeManager *emerge)
noise_cave2 = new Noise(&sp->np_cave2, seed, csize.X, csize.Y + 2, csize.Z);

//// Biome noise
noise_heat = new Noise(&params->np_biome_heat, seed, csize.X, csize.Z);
noise_humidity = new Noise(&params->np_biome_humidity, seed, csize.X, csize.Z);
noise_heat = new Noise(&params->np_biome_heat, seed, csize.X, csize.Z);
noise_humidity = new Noise(&params->np_biome_humidity, seed, csize.X, csize.Z);
noise_heat_blend = new Noise(&params->np_biome_heat_blend, seed, csize.X, csize.Z);
noise_humidity_blend = new Noise(&params->np_biome_humidity_blend, seed, csize.X, csize.Z);

//// Resolve nodes to be used
INodeDefManager *ndef = emerge->ndef;
Expand Down Expand Up @@ -130,6 +132,8 @@ MapgenV7::~MapgenV7()

delete noise_heat;
delete noise_humidity;
delete noise_heat_blend;
delete noise_humidity_blend;

delete[] ridge_heightmap;
delete[] heightmap;
Expand Down Expand Up @@ -227,11 +231,11 @@ void MapgenV7::makeChunk(BlockMakeData *data)
assert(data->vmanip);
assert(data->nodedef);
assert(data->blockpos_requested.X >= data->blockpos_min.X &&
data->blockpos_requested.Y >= data->blockpos_min.Y &&
data->blockpos_requested.Z >= data->blockpos_min.Z);
data->blockpos_requested.Y >= data->blockpos_min.Y &&
data->blockpos_requested.Z >= data->blockpos_min.Z);
assert(data->blockpos_requested.X <= data->blockpos_max.X &&
data->blockpos_requested.Y <= data->blockpos_max.Y &&
data->blockpos_requested.Z <= data->blockpos_max.Z);
data->blockpos_requested.Y <= data->blockpos_max.Y &&
data->blockpos_requested.Z <= data->blockpos_max.Z);

this->generating = true;
this->vm = data->vmanip;
Expand Down Expand Up @@ -365,14 +369,23 @@ void MapgenV7::calculateNoise()
noise_filler_depth->perlinMap2D(x, z);
noise_heat->perlinMap2D(x, z);
noise_humidity->perlinMap2D(x, z);
noise_heat_blend->perlinMap2D(x, z);
noise_humidity_blend->perlinMap2D(x, z);

for (s32 i = 0; i < csize.X * csize.Z; i++) {
noise_heat->result[i] += noise_heat_blend->result[i];
noise_humidity->result[i] += noise_humidity_blend->result[i];
}
//printf("calculateNoise: %dus\n", t.stop());
}


Biome *MapgenV7::getBiomeAtPoint(v3s16 p)
{
float heat = NoisePerlin2D(&noise_heat->np, p.X, p.Z, seed);
float humidity = NoisePerlin2D(&noise_humidity->np, p.X, p.Z, seed);
float heat = NoisePerlin2D(&noise_heat->np, p.X, p.Z, seed) +
NoisePerlin2D(&noise_heat_blend->np, p.X, p.Z, seed);
float humidity = NoisePerlin2D(&noise_humidity->np, p.X, p.Z, seed) +
NoisePerlin2D(&noise_humidity_blend->np, p.X, p.Z, seed);
s16 groundlevel = baseTerrainLevelAtPoint(p.X, p.Z);

return bmgr->getBiome(heat, humidity, groundlevel);
Expand Down
2 changes: 2 additions & 0 deletions src/mapgen_v7.h
Expand Up @@ -82,6 +82,8 @@ class MapgenV7 : public Mapgen {

Noise *noise_heat;
Noise *noise_humidity;
Noise *noise_heat_blend;
Noise *noise_humidity_blend;

content_t c_stone;
content_t c_water_source;
Expand Down

0 comments on commit e45ecad

Please sign in to comment.