void EmergeManager::loadMapgenParams()
{
- loadParamsFromSettings(g_settings);
+ params.load(*g_settings);
}
MapgenSpecificParams *EmergeManager::createMapgenParams(const std::string &mgname)
{
u32 i;
- for (i = 0; i != ARRLEN(reg_mapgens) && mgname != reg_mapgens[i].name; i++);
+ for (i = 0; i < ARRLEN(reg_mapgens) && mgname != reg_mapgens[i].name; i++);
if (i == ARRLEN(reg_mapgens)) {
- errorstream << "EmergeManager; mapgen " << mgname <<
+ errorstream << "EmergeManager: Mapgen " << mgname <<
" not registered" << std::endl;
return NULL;
}
}
-void EmergeManager::loadParamsFromSettings(Settings *settings)
-{
- std::string seed_str;
- const char *setname = (settings == g_settings) ? "fixed_map_seed" : "seed";
-
- if (!settings->getNoEx("seed", seed_str)) {
- g_settings->getNoEx(setname, seed_str);
- }
- if (!seed_str.empty()) {
- params.seed = read_seed(seed_str.c_str());
- } else {
- params.seed =
- ((u64)(myrand() & 0xffff) << 0) |
- ((u64)(myrand() & 0xffff) << 16) |
- ((u64)(myrand() & 0xffff) << 32) |
- ((u64)(myrand() & 0xffff) << 48);
- }
-
- settings->getNoEx("mg_name", params.mg_name);
- 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);
-
- if (params.sparams) {
- params.sparams->readParams(g_settings);
- params.sparams->readParams(settings);
- }
-}
-
-
-void EmergeManager::saveParamsToSettings(Settings *settings)
-{
- settings->set("mg_name", params.mg_name);
- settings->setU64("seed", params.seed);
- 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);
-}
-
-
////////////////////////////// Emerge Thread //////////////////////////////////
bool EmergeThread::popBlockEmerge(v3s16 *pos, u8 *flags)
~EmergeManager();
void loadMapgenParams();
+ static MapgenSpecificParams *createMapgenParams(const std::string &mgname);
void initMapgens();
Mapgen *getCurrentMapgen();
Mapgen *createMapgen(const std::string &mgname, int mgid,
MapgenParams *mgparams);
- MapgenSpecificParams *createMapgenParams(const std::string &mgname);
static void getMapgenNames(std::list<const char *> &mgnames);
void startThreads();
void stopThreads();
bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate);
- void loadParamsFromSettings(Settings *settings);
- void saveParamsToSettings(Settings *settings);
-
//mapgen helper methods
Biome *getBiomeAtPoint(v3s16 p);
int getGroundLevelAtPoint(v2s16 p);
{
DSTACK(__FUNCTION_NAME);
- /*infostream<<"ServerMap::saveMapMeta(): "
- <<"seed="<<m_seed
- <<std::endl;*/
-
createDirs(m_savedir);
- std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
- std::ostringstream ss(std::ios_base::binary);
-
- Settings params;
+ std::string fullpath = m_savedir + DIR_DELIM + "map_meta.txt";
+ std::ostringstream oss(std::ios_base::binary);
+ Settings conf;
- m_emerge->saveParamsToSettings(¶ms);
- params.writeLines(ss);
+ m_emerge->params.save(conf);
+ conf.writeLines(oss);
- ss<<"[end_of_params]\n";
+ oss << "[end_of_params]\n";
- if(!fs::safeWriteToFile(fullpath, ss.str()))
- {
- infostream<<"ERROR: ServerMap::saveMapMeta(): "
- <<"could not write "<<fullpath<<std::endl;
+ if(!fs::safeWriteToFile(fullpath, oss.str())) {
+ errorstream << "ServerMap::saveMapMeta(): "
+ << "could not write " << fullpath << std::endl;
throw FileNotGoodException("Cannot save chunk metadata");
}
{
DSTACK(__FUNCTION_NAME);
- Settings params;
- std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
+ Settings conf;
+ std::string fullpath = m_savedir + DIR_DELIM + "map_meta.txt";
- if (fs::PathExists(fullpath)) {
- std::ifstream is(fullpath.c_str(), std::ios_base::binary);
- if (!is.good()) {
- errorstream << "ServerMap::loadMapMeta(): "
- "could not open " << fullpath << std::endl;
- throw FileNotGoodException("Cannot open map metadata");
- }
+ std::ifstream is(fullpath.c_str(), std::ios_base::binary);
+ if (!is.good()) {
+ errorstream << "ServerMap::loadMapMeta(): "
+ "could not open " << fullpath << std::endl;
+ throw FileNotGoodException("Cannot open map metadata");
+ }
- if (!params.parseConfigLines(is, "[end_of_params]")) {
- throw SerializationError("ServerMap::loadMapMeta(): "
+ if (!conf.parseConfigLines(is, "[end_of_params]")) {
+ throw SerializationError("ServerMap::loadMapMeta(): "
"[end_of_params] not found!");
- }
}
- m_emerge->loadParamsFromSettings(¶ms);
+ m_emerge->params.load(conf);
verbosestream << "ServerMap::loadMapMeta(): seed="
<< m_emerge->params.seed << std::endl;
{
m_elements.clear();
}
+
+
+void MapgenParams::load(const Settings &settings)
+{
+ std::string seed_str;
+ const char *seed_name = (&settings == g_settings) ? "fixed_map_seed" : "seed";
+
+ if (settings.getNoEx(seed_name, seed_str) && !seed_str.empty()) {
+ seed = read_seed(seed_str.c_str());
+ } else {
+ seed = ((u64)(myrand() & 0xFFFF) << 0) |
+ ((u64)(myrand() & 0xFFFF) << 16) |
+ ((u64)(myrand() & 0xFFFF) << 32) |
+ ((u64)(myrand() & 0xFFFF) << 48);
+ }
+
+ settings.getNoEx("mg_name", mg_name);
+ settings.getS16NoEx("water_level", water_level);
+ 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_humidity", np_biome_humidity);
+
+ delete sparams;
+ sparams = EmergeManager::createMapgenParams(mg_name);
+ if (sparams)
+ sparams->readParams(&settings);
+}
+
+
+void MapgenParams::save(Settings &settings) const
+{
+ settings.set("mg_name", mg_name);
+ settings.setU64("seed", seed);
+ settings.setS16("water_level", water_level);
+ 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_humidity", np_biome_humidity);
+
+ if (sparams)
+ sparams->writeParams(&settings);
+}
+
};
struct MapgenSpecificParams {
- virtual void readParams(Settings *settings) = 0;
- virtual void writeParams(Settings *settings) = 0;
+ virtual void readParams(const Settings *settings) = 0;
+ virtual void writeParams(Settings *settings) const = 0;
virtual ~MapgenSpecificParams() {}
};
-struct MapgenParams {
+class MapgenParams {
+public:
std::string mg_name;
s16 chunksize;
u64 seed;
MapgenSpecificParams *sparams;
- MapgenParams()
- {
- mg_name = DEFAULT_MAPGEN;
- seed = 0;
- water_level = 1;
- 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.5, 2.0);
- np_biome_humidity = NoiseParams(50, 50, v3f(500.0, 500.0, 500.0), 842, 3, 0.5, 2.0);
- }
+ MapgenParams() :
+ mg_name(DEFAULT_MAPGEN),
+ chunksize(5),
+ seed(0),
+ water_level(1),
+ flags(MG_TREES | MG_CAVES | MG_LIGHT),
+ np_biome_heat(NoiseParams(50, 50, v3f(500.0, 500.0, 500.0), 5349, 3, 0.5, 2.0)),
+ np_biome_humidity(NoiseParams(50, 50, v3f(500.0, 500.0, 500.0), 842, 3, 0.5, 2.0)),
+ sparams(NULL)
+ {}
+
+ void load(const Settings &settings);
+ void save(Settings &settings) const;
};
class Mapgen {
#include "profiler.h"
#include "emerge.h"
-//////////////////////// Mapgen Singlenode parameter read/write
-
-void MapgenSinglenodeParams::readParams(Settings *settings)
-{
-}
-
-
-void MapgenSinglenodeParams::writeParams(Settings *settings)
-{
-}
-
-///////////////////////////////////////////////////////////////////////////////
MapgenSinglenode::MapgenSinglenode(int mapgenid,
MapgenParams *params, EmergeManager *emerge)
MapgenSinglenodeParams() {}
~MapgenSinglenodeParams() {}
- void readParams(Settings *settings);
- void writeParams(Settings *settings);
+ void readParams(const Settings *settings) {}
+ void writeParams(Settings *settings) const {}
};
class MapgenSinglenode : public Mapgen {
//#define CAVE_NOISE_THRESHOLD (1.5/CAVE_NOISE_SCALE) = 0.125
-void MapgenV5Params::readParams(Settings *settings)
+void MapgenV5Params::readParams(const Settings *settings)
{
settings->getFlagStrNoEx("mgv5_spflags", spflags, flagdesc_mapgen_v5);
}
-void MapgenV5Params::writeParams(Settings *settings)
+void MapgenV5Params::writeParams(Settings *settings) const
{
settings->setFlagStr("mgv5_spflags", spflags, flagdesc_mapgen_v5, (u32)-1);
MapgenV5Params();
~MapgenV5Params() {}
- void readParams(Settings *settings);
- void writeParams(Settings *settings);
+ void readParams(const Settings *settings);
+ void writeParams(Settings *settings) const;
};
}
-void MapgenV6Params::readParams(Settings *settings)
+void MapgenV6Params::readParams(const Settings *settings)
{
settings->getFlagStrNoEx("mgv6_spflags", spflags, flagdesc_mapgen_v6);
settings->getFloatNoEx("mgv6_freq_desert", freq_desert);
}
-void MapgenV6Params::writeParams(Settings *settings)
+void MapgenV6Params::writeParams(Settings *settings) const
{
settings->setFlagStr("mgv6_spflags", spflags, flagdesc_mapgen_v6, (u32)-1);
settings->setFloat("mgv6_freq_desert", freq_desert);
MapgenV6Params();
~MapgenV6Params() {}
- void readParams(Settings *settings);
- void writeParams(Settings *settings);
+ void readParams(const Settings *settings);
+ void writeParams(Settings *settings) const;
};
class MapgenV6 : public Mapgen {
}
-void MapgenV7Params::readParams(Settings *settings)
+void MapgenV7Params::readParams(const Settings *settings)
{
settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7);
}
-void MapgenV7Params::writeParams(Settings *settings)
+void MapgenV7Params::writeParams(Settings *settings) const
{
settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, (u32)-1);
MapgenV7Params();
~MapgenV7Params() {}
- void readParams(Settings *settings);
- void writeParams(Settings *settings);
+ void readParams(const Settings *settings);
+ void writeParams(Settings *settings) const;
};
class MapgenV7 : public Mapgen {
infostream<<"- world: "<<m_path_world<<std::endl;
infostream<<"- game: "<<m_gamespec.path<<std::endl;
- // Initialize default settings and override defaults with those provided
- // by the game
- set_default_settings(g_settings);
- Settings gamedefaults;
- getGameMinetestConfig(gamespec.path, gamedefaults);
- override_default_settings(g_settings, &gamedefaults);
+ // Create world if it doesn't exist
+ if(!initializeWorld(m_path_world, m_gamespec.id))
+ throw ServerError("Failed to initialize world");
// Create server thread
m_thread = new ServerThread(this);
// Create emerge manager
m_emerge = new EmergeManager(this);
- // Create world if it doesn't exist
- if(!initializeWorld(m_path_world, m_gamespec.id))
- throw ServerError("Failed to initialize world");
-
// Create ban manager
std::string ban_path = m_path_world + DIR_DELIM "ipban.txt";
m_banmanager = new BanManager(ban_path);
#include "main.h"
#include "log.h"
#include "strfnd.h"
+#include "defaultsettings.h" // for override_default_settings
+#include "mapgen.h" // for MapgenParams
+#include "main.h" // for g_settings
#ifndef SERVER
#include "client/tile.h" // getImagePath
#endif
fs::CreateAllDirs(path);
+ // Initialize default settings and override defaults with those
+ // provided by the game
+ Settings game_defaults;
+ getGameMinetestConfig(path, game_defaults);
+ override_default_settings(g_settings, &game_defaults);
+
// Create world.mt if does not already exist
std::string worldmt_path = path + DIR_DELIM "world.mt";
if (!fs::PathExists(worldmt_path)) {
}
// Create map_meta.txt if does not already exist
- std::string mapmeta_path = path + DIR_DELIM "map_meta.txt";
- if (!fs::PathExists(mapmeta_path)) {
- std::ostringstream ss(std::ios_base::binary);
- ss
- << "mg_name = " << g_settings->get("mg_name")
- << "\nseed = " << g_settings->get("fixed_map_seed")
- << "\nchunksize = " << g_settings->get("chunksize")
- << "\nwater_level = " << g_settings->get("water_level")
- << "\nmg_flags = " << g_settings->get("mg_flags")
- << "\n[end_of_params]\n";
- if (!fs::safeWriteToFile(mapmeta_path, ss.str()))
- return false;
+ std::string map_meta_path = path + DIR_DELIM + "map_meta.txt";
+ if (!fs::PathExists(map_meta_path)){
+ verbosestream << "Creating map_meta.txt (" << map_meta_path << ")" << std::endl;
+ fs::CreateAllDirs(path);
+ std::ostringstream oss(std::ios_base::binary);
- infostream << "Wrote map_meta.txt (" << mapmeta_path << ")" << std::endl;
- }
+ Settings conf;
+ MapgenParams params;
+ params.load(*g_settings);
+ params.save(conf);
+ conf.writeLines(oss);
+ oss << "[end_of_params]\n";
+
+ fs::safeWriteToFile(map_meta_path, oss.str());
+ }
return true;
}
+