mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add flags and lacunarity as new noise parameters
Add 'absolute value' option to noise map functions Extend persistence modulation to 3D noise Extend 'eased' option to noise2d_perlin* functions Some noise.cpp formatting fixups
This commit is contained in:
parent
638f3a8454
commit
2fd3d52020
16 changed files with 306 additions and 214 deletions
|
@ -608,13 +608,13 @@ int ModApiEnvMod::l_get_perlin_map(lua_State *L)
|
|||
{
|
||||
GET_ENV_PTR;
|
||||
|
||||
NoiseParams *np = read_noiseparams(L, 1);
|
||||
if (!np)
|
||||
NoiseParams np;
|
||||
if (!read_noiseparams(L, 1, &np))
|
||||
return 0;
|
||||
v3s16 size = read_v3s16(L, 2);
|
||||
|
||||
int seed = (int)(env->getServerMap().getSeed());
|
||||
LuaPerlinNoiseMap *n = new LuaPerlinNoiseMap(np, seed, size);
|
||||
LuaPerlinNoiseMap *n = new LuaPerlinNoiseMap(&np, seed, size);
|
||||
*(void **)(lua_newuserdata(L, sizeof(void *))) = n;
|
||||
luaL_getmetatable(L, "PerlinNoiseMap");
|
||||
lua_setmetatable(L, -2);
|
||||
|
|
|
@ -274,7 +274,10 @@ int ModApiMapgen::l_set_noiseparam_defaults(lua_State *L)
|
|||
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, 1)) {
|
||||
if (read_noiseparams_nc(L, -1, &np)) {
|
||||
if (read_noiseparams(L, -1, &np)) {
|
||||
/// TODO(hmmmm): Update this for newer noiseparam formats
|
||||
/// Right now this is safe because serializeStructToString() won't
|
||||
/// touch memory outside of what the format string specifies
|
||||
if (!serializeStructToString(&val, NOISEPARAMS_FMT_STR, &np))
|
||||
continue;
|
||||
if (!lua_isstring(L, -2))
|
||||
|
@ -406,7 +409,7 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
|
|||
|
||||
//// Get NoiseParams to define how decoration is placed
|
||||
lua_getfield(L, index, "noise_params");
|
||||
deco->np = read_noiseparams(L, -1);
|
||||
deco->np = get_noiseparams(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
//// Get biomes associated with this decoration (if any)
|
||||
|
@ -556,7 +559,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
|
|||
getflagsfield(L, index, "flags", flagdesc_ore, &ore->flags, NULL);
|
||||
|
||||
lua_getfield(L, index, "noise_params");
|
||||
ore->np = read_noiseparams(L, -1);
|
||||
ore->np = get_noiseparams(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
u32 id = oremgr->add(ore);
|
||||
|
|
|
@ -31,6 +31,7 @@ int LuaPerlinNoise::gc_object(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int LuaPerlinNoise::l_get2d(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
|
@ -40,6 +41,8 @@ int LuaPerlinNoise::l_get2d(lua_State *L)
|
|||
lua_pushnumber(L, val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int LuaPerlinNoise::l_get3d(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
|
@ -60,10 +63,12 @@ LuaPerlinNoise::LuaPerlinNoise(int a_seed, int a_octaves, float a_persistence,
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
LuaPerlinNoise::~LuaPerlinNoise()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// LuaPerlinNoise(seed, octaves, persistence, scale)
|
||||
// Creates an LuaPerlinNoise and leaves it on top of stack
|
||||
int LuaPerlinNoise::create_object(lua_State *L)
|
||||
|
@ -80,15 +85,18 @@ int LuaPerlinNoise::create_object(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
LuaPerlinNoise* LuaPerlinNoise::checkobject(lua_State *L, int narg)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
luaL_checktype(L, narg, LUA_TUSERDATA);
|
||||
void *ud = luaL_checkudata(L, narg, className);
|
||||
if(!ud) luaL_typerror(L, narg, className);
|
||||
if (!ud)
|
||||
luaL_typerror(L, narg, className);
|
||||
return *(LuaPerlinNoise**)ud; // unbox pointer
|
||||
}
|
||||
|
||||
|
||||
void LuaPerlinNoise::Register(lua_State *L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
|
@ -117,6 +125,7 @@ void LuaPerlinNoise::Register(lua_State *L)
|
|||
lua_register(L, className, create_object);
|
||||
}
|
||||
|
||||
|
||||
const char LuaPerlinNoise::className[] = "PerlinNoise";
|
||||
const luaL_reg LuaPerlinNoise::methods[] = {
|
||||
luamethod(LuaPerlinNoise, get2d),
|
||||
|
@ -124,11 +133,11 @@ const luaL_reg LuaPerlinNoise::methods[] = {
|
|||
{0,0}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
PerlinNoiseMap
|
||||
*/
|
||||
|
||||
|
||||
int LuaPerlinNoiseMap::gc_object(lua_State *L)
|
||||
{
|
||||
LuaPerlinNoiseMap *o = *(LuaPerlinNoiseMap **)(lua_touserdata(L, 1));
|
||||
|
@ -136,6 +145,7 @@ int LuaPerlinNoiseMap::gc_object(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int LuaPerlinNoiseMap::l_get2dMap(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
|
@ -160,6 +170,7 @@ int LuaPerlinNoiseMap::l_get2dMap(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int LuaPerlinNoiseMap::l_get2dMap_flat(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
|
@ -181,6 +192,7 @@ int LuaPerlinNoiseMap::l_get2dMap_flat(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int LuaPerlinNoiseMap::l_get3dMap(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
|
@ -190,7 +202,7 @@ int LuaPerlinNoiseMap::l_get3dMap(lua_State *L)
|
|||
v3f p = read_v3f(L, 2);
|
||||
|
||||
Noise *n = o->noise;
|
||||
n->perlinMap3D(p.X, p.Y, p.Z, n->np->eased);
|
||||
n->perlinMap3D(p.X, p.Y, p.Z);
|
||||
|
||||
lua_newtable(L);
|
||||
for (int z = 0; z != n->sz; z++) {
|
||||
|
@ -208,6 +220,7 @@ int LuaPerlinNoiseMap::l_get3dMap(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int LuaPerlinNoiseMap::l_get3dMap_flat(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
|
@ -216,7 +229,7 @@ int LuaPerlinNoiseMap::l_get3dMap_flat(lua_State *L)
|
|||
v3f p = read_v3f(L, 2);
|
||||
|
||||
Noise *n = o->noise;
|
||||
n->perlinMap3D(p.X, p.Y, p.Z, n->np->eased);
|
||||
n->perlinMap3D(p.X, p.Y, p.Z);
|
||||
|
||||
|
||||
int maplen = n->sx * n->sy * n->sz;
|
||||
|
@ -230,37 +243,42 @@ int LuaPerlinNoiseMap::l_get3dMap_flat(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
LuaPerlinNoiseMap::LuaPerlinNoiseMap(NoiseParams *np, int seed, v3s16 size) {
|
||||
|
||||
LuaPerlinNoiseMap::LuaPerlinNoiseMap(NoiseParams *np, int seed, v3s16 size)
|
||||
{
|
||||
memcpy(&m_noise_params, np, sizeof(m_noise_params));
|
||||
try {
|
||||
noise = new Noise(np, seed, size.X, size.Y, size.Z);
|
||||
noise = new Noise(&m_noise_params, seed, size.X, size.Y, size.Z);
|
||||
} catch (InvalidNoiseParamsException &e) {
|
||||
throw LuaError(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LuaPerlinNoiseMap::~LuaPerlinNoiseMap()
|
||||
{
|
||||
delete noise->np;
|
||||
delete noise;
|
||||
}
|
||||
|
||||
|
||||
// LuaPerlinNoiseMap(np, size)
|
||||
// Creates an LuaPerlinNoiseMap and leaves it on top of stack
|
||||
int LuaPerlinNoiseMap::create_object(lua_State *L)
|
||||
{
|
||||
NoiseParams *np = read_noiseparams(L, 1);
|
||||
if (!np)
|
||||
NoiseParams np;
|
||||
if (!read_noiseparams(L, 1, &np))
|
||||
return 0;
|
||||
v3s16 size = read_v3s16(L, 2);
|
||||
|
||||
LuaPerlinNoiseMap *o = new LuaPerlinNoiseMap(np, 0, size);
|
||||
LuaPerlinNoiseMap *o = new LuaPerlinNoiseMap(&np, 0, size);
|
||||
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
|
||||
luaL_getmetatable(L, className);
|
||||
lua_setmetatable(L, -2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
LuaPerlinNoiseMap* LuaPerlinNoiseMap::checkobject(lua_State *L, int narg)
|
||||
|
||||
LuaPerlinNoiseMap *LuaPerlinNoiseMap::checkobject(lua_State *L, int narg)
|
||||
{
|
||||
luaL_checktype(L, narg, LUA_TUSERDATA);
|
||||
|
||||
|
@ -271,6 +289,7 @@ LuaPerlinNoiseMap* LuaPerlinNoiseMap::checkobject(lua_State *L, int narg)
|
|||
return *(LuaPerlinNoiseMap **)ud; // unbox pointer
|
||||
}
|
||||
|
||||
|
||||
void LuaPerlinNoiseMap::Register(lua_State *L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
|
@ -299,6 +318,7 @@ void LuaPerlinNoiseMap::Register(lua_State *L)
|
|||
lua_register(L, className, create_object);
|
||||
}
|
||||
|
||||
|
||||
const char LuaPerlinNoiseMap::className[] = "PerlinNoiseMap";
|
||||
const luaL_reg LuaPerlinNoiseMap::methods[] = {
|
||||
luamethod(LuaPerlinNoiseMap, get2dMap),
|
||||
|
@ -320,6 +340,7 @@ int LuaPseudoRandom::gc_object(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// next(self, min=0, max=32767) -> get next value
|
||||
int LuaPseudoRandom::l_next(lua_State *L)
|
||||
{
|
||||
|
@ -354,19 +375,23 @@ LuaPseudoRandom::LuaPseudoRandom(int seed):
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
LuaPseudoRandom::~LuaPseudoRandom()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const PseudoRandom& LuaPseudoRandom::getItem() const
|
||||
{
|
||||
return m_pseudo;
|
||||
}
|
||||
|
||||
PseudoRandom& LuaPseudoRandom::getItem()
|
||||
{
|
||||
return m_pseudo;
|
||||
}
|
||||
|
||||
|
||||
// LuaPseudoRandom(seed)
|
||||
// Creates an LuaPseudoRandom and leaves it on top of stack
|
||||
int LuaPseudoRandom::create_object(lua_State *L)
|
||||
|
@ -379,14 +404,17 @@ int LuaPseudoRandom::create_object(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
LuaPseudoRandom* LuaPseudoRandom::checkobject(lua_State *L, int narg)
|
||||
{
|
||||
luaL_checktype(L, narg, LUA_TUSERDATA);
|
||||
void *ud = luaL_checkudata(L, narg, className);
|
||||
if(!ud) luaL_typerror(L, narg, className);
|
||||
if (!ud)
|
||||
luaL_typerror(L, narg, className);
|
||||
return *(LuaPseudoRandom**)ud; // unbox pointer
|
||||
}
|
||||
|
||||
|
||||
void LuaPseudoRandom::Register(lua_State *L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
|
@ -415,6 +443,7 @@ void LuaPseudoRandom::Register(lua_State *L)
|
|||
lua_register(L, className, create_object);
|
||||
}
|
||||
|
||||
|
||||
const char LuaPseudoRandom::className[] = "PseudoRandom";
|
||||
const luaL_reg LuaPseudoRandom::methods[] = {
|
||||
luamethod(LuaPseudoRandom, next),
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
// Creates an LuaPerlinNoise and leaves it on top of stack
|
||||
static int create_object(lua_State *L);
|
||||
|
||||
static LuaPerlinNoise* checkobject(lua_State *L, int narg);
|
||||
static LuaPerlinNoise *checkobject(lua_State *L, int narg);
|
||||
|
||||
static void Register(lua_State *L);
|
||||
};
|
||||
|
@ -63,7 +63,7 @@ public:
|
|||
LuaPerlinNoiseMap
|
||||
*/
|
||||
class LuaPerlinNoiseMap : public ModApiBase {
|
||||
private:
|
||||
NoiseParams m_noise_params;
|
||||
Noise *noise;
|
||||
static const char className[];
|
||||
static const luaL_reg methods[];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue