mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Use setting groups for NoiseParams
Add format example to minetest.conf.example Add Settings::setU16() Throw exception on attempted access of NULL settings groups
This commit is contained in:
parent
78103e622c
commit
68c799bf99
5 changed files with 103 additions and 10 deletions
|
@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "log.h"
|
||||
#include "util/serialize.h"
|
||||
#include "filesys.h"
|
||||
#include "noise.h"
|
||||
#include <cctype>
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -358,7 +359,10 @@ const SettingsEntry &Settings::getEntry(const std::string &name) const
|
|||
|
||||
Settings *Settings::getGroup(const std::string &name) const
|
||||
{
|
||||
return getEntry(name).group;
|
||||
Settings *group = getEntry(name).group;
|
||||
if (group == NULL)
|
||||
throw SettingNotFoundException("Setting [" + name + "] is not a group.");
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
|
@ -461,6 +465,55 @@ bool Settings::getStruct(const std::string &name, const std::string &format,
|
|||
}
|
||||
|
||||
|
||||
bool Settings::getNoiseParams(const std::string &name, NoiseParams &np) const
|
||||
{
|
||||
return getNoiseParamsFromGroup(name, np) || getNoiseParamsFromValue(name, np);
|
||||
}
|
||||
|
||||
|
||||
bool Settings::getNoiseParamsFromValue(const std::string &name,
|
||||
NoiseParams &np) const
|
||||
{
|
||||
std::string value;
|
||||
|
||||
if (!getNoEx(name, value))
|
||||
return false;
|
||||
|
||||
Strfnd f(value);
|
||||
|
||||
np.offset = stof(f.next(","));
|
||||
np.scale = stof(f.next(","));
|
||||
f.next("(");
|
||||
np.spread.X = stof(f.next(","));
|
||||
np.spread.Y = stof(f.next(","));
|
||||
np.spread.Z = stof(f.next(")"));
|
||||
np.seed = stoi(f.next(","));
|
||||
np.octaves = stoi(f.next(","));
|
||||
np.persist = stof(f.next(""));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Settings::getNoiseParamsFromGroup(const std::string &name,
|
||||
NoiseParams &np) const
|
||||
{
|
||||
Settings *group = NULL;
|
||||
|
||||
if (!getGroupNoEx(name, group))
|
||||
return false;
|
||||
|
||||
group->getFloatNoEx("offset", np.offset);
|
||||
group->getFloatNoEx("scale", np.scale);
|
||||
group->getV3FNoEx("spread", np.spread);
|
||||
group->getS32NoEx("seed", np.seed);
|
||||
group->getU16NoEx("octaves", np.octaves);
|
||||
group->getFloatNoEx("persistence", np.persist);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Settings::exists(const std::string &name) const
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
|
@ -682,6 +735,12 @@ void Settings::setS16(const std::string &name, s16 value)
|
|||
}
|
||||
|
||||
|
||||
void Settings::setU16(const std::string &name, u16 value)
|
||||
{
|
||||
set(name, itos(value));
|
||||
}
|
||||
|
||||
|
||||
void Settings::setS32(const std::string &name, s32 value)
|
||||
{
|
||||
set(name, itos(value));
|
||||
|
@ -737,6 +796,21 @@ bool Settings::setStruct(const std::string &name, const std::string &format,
|
|||
}
|
||||
|
||||
|
||||
void Settings::setNoiseParams(const std::string &name, const NoiseParams &np)
|
||||
{
|
||||
Settings *group = new Settings;
|
||||
|
||||
group->setFloat("offset", np.offset);
|
||||
group->setFloat("scale", np.scale);
|
||||
group->setV3F("spread", np.spread);
|
||||
group->setS32("seed", np.seed);
|
||||
group->setU16("octaves", np.octaves);
|
||||
group->setFloat("persistence", np.persist);
|
||||
|
||||
setGroup(name, group);
|
||||
}
|
||||
|
||||
|
||||
bool Settings::remove(const std::string &name)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue