Make mapgen factory setup more elegant, add mapgen_v6.h

This commit is contained in:
kwolekr 2013-01-22 22:32:30 -05:00
parent 035933f806
commit 91e88196c7
7 changed files with 295 additions and 235 deletions

@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gamedef.h" #include "gamedef.h"
#include "util/directiontables.h" #include "util/directiontables.h"
#include "rollback_interface.h" #include "rollback_interface.h"
#include "mapgen_v6.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@ -1993,10 +1994,9 @@ void Map::removeNodeTimer(v3s16 p)
/* /*
ServerMap ServerMap
*/ */
ServerMap::ServerMap(std::string savedir, IGameDef *gamedef): ServerMap::ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge):
Map(dout_server, gamedef), Map(dout_server, gamedef),
m_seed(0), m_seed(0),
m_emerge(NULL),
m_map_metadata_changed(true), m_map_metadata_changed(true),
m_database(NULL), m_database(NULL),
m_database_read(NULL), m_database_read(NULL),
@ -2004,9 +2004,8 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
{ {
verbosestream<<__FUNCTION_NAME<<std::endl; verbosestream<<__FUNCTION_NAME<<std::endl;
//m_chunksize = 8; // Takes a few seconds m_emerge = emerge;
m_mgparams = m_emerge->getParamsFromSettings(g_settings);
m_mgparams = MapgenParams::getParamsFromSettings(g_settings);
if (!m_mgparams) if (!m_mgparams)
m_mgparams = new MapgenV6Params(); m_mgparams = new MapgenV6Params();
@ -3080,32 +3079,12 @@ void ServerMap::saveMapMeta()
Settings params; Settings params;
params.set("mg_name", m_emerge->params->mg_name); params.set("mg_name", m_emerge->params->mg_name);
params.setU64("seed", m_emerge->params->seed); params.setU64("seed", m_emerge->params->seed);
params.setS16("water_level", m_emerge->params->water_level); params.setS16("water_level", m_emerge->params->water_level);
params.setS16("chunksize", m_emerge->params->chunksize); params.setS16("chunksize", m_emerge->params->chunksize);
params.setS32("mg_flags", m_emerge->params->flags); params.setS32("mg_flags", m_emerge->params->flags);
/* switch (m_emerge->params->mg_version) {
case 6:
{*/
MapgenV6Params *v6params = (MapgenV6Params *)m_emerge->params;
params.setFloat("mgv6_freq_desert", v6params->freq_desert); m_emerge->params->writeParams(&params);
params.setFloat("mgv6_freq_beach", v6params->freq_beach);
params.setNoiseParams("mgv6_np_terrain_base", v6params->np_terrain_base);
params.setNoiseParams("mgv6_np_terrain_higher", v6params->np_terrain_higher);
params.setNoiseParams("mgv6_np_steepness", v6params->np_steepness);
params.setNoiseParams("mgv6_np_height_select", v6params->np_height_select);
params.setNoiseParams("mgv6_np_trees", v6params->np_trees);
params.setNoiseParams("mgv6_np_mud", v6params->np_mud);
params.setNoiseParams("mgv6_np_beach", v6params->np_beach);
params.setNoiseParams("mgv6_np_biome", v6params->np_biome);
params.setNoiseParams("mgv6_np_cave", v6params->np_cave);
/* break;
}
default:
; //complain here
}*/
params.writeLines(os); params.writeLines(os);
@ -3145,7 +3124,7 @@ void ServerMap::loadMapMeta()
params.parseConfigLine(line); params.parseConfigLine(line);
} }
MapgenParams *mgparams = MapgenParams::getParamsFromSettings(&params); MapgenParams *mgparams = m_emerge->getParamsFromSettings(&params);
if (mgparams) { if (mgparams) {
if (m_mgparams) if (m_mgparams)
delete m_mgparams; delete m_mgparams;

@ -358,7 +358,7 @@ public:
/* /*
savedir: directory to which map data should be saved savedir: directory to which map data should be saved
*/ */
ServerMap(std::string savedir, IGameDef *gamedef); ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge);
~ServerMap(); ~ServerMap();
s32 mapType() const s32 mapType() const
@ -480,16 +480,12 @@ public:
MapgenParams *getMapgenParams(){ return m_mgparams; } MapgenParams *getMapgenParams(){ return m_mgparams; }
void setEmerge(EmergeManager *emerge){ m_emerge = emerge; }
// Parameters fed to the Mapgen // Parameters fed to the Mapgen
MapgenParams *m_mgparams; MapgenParams *m_mgparams;
private: private:
// Seed used for all kinds of randomness in generation // Seed used for all kinds of randomness in generation
u64 m_seed; u64 m_seed;
// Emerge manager // Emerge manager
EmergeManager *m_emerge; EmergeManager *m_emerge;

@ -33,66 +33,53 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h" // For g_settings #include "settings.h" // For g_settings
#include "main.h" // For g_profiler #include "main.h" // For g_profiler
#include "treegen.h" #include "treegen.h"
#include "mapgen_v6.h"
/////////////////// Mapgen V6 perlin noise default values
NoiseParams nparams_v6_def_terrain_base =
{-AVERAGE_MUD_AMOUNT, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6};
NoiseParams nparams_v6_def_terrain_higher =
{20.0, 16.0, v3f(500.0, 500.0, 500.0), 85039, 5, 0.6};
NoiseParams nparams_v6_def_steepness =
{0.85, 0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7};
NoiseParams nparams_v6_def_height_select =
{0.5, 1.0, v3f(250.0, 250.0, 250.0), 4213, 5, 0.69};
NoiseParams nparams_v6_def_trees =
{0.0, 1.0, v3f(125.0, 125.0, 125.0), 2, 4, 0.66};
NoiseParams nparams_v6_def_mud =
{AVERAGE_MUD_AMOUNT, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55};
NoiseParams nparams_v6_def_beach =
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 59420, 3, 0.50};
NoiseParams nparams_v6_def_biome =
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 9130, 3, 0.50};
NoiseParams nparams_v6_def_cave =
{6.0, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50};
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////// Emerge Manager //////////////////////////////// /////////////////////////////// Emerge Manager ////////////////////////////////
EmergeManager::EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef) {
EmergeManager::EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef, //register built-in mapgens
MapgenParams *mgparams) { registerMapgen("v6", new MapgenFactoryV6());
//the order of these assignments is pretty important //the order of these assignments is pretty important
this->biomedef = bdef ? bdef : new BiomeDefManager(gamedef); this->biomedef = bdef ? bdef : new BiomeDefManager(gamedef);
this->params = mgparams; this->params = NULL;
this->mapgen = NULL; this->mapgen = NULL;
this->mapgen = getMapgen();
} }
EmergeManager::~EmergeManager() { EmergeManager::~EmergeManager() {
delete biomedef; delete biomedef;
delete mapgen;
delete params; delete params;
} }
void EmergeManager::initMapgens(MapgenParams *mgparams) {
if (mapgen)
return;
this->params = mgparams;
this->mapgen = getMapgen(); //only one mapgen for now!
}
Mapgen *EmergeManager::getMapgen() { Mapgen *EmergeManager::getMapgen() {
if (!mapgen) { if (!mapgen) {
/*switch (params->mg_version) { mapgen = createMapgen(params->mg_name, 0, params, this);
case 6:*/ if (!mapgen) {
mapgen = new MapgenV6(0, (MapgenV6Params *)params); infostream << "EmergeManager: falling back to mapgen v6" << std::endl;
/* break; delete params;
default: params = createMapgenParams("v6");
errorstream << "EmergeManager: Unsupported mapgen version " mapgen = createMapgen("v6", 0, params, this);
<< params->mg_version << ", falling back to V6" << std::endl; }
params->mg_version = 6;
mapgen = new MapgenV6(0, (MapgenV6Params *)params);
}*/
} }
return mapgen; return mapgen;
} }
void EmergeManager::addBlockToQueue() { void EmergeManager::addBlockToQueue() {
//STUB //STUB
} }
@ -127,60 +114,94 @@ u32 EmergeManager::getBlockSeed(v3s16 p) {
} }
MapgenParams *MapgenParams::createMapgenParams(std::string &mgstr) { Mapgen *EmergeManager::createMapgen(std::string mgname, int mgid,
return new MapgenV6Params(); // this will be fixed later MapgenParams *mgparams, EmergeManager *emerge) {
/*switch (mgver) { std::map<std::string, MapgenFactory *>::const_iterator iter = mglist.find(mgname);
case 6: if (iter == mglist.end()) {
return new MapgenV6Params(); errorstream << "EmergeManager; mapgen " << mgname <<
default: //instead of complaining, default to 6 " not registered" << std::endl;
return new MapgenV6Params(); return NULL;
}*/ }
MapgenFactory *mgfactory = iter->second;
return mgfactory->createMapgen(mgid, mgparams, emerge);
} }
MapgenParams *MapgenParams::getParamsFromSettings(Settings *settings) { MapgenParams *EmergeManager::createMapgenParams(std::string mgname) {
std::map<std::string, MapgenFactory *>::const_iterator iter = mglist.find(mgname);
if (iter == mglist.end()) {
errorstream << "EmergeManager: mapgen " << mgname <<
" not registered" << std::endl;
return NULL;
}
MapgenFactory *mgfactory = iter->second;
return mgfactory->createMapgenParams();
}
MapgenParams *EmergeManager::getParamsFromSettings(Settings *settings) {
std::string mg_name = settings->get("mg_name"); std::string mg_name = settings->get("mg_name");
MapgenParams *mgparams = MapgenParams::createMapgenParams(mg_name); MapgenParams *mgparams = createMapgenParams(mg_name);
mgparams->mg_name = mg_name; mgparams->mg_name = mg_name;
mgparams->seed = settings->getU64(settings == g_settings ? "fixed_map_seed" : "seed"); mgparams->seed = settings->getU64(settings == g_settings ? "fixed_map_seed" : "seed");
mgparams->water_level = settings->getS16("water_level"); mgparams->water_level = settings->getS16("water_level");
mgparams->chunksize = settings->getS16("chunksize"); mgparams->chunksize = settings->getS16("chunksize");
mgparams->flags = settings->getS32("mg_flags"); mgparams->flags = settings->getS32("mg_flags");
/* switch (mg_version) { if (!mgparams->readParams(settings)) {
case 6: delete mgparams;
{*/ return NULL;
MapgenV6Params *v6params = (MapgenV6Params *)mgparams; }
v6params->freq_desert = settings->getFloat("mgv6_freq_desert");
v6params->freq_beach = settings->getFloat("mgv6_freq_beach");
v6params->np_terrain_base = settings->getNoiseParams("mgv6_np_terrain_base");
v6params->np_terrain_higher = settings->getNoiseParams("mgv6_np_terrain_higher");
v6params->np_steepness = settings->getNoiseParams("mgv6_np_steepness");
v6params->np_height_select = settings->getNoiseParams("mgv6_np_height_select");
v6params->np_trees = settings->getNoiseParams("mgv6_np_trees");
v6params->np_mud = settings->getNoiseParams("mgv6_np_mud");
v6params->np_beach = settings->getNoiseParams("mgv6_np_beach");
v6params->np_biome = settings->getNoiseParams("mgv6_np_biome");
v6params->np_cave = settings->getNoiseParams("mgv6_np_cave");
if (!v6params->np_terrain_base || !v6params->np_terrain_higher ||
!v6params->np_steepness || !v6params->np_height_select ||
!v6params->np_trees || !v6params->np_mud ||
!v6params->np_beach || !v6params->np_biome || !v6params->np_cave) {
delete mgparams;
return NULL;
}
/*
break;
}
default:
delete mgparams;
return NULL;
}*/
return mgparams; return mgparams;
}
bool EmergeManager::registerMapgen(std::string mgname, MapgenFactory *mgfactory) {
mglist.insert(std::make_pair(mgname, mgfactory));
infostream << "EmergeManager: registered mapgen " << mgname << std::endl;
}
/////////////////////
bool MapgenV6Params::readParams(Settings *settings) {
freq_desert = settings->getFloat("mgv6_freq_desert");
freq_beach = settings->getFloat("mgv6_freq_beach");
np_terrain_base = settings->getNoiseParams("mgv6_np_terrain_base");
np_terrain_higher = settings->getNoiseParams("mgv6_np_terrain_higher");
np_steepness = settings->getNoiseParams("mgv6_np_steepness");
np_height_select = settings->getNoiseParams("mgv6_np_height_select");
np_trees = settings->getNoiseParams("mgv6_np_trees");
np_mud = settings->getNoiseParams("mgv6_np_mud");
np_beach = settings->getNoiseParams("mgv6_np_beach");
np_biome = settings->getNoiseParams("mgv6_np_biome");
np_cave = settings->getNoiseParams("mgv6_np_cave");
bool success =
np_terrain_base && np_terrain_higher && np_steepness &&
np_height_select && np_trees && np_mud &&
np_beach && np_biome && np_cave;
return success;
}
void MapgenV6Params::writeParams(Settings *settings) {
settings->setFloat("mgv6_freq_desert", freq_desert);
settings->setFloat("mgv6_freq_beach", freq_beach);
settings->setNoiseParams("mgv6_np_terrain_base", np_terrain_base);
settings->setNoiseParams("mgv6_np_terrain_higher", np_terrain_higher);
settings->setNoiseParams("mgv6_np_steepness", np_steepness);
settings->setNoiseParams("mgv6_np_height_select", np_height_select);
settings->setNoiseParams("mgv6_np_trees", np_trees);
settings->setNoiseParams("mgv6_np_mud", np_mud);
settings->setNoiseParams("mgv6_np_beach", np_beach);
settings->setNoiseParams("mgv6_np_biome", np_biome);
settings->setNoiseParams("mgv6_np_cave", np_cave);
} }

