From 18882a4d2603488bdfb5a519a8bedf300b154940 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Wed, 26 Jun 2013 21:04:06 -0400 Subject: [PATCH] Add Lua PerlinNoiseMap:get#dMap_flat API --- doc/lua_api.txt | 9 +++++++ src/script/lua_api/l_noise.cpp | 45 ++++++++++++++++++++++++++++++++++ src/script/lua_api/l_noise.h | 3 ++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 84769f8d..62abb2e3 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1529,6 +1529,15 @@ methods: - get2d(pos) -> 2d noise value at pos={x=,y=} - get3d(pos) -> 3d noise value at pos={x=,y=,z=} +PerlinNoiseMap: A fast, bulk perlin noise generator +- Can be created via PerlinNoiseMap(noiseparams, size) +- Also minetest.get_perlin_map(noiseparams, size) +methods: +- get2dMap(pos) -> X 2d array of 2d noise values starting at pos={x=,y=} +- get3dMap(pos) -> XX 3d array of 3d noise values starting at pos={x=,y=,z=} +- get2dMap_flat(pos) -> Flat element array of 2d noise values starting at pos={x=,y=} +- get3dMap_flat(pos) -> Same as get2dMap_flat, but 3d noise + VoxelManip: An interface to the MapVoxelManipulator for Lua - Can be created via VoxelManip() - Also minetest.get_voxel_manip() diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp index e0abeae9..43149e93 100644 --- a/src/script/lua_api/l_noise.cpp +++ b/src/script/lua_api/l_noise.cpp @@ -159,6 +159,27 @@ int LuaPerlinNoiseMap::l_get2dMap(lua_State *L) return 1; } +int LuaPerlinNoiseMap::l_get2dMap_flat(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + + LuaPerlinNoiseMap *o = checkobject(L, 1); + v2f p = read_v2f(L, 2); + + Noise *n = o->noise; + n->perlinMap2D(p.X, p.Y); + + int maplen = n->sx * n->sy; + + lua_newtable(L); + for (int i = 0; i != maplen; i++) { + float noiseval = n->np->offset + n->np->scale * n->result[i]; + lua_pushnumber(L, noiseval); + lua_rawseti(L, -2, i + 1); + } + return 1; +} + int LuaPerlinNoiseMap::l_get3dMap(lua_State *L) { NO_MAP_LOCK_REQUIRED; @@ -186,6 +207,28 @@ int LuaPerlinNoiseMap::l_get3dMap(lua_State *L) return 1; } +int LuaPerlinNoiseMap::l_get3dMap_flat(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + + LuaPerlinNoiseMap *o = checkobject(L, 1); + v3f p = read_v3f(L, 2); + + Noise *n = o->noise; + n->perlinMap3D(p.X, p.Y, p.Z); + + + int maplen = n->sx * n->sy * n->sz; + + lua_newtable(L); + for (int i = 0; i != maplen; i++) { + float noiseval = n->np->offset + n->np->scale * n->result[i]; + lua_pushnumber(L, noiseval); + lua_rawseti(L, -2, i + 1); + } + return 1; +} + LuaPerlinNoiseMap::LuaPerlinNoiseMap(NoiseParams *np, int seed, v3s16 size) { noise = new Noise(np, seed, size.X, size.Y, size.Z); } @@ -254,7 +297,9 @@ void LuaPerlinNoiseMap::Register(lua_State *L) const char LuaPerlinNoiseMap::className[] = "PerlinNoiseMap"; const luaL_reg LuaPerlinNoiseMap::methods[] = { luamethod(LuaPerlinNoiseMap, get2dMap), + luamethod(LuaPerlinNoiseMap, get2dMap_flat), luamethod(LuaPerlinNoiseMap, get3dMap), + luamethod(LuaPerlinNoiseMap, get3dMap_flat), {0,0} }; diff --git a/src/script/lua_api/l_noise.h b/src/script/lua_api/l_noise.h index d0b51d75..6275ca47 100644 --- a/src/script/lua_api/l_noise.h +++ b/src/script/lua_api/l_noise.h @@ -74,8 +74,9 @@ private: static int gc_object(lua_State *L); static int l_get2dMap(lua_State *L); - + static int l_get2dMap_flat(lua_State *L); static int l_get3dMap(lua_State *L); + static int l_get3dMap_flat(lua_State *L); public: LuaPerlinNoiseMap(NoiseParams *np, int seed, v3s16 size);