aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_env.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2014-12-12 02:02:26 -0500
committerkwolekr <kwolekr@minetest.net>2014-12-12 02:02:44 -0500
commit2b8180a417465845759096670f498bf71cd39403 (patch)
tree85fae3cd3b729f3548bda9f58ac3a06ab7e28e88 /src/script/lua_api/l_env.cpp
parentc151099b79e3e5eae39969495a10af28a44bf10f (diff)
downloadminetest-2b8180a417465845759096670f498bf71cd39403.tar.gz
minetest-2b8180a417465845759096670f498bf71cd39403.tar.bz2
minetest-2b8180a417465845759096670f498bf71cd39403.zip
Add support for NoiseParams in minetest.get_perlin() and add docs on NoiseParams to lua_api.txt
Diffstat (limited to 'src/script/lua_api/l_env.cpp')
-rw-r--r--src/script/lua_api/l_env.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 8f1f851d7..3d2e20424 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -590,12 +590,20 @@ int ModApiEnvMod::l_get_perlin(lua_State *L)
{
GET_ENV_PTR;
- int seeddiff = luaL_checkint(L, 1);
- int octaves = luaL_checkint(L, 2);
- float persistence = luaL_checknumber(L, 3);
- float scale = luaL_checknumber(L, 4);
+ NoiseParams params;
- LuaPerlinNoise *n = new LuaPerlinNoise(seeddiff + int(env->getServerMap().getSeed()), octaves, persistence, scale);
+ if (lua_istable(L, 1)) {
+ read_noiseparams(L, 1, &params);
+ } else {
+ params.seed = luaL_checkint(L, 1);
+ params.octaves = luaL_checkint(L, 2);
+ params.persist = luaL_checknumber(L, 3);
+ params.spread = v3f(1, 1, 1) * luaL_checknumber(L, 4);
+ }
+
+ params.seed += (int)env->getServerMap().getSeed();
+
+ LuaPerlinNoise *n = new LuaPerlinNoise(&params);
*(void **)(lua_newuserdata(L, sizeof(void *))) = n;
luaL_getmetatable(L, "PerlinNoise");
lua_setmetatable(L, -2);