diff options
-rw-r--r-- | src/emerge.cpp | 56 | ||||
-rw-r--r-- | src/emerge.h | 5 | ||||
-rw-r--r-- | src/map.cpp | 48 | ||||
-rw-r--r-- | src/mapgen.cpp | 44 | ||||
-rw-r--r-- | src/mapgen.h | 31 | ||||
-rw-r--r-- | src/mapgen_singlenode.cpp | 12 | ||||
-rw-r--r-- | src/mapgen_singlenode.h | 4 | ||||
-rw-r--r-- | src/mapgen_v5.cpp | 4 | ||||
-rw-r--r-- | src/mapgen_v5.h | 4 | ||||
-rw-r--r-- | src/mapgen_v6.cpp | 4 | ||||
-rw-r--r-- | src/mapgen_v6.h | 4 | ||||
-rw-r--r-- | src/mapgen_v7.cpp | 4 | ||||
-rw-r--r-- | src/mapgen_v7.h | 4 | ||||
-rw-r--r-- | src/server.cpp | 13 | ||||
-rw-r--r-- | src/subgame.cpp | 38 |
15 files changed, 126 insertions, 149 deletions
diff --git a/src/emerge.cpp b/src/emerge.cpp index a697bcb07..89153cdb6 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -166,7 +166,7 @@ EmergeManager::~EmergeManager() void EmergeManager::loadMapgenParams() { - loadParamsFromSettings(g_settings); + params.load(*g_settings); } @@ -344,9 +344,9 @@ Mapgen *EmergeManager::createMapgen(const std::string &mgname, int mgid, 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; } @@ -356,56 +356,6 @@ MapgenSpecificParams *EmergeManager::createMapgenParams(const std::string &mgnam } -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) diff --git a/src/emerge.h b/src/emerge.h index 8bcc96ee0..1653199ec 100644 --- a/src/emerge.h +++ b/src/emerge.h @@ -101,19 +101,16 @@ public: ~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); diff --git a/src/map.cpp b/src/map.cpp index 14a237c0a..899c80b27 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -3005,26 +3005,20 @@ void ServerMap::saveMapMeta() { 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"); } @@ -3035,24 +3029,22 @@ void ServerMap::loadMapMeta() { 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; diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 17aa1dd92..67cf3d065 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -522,3 +522,47 @@ void GenElementManager::clear() { 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); +} + diff --git a/src/mapgen.h b/src/mapgen.h index 01710786b..c9aee5ef5 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -95,12 +95,13 @@ private: }; 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; @@ -112,17 +113,19 @@ struct MapgenParams { 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 { diff --git a/src/mapgen_singlenode.cpp b/src/mapgen_singlenode.cpp index acf811dea..a40020ab3 100644 --- a/src/mapgen_singlenode.cpp +++ b/src/mapgen_singlenode.cpp @@ -27,18 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #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) diff --git a/src/mapgen_singlenode.h b/src/mapgen_singlenode.h index 9fd1d75b3..35f2ba385 100644 --- a/src/mapgen_singlenode.h +++ b/src/mapgen_singlenode.h @@ -27,8 +27,8 @@ struct MapgenSinglenodeParams : public MapgenSpecificParams { MapgenSinglenodeParams() {} ~MapgenSinglenodeParams() {} - void readParams(Settings *settings); - void writeParams(Settings *settings); + void readParams(const Settings *settings) {} + void writeParams(Settings *settings) const {} }; class MapgenSinglenode : public Mapgen { diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp index ffd164774..48f524e6e 100644 --- a/src/mapgen_v5.cpp +++ b/src/mapgen_v5.cpp @@ -142,7 +142,7 @@ MapgenV5Params::MapgenV5Params() //#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); @@ -155,7 +155,7 @@ void MapgenV5Params::readParams(Settings *settings) } -void MapgenV5Params::writeParams(Settings *settings) +void MapgenV5Params::writeParams(Settings *settings) const { settings->setFlagStr("mgv5_spflags", spflags, flagdesc_mapgen_v5, (u32)-1); diff --git a/src/mapgen_v5.h b/src/mapgen_v5.h index e95874e84..28bc37f92 100644 --- a/src/mapgen_v5.h +++ b/src/mapgen_v5.h @@ -42,8 +42,8 @@ struct MapgenV5Params : public MapgenSpecificParams { MapgenV5Params(); ~MapgenV5Params() {} - void readParams(Settings *settings); - void writeParams(Settings *settings); + void readParams(const Settings *settings); + void writeParams(Settings *settings) const; }; diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index b7bfaef0c..89efcb9d3 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -144,7 +144,7 @@ MapgenV6Params::MapgenV6Params() } -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); @@ -164,7 +164,7 @@ void MapgenV6Params::readParams(Settings *settings) } -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); diff --git a/src/mapgen_v6.h b/src/mapgen_v6.h index 64aa2d87a..c805b4d25 100644 --- a/src/mapgen_v6.h +++ b/src/mapgen_v6.h @@ -59,8 +59,8 @@ struct MapgenV6Params : public MapgenSpecificParams { MapgenV6Params(); ~MapgenV6Params() {} - void readParams(Settings *settings); - void writeParams(Settings *settings); + void readParams(const Settings *settings); + void writeParams(Settings *settings) const; }; class MapgenV6 : public Mapgen { diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp index 923f85a0f..4b5a10ca1 100644 --- a/src/mapgen_v7.cpp +++ b/src/mapgen_v7.cpp @@ -144,7 +144,7 @@ MapgenV7Params::MapgenV7Params() } -void MapgenV7Params::readParams(Settings *settings) +void MapgenV7Params::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7); @@ -162,7 +162,7 @@ void MapgenV7Params::readParams(Settings *settings) } -void MapgenV7Params::writeParams(Settings *settings) +void MapgenV7Params::writeParams(Settings *settings) const { settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, (u32)-1); diff --git a/src/mapgen_v7.h b/src/mapgen_v7.h index 8a02bf564..87d67da9a 100644 --- a/src/mapgen_v7.h +++ b/src/mapgen_v7.h @@ -48,8 +48,8 @@ struct MapgenV7Params : public MapgenSpecificParams { MapgenV7Params(); ~MapgenV7Params() {} - void readParams(Settings *settings); - void writeParams(Settings *settings); + void readParams(const Settings *settings); + void writeParams(Settings *settings) const; }; class MapgenV7 : public Mapgen { diff --git a/src/server.cpp b/src/server.cpp index de23820dd..1e2c445f7 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -222,12 +222,9 @@ Server::Server( 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); @@ -235,10 +232,6 @@ Server::Server( // 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); diff --git a/src/subgame.cpp b/src/subgame.cpp index ccf477e8f..4e8777d13 100644 --- a/src/subgame.cpp +++ b/src/subgame.cpp @@ -24,6 +24,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #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 @@ -270,6 +273,12 @@ bool initializeWorld(const std::string &path, const std::string &gameid) 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)) { @@ -282,21 +291,22 @@ bool initializeWorld(const std::string &path, const std::string &gameid) } // 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; } + |