Skip to content

Commit

Permalink
Biomes: Make biome heat and humidity noise parameters user-configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
kwolekr committed Dec 9, 2014
1 parent 7490368 commit 29b413b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/emerge.cpp
Expand Up @@ -363,6 +363,8 @@ void EmergeManager::loadParamsFromSettings(Settings *settings) {
settings->getS16NoEx("water_level", params.water_level);
settings->getS16NoEx("chunksize", params.chunksize);
settings->getFlagStrNoEx("mg_flags", params.flags, flagdesc_mapgen);
settings->getNoiseParams("mg_biome_np_heat", params.np_biome_heat);
settings->getNoiseParams("mg_biome_np_humidity", params.np_biome_humidity);

delete params.sparams;
params.sparams = createMapgenParams(params.mg_name);
Expand All @@ -377,6 +379,8 @@ void EmergeManager::saveParamsToSettings(Settings *settings) {
settings->setS16("water_level", params.water_level);
settings->setS16("chunksize", params.chunksize);
settings->setFlagStr("mg_flags", params.flags, flagdesc_mapgen, (u32)-1);
settings->setNoiseParams("mg_biome_np_heat", params.np_biome_heat);
settings->setNoiseParams("mg_biome_np_humidity", params.np_biome_humidity);

if (params.sparams)
params.sparams->writeParams(settings);
Expand Down
6 changes: 6 additions & 0 deletions src/mapgen.h
Expand Up @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef MAPGEN_HEADER
#define MAPGEN_HEADER

#include "noise.h"
#include "nodedef.h"
#include "mapnode.h"
#include "util/string.h"
Expand Down Expand Up @@ -107,6 +108,9 @@ struct MapgenParams {
s16 water_level;
u32 flags;

NoiseParams np_biome_heat;
NoiseParams np_biome_humidity;

MapgenSpecificParams *sparams;

MapgenParams()
Expand All @@ -117,6 +121,8 @@ struct MapgenParams {
chunksize = 5;
flags = MG_TREES | MG_CAVES | MG_LIGHT;
sparams = NULL;
np_biome_heat = NoiseParams(50, 50, v3f(500.0, 500.0, 500.0), 5349, 3, 0.70, 2.0);
np_biome_humidity = NoiseParams(50, 50, v3f(500.0, 500.0, 500.0), 842, 3, 0.55, 2.0);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/mapgen_v5.cpp
Expand Up @@ -77,8 +77,8 @@ MapgenV5::MapgenV5(int mapgenid, MapgenParams *params, EmergeManager *emerge)
noise_wetness = new Noise(&sp->np_wetness, seed, csize.X, csize.Y + 2, csize.Z);

// Biome noise
noise_heat = new Noise(bmgr->np_heat, seed, csize.X, csize.Z);
noise_humidity = new Noise(bmgr->np_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);

//// Resolve nodes to be used
INodeDefManager *ndef = emerge->ndef;
Expand Down
8 changes: 4 additions & 4 deletions src/mapgen_v7.cpp
Expand Up @@ -81,8 +81,8 @@ MapgenV7::MapgenV7(int mapgenid, MapgenParams *params, EmergeManager *emerge)
noise_ridge = new Noise(&sp->np_ridge, seed, csize.X, csize.Y, csize.Z);

//// Biome noise
noise_heat = new Noise(bmgr->np_heat, seed, csize.X, csize.Z);
noise_humidity = new Noise(bmgr->np_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);

//// Resolve nodes to be used
INodeDefManager *ndef = emerge->ndef;
Expand Down Expand Up @@ -305,8 +305,8 @@ void MapgenV7::calculateNoise() {


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

return bmgr->getBiome(heat, humidity, groundlevel);
Expand Down
5 changes: 0 additions & 5 deletions src/mg_biome.cpp
Expand Up @@ -29,17 +29,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,

const char *BiomeManager::ELEMENT_TITLE = "biome";

NoiseParams nparams_biome_def_heat(50, 50, v3f(500.0, 500.0, 500.0), 5349, 3, 0.70, 2.0);
NoiseParams nparams_biome_def_humidity(50, 50, v3f(500.0, 500.0, 500.0), 842, 3, 0.55, 2.0);


///////////////////////////////////////////////////////////////////////////////

BiomeManager::BiomeManager(IGameDef *gamedef)
{
m_resolver = gamedef->getNodeDefManager()->getResolver();
np_heat = &nparams_biome_def_heat;
np_humidity = &nparams_biome_def_humidity;

// Create default biome to be used in case none exist
Biome *b = new Biome;
Expand Down
10 changes: 2 additions & 8 deletions src/mg_biome.h
Expand Up @@ -21,7 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MG_BIOME_HEADER

#include "mapgen.h"
#include "noise.h"

struct NoiseParams;

enum BiomeType
{
Expand All @@ -32,10 +33,6 @@ enum BiomeType
BIOME_TYPE_FLAT
};

extern NoiseParams nparams_biome_def_heat;
extern NoiseParams nparams_biome_def_humidity;


class Biome : public GenElement {
public:
u32 flags;
Expand All @@ -61,9 +58,6 @@ class BiomeManager : public GenElementManager {
static const char *ELEMENT_TITLE;
static const size_t ELEMENT_LIMIT = 0x100;

NoiseParams *np_heat;
NoiseParams *np_humidity;

BiomeManager(IGameDef *gamedef);
~BiomeManager();

Expand Down

0 comments on commit 29b413b

Please sign in to comment.