diff options
author | kwolekr <kwolekr@minetest.net> | 2014-02-03 22:42:10 -0500 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2014-02-03 22:50:14 -0500 |
commit | 5a34f40d80ea1a339b599bc11db549a6bd86912f (patch) | |
tree | 07ead9e3ff4732479af41b739a26b5dc8182c5fd /src/script/lua_api | |
parent | a439343844cf821e4922e23f1638b92e2cfb14ac (diff) | |
download | minetest-5a34f40d80ea1a339b599bc11db549a6bd86912f.tar.gz minetest-5a34f40d80ea1a339b599bc11db549a6bd86912f.tar.bz2 minetest-5a34f40d80ea1a339b599bc11db549a6bd86912f.zip |
Huge overhaul of the entire MapgenParams system
MapgenParams is no longer a polymorphic class, eliminating the need for messy and bug-prone reallocations.
Separation between the common and mapgen-specific parameters is now strongly defined.
Mapgen parameters objects are now properly encapsulated within the proper subsystems.
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_mapgen.cpp | 47 | ||||
-rw-r--r-- | src/script/lua_api/l_vmanip.cpp | 2 |
2 files changed, 18 insertions, 31 deletions
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 5489531b6..709c7de35 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -137,7 +137,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) return 1; } case MGOBJ_HEATMAP: { // Mapgen V7 specific objects case MGOBJ_HUMIDMAP: - if (strcmp(emerge->params->mg_name.c_str(), "v7")) + if (strcmp(emerge->params.mg_name.c_str(), "v7")) return 0; MapgenV7 *mgv7 = (MapgenV7 *)mg; @@ -188,50 +188,37 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L) return 0; EmergeManager *emerge = getServer(L)->getEmergeManager(); - if (!emerge || emerge->mapgen.size()) - return 0; + ASSERT(emerge); - MapgenParams *oparams = new MapgenParams; - u32 paramsmodified = 0; - u32 flagmask = 0; + std::string flagstr; lua_getfield(L, 1, "mgname"); if (lua_isstring(L, -1)) { - oparams->mg_name = std::string(lua_tostring(L, -1)); - paramsmodified |= MGPARAMS_SET_MGNAME; + emerge->params.mg_name = std::string(lua_tostring(L, -1)); + delete emerge->params.sparams; + emerge->params.sparams = NULL; } lua_getfield(L, 1, "seed"); - if (lua_isnumber(L, -1)) { - oparams->seed = lua_tointeger(L, -1); - paramsmodified |= MGPARAMS_SET_SEED; - } + if (lua_isnumber(L, -1)) + emerge->params.seed = lua_tointeger(L, -1); lua_getfield(L, 1, "water_level"); - if (lua_isnumber(L, -1)) { - oparams->water_level = lua_tointeger(L, -1); - paramsmodified |= MGPARAMS_SET_WATER_LEVEL; + if (lua_isnumber(L, -1)) + emerge->params.water_level = lua_tointeger(L, -1); + + lua_getfield(L, 1, "flagmask"); + if (lua_isstring(L, -1)) { + flagstr = lua_tostring(L, -1); + emerge->params.flags &= ~readFlagString(flagstr, flagdesc_mapgen); } lua_getfield(L, 1, "flags"); if (lua_isstring(L, -1)) { - std::string flagstr = std::string(lua_tostring(L, -1)); - oparams->flags = readFlagString(flagstr, flagdesc_mapgen); - paramsmodified |= MGPARAMS_SET_FLAGS; - - lua_getfield(L, 1, "flagmask"); - if (lua_isstring(L, -1)) { - flagstr = std::string(lua_tostring(L, -1)); - flagmask = readFlagString(flagstr, flagdesc_mapgen); - } + flagstr = lua_tostring(L, -1); + emerge->params.flags |= readFlagString(flagstr, flagdesc_mapgen); } - delete emerge->luaoverride_params; - - emerge->luaoverride_params = oparams; - emerge->luaoverride_params_modified = paramsmodified; - emerge->luaoverride_flagmask = flagmask; - return 0; } diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index 4c9047bd9..b48b3a8f1 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -149,7 +149,7 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L) Mapgen mg; mg.vm = vm; mg.ndef = ndef; - mg.water_level = emerge->params->water_level; + mg.water_level = emerge->params.water_level; mg.calcLighting(p1, p2); |