@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapnode.h" #include "mapnode.h"
#include "noise.h" #include "noise.h"
#include "settings.h" #include "settings.h"
#include <map>
/////////////////// Mapgen flags /////////////////// Mapgen flags
#define MG_TREES 0x01 #define MG_TREES 0x01
@ -34,39 +35,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MGV6_FORESTS 0x08 #define MGV6_FORESTS 0x08
#define MGV6_BIOME_BLEND 0x10 #define MGV6_BIOME_BLEND 0x10
#define AVERAGE_MUD_AMOUNT 4
class BiomeDefManager; class BiomeDefManager;
class Biome; class Biome;
class EmergeManager;
//struct BlockMakeData;
class MapBlock; class MapBlock;
class ManualMapVoxelManipulator; class ManualMapVoxelManipulator;
class VoxelManipulator; class VoxelManipulator;
class INodeDefManager; class INodeDefManager;
extern NoiseParams nparams_v6_def_terrain_base;
extern NoiseParams nparams_v6_def_terrain_higher;
extern NoiseParams nparams_v6_def_steepness;
extern NoiseParams nparams_v6_def_height_select;
extern NoiseParams nparams_v6_def_trees;
extern NoiseParams nparams_v6_def_mud;
extern NoiseParams nparams_v6_def_beach;
extern NoiseParams nparams_v6_def_biome;
extern NoiseParams nparams_v6_def_cave;
extern NoiseParams nparams_v7_def_terrain;
extern NoiseParams nparams_v7_def_bgroup;
extern NoiseParams nparams_v7_def_heat;
extern NoiseParams nparams_v7_def_humidity;
enum BiomeType
{
BT_NORMAL,
BT_DESERT
};
struct BlockMakeData { struct BlockMakeData {
bool no_op; bool no_op;
ManualMapVoxelManipulator *vmanip; ManualMapVoxelManipulator *vmanip;
@ -81,7 +57,6 @@ struct BlockMakeData {
~BlockMakeData(); ~BlockMakeData();
}; };
struct MapgenParams { struct MapgenParams {
std::string mg_name; std::string mg_name;
int chunksize; int chunksize;
@ -96,41 +71,11 @@ struct MapgenParams {
chunksize = 5; chunksize = 5;
flags = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND; flags = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
} }
static MapgenParams *createMapgenParams(std::string &mgname); virtual bool readParams(Settings *settings) = 0;
static MapgenParams *getParamsFromSettings(Settings *settings); virtual void writeParams(Settings *settings) {};
}; };
struct MapgenV6Params : public MapgenParams {
float freq_desert;
float freq_beach;
NoiseParams *np_terrain_base;
NoiseParams *np_terrain_higher;
NoiseParams *np_steepness;
NoiseParams *np_height_select;
NoiseParams *np_trees;
NoiseParams *np_mud;
NoiseParams *np_beach;
NoiseParams *np_biome;
NoiseParams *np_cave;
MapgenV6Params() {
freq_desert = 0.45;
freq_beach = 0.15;
np_terrain_base = &nparams_v6_def_terrain_base;
np_terrain_higher = &nparams_v6_def_terrain_higher;
np_steepness = &nparams_v6_def_steepness;
np_height_select = &nparams_v6_def_height_select;
np_trees = &nparams_v6_def_trees;
np_mud = &nparams_v6_def_mud;
np_beach = &nparams_v6_def_beach;
np_biome = &nparams_v6_def_biome;
np_cave = &nparams_v6_def_cave;
}
};
class Mapgen { class Mapgen {
public: public:
int seed; int seed;
@ -147,64 +92,16 @@ public:
static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision); static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
}; };
struct MapgenFactory {
class MapgenV6 : public Mapgen { virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
public: EmergeManager *emerge) = 0;
//ManualMapVoxelManipulator &vmanip; virtual MapgenParams *createMapgenParams() = 0;
int ystride;
v3s16 csize;
v3s16 node_min;
v3s16 node_max;
Noise *noise_terrain_base;
Noise *noise_terrain_higher;
Noise *noise_steepness;
Noise *noise_height_select;
Noise *noise_trees;
Noise *noise_mud;
Noise *noise_beach;
Noise *noise_biome;
float *map_terrain_base;
float *map_terrain_higher;
float *map_steepness;
float *map_height_select;
float *map_trees;
float *map_mud;
float *map_beach;
float *map_biome;
NoiseParams *np_cave;
u32 flags;
float freq_desert;
float freq_beach;
MapgenV6(int mapgenid, MapgenV6Params *params);
~MapgenV6();
void makeChunk(BlockMakeData *data);
int getGroundLevelAtPoint(v2s16 p);
double baseRockLevelFromNoise(v2s16 p);
static s16 find_ground_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
static s16 find_stone_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, bool is_apple_tree, INodeDefManager *ndef);
double tree_amount_2d(u64 seed, v2s16 p);
bool block_is_underground(u64 seed, v3s16 blockpos);
double base_rock_level_2d(u64 seed, v2s16 p);
s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
double get_mud_add_amount(u64 seed, v2s16 p);
bool get_have_beach(u64 seed, v2s16 p2d);
BiomeType get_biome(u64 seed, v2s16 p2d);
u32 get_blockseed(u64 seed, v3s16 p);
}; };
class EmergeManager { class EmergeManager {
public: public:
std::map<std::string, MapgenFactory *> mglist;
//settings //settings
MapgenParams *params; MapgenParams *params;
@ -214,12 +111,19 @@ public:
//biome manager //biome manager
BiomeDefManager *biomedef; BiomeDefManager *biomedef;
EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef, MapgenParams *mgparams); EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef);
~EmergeManager(); ~EmergeManager();
void initMapgens(MapgenParams *mgparams);
Mapgen *createMapgen(std::string mgname, int mgid,
MapgenParams *mgparams, EmergeManager *emerge);
MapgenParams *createMapgenParams(std::string mgname);
Mapgen *getMapgen(); Mapgen *getMapgen();
void addBlockToQueue(); void addBlockToQueue();
bool registerMapgen(std::string name, MapgenFactory *mgfactory);
MapgenParams *getParamsFromSettings(Settings *settings);
//mapgen helper methods //mapgen helper methods
Biome *getBiomeAtPoint(v3s16 p); Biome *getBiomeAtPoint(v3s16 p);
int getGroundLevelAtPoint(v2s16 p); int getGroundLevelAtPoint(v2s16 p);

