Enforces the setting value bounds that are currently only limited by the GUI (settingtypes.txt).
local function queue_download(package, reason)
local max_concurrent_downloads = tonumber(core.settings:get("contentdb_max_concurrent_downloads"))
- if number_downloading < max_concurrent_downloads then
+ if number_downloading < math.max(max_concurrent_downloads, 1) then
start_install(package, reason)
else
table.insert(download_queue, { package = package, reason = reason })
# The time in seconds it takes between repeated node placements when holding
# the place button.
-repeat_place_time (Place repetition interval) float 0.25 0.001
+repeat_place_time (Place repetition interval) float 0.25 0.25 2
# Automatically jump up single-node obstacles.
autojump (Automatic jumping) bool false
# Multiplier for fall bobbing.
# For example: 0 for no view bobbing; 1.0 for normal; 2.0 for double.
-fall_bobbing_amount (Fall bobbing factor) float 0.03 0.0
+fall_bobbing_amount (Fall bobbing factor) float 0.03 0.0 100.0
[**Camera]
# Reducing this value increases cave and dungeon density.
# Altering this value is for special usage, leaving it unchanged is
# recommended.
-chunksize (Chunk size) int 5 1 5
+chunksize (Chunk size) int 5 1 10
# Dump the mapgen debug information.
enable_mapgen_debug_info (Mapgen debug) bool false
screen_dpi (DPI) int 72 1
# Adjust the detected display density, used for scaling UI elements.
-display_density_factor (Display Density Scaling Factor) float 1
+display_density_factor (Display Density Scaling Factor) float 1 0.5 5.0
# Windows systems only: Start Minetest with the command line window in the background.
# Contains the same information as the file debug.txt (default name).
* (as opposed to the this local caching). This can be addressed in
* a later release.
*/
- m_cache_fall_bobbing_amount = g_settings->getFloat("fall_bobbing_amount");
- m_cache_view_bobbing_amount = g_settings->getFloat("view_bobbing_amount");
+ m_cache_fall_bobbing_amount = g_settings->getFloat("fall_bobbing_amount", 0.0f, 100.0f);
+ m_cache_view_bobbing_amount = g_settings->getFloat("view_bobbing_amount", 0.0f, 7.9f);
// 45 degrees is the lowest FOV that doesn't cause the server to treat this
// as a zoom FOV and load world beyond the set server limits.
- m_cache_fov = std::fmax(g_settings->getFloat("fov"), 45.0f);
+ m_cache_fov = g_settings->getFloat("fov", 45.0f, 160.0f);
m_arm_inertia = g_settings->getBool("arm_inertia");
m_nametags.clear();
m_show_nametag_backgrounds = g_settings->getBool("show_nametag_backgrounds");
m_particle_manager(&m_env),
m_con(new con::Connection(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this)),
m_address_name(address_name),
+ m_allow_login_or_register(allow_login_or_register),
m_server_ser_ver(SER_FMT_VER_INVALID),
m_last_chat_message_sent(time(NULL)),
m_password(password),
m_media_downloader(new ClientMediaDownloader()),
m_state(LC_Created),
m_game_ui(game_ui),
- m_modchannel_mgr(new ModChannelMgr()),
- m_allow_login_or_register(allow_login_or_register)
+ m_modchannel_mgr(new ModChannelMgr())
{
// Add local player
m_env.setLocalPlayer(new LocalPlayer(this, playername));
if(m_map_timer_and_unload_interval.step(dtime, map_timer_and_unload_dtime)) {
std::vector<v3s16> deleted_blocks;
m_env.getMap().timerUpdate(map_timer_and_unload_dtime,
- g_settings->getFloat("client_unload_unused_data_timeout"),
+ std::max(g_settings->getFloat("client_unload_unused_data_timeout"), 0.0f),
g_settings->getS32("client_mapblock_limit"),
&deleted_blocks);
pkt << message;
Send(&pkt);
- } else if (m_out_chat_queue.size() < (u16) max_queue_size || max_queue_size == -1) {
+ } else if (m_out_chat_queue.size() < (u16) max_queue_size || max_queue_size < 0) {
m_out_chat_queue.push(message);
} else {
infostream << "Could not queue chat message because maximum out chat queue size ("
u16 getProtoVersion()
{ return m_proto_ver; }
- ELoginRegister m_allow_login_or_register = ELoginRegister::Any;
bool m_simple_singleplayer_mode;
float mediaReceiveProgress();
ParticleManager m_particle_manager;
std::unique_ptr<con::Connection> m_con;
std::string m_address_name;
+ ELoginRegister m_allow_login_or_register = ELoginRegister::Any;
Camera *m_camera = nullptr;
Minimap *m_minimap = nullptr;
bool m_minimap_disabled_by_server = false;
void Clouds::readSettings()
{
- m_cloud_radius_i = g_settings->getU16("cloud_radius");
+ // Upper limit was chosen due to posible render bugs
+ m_cloud_radius_i = rangelim(g_settings->getU16("cloud_radius"), 1, 62);
m_enable_3d = g_settings->getBool("enable_3d_clouds");
}
#include "filesys.h"
#include "gettext.h"
#include "irrlicht_changes/CGUITTFont.h"
+#include "util/numeric.h" // rangelim
/** maximum size distance for getting a "similar" font size */
#define MAX_FONT_SIZE_OFFSET 10
/******************************************************************************/
void FontEngine::readSettings()
{
- m_default_size[FM_Standard] = g_settings->getU16("font_size");
- m_default_size[_FM_Fallback] = g_settings->getU16("font_size");
- m_default_size[FM_Mono] = g_settings->getU16("mono_font_size");
+ m_default_size[FM_Standard] = rangelim(g_settings->getU16("font_size"), 5, 72);
+ m_default_size[_FM_Fallback] = m_default_size[FM_Standard];
+ m_default_size[FM_Mono] = rangelim(g_settings->getU16("mono_font_size"), 5, 72);
m_default_bold = g_settings->getBool("font_bold");
m_default_italic = g_settings->getBool("font_italic");
if (spec.italic)
setting_suffix.append("_italic");
- u32 size = std::max<u32>(spec.size * RenderingEngine::getDisplayDensity() *
- g_settings->getFloat("gui_scaling"), 1);
+ // Font size in pixels for FreeType
+ u32 size = rangelim(spec.size * RenderingEngine::getDisplayDensity() *
+ g_settings->getFloat("gui_scaling"), 1U, 500U);
// Constrain the font size to a certain multiple, if necessary
u16 divisible_by = g_settings->getU16(setting_prefix + "font_size_divisible_by");
}
} else if (wasKeyDown(KeyType::INC_VOLUME)) {
if (g_settings->getBool("enable_sound")) {
- float new_volume = rangelim(g_settings->getFloat("sound_volume") + 0.1f, 0.0f, 1.0f);
+ float new_volume = g_settings->getFloat("sound_volume", 0.0f, 0.9f) + 0.1f;
g_settings->setFloat("sound_volume", new_volume);
std::wstring msg = fwgettext("Volume changed to %d%%", myround(new_volume * 100));
m_game_ui->showStatusText(msg);
}
} else if (wasKeyDown(KeyType::DEC_VOLUME)) {
if (g_settings->getBool("enable_sound")) {
- float new_volume = rangelim(g_settings->getFloat("sound_volume") - 0.1f, 0.0f, 1.0f);
+ float new_volume = g_settings->getFloat("sound_volume", 0.1f, 1.0f) - 0.1f;
g_settings->setFloat("sound_volume", new_volume);
std::wstring msg = fwgettext("Volume changed to %d%%", myround(new_volume * 100));
m_game_ui->showStatusText(msg);
*/
void FpsControl::limit(IrrlichtDevice *device, f32 *dtime)
{
- const u64 frametime_min = 1000000.0f / (
- device->isWindowFocused() && !g_menumgr.pausesGame()
+ const float fps_limit = (device->isWindowFocused() && !g_menumgr.pausesGame())
? g_settings->getFloat("fps_max")
- : g_settings->getFloat("fps_max_unfocused"));
+ : g_settings->getFloat("fps_max_unfocused");
+ const u64 frametime_min = 1000000.0f / std::max(fps_limit, 1.0f);
u64 time = porting::getTimeUs();
m_cache_enable_joysticks = g_settings->getBool("enable_joysticks");
m_cache_enable_particles = g_settings->getBool("enable_particles");
m_cache_enable_fog = g_settings->getBool("enable_fog");
- m_cache_mouse_sensitivity = g_settings->getFloat("mouse_sensitivity");
- m_cache_joystick_frustum_sensitivity = g_settings->getFloat("joystick_frustum_sensitivity");
- m_repeat_place_time = g_settings->getFloat("repeat_place_time");
+ m_cache_mouse_sensitivity = g_settings->getFloat("mouse_sensitivity", 0.001f, 10.0f);
+ m_cache_joystick_frustum_sensitivity = std::max(g_settings->getFloat("joystick_frustum_sensitivity"), 0.001f);
+ m_repeat_place_time = g_settings->getFloat("repeat_place_time", 0.25f, 2.0);
m_cache_enable_noclip = g_settings->getBool("noclip");
m_cache_enable_free_move = g_settings->getBool("free_move");
u16 chat_font_size = g_settings->getU16("chat_font_size");
if (chat_font_size != 0) {
m_guitext_chat->setOverrideFont(g_fontengine->getFont(
- chat_font_size, FM_Unspecified));
+ rangelim(chat_font_size, 5, 72), FM_Unspecified));
}
this->player = player;
this->inventory = inventory;
- m_hud_scaling = g_settings->getFloat("hud_scaling");
+ m_hud_scaling = g_settings->getFloat("hud_scaling", 1.0f, 20.0f);
m_scale_factor = m_hud_scaling * RenderingEngine::getDisplayDensity();
m_hotbar_imagesize = std::floor(HOTBAR_IMAGE_SIZE *
RenderingEngine::getDisplayDensity() + 0.5f);
#include "gettime.h"
#include "porting.h"
#include "util/string.h"
+#include "util/numeric.h"
bool JoystickButtonCmb::isTriggered(const irr::SEvent::SJoystickEvent &ev) const
{
}
-JoystickController::JoystickController() :
- doubling_dtime(g_settings->getFloat("repeat_joystick_button_time"))
+JoystickController::JoystickController()
{
+ doubling_dtime = std::max(g_settings->getFloat("repeat_joystick_button_time"), 0.001f);
for (float &i : m_past_pressed_time) {
i = 0;
}
s32 id = g_settings->getS32("joystick_id");
std::string layout = g_settings->get("joystick_type");
- if (id < 0 || (u16)id >= joystick_infos.size()) {
+ if (id < 0 || id >= (s32)joystick_infos.size()) {
// TODO: auto detection
id = 0;
}
- if (id >= 0 && (u16)id < joystick_infos.size()) {
+ if (id >= 0 && id < (s32)joystick_infos.size()) {
if (layout.empty() || layout == "auto")
setLayoutFromControllerName(joystick_infos[id].Name.c_str());
else
setLayoutFromControllerName(layout);
}
- m_joystick_id = id;
+ // Irrlicht restriction.
+ m_joystick_id = rangelim(id, 0, UINT8_MAX);
}
void JoystickController::setLayoutFromControllerName(const std::string &name)
IrrlichtDevice *_device, Client *_client, Hud *_hud)
: RenderingCore(_device, _client, _hud)
{
- eye_offset = BS * g_settings->getFloat("3d_paralax_strength");
+ eye_offset = BS * g_settings->getFloat("3d_paralax_strength", -0.087f, 0.087f);
}
void RenderingCoreStereo::beforeDraw()
// Resolution selection
bool fullscreen = g_settings->getBool("fullscreen");
- u16 screen_w = g_settings->getU16("screen_w");
- u16 screen_h = g_settings->getU16("screen_h");
+ u16 screen_w = std::max<u16>(g_settings->getU16("screen_w"), 1);
+ u16 screen_h = std::max<u16>(g_settings->getU16("screen_h"), 1);
// bpp, fsaa, vsync
bool vsync = g_settings->getBool("vsync");
float RenderingEngine::getDisplayDensity()
{
static float cached_display_density = calcDisplayDensity();
- return cached_display_density * g_settings->getFloat("display_density_factor");
+ return std::max(cached_display_density * g_settings->getFloat("display_density_factor"), 0.5f);
}
#elif defined(_WIN32)
display_density = calcDisplayDensity(get_video_driver());
cached = true;
}
- return display_density * g_settings->getFloat("display_density_factor");
+ return std::max(display_density * g_settings->getFloat("display_density_factor"), 0.5f);
}
#else
float RenderingEngine::getDisplayDensity()
{
- return (g_settings->getFloat("screen_dpi") / 96.0) * g_settings->getFloat("display_density_factor");
+ return std::max(g_settings->getFloat("screen_dpi") / 96.0f *
+ g_settings->getFloat("display_density_factor"), 0.5f);
}
#endif
* textures that don't have the resources to offer high-res alternatives.
*/
const bool filter = m_setting_trilinear_filter || m_setting_bilinear_filter;
- const s32 scaleto = filter ? g_settings->getS32("texture_min_size") : 1;
+ const s32 scaleto = filter ? g_settings->getU16("texture_min_size") : 1;
if (scaleto > 1) {
const core::dimension2d<u32> dim = baseimg->getDimension();
g_settings->getS16NoEx("num_emerge_threads", nthreads);
// If automatic, leave a proc for the main thread and one for
// some other misc thread
- if (nthreads == 0)
+ if (nthreads <= 0)
nthreads = Thread::getNumberOfProcessors() - 2;
if (nthreads < 1)
nthreads = 1;
m_background_color.setBlue(clamp_u8(myround(console_color.Z)));
}
- u16 chat_font_size = g_settings->getU16("chat_font_size");
+ const u16 chat_font_size = g_settings->getU16("chat_font_size");
m_font = g_fontengine->getFont(chat_font_size != 0 ?
- chat_font_size : FONT_SIZE_UNSPECIFIED, FM_Mono);
+ rangelim(chat_font_size, 5, 72) : FONT_SIZE_UNSPECIFIED, FM_Mono);
if (!m_font) {
errorstream << "GUIChatConsole: Unable to load mono font" << std::endl;
offset = v2s32(0,0);
}
- double gui_scaling = g_settings->getFloat("gui_scaling");
- double screen_dpi = RenderingEngine::getDisplayDensity() * 96;
+ const double gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 42.0f);
+ const double screen_dpi = RenderingEngine::getDisplayDensity() * 96;
double use_imgsize;
if (m_lock) {
#endif
core::rect<s32> relative_rect = m_scrollbar->getRelativePosition();
s32 width = (relative_rect.getWidth() / (2.0 / 3.0)) * density *
- g_settings->getFloat("gui_scaling");
+ g_settings->getFloat("gui_scaling", 0.5f, 20.0f);
m_scrollbar->setRelativePosition(core::rect<s32>(
relative_rect.LowerRightCorner.X-width,relative_rect.UpperLeftCorner.Y,
relative_rect.LowerRightCorner.X,relative_rect.LowerRightCorner.Y
m_menumgr(menumgr),
m_remap_dbl_click(remap_dbl_click)
{
- m_gui_scale = g_settings->getFloat("gui_scaling");
+ m_gui_scale = std::max(g_settings->getFloat("gui_scaling"), 0.5f);
#ifdef HAVE_TOUCHSCREENGUI
float d = RenderingEngine::getDisplayDensity();
m_gui_scale *= 1.1 - 0.3 * d + 0.2 * d * d;
s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y;
// adapt to similar behaviour as pc screen
- double d = g_settings->getFloat("mouse_sensitivity") * 3.0f;
+ const double d = g_settings->getFloat("mouse_sensitivity", 0.001f, 10.0f) * 3.0f;
m_camera_yaw_change -= dx * d;
m_camera_pitch = MYMIN(MYMAX(m_camera_pitch + (dy * d), -180), 180);
/*
Updates usage timers
*/
-void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks,
+void Map::timerUpdate(float dtime, float unload_timeout, s32 max_loaded_blocks,
std::vector<v3s16> *unloaded_blocks)
{
bool save_before_unloading = maySaveBlocks();
beginSave();
// If there is no practical limit, we spare creation of mapblock_queue
- if (max_loaded_blocks == U32_MAX) {
+ if (max_loaded_blocks < 0) {
for (auto §or_it : m_sectors) {
MapSector *sector = sector_it.second;
block_count_all = mapblock_queue.size();
// Delete old blocks, and blocks over the limit from the memory
- while (!mapblock_queue.empty() && (mapblock_queue.size() > max_loaded_blocks
+ while (!mapblock_queue.empty() && ((s32)mapblock_queue.size() > max_loaded_blocks
|| mapblock_queue.top().block->getUsageTimer() > unload_timeout)) {
TimeOrderedMapBlock b = mapblock_queue.top();
mapblock_queue.pop();
Updates usage timers and unloads unused blocks and sectors.
Saves modified blocks before unloading if possible.
*/
- void timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks,
+ void timerUpdate(float dtime, float unload_timeout, s32 max_loaded_blocks,
std::vector<v3s16> *unloaded_blocks=NULL);
/*
settings->getS16NoEx("chunksize", chunksize);
settings->getFlagStrNoEx("mg_flags", flags, flagdesc_mapgen);
+ chunksize = rangelim(chunksize, 1, 10);
+
delete bparams;
bparams = BiomeManager::createBiomeParams(BIOMEGEN_ORIGINAL);
if (bparams) {
settings->getNoiseParams("mgfractal_np_cave1", np_cave1);
settings->getNoiseParams("mgfractal_np_cave2", np_cave2);
settings->getNoiseParams("mgfractal_np_dungeons", np_dungeons);
+ iterations = std::max<u16>(iterations, 1);
}
bool smooth_lighting = g_settings->getBool("smooth_lighting");
enable_mesh_cache = g_settings->getBool("enable_mesh_cache");
enable_minimap = g_settings->getBool("enable_minimap");
- node_texture_size = g_settings->getU16("texture_min_size");
+ node_texture_size = std::min<u16>(g_settings->getU16("texture_min_size"), 1);
std::string leaves_style_str = g_settings->get("leaves_style");
std::string world_aligned_mode_str = g_settings->get("world_aligned_mode");
std::string autoscale_mode_str = g_settings->get("autoscale_mode");
// Run Map's timers and unload unused data
ScopeProfiler sp(g_profiler, "Server: map timer and unload");
m_env->getMap().timerUpdate(map_timer_and_unload_dtime,
- g_settings->getFloat("server_unload_unused_data_timeout"),
- U32_MAX);
+ std::max(g_settings->getFloat("server_unload_unused_data_timeout"), 0.0f),
+ -1);
}
/*
#include "irrlichttypes_bloated.h"
#include "exceptions.h"
#include "threading/mutex_auto_lock.h"
+#include "util/numeric.h" // rangelim
#include "util/strfnd.h"
#include <iostream>
#include <fstream>
}
+float Settings::getFloat(const std::string &name, float min, float max) const
+{
+ float val = stof(get(name));
+ return rangelim(val, min, max);
+}
+
+
u64 Settings::getU64(const std::string &name) const
{
std::string s = get(name);
s32 getS32(const std::string &name) const;
u64 getU64(const std::string &name) const;
float getFloat(const std::string &name) const;
+ float getFloat(const std::string &name, float min, float max) const;
v2f getV2F(const std::string &name) const;
v3f getV3F(const std::string &name) const;
u32 getFlagStr(const std::string &name, const FlagDesc *flagdesc,