mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Improvements/fixes for noise parameter input in advanced settings
Formspec input for each individual noise parameter and flag. Allow noise flags to be set in advanced settings, previously only settable in minetest.conf. Standardise 'group format' for noise parameters set in minetest.conf, as only these support noise flags. However the older 'single line' format is still accepted to support existing minetest.conf files. Therefore auto-generate minetest.conf.example with noise parameters in 'group format'. Setting 'type' in settingtypes.txt is now either 'noise_params_2D' or 'noise_params_3D', the dimension number is displayed in the advanced settings edit page.
This commit is contained in:
parent
c60abb2aec
commit
a1e1a19ac3
9 changed files with 476 additions and 145 deletions
|
@ -1586,13 +1586,13 @@ bool read_noiseparams(lua_State *L, int index, NoiseParams *np)
|
|||
void push_noiseparams(lua_State *L, NoiseParams *np)
|
||||
{
|
||||
lua_newtable(L);
|
||||
lua_pushnumber(L, np->offset);
|
||||
push_float_string(L, np->offset);
|
||||
lua_setfield(L, -2, "offset");
|
||||
lua_pushnumber(L, np->scale);
|
||||
push_float_string(L, np->scale);
|
||||
lua_setfield(L, -2, "scale");
|
||||
lua_pushnumber(L, np->persist);
|
||||
push_float_string(L, np->persist);
|
||||
lua_setfield(L, -2, "persistence");
|
||||
lua_pushnumber(L, np->lacunarity);
|
||||
push_float_string(L, np->lacunarity);
|
||||
lua_setfield(L, -2, "lacunarity");
|
||||
lua_pushnumber(L, np->seed);
|
||||
lua_setfield(L, -2, "seed");
|
||||
|
@ -1603,7 +1603,7 @@ void push_noiseparams(lua_State *L, NoiseParams *np)
|
|||
np->flags);
|
||||
lua_setfield(L, -2, "flags");
|
||||
|
||||
push_v3f(L, np->spread);
|
||||
push_v3_float_string(L, np->spread);
|
||||
lua_setfield(L, -2, "spread");
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,15 @@ if (value < F1000_MIN || value > F1000_MAX) { \
|
|||
#define CHECK_POS_TAB(index) CHECK_TYPE(index, "position", LUA_TTABLE)
|
||||
|
||||
|
||||
void push_float_string(lua_State *L, float value)
|
||||
{
|
||||
std::stringstream ss;
|
||||
std::string str;
|
||||
ss << value;
|
||||
str = ss.str();
|
||||
lua_pushstring(L, str.c_str());
|
||||
}
|
||||
|
||||
void push_v3f(lua_State *L, v3f p)
|
||||
{
|
||||
lua_newtable(L);
|
||||
|
@ -71,6 +80,26 @@ void push_v2f(lua_State *L, v2f p)
|
|||
lua_setfield(L, -2, "y");
|
||||
}
|
||||
|
||||
void push_v3_float_string(lua_State *L, v3f p)
|
||||
{
|
||||
lua_newtable(L);
|
||||
push_float_string(L, p.X);
|
||||
lua_setfield(L, -2, "x");
|
||||
push_float_string(L, p.Y);
|
||||
lua_setfield(L, -2, "y");
|
||||
push_float_string(L, p.Z);
|
||||
lua_setfield(L, -2, "z");
|
||||
}
|
||||
|
||||
void push_v2_float_string(lua_State *L, v2f p)
|
||||
{
|
||||
lua_newtable(L);
|
||||
push_float_string(L, p.X);
|
||||
lua_setfield(L, -2, "x");
|
||||
push_float_string(L, p.Y);
|
||||
lua_setfield(L, -2, "y");
|
||||
}
|
||||
|
||||
v2s16 read_v2s16(lua_State *L, int index)
|
||||
{
|
||||
v2s16 p;
|
||||
|
|
|
@ -99,6 +99,9 @@ std::vector<aabb3f> read_aabb3f_vector (lua_State *L, int index, f32 scale);
|
|||
size_t read_stringlist (lua_State *L, int index,
|
||||
std::vector<std::string> *result);
|
||||
|
||||
void push_float_string (lua_State *L, float value);
|
||||
void push_v3_float_string(lua_State *L, v3f p);
|
||||
void push_v2_float_string(lua_State *L, v2f p);
|
||||
void push_v2s16 (lua_State *L, v2s16 p);
|
||||
void push_v2s32 (lua_State *L, v2s32 p);
|
||||
void push_v3s16 (lua_State *L, v3s16 p);
|
||||
|
|
|
@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "lua_api/l_internal.h"
|
||||
#include "cpp_api/s_security.h"
|
||||
#include "settings.h"
|
||||
#include "noise.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
|
@ -105,6 +106,24 @@ int LuaSettings::l_get_bool(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// get_np_group(self, key) -> value
|
||||
int LuaSettings::l_get_np_group(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
LuaSettings *o = checkobject(L, 1);
|
||||
|
||||
std::string key = std::string(luaL_checkstring(L, 2));
|
||||
if (o->m_settings->exists(key)) {
|
||||
NoiseParams np;
|
||||
o->m_settings->getNoiseParams(key, np);
|
||||
push_noiseparams(L, &np);
|
||||
} else {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// set(self, key, value)
|
||||
int LuaSettings::l_set(lua_State* L)
|
||||
{
|
||||
|
@ -138,6 +157,23 @@ int LuaSettings::l_set_bool(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// set(self, key, value)
|
||||
int LuaSettings::l_set_np_group(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
LuaSettings *o = checkobject(L, 1);
|
||||
|
||||
std::string key = std::string(luaL_checkstring(L, 2));
|
||||
NoiseParams value;
|
||||
read_noiseparams(L, 3, &value);
|
||||
|
||||
SET_SECURITY_CHECK(L, key);
|
||||
|
||||
o->m_settings->setNoiseParams(key, value, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// remove(self, key) -> success
|
||||
int LuaSettings::l_remove(lua_State* L)
|
||||
{
|
||||
|
@ -264,8 +300,10 @@ const char LuaSettings::className[] = "Settings";
|
|||
const luaL_Reg LuaSettings::methods[] = {
|
||||
luamethod(LuaSettings, get),
|
||||
luamethod(LuaSettings, get_bool),
|
||||
luamethod(LuaSettings, get_np_group),
|
||||
luamethod(LuaSettings, set),
|
||||
luamethod(LuaSettings, set_bool),
|
||||
luamethod(LuaSettings, set_np_group),
|
||||
luamethod(LuaSettings, remove),
|
||||
luamethod(LuaSettings, get_names),
|
||||
luamethod(LuaSettings, write),
|
||||
|
|
|
@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "common/c_content.h"
|
||||
#include "lua_api/l_base.h"
|
||||
|
||||
class Settings;
|
||||
|
@ -38,12 +39,18 @@ private:
|
|||
// get_bool(self, key) -> boolean
|
||||
static int l_get_bool(lua_State *L);
|
||||
|
||||
// get_np_group(self, key) -> noiseparam
|
||||
static int l_get_np_group(lua_State *L);
|
||||
|
||||
// set(self, key, value)
|
||||
static int l_set(lua_State *L);
|
||||
|
||||
// set_bool(self, key, value)
|
||||
static int l_set_bool(lua_State *L);
|
||||
|
||||
// set_np_group(self, key, value)
|
||||
static int l_set_np_group(lua_State *L);
|
||||
|
||||
// remove(self, key) -> success
|
||||
static int l_remove(lua_State *L);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue