예제 #1
0
파일: l_noise.cpp 프로젝트: 0151n/minetest
int LuaPerlinNoiseMap::l_get3dMap(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	int i = 0;

	LuaPerlinNoiseMap *o = checkobject(L, 1);
	v3f p = read_v3f(L, 2);

	Noise *n = o->noise;
	n->perlinMap3D(p.X, p.Y, p.Z);

	lua_newtable(L);
	for (int z = 0; z != n->sz; z++) {
		lua_newtable(L);
		for (int y = 0; y != n->sy; y++) {
			lua_newtable(L);
			for (int x = 0; x != n->sx; x++) {
				lua_pushnumber(L, n->np->offset + n->np->scale * n->result[i++]);
				lua_rawseti(L, -2, x + 1);
			}
			lua_rawseti(L, -2, y + 1);
		}
		lua_rawseti(L, -2, z + 1);
	}
	return 1;
}
예제 #2
0
int LuaPerlinNoiseMap::l_get3dMap_flat(lua_State *L)
{
    NO_MAP_LOCK_REQUIRED;

    LuaPerlinNoiseMap *o = checkobject(L, 1);
    v3f p                = check_v3f(L, 2);
    bool use_buffer      = lua_istable(L, 3);

    if (!o->m_is3d)
        return 0;

    Noise *n = o->noise;
    n->perlinMap3D(p.X, p.Y, p.Z);

    size_t maplen = n->sx * n->sy * n->sz;

    if (use_buffer)
        lua_pushvalue(L, 3);
    else
        lua_newtable(L);

    for (size_t i = 0; i != maplen; i++) {
        lua_pushnumber(L, n->result[i]);
        lua_rawseti(L, -2, i + 1);
    }
    return 1;
}
예제 #3
0
int LuaPerlinNoiseMap::l_get3dMap(lua_State *L)
{
    NO_MAP_LOCK_REQUIRED;
    size_t i = 0;

    LuaPerlinNoiseMap *o = checkobject(L, 1);
    v3f p = check_v3f(L, 2);

    if (!o->m_is3d)
        return 0;

    Noise *n = o->noise;
    n->perlinMap3D(p.X, p.Y, p.Z);

    lua_newtable(L);
    for (u32 z = 0; z != n->sz; z++) {
        lua_newtable(L);
        for (u32 y = 0; y != n->sy; y++) {
            lua_newtable(L);
            for (u32 x = 0; x != n->sx; x++) {
                lua_pushnumber(L, n->result[i++]);
                lua_rawseti(L, -2, x + 1);
            }
            lua_rawseti(L, -2, y + 1);
        }
        lua_rawseti(L, -2, z + 1);
    }
    return 1;
}
예제 #4
0
int LuaPerlinNoiseMap::l_calc3dMap(lua_State *L)
{
    NO_MAP_LOCK_REQUIRED;

    LuaPerlinNoiseMap *o = checkobject(L, 1);
    v3f p                = check_v3f(L, 2);

    if (!o->m_is3d)
        return 0;

    Noise *n = o->noise;
    n->perlinMap3D(p.X, p.Y, p.Z);

    return 0;
}
예제 #5
0
파일: l_noise.cpp 프로젝트: 0151n/minetest
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;
}