aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2014-02-15 18:20:15 -0500
committerkwolekr <kwolekr@minetest.net>2014-02-15 19:13:14 -0500
commit3570f3e396acad4a6b5381d06c2dae5cf4e95fbd (patch)
tree1ce53a41271802efdd9f88de83b2c68e06cd2f33 /src/script
parentc87316487840fd176662207acef4fb15286e32e8 (diff)
downloadminetest-3570f3e396acad4a6b5381d06c2dae5cf4e95fbd.tar.gz
minetest-3570f3e396acad4a6b5381d06c2dae5cf4e95fbd.tar.bz2
minetest-3570f3e396acad4a6b5381d06c2dae5cf4e95fbd.zip
Add minetest.set_noiseparam_defaults() Lua API
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp27
-rw-r--r--src/script/common/c_content.h3
-rw-r--r--src/script/lua_api/l_mapgen.cpp28
-rw-r--r--src/script/lua_api/l_mapgen.h3
4 files changed, 53 insertions, 8 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 8e4da1b05..74e1b0956 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -959,24 +959,35 @@ void luaentity_get(lua_State *L, u16 id)
/******************************************************************************/
NoiseParams *read_noiseparams(lua_State *L, int index)
{
+ NoiseParams *np = new NoiseParams;
+
+ if (!read_noiseparams_nc(L, index, np)) {
+ delete np;
+ np = NULL;
+ }
+
+ return np;
+}
+
+bool read_noiseparams_nc(lua_State *L, int index, NoiseParams *np)
+{
if (index < 0)
index = lua_gettop(L) + 1 + index;
if (!lua_istable(L, index))
- return NULL;
+ return false;
- NoiseParams *np = new NoiseParams;
+ np->offset = getfloatfield_default(L, index, "offset", 0.0);
+ np->scale = getfloatfield_default(L, index, "scale", 0.0);
+ np->persist = getfloatfield_default(L, index, "persist", 0.0);
+ np->seed = getintfield_default(L, index, "seed", 0);
+ np->octaves = getintfield_default(L, index, "octaves", 0);
- np->offset = getfloatfield_default(L, index, "offset", 0.0);
- np->scale = getfloatfield_default(L, index, "scale", 0.0);
lua_getfield(L, index, "spread");
np->spread = read_v3f(L, -1);
lua_pop(L, 1);
- np->seed = getintfield_default(L, index, "seed", 0);
- np->octaves = getintfield_default(L, index, "octaves", 0);
- np->persist = getfloatfield_default(L, index, "persist", 0.0);
- return np;
+ return true;
}
/******************************************************************************/
diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h
index 61617d7ab..9aed5ccfa 100644
--- a/src/script/common/c_content.h
+++ b/src/script/common/c_content.h
@@ -144,6 +144,9 @@ bool string_to_enum (const EnumString *spec,
NoiseParams* read_noiseparams (lua_State *L, int index);
+bool read_noiseparams_nc (lua_State *L, int index,
+ NoiseParams *np);
+
bool read_schematic (lua_State *L, int index,
DecoSchematic *dschem,
Server *server);
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index 2e6d848b3..a7af856de 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -229,6 +229,33 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L)
return 0;
}
+// minetest.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)
+{
+ NoiseParams np;
+ std::string val, name;
+
+ if (!lua_istable(L, 1))
+ return 0;
+
+ lua_pushnil(L);
+ while (lua_next(L, 1)) {
+ if (read_noiseparams_nc(L, -1, &np)) {
+ 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);
+ }
+
+ return 0;
+}
+
// set_gen_notify(string)
int ModApiMapgen::l_set_gen_notify(lua_State *L)
{
@@ -607,6 +634,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_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 43fd6a09f..8624f9775 100644
--- a/src/script/lua_api/l_mapgen.h
+++ b/src/script/lua_api/l_mapgen.h
@@ -32,6 +32,9 @@ private:
// set mapgen parameters
static int l_set_mapgen_params(lua_State *L);
+ // minetest.set_noiseparam_defaults({np1={noise params}, ...})
+ static int l_set_noiseparam_defaults(lua_State *L);
+
// set_gen_notify(flagstring)
static int l_set_gen_notify(lua_State *L);