@ -31,6 +31,27 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "profiler.h" #include "profiler.h"
#include "settings.h" // For g_settings #include "settings.h" // For g_settings
#include "main.h" // For g_profiler #include "main.h" // For g_profiler
#include "mapgen_v6.h"
/////////////////// Mapgen V6 perlin noise default values
NoiseParams nparams_v6_def_terrain_base =
{-AVERAGE_MUD_AMOUNT, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6};
NoiseParams nparams_v6_def_terrain_higher =
{20.0, 16.0, v3f(500.0, 500.0, 500.0), 85039, 5, 0.6};
NoiseParams nparams_v6_def_steepness =
{0.85, 0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7};
NoiseParams nparams_v6_def_height_select =
{0.5, 1.0, v3f(250.0, 250.0, 250.0), 4213, 5, 0.69};
NoiseParams nparams_v6_def_trees =
{0.0, 1.0, v3f(125.0, 125.0, 125.0), 2, 4, 0.66};
NoiseParams nparams_v6_def_mud =
{AVERAGE_MUD_AMOUNT, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55};
NoiseParams nparams_v6_def_beach =
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 59420, 3, 0.50};
NoiseParams nparams_v6_def_biome =
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 9130, 3, 0.50};
NoiseParams nparams_v6_def_cave =
{6.0, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50};
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -397,7 +418,6 @@ int MapgenV6::getGroundLevelAtPoint(v2s16 p) {
return baseRockLevelFromNoise(p) + AVERAGE_MUD_AMOUNT; return baseRockLevelFromNoise(p) + AVERAGE_MUD_AMOUNT;
} }
#define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1 #define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
void MapgenV6::makeChunk(BlockMakeData *data) void MapgenV6::makeChunk(BlockMakeData *data)

