diff options
Diffstat (limited to 'src/emerge.cpp')
-rw-r--r-- | src/emerge.cpp | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src/emerge.cpp b/src/emerge.cpp index 2828d490b..aa2c3c531 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -48,6 +48,17 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapgen_v7.h" #include "mapgen_singlenode.h" +struct MapgenDesc { + const char *name; + MapgenFactory *factory; +}; + +MapgenDesc reg_mapgens[] = { + {"v5", new MapgenFactoryV5}, + {"v6", new MapgenFactoryV6}, + {"v7", new MapgenFactoryV7}, + {"singlenode", new MapgenFactorySinglenode}, +}; class EmergeThread : public JThread { @@ -84,12 +95,6 @@ public: EmergeManager::EmergeManager(IGameDef *gamedef) { - //register built-in mapgens - registerMapgen("v5", new MapgenFactoryV5()); - registerMapgen("v6", new MapgenFactoryV6()); - registerMapgen("v7", new MapgenFactoryV7()); - registerMapgen("singlenode", new MapgenFactorySinglenode()); - this->ndef = gamedef->getNodeDefManager(); this->biomemgr = new BiomeManager(gamedef); this->oremgr = new OreManager(gamedef); @@ -147,11 +152,6 @@ EmergeManager::~EmergeManager() emergethread.clear(); mapgen.clear(); - std::map<std::string, MapgenFactory *>::iterator it; - for (it = mglist.begin(); it != mglist.end(); ++it) - delete it->second; - mglist.clear(); - delete biomemgr; delete oremgr; delete decomgr; @@ -334,33 +334,40 @@ u32 EmergeManager::getBlockSeed(v3s16 p) } -Mapgen *EmergeManager::createMapgen(std::string mgname, int mgid, +void EmergeManager::getMapgenNames(std::list<const char *> &mgnames) +{ + for (u32 i = 0; i != ARRLEN(reg_mapgens); i++) + mgnames.push_back(reg_mapgens[i].name); +} + + +Mapgen *EmergeManager::createMapgen(const std::string &mgname, int mgid, MapgenParams *mgparams) { - std::map<std::string, MapgenFactory *>::const_iterator iter; - iter = mglist.find(mgname); - if (iter == mglist.end()) { + u32 i; + for (i = 0; i != ARRLEN(reg_mapgens) && mgname != reg_mapgens[i].name; i++); + if (i == ARRLEN(reg_mapgens)) { errorstream << "EmergeManager; mapgen " << mgname << " not registered" << std::endl; return NULL; } - MapgenFactory *mgfactory = iter->second; + MapgenFactory *mgfactory = reg_mapgens[i].factory; return mgfactory->createMapgen(mgid, mgparams, this); } -MapgenSpecificParams *EmergeManager::createMapgenParams(std::string mgname) +MapgenSpecificParams *EmergeManager::createMapgenParams(const std::string &mgname) { - std::map<std::string, MapgenFactory *>::const_iterator iter; - iter = mglist.find(mgname); - if (iter == mglist.end()) { - errorstream << "EmergeManager: mapgen " << mgname << + u32 i; + for (i = 0; i != ARRLEN(reg_mapgens) && mgname != reg_mapgens[i].name; i++); + if (i == ARRLEN(reg_mapgens)) { + errorstream << "EmergeManager; mapgen " << mgname << " not registered" << std::endl; return NULL; } - MapgenFactory *mgfactory = iter->second; + MapgenFactory *mgfactory = reg_mapgens[i].factory; return mgfactory->createMapgenParams(); } @@ -402,13 +409,6 @@ void EmergeManager::saveParamsToSettings(Settings *settings) } -void EmergeManager::registerMapgen(std::string mgname, MapgenFactory *mgfactory) -{ - mglist.insert(std::make_pair(mgname, mgfactory)); - infostream << "EmergeManager: registered mapgen " << mgname << std::endl; -} - - ////////////////////////////// Emerge Thread ////////////////////////////////// bool EmergeThread::popBlockEmerge(v3s16 *pos, u8 *flags) |