summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/mainmenu/dlg_create_world.lua2
-rw-r--r--doc/menu_lua_api.txt2
-rw-r--r--src/emerge.cpp58
-rw-r--r--src/emerge.h8
-rw-r--r--src/script/lua_api/l_mainmenu.cpp22
-rw-r--r--src/script/lua_api/l_mainmenu.h4
6 files changed, 60 insertions, 36 deletions
diff --git a/builtin/mainmenu/dlg_create_world.lua b/builtin/mainmenu/dlg_create_world.lua
index 9fcd9104b..32e1fbf83 100644
--- a/builtin/mainmenu/dlg_create_world.lua
+++ b/builtin/mainmenu/dlg_create_world.lua
@@ -16,7 +16,7 @@
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
local function create_world_formspec(dialogdata)
- local mapgens = {"v5", "v6", "v7", "singlenode"}
+ local mapgens = core.get_mapgen_names()
local current_seed = core.setting_get("fixed_map_seed") or ""
local current_mg = core.setting_get("mg_name")
diff --git a/doc/menu_lua_api.txt b/doc/menu_lua_api.txt
index b67d6ca00..45db89fb0 100644
--- a/doc/menu_lua_api.txt
+++ b/doc/menu_lua_api.txt
@@ -143,6 +143,8 @@ core.get_game(index)
addon_mods_paths = {[1] = <path>,},
}
core.get_games() -> table of all games in upper format (possible in async calls)
+core.get_mapgen_names() -> table of all map generator algorithms registered in
+ the core (possible in async calls)
Favorites:
core.get_favorites(location) -> list of favorites (possible in async calls)
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)
diff --git a/src/emerge.h b/src/emerge.h
index 5c84c70f9..e5d1b68b2 100644
--- a/src/emerge.h
+++ b/src/emerge.h
@@ -70,8 +70,6 @@ class EmergeManager {
public:
INodeDefManager *ndef;
- std::map<std::string, MapgenFactory *> mglist;
-
std::vector<Mapgen *> mapgen;
std::vector<EmergeThread *> emergethread;
@@ -105,14 +103,14 @@ public:
void loadMapgenParams();
void initMapgens();
Mapgen *getCurrentMapgen();
- Mapgen *createMapgen(std::string mgname, int mgid,
+ Mapgen *createMapgen(const std::string &mgname, int mgid,
MapgenParams *mgparams);
- MapgenSpecificParams *createMapgenParams(std::string mgname);
+ 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 registerMapgen(std::string name, MapgenFactory *mgfactory);
void loadParamsFromSettings(Settings *settings);
void saveParamsToSettings(Settings *settings);
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index 1760d2794..572b8efc8 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "filesys.h"
#include "convert_json.h"
#include "serverlist.h"
+#include "emerge.h"
#include "sound.h"
#include "settings.h"
#include "main.h" // for g_settings
@@ -689,6 +690,25 @@ int ModApiMainMenu::l_set_topleft_text(lua_State *L)
}
/******************************************************************************/
+int ModApiMainMenu::l_get_mapgen_names(lua_State *L)
+{
+ lua_newtable(L);
+
+ std::list<const char *> names;
+ EmergeManager::getMapgenNames(names);
+
+ int i = 1;
+ for (std::list<const char *>::const_iterator
+ it = names.begin(); it != names.end(); ++it) {
+ lua_pushstring(L, *it);
+ lua_rawseti(L, -2, i++);
+ }
+
+ return 1;
+}
+
+
+/******************************************************************************/
int ModApiMainMenu::l_get_modpath(lua_State *L)
{
std::string modpath
@@ -1107,6 +1127,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(delete_favorite);
API_FCT(set_background);
API_FCT(set_topleft_text);
+ API_FCT(get_mapgen_names);
API_FCT(get_modpath);
API_FCT(get_gamepath);
API_FCT(get_texturepath);
@@ -1137,6 +1158,7 @@ void ModApiMainMenu::InitializeAsync(AsyncEngine& engine)
ASYNC_API_FCT(get_worlds);
ASYNC_API_FCT(get_games);
ASYNC_API_FCT(get_favorites);
+ ASYNC_API_FCT(get_mapgen_names);
ASYNC_API_FCT(get_modpath);
ASYNC_API_FCT(get_gamepath);
ASYNC_API_FCT(get_texturepath);
diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h
index 1783a3f7f..ff61dd97a 100644
--- a/src/script/lua_api/l_mainmenu.h
+++ b/src/script/lua_api/l_mainmenu.h
@@ -73,6 +73,8 @@ private:
static int l_get_games(lua_State *L);
+ static int l_get_mapgen_names(lua_State *L);
+
static int l_get_favorites(lua_State *L);
static int l_delete_favorite(lua_State *L);
@@ -112,7 +114,7 @@ private:
static int l_get_modpath(lua_State *L);
static int l_get_gamepath(lua_State *L);
-
+
static int l_get_texturepath(lua_State *L);
static int l_get_texturepath_share(lua_State *L);