141
src/mapgen_v6.h Normal file

@ -0,0 +1,141 @@
/*
Minetest-c55
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MAPGENV6_HEADER
#define MAPGENV6_HEADER
#include "mapgen.h"
#define AVERAGE_MUD_AMOUNT 4
enum BiomeType
{
BT_NORMAL,
BT_DESERT
};
extern NoiseParams nparams_v6_def_terrain_base;
extern NoiseParams nparams_v6_def_terrain_higher;
extern NoiseParams nparams_v6_def_steepness;
extern NoiseParams nparams_v6_def_height_select;
extern NoiseParams nparams_v6_def_trees;
extern NoiseParams nparams_v6_def_mud;
extern NoiseParams nparams_v6_def_beach;
extern NoiseParams nparams_v6_def_biome;
extern NoiseParams nparams_v6_def_cave;
struct MapgenV6Params : public MapgenParams {
float freq_desert;
float freq_beach;
NoiseParams *np_terrain_base;
NoiseParams *np_terrain_higher;
NoiseParams *np_steepness;
NoiseParams *np_height_select;
NoiseParams *np_trees;
NoiseParams *np_mud;
NoiseParams *np_beach;
NoiseParams *np_biome;
NoiseParams *np_cave;
MapgenV6Params() {
freq_desert = 0.45;
freq_beach = 0.15;
np_terrain_base = &nparams_v6_def_terrain_base;
np_terrain_higher = &nparams_v6_def_terrain_higher;
np_steepness = &nparams_v6_def_steepness;
np_height_select = &nparams_v6_def_height_select;
np_trees = &nparams_v6_def_trees;
np_mud = &nparams_v6_def_mud;
np_beach = &nparams_v6_def_beach;
np_biome = &nparams_v6_def_biome;
np_cave = &nparams_v6_def_cave;
}
bool readParams(Settings *settings);
void writeParams(Settings *settings);
};
class MapgenV6 : public Mapgen {
public:
//ManualMapVoxelManipulator &vmanip;
int ystride;
v3s16 csize;
v3s16 node_min;
v3s16 node_max;
Noise *noise_terrain_base;
Noise *noise_terrain_higher;
Noise *noise_steepness;
Noise *noise_height_select;
Noise *noise_trees;
Noise *noise_mud;
Noise *noise_beach;
Noise *noise_biome;
float *map_terrain_base;
float *map_terrain_higher;
float *map_steepness;
float *map_height_select;
float *map_trees;
float *map_mud;
float *map_beach;
float *map_biome;
NoiseParams *np_cave;
u32 flags;
float freq_desert;
float freq_beach;
MapgenV6(int mapgenid, MapgenV6Params *params);
~MapgenV6();
void makeChunk(BlockMakeData *data);
int getGroundLevelAtPoint(v2s16 p);
double baseRockLevelFromNoise(v2s16 p);
static s16 find_ground_level(VoxelManipulator &vmanip,
v2s16 p2d, INodeDefManager *ndef);
static s16 find_stone_level(VoxelManipulator &vmanip,
v2s16 p2d, INodeDefManager *ndef);
void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0,
bool is_apple_tree, INodeDefManager *ndef);
double tree_amount_2d(u64 seed, v2s16 p);
bool block_is_underground(u64 seed, v3s16 blockpos);
double base_rock_level_2d(u64 seed, v2s16 p);
s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
double get_mud_add_amount(u64 seed, v2s16 p);
bool get_have_beach(u64 seed, v2s16 p2d);
BiomeType get_biome(u64 seed, v2s16 p2d);
u32 get_blockseed(u64 seed, v3s16 p);
};
struct MapgenFactoryV6 : public MapgenFactory {
Mapgen *createMapgen(int mgid, MapgenParams *params, EmergeManager *emerge) {
return new MapgenV6(mgid, (MapgenV6Params *)params);
};
MapgenParams *createMapgenParams() {
return new MapgenV6Params();
};
};
#endif

@ -1097,15 +1097,14 @@ Server::Server(
// Add default biomes after nodedef had its aliases added // Add default biomes after nodedef had its aliases added
m_biomedef->addDefaultBiomes(); m_biomedef->addDefaultBiomes();
// Initialize Environment
ServerMap *servermap = new ServerMap(path_world, this);
m_env = new ServerEnvironment(servermap, m_lua, this, this);
// Create emerge manager // Create emerge manager
m_emerge = new EmergeManager(this, m_biomedef, servermap->getMapgenParams()); m_emerge = new EmergeManager(this, m_biomedef);
// Give map pointer to the emerge manager // Initialize Environment
servermap->setEmerge(m_emerge); ServerMap *servermap = new ServerMap(path_world, this, m_emerge);
m_env = new ServerEnvironment(servermap, m_lua, this, this);
m_emerge->initMapgens(servermap->getMapgenParams());
// Give environment reference to scripting api // Give environment reference to scripting api
scriptapi_add_environment(m_lua, m_env); scriptapi_add_environment(m_lua, m_env);