1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add Lua PerlinNoiseMap:get#dMap_flat API

This commit is contained in:
kwolekr 2013-06-26 21:04:06 -04:00
parent 8aa930f28e
commit 18882a4d26
3 changed files with 56 additions and 1 deletions

View file

@ -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}
};

View file

@ -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);