summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2014-12-09 23:44:04 -0500
committerkwolekr <kwolekr@minetest.net>2014-12-09 23:44:04 -0500
commitd50878d608fdea2be890ff75b93212f5bba1d6f8 (patch)
tree46a7b42aa7c59f6fdfbae94c329ae4de9359b5e2
parentf2c18511a4a3c3cfdda3671d02f1b7468cb56405 (diff)
downloadminetest-d50878d608fdea2be890ff75b93212f5bba1d6f8.tar.gz
minetest-d50878d608fdea2be890ff75b93212f5bba1d6f8.tar.bz2
minetest-d50878d608fdea2be890ff75b93212f5bba1d6f8.zip
Rename and repurpose minetest.set_noiseparam_defaults to set_noiseparams
-rw-r--r--doc/lua_api.txt8
-rw-r--r--src/script/lua_api/l_mapgen.cpp33
-rw-r--r--src/script/lua_api/l_mapgen.h4
3 files changed, 16 insertions, 29 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index df4b59a05..4e63a02e0 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -1547,10 +1547,10 @@ minetest.set_mapgen_params(MapgenParams)
^ Leave field unset to leave that parameter unchanged
^ flags contains a comma-delimited string of flags to set, or if the prefix "no" is attached, clears instead.
^ flags is in the same format and has the same options as 'mg_flags' in minetest.conf
-minetest.set_noiseparam_defaults({np1=NoiseParams, np2= NoiseParams, ...})
-^ Sets the default value of a noiseparam setting
-^ Takes a table as an argument that maps one or more setting names to NoiseParams structures
-^ Possible setting names consist of any NoiseParams setting exposed through the global settings
+minetest.set_noiseparams(name, noiseparams, set_default)
+^ Sets the noiseparams setting of 'name' to the noiseparams table specified in 'noiseparams'.
+^ 'set_default', is an optional boolean (default of true) that specifies whether the setting
+^ should be applied to the default config or current active config
minetest.clear_objects()
^ clear all objects in the environments
minetest.line_of_sight(pos1, pos2, stepsize) -> true/false, pos
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index 78cf389e0..0e3d219a4 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -262,32 +262,19 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L)
return 0;
}
-// set_noiseparam_defaults({np1={noise params}, ...})
-// set default values for noise parameters if not present in global settings
-int ModApiMapgen::l_set_noiseparam_defaults(lua_State *L)
+// set_noiseparams(name, noiseparams, set_default)
+// set global config values for noise parameters
+int ModApiMapgen::l_set_noiseparams(lua_State *L)
{
- NoiseParams np;
- std::string val, name;
+ const char *name = luaL_checkstring(L, 1);
- if (!lua_istable(L, 1))
+ NoiseParams np;
+ if (!read_noiseparams(L, 2, &np))
return 0;
- lua_pushnil(L);
- while (lua_next(L, 1)) {
- if (read_noiseparams(L, -1, &np)) {
- /// TODO(hmmmm): Update this for newer noiseparam formats
- /// Right now this is safe because serializeStructToString() won't
- /// touch memory outside of what the format string specifies
- if (!serializeStructToString(&val, NOISEPARAMS_FMT_STR, &np))
- continue;
- if (!lua_isstring(L, -2))
- continue;
-
- name = lua_tostring(L, -2);
- g_settings->setDefault(name, val);
- }
- lua_pop(L, 1);
- }
+ bool set_default = lua_isboolean(L, 3) ? lua_toboolean(L, 3) : true;
+
+ g_settings->setNoiseParams(name, np, set_default);
return 0;
}
@@ -682,7 +669,7 @@ void ModApiMapgen::Initialize(lua_State *L, int top)
API_FCT(get_mapgen_object);
API_FCT(set_mapgen_params);
- API_FCT(set_noiseparam_defaults);
+ API_FCT(set_noiseparams);
API_FCT(set_gen_notify);
API_FCT(register_biome);
diff --git a/src/script/lua_api/l_mapgen.h b/src/script/lua_api/l_mapgen.h
index d76190f27..72bf1f59b 100644
--- a/src/script/lua_api/l_mapgen.h
+++ b/src/script/lua_api/l_mapgen.h
@@ -37,8 +37,8 @@ private:
// set mapgen parameters
static int l_set_mapgen_params(lua_State *L);
- // set_noiseparam_defaults({np1={noise params}, ...})
- static int l_set_noiseparam_defaults(lua_State *L);
+ // set_noiseparam_defaults(name, noiseparams, set_default)
+ static int l_set_noiseparams(lua_State *L);
// set_gen_notify(flagstring)
static int l_set_gen_notify(lua_State *L);