Header file tweaking; mainly for speed

This commit is contained in:
Perttu Ahola 2011-10-12 13:53:38 +03:00
parent b60b58b627
commit 9e46cbf7ea
37 changed files with 1198 additions and 946 deletions

@ -95,7 +95,6 @@ set(common_SRCS
content_inventory.cpp content_inventory.cpp
content_nodemeta.cpp content_nodemeta.cpp
content_craft.cpp content_craft.cpp
content_mapblock.cpp
content_mapnode.cpp content_mapnode.cpp
auth.cpp auth.cpp
collision.cpp collision.cpp
@ -138,6 +137,7 @@ endif()
# Client sources # Client sources
set(minetest_SRCS set(minetest_SRCS
${common_SRCS} ${common_SRCS}
content_mapblock.cpp
content_cao.cpp content_cao.cpp
mapblock_mesh.cpp mapblock_mesh.cpp
farmesh.cpp farmesh.cpp

@ -25,6 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "player.h" #include "player.h"
#include "tile.h" #include "tile.h"
#include <cmath> #include <cmath>
#include <SAnimatedMesh.h>
#include "settings.h"
Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control): Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control):
m_smgr(smgr), m_smgr(smgr),
@ -299,8 +301,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize)
v3f speed = player->getSpeed(); v3f speed = player->getSpeed();
if ((hypot(speed.X, speed.Z) > BS) && if ((hypot(speed.X, speed.Z) > BS) &&
(player->touching_ground) && (player->touching_ground) &&
(g_settings.getBool("view_bobbing") == true) && (g_settings->getBool("view_bobbing") == true) &&
(g_settings.getBool("free_move") == false)) (g_settings->getBool("free_move") == false))
{ {
// Start animation // Start animation
m_view_bobbing_state = 1; m_view_bobbing_state = 1;
@ -427,18 +429,18 @@ void Camera::updateViewingRange(f32 frametime_in)
void Camera::updateSettings() void Camera::updateSettings()
{ {
m_viewing_range_min = g_settings.getS16("viewing_range_nodes_min"); m_viewing_range_min = g_settings->getS16("viewing_range_nodes_min");
m_viewing_range_min = MYMAX(5.0, m_viewing_range_min); m_viewing_range_min = MYMAX(5.0, m_viewing_range_min);
m_viewing_range_max = g_settings.getS16("viewing_range_nodes_max"); m_viewing_range_max = g_settings->getS16("viewing_range_nodes_max");
m_viewing_range_max = MYMAX(m_viewing_range_min, m_viewing_range_max); m_viewing_range_max = MYMAX(m_viewing_range_min, m_viewing_range_max);
f32 fov_degrees = g_settings.getFloat("fov"); f32 fov_degrees = g_settings->getFloat("fov");
fov_degrees = MYMAX(fov_degrees, 10.0); fov_degrees = MYMAX(fov_degrees, 10.0);
fov_degrees = MYMIN(fov_degrees, 170.0); fov_degrees = MYMIN(fov_degrees, 170.0);
m_fov_y = fov_degrees * PI / 180.0; m_fov_y = fov_degrees * PI / 180.0;
f32 wanted_fps = g_settings.getFloat("wanted_fps"); f32 wanted_fps = g_settings->getFloat("wanted_fps");
wanted_fps = MYMAX(wanted_fps, 1.0); wanted_fps = MYMAX(wanted_fps, 1.0);
m_wanted_frametime = 1.0 / wanted_fps; m_wanted_frametime = 1.0 / wanted_fps;
} }

@ -24,6 +24,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "inventory.h" #include "inventory.h"
#include "tile.h" #include "tile.h"
#include "utility.h" #include "utility.h"
#include <ICameraSceneNode.h>
#include <IMeshCache.h>
#include <IAnimatedMesh.h>
class LocalPlayer; class LocalPlayer;
class MapDrawControl; class MapDrawControl;

@ -28,6 +28,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapsector.h" #include "mapsector.h"
#include "mapblock_mesh.h" #include "mapblock_mesh.h"
#include "mapblock.h" #include "mapblock.h"
#include "settings.h"
#include "profiler.h"
/* /*
QueuedMeshUpdate QueuedMeshUpdate
@ -151,7 +153,7 @@ void * MeshUpdateThread::Thread()
continue; continue;
} }
ScopeProfiler sp(&g_profiler, "mesh make"); ScopeProfiler sp(g_profiler, "mesh make");
scene::SMesh *mesh_new = NULL; scene::SMesh *mesh_new = NULL;
mesh_new = makeMapBlockMesh(q->data); mesh_new = makeMapBlockMesh(q->data);
@ -327,7 +329,7 @@ void Client::step(float dtime)
core::list<v3s16> deleted_blocks; core::list<v3s16> deleted_blocks;
float delete_unused_sectors_timeout = float delete_unused_sectors_timeout =
g_settings.getFloat("client_delete_unused_sectors_timeout"); g_settings->getFloat("client_delete_unused_sectors_timeout");
// Delete sector blocks // Delete sector blocks
/*u32 num = m_env.getMap().unloadUnusedData /*u32 num = m_env.getMap().unloadUnusedData
@ -449,10 +451,10 @@ void Client::step(float dtime)
const float map_timer_and_unload_dtime = 5.25; const float map_timer_and_unload_dtime = 5.25;
if(m_map_timer_and_unload_interval.step(dtime, map_timer_and_unload_dtime)) if(m_map_timer_and_unload_interval.step(dtime, map_timer_and_unload_dtime))
{ {
ScopeProfiler sp(&g_profiler, "Client: map timer and unload"); ScopeProfiler sp(g_profiler, "Client: map timer and unload");
core::list<v3s16> deleted_blocks; core::list<v3s16> deleted_blocks;
m_env.getMap().timerUpdate(map_timer_and_unload_dtime, m_env.getMap().timerUpdate(map_timer_and_unload_dtime,
g_settings.getFloat("client_unload_unused_data_timeout"), g_settings->getFloat("client_unload_unused_data_timeout"),
&deleted_blocks); &deleted_blocks);
/*if(deleted_blocks.size() > 0) /*if(deleted_blocks.size() > 0)
@ -1403,7 +1405,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
} }
else if(command == TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD) else if(command == TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD)
{ {
//if(g_settings.getBool("enable_experimental")) //if(g_settings->getBool("enable_experimental"))
{ {
/* /*
u16 command u16 command
@ -1462,7 +1464,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
} }
else if(command == TOCLIENT_ACTIVE_OBJECT_MESSAGES) else if(command == TOCLIENT_ACTIVE_OBJECT_MESSAGES)
{ {
//if(g_settings.getBool("enable_experimental")) //if(g_settings->getBool("enable_experimental"))
{ {
/* /*
u16 command u16 command

@ -23,7 +23,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define endSceneX(d){d->draw2DLine(v2s32(0,0),v2s32(1,0),\ #define endSceneX(d){d->draw2DLine(v2s32(0,0),v2s32(1,0),\
video::SColor(255,30,30,30));d->endScene();} video::SColor(255,30,30,30));d->endScene();}
#include <irrlicht.h> #include <irrTypes.h>
#include <vector2d.h>
#include <vector3d.h>
#include <irrMap.h>
#include <irrList.h>
#include <irrArray.h>
#include <aabbox3d.h>
#ifndef SERVER
#include <SColor.h>
#include <IMesh.h>
#include <IImage.h>
#include <IrrlichtDevice.h>
#include <IMeshSceneNode.h>
#include <SMesh.h>
#include <ISceneManager.h>
#include <IMeshBuffer.h>
#include <SMeshBuffer.h>
#include <IGUIElement.h>
#include <IGUIEnvironment.h>
#endif
using namespace irr; using namespace irr;
typedef core::vector3df v3f; typedef core::vector3df v3f;
typedef core::vector3d<s16> v3s16; typedef core::vector3d<s16> v3s16;

@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "main.h" // For g_settings and g_texturesource #include "main.h" // For g_settings and g_texturesource
#include "mineral.h" #include "mineral.h"
#include "mapblock_mesh.h" // For MapBlock_LightColor() #include "mapblock_mesh.h" // For MapBlock_LightColor()
#include "settings.h"
#ifndef SERVER #ifndef SERVER
// Create a cuboid. // Create a cuboid.
@ -128,10 +129,10 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
/* /*
Some settings Some settings
*/ */
bool new_style_water = g_settings.getBool("new_style_water"); bool new_style_water = g_settings->getBool("new_style_water");
bool new_style_leaves = g_settings.getBool("new_style_leaves"); bool new_style_leaves = g_settings->getBool("new_style_leaves");
//bool smooth_lighting = g_settings.getBool("smooth_lighting"); //bool smooth_lighting = g_settings->getBool("smooth_lighting");
bool invisible_stone = g_settings.getBool("invisible_stone"); bool invisible_stone = g_settings->getBool("invisible_stone");
float node_liquid_level = 1.0; float node_liquid_level = 1.0;
if(new_style_water) if(new_style_water)

@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_mapnode.h" #include "content_mapnode.h"
#include "mapnode.h" #include "mapnode.h"
#include "content_nodemeta.h" #include "content_nodemeta.h"
#include "settings.h"
#define WATER_ALPHA 160 #define WATER_ALPHA 160
@ -103,9 +104,9 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version)
void content_mapnode_init() void content_mapnode_init()
{ {
// Read some settings // Read some settings
bool new_style_water = g_settings.getBool("new_style_water"); bool new_style_water = g_settings->getBool("new_style_water");
bool new_style_leaves = g_settings.getBool("new_style_leaves"); bool new_style_leaves = g_settings->getBool("new_style_leaves");
bool invisible_stone = g_settings.getBool("invisible_stone"); bool invisible_stone = g_settings->getBool("invisible_stone");
content_t i; content_t i;
ContentFeatures *f = NULL; ContentFeatures *f = NULL;
@ -390,6 +391,7 @@ void content_mapnode_init()
f->liquid_alternative_flowing = CONTENT_WATER; f->liquid_alternative_flowing = CONTENT_WATER;
f->liquid_alternative_source = CONTENT_WATERSOURCE; f->liquid_alternative_source = CONTENT_WATERSOURCE;
f->liquid_viscosity = WATER_VISC; f->liquid_viscosity = WATER_VISC;
#ifndef SERVER
f->vertex_alpha = WATER_ALPHA; f->vertex_alpha = WATER_ALPHA;
f->post_effect_color = video::SColor(64, 100, 100, 200); f->post_effect_color = video::SColor(64, 100, 100, 200);
if(f->special_material == NULL && g_texturesource) if(f->special_material == NULL && g_texturesource)
@ -406,6 +408,7 @@ void content_mapnode_init()
f->special_material->setTexture(0, pa_water1->atlas); f->special_material->setTexture(0, pa_water1->atlas);
f->special_atlas = pa_water1; f->special_atlas = pa_water1;
} }
#endif
i = CONTENT_WATERSOURCE; i = CONTENT_WATERSOURCE;
f = &content_features(i); f = &content_features(i);
@ -418,7 +421,7 @@ void content_mapnode_init()
else // old style else // old style
{ {
f->solidness = 1; f->solidness = 1;
#ifndef SERVER
TileSpec t; TileSpec t;
if(g_texturesource) if(g_texturesource)
t.texture = g_texturesource->getTexture("water.png"); t.texture = g_texturesource->getTexture("water.png");
@ -427,6 +430,7 @@ void content_mapnode_init()
t.material_type = MATERIAL_ALPHA_VERTEX; t.material_type = MATERIAL_ALPHA_VERTEX;
t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING; t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
f->setAllTiles(t); f->setAllTiles(t);
#endif
} }
f->param_type = CPT_LIGHT; f->param_type = CPT_LIGHT;
f->light_propagates = true; f->light_propagates = true;
@ -439,6 +443,7 @@ void content_mapnode_init()
f->liquid_alternative_flowing = CONTENT_WATER; f->liquid_alternative_flowing = CONTENT_WATER;
f->liquid_alternative_source = CONTENT_WATERSOURCE; f->liquid_alternative_source = CONTENT_WATERSOURCE;
f->liquid_viscosity = WATER_VISC; f->liquid_viscosity = WATER_VISC;
#ifndef SERVER
f->vertex_alpha = WATER_ALPHA; f->vertex_alpha = WATER_ALPHA;
f->post_effect_color = video::SColor(64, 100, 100, 200); f->post_effect_color = video::SColor(64, 100, 100, 200);
if(f->special_material == NULL && g_texturesource) if(f->special_material == NULL && g_texturesource)
@ -455,6 +460,7 @@ void content_mapnode_init()
f->special_material->setTexture(0, pa_water1->atlas); f->special_material->setTexture(0, pa_water1->atlas);
f->special_atlas = pa_water1; f->special_atlas = pa_water1;
} }
#endif
i = CONTENT_LAVA; i = CONTENT_LAVA;
f = &content_features(i); f = &content_features(i);
@ -473,6 +479,7 @@ void content_mapnode_init()
f->liquid_alternative_source = CONTENT_LAVASOURCE; f->liquid_alternative_source = CONTENT_LAVASOURCE;
f->liquid_viscosity = LAVA_VISC; f->liquid_viscosity = LAVA_VISC;
f->damage_per_second = 4*2; f->damage_per_second = 4*2;
#ifndef SERVER
f->post_effect_color = video::SColor(192, 255, 64, 0); f->post_effect_color = video::SColor(192, 255, 64, 0);
if(f->special_material == NULL && g_texturesource) if(f->special_material == NULL && g_texturesource)
{ {
@ -489,6 +496,7 @@ void content_mapnode_init()
f->special_material->setTexture(0, pa_lava1->atlas); f->special_material->setTexture(0, pa_lava1->atlas);
f->special_atlas = pa_lava1; f->special_atlas = pa_lava1;
} }
#endif
i = CONTENT_LAVASOURCE; i = CONTENT_LAVASOURCE;
f = &content_features(i); f = &content_features(i);
@ -500,7 +508,7 @@ void content_mapnode_init()
else // old style else // old style
{ {
f->solidness = 2; f->solidness = 2;
#ifndef SERVER
TileSpec t; TileSpec t;
if(g_texturesource) if(g_texturesource)
t.texture = g_texturesource->getTexture("lava.png"); t.texture = g_texturesource->getTexture("lava.png");
@ -509,6 +517,7 @@ void content_mapnode_init()
//t.material_type = MATERIAL_ALPHA_VERTEX; //t.material_type = MATERIAL_ALPHA_VERTEX;
//t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING; //t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
f->setAllTiles(t); f->setAllTiles(t);
#endif
} }
f->param_type = CPT_LIGHT; f->param_type = CPT_LIGHT;
f->light_propagates = false; f->light_propagates = false;
@ -523,6 +532,7 @@ void content_mapnode_init()
f->liquid_alternative_source = CONTENT_LAVASOURCE; f->liquid_alternative_source = CONTENT_LAVASOURCE;
f->liquid_viscosity = LAVA_VISC; f->liquid_viscosity = LAVA_VISC;
f->damage_per_second = 4*2; f->damage_per_second = 4*2;
#ifndef SERVER
f->post_effect_color = video::SColor(192, 255, 64, 0); f->post_effect_color = video::SColor(192, 255, 64, 0);
if(f->special_material == NULL && g_texturesource) if(f->special_material == NULL && g_texturesource)
{ {
@ -539,6 +549,7 @@ void content_mapnode_init()
f->special_material->setTexture(0, pa_lava1->atlas); f->special_material->setTexture(0, pa_lava1->atlas);
f->special_atlas = pa_lava1; f->special_atlas = pa_lava1;
} }
#endif
i = CONTENT_TORCH; i = CONTENT_TORCH;
f = &content_features(i); f = &content_features(i);

@ -17,92 +17,90 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "utility.h" #include "settings.h"
extern Settings g_settings; void set_default_settings(Settings *settings)
void set_default_settings()
{ {
// Client and server // Client and server
g_settings.setDefault("port", ""); settings->setDefault("port", "");
g_settings.setDefault("name", ""); settings->setDefault("name", "");
g_settings.setDefault("footprints", "false"); settings->setDefault("footprints", "false");
// Client stuff // Client stuff
g_settings.setDefault("keymap_forward", "KEY_KEY_W"); settings->setDefault("keymap_forward", "KEY_KEY_W");
g_settings.setDefault("keymap_backward", "KEY_KEY_S"); settings->setDefault("keymap_backward", "KEY_KEY_S");
g_settings.setDefault("keymap_left", "KEY_KEY_A"); settings->setDefault("keymap_left", "KEY_KEY_A");
g_settings.setDefault("keymap_right", "KEY_KEY_D"); settings->setDefault("keymap_right", "KEY_KEY_D");
g_settings.setDefault("keymap_jump", "KEY_SPACE"); settings->setDefault("keymap_jump", "KEY_SPACE");
g_settings.setDefault("keymap_sneak", "KEY_LSHIFT"); settings->setDefault("keymap_sneak", "KEY_LSHIFT");
g_settings.setDefault("keymap_inventory", "KEY_KEY_I"); settings->setDefault("keymap_inventory", "KEY_KEY_I");
g_settings.setDefault("keymap_chat", "KEY_KEY_T"); settings->setDefault("keymap_chat", "KEY_KEY_T");
g_settings.setDefault("keymap_cmd", "/"); settings->setDefault("keymap_cmd", "/");
g_settings.setDefault("keymap_rangeselect", "KEY_KEY_R"); settings->setDefault("keymap_rangeselect", "KEY_KEY_R");
g_settings.setDefault("keymap_freemove", "KEY_KEY_K"); settings->setDefault("keymap_freemove", "KEY_KEY_K");
g_settings.setDefault("keymap_fastmove", "KEY_KEY_J"); settings->setDefault("keymap_fastmove", "KEY_KEY_J");
g_settings.setDefault("keymap_frametime_graph", "KEY_F1"); settings->setDefault("keymap_frametime_graph", "KEY_F1");
g_settings.setDefault("keymap_screenshot", "KEY_F12"); settings->setDefault("keymap_screenshot", "KEY_F12");
// Some (temporary) keys for debugging // Some (temporary) keys for debugging
g_settings.setDefault("keymap_special1", "KEY_KEY_E"); settings->setDefault("keymap_special1", "KEY_KEY_E");
g_settings.setDefault("keymap_print_debug_stacks", "KEY_KEY_P"); settings->setDefault("keymap_print_debug_stacks", "KEY_KEY_P");
g_settings.setDefault("wanted_fps", "30"); settings->setDefault("wanted_fps", "30");
g_settings.setDefault("fps_max", "60"); settings->setDefault("fps_max", "60");
g_settings.setDefault("viewing_range_nodes_max", "300"); settings->setDefault("viewing_range_nodes_max", "300");
g_settings.setDefault("viewing_range_nodes_min", "15"); settings->setDefault("viewing_range_nodes_min", "15");
g_settings.setDefault("screenW", "800"); settings->setDefault("screenW", "800");
g_settings.setDefault("screenH", "600"); settings->setDefault("screenH", "600");
g_settings.setDefault("address", ""); settings->setDefault("address", "");
g_settings.setDefault("random_input", "false"); settings->setDefault("random_input", "false");
g_settings.setDefault("client_unload_unused_data_timeout", "600"); settings->setDefault("client_unload_unused_data_timeout", "600");
g_settings.setDefault("enable_fog", "true"); settings->setDefault("enable_fog", "true");
g_settings.setDefault("fov", "72"); settings->setDefault("fov", "72");
g_settings.setDefault("view_bobbing", "true"); settings->setDefault("view_bobbing", "true");
g_settings.setDefault("new_style_water", "false"); settings->setDefault("new_style_water", "false");
g_settings.setDefault("new_style_leaves", "true"); settings->setDefault("new_style_leaves", "true");
g_settings.setDefault("smooth_lighting", "true"); settings->setDefault("smooth_lighting", "true");
g_settings.setDefault("frametime_graph", "false"); settings->setDefault("frametime_graph", "false");
g_settings.setDefault("enable_texture_atlas", "true"); settings->setDefault("enable_texture_atlas", "true");
g_settings.setDefault("texture_path", ""); settings->setDefault("texture_path", "");
g_settings.setDefault("video_driver", "opengl"); settings->setDefault("video_driver", "opengl");
g_settings.setDefault("free_move", "false"); settings->setDefault("free_move", "false");
g_settings.setDefault("continuous_forward", "false"); settings->setDefault("continuous_forward", "false");
g_settings.setDefault("fast_move", "false"); settings->setDefault("fast_move", "false");
g_settings.setDefault("invert_mouse", "false"); settings->setDefault("invert_mouse", "false");
g_settings.setDefault("enable_farmesh", "false"); settings->setDefault("enable_farmesh", "false");
g_settings.setDefault("enable_clouds", "true"); settings->setDefault("enable_clouds", "true");
g_settings.setDefault("invisible_stone", "false"); settings->setDefault("invisible_stone", "false");
g_settings.setDefault("screenshot_path", "."); settings->setDefault("screenshot_path", ".");
// Server stuff // Server stuff
g_settings.setDefault("motd", ""); settings->setDefault("motd", "");
g_settings.setDefault("max_users", "20"); settings->setDefault("max_users", "20");
g_settings.setDefault("enable_experimental", "false"); settings->setDefault("enable_experimental", "false");
g_settings.setDefault("creative_mode", "false"); settings->setDefault("creative_mode", "false");
g_settings.setDefault("enable_damage", "true"); settings->setDefault("enable_damage", "true");
g_settings.setDefault("give_initial_stuff", "false"); settings->setDefault("give_initial_stuff", "false");
g_settings.setDefault("default_password", ""); settings->setDefault("default_password", "");
g_settings.setDefault("default_privs", "build, shout"); settings->setDefault("default_privs", "build, shout");
g_settings.setDefault("profiler_print_interval", "0"); settings->setDefault("profiler_print_interval", "0");
g_settings.setDefault("enable_mapgen_debug_info", "false"); settings->setDefault("enable_mapgen_debug_info", "false");
g_settings.setDefault("fixed_map_seed", ""); settings->setDefault("fixed_map_seed", "");
g_settings.setDefault("objectdata_interval", "0.2"); settings->setDefault("objectdata_interval", "0.2");
g_settings.setDefault("active_object_range", "2"); settings->setDefault("active_object_range", "2");
//g_settings.setDefault("max_simultaneous_block_sends_per_client", "1"); //settings->setDefault("max_simultaneous_block_sends_per_client", "1");
// This causes frametime jitter on client side, or does it? // This causes frametime jitter on client side, or does it?
g_settings.setDefault("max_simultaneous_block_sends_per_client", "2"); settings->setDefault("max_simultaneous_block_sends_per_client", "2");
g_settings.setDefault("max_simultaneous_block_sends_server_total", "8"); settings->setDefault("max_simultaneous_block_sends_server_total", "8");
g_settings.setDefault("max_block_send_distance", "8"); settings->setDefault("max_block_send_distance", "8");
g_settings.setDefault("max_block_generate_distance", "8"); settings->setDefault("max_block_generate_distance", "8");
g_settings.setDefault("time_send_interval", "20"); settings->setDefault("time_send_interval", "20");
g_settings.setDefault("time_speed", "96"); settings->setDefault("time_speed", "96");
g_settings.setDefault("server_unload_unused_data_timeout", "60"); settings->setDefault("server_unload_unused_data_timeout", "60");
g_settings.setDefault("server_map_save_interval", "60"); settings->setDefault("server_map_save_interval", "60");
g_settings.setDefault("full_block_send_enable_min_time_from_building", "2.0"); settings->setDefault("full_block_send_enable_min_time_from_building", "2.0");
//g_settings.setDefault("dungeon_rarity", "0.025"); //settings->setDefault("dungeon_rarity", "0.025");
} }

28
src/defaultsettings.h Normal file

@ -0,0 +1,28 @@
/*
Minetest-c55
Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef DEFAULTSETTINGS_HEADER
#define DEFAULTSETTINGS_HEADER
class Settings;
void set_default_settings(Settings *settings);
#endif

@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serverobject.h" #include "serverobject.h"
#include "content_sao.h" #include "content_sao.h"
#include "mapgen.h" #include "mapgen.h"
#include "settings.h"
Environment::Environment(): Environment::Environment():
m_time_of_day(9000) m_time_of_day(9000)
@ -649,7 +650,7 @@ void ServerEnvironment::step(float dtime)
//TimeTaker timer("ServerEnv step"); //TimeTaker timer("ServerEnv step");
// Get some settings // Get some settings
bool footprints = g_settings.getBool("footprints"); bool footprints = g_settings->getBool("footprints");
/* /*
Increment game time Increment game time
@ -1013,7 +1014,7 @@ void ServerEnvironment::step(float dtime)
removeRemovedObjects(); removeRemovedObjects();
} }
if(g_settings.getBool("enable_experimental")) if(g_settings->getBool("enable_experimental"))
{ {
/* /*
@ -1541,8 +1542,8 @@ void ClientEnvironment::step(float dtime)
DSTACK(__FUNCTION_NAME); DSTACK(__FUNCTION_NAME);
// Get some settings // Get some settings
bool free_move = g_settings.getBool("free_move"); bool free_move = g_settings->getBool("free_move");
bool footprints = g_settings.getBool("footprints"); bool footprints = g_settings->getBool("footprints");
// Get local player // Get local player
LocalPlayer *lplayer = getLocalPlayer(); LocalPlayer *lplayer = getLocalPlayer();

@ -17,8 +17,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "common_irrlicht.h"
#include "game.h" #include "game.h"
#include "common_irrlicht.h"
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
#include "client.h" #include "client.h"
#include "server.h" #include "server.h"
#include "guiPauseMenu.h" #include "guiPauseMenu.h"
@ -31,6 +36,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "camera.h" #include "camera.h"
#include "farmesh.h" #include "farmesh.h"
#include "mapblock.h" #include "mapblock.h"
#include "settings.h"
#include "profiler.h"
#include "mainmenumanager.h"
/* /*
TODO: Move content-aware stuff to separate file by adding properties TODO: Move content-aware stuff to separate file by adding properties
@ -583,7 +591,7 @@ void update_skybox(video::IVideoDriver* driver,
} }
/*// Disable skybox if FarMesh is enabled /*// Disable skybox if FarMesh is enabled
if(g_settings.getBool("enable_farmesh")) if(g_settings->getBool("enable_farmesh"))
return;*/ return;*/
if(brightness >= 0.5) if(brightness >= 0.5)
@ -825,7 +833,7 @@ void the_game(
float cloud_height = BS*100; float cloud_height = BS*100;
Clouds *clouds = NULL; Clouds *clouds = NULL;
if(g_settings.getBool("enable_clouds")) if(g_settings->getBool("enable_clouds"))
{ {
clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1, clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
cloud_height, time(0)); cloud_height, time(0));
@ -836,7 +844,7 @@ void the_game(
*/ */
FarMesh *farmesh = NULL; FarMesh *farmesh = NULL;
if(g_settings.getBool("enable_farmesh")) if(g_settings->getBool("enable_farmesh"))
{ {
farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed(), &client); farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed(), &client);
} }
@ -919,7 +927,7 @@ void the_game(
float damage_flash_timer = 0; float damage_flash_timer = 0;
s16 farmesh_range = 20*MAP_BLOCKSIZE; s16 farmesh_range = 20*MAP_BLOCKSIZE;
bool invert_mouse = g_settings.getBool("invert_mouse"); bool invert_mouse = g_settings->getBool("invert_mouse");
/* /*
Main loop Main loop
@ -1020,7 +1028,7 @@ void the_game(
*/ */
{ {
float fps_max = g_settings.getFloat("fps_max"); float fps_max = g_settings->getFloat("fps_max");
u32 frametime_min = 1000./fps_max; u32 frametime_min = 1000./fps_max;
if(busytime_u32 < frametime_min) if(busytime_u32 < frametime_min)
@ -1133,14 +1141,14 @@ void the_game(
Profiler Profiler
*/ */
float profiler_print_interval = float profiler_print_interval =
g_settings.getFloat("profiler_print_interval"); g_settings->getFloat("profiler_print_interval");
if(profiler_print_interval != 0) if(profiler_print_interval != 0)
{ {
if(m_profiler_interval.step(0.030, profiler_print_interval)) if(m_profiler_interval.step(0.030, profiler_print_interval))
{ {
dstream<<"Profiler:"<<std::endl; dstream<<"Profiler:"<<std::endl;
g_profiler.print(dstream); g_profiler->print(dstream);
g_profiler.clear(); g_profiler->clear();
} }
} }
@ -1215,40 +1223,40 @@ void the_game(
} }
else if(input->wasKeyDown(getKeySetting("keymap_freemove"))) else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
{ {
if(g_settings.getBool("free_move")) if(g_settings->getBool("free_move"))
{ {
g_settings.set("free_move","false"); g_settings->set("free_move","false");
chat_lines.push_back(ChatLine(L"free_move disabled")); chat_lines.push_back(ChatLine(L"free_move disabled"));
} }
else else
{ {
g_settings.set("free_move","true"); g_settings->set("free_move","true");
chat_lines.push_back(ChatLine(L"free_move enabled")); chat_lines.push_back(ChatLine(L"free_move enabled"));
} }
} }
else if(input->wasKeyDown(getKeySetting("keymap_fastmove"))) else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
{ {
if(g_settings.getBool("fast_move")) if(g_settings->getBool("fast_move"))
{ {
g_settings.set("fast_move","false"); g_settings->set("fast_move","false");
chat_lines.push_back(ChatLine(L"fast_move disabled")); chat_lines.push_back(ChatLine(L"fast_move disabled"));
} }
else else
{ {
g_settings.set("fast_move","true"); g_settings->set("fast_move","true");
chat_lines.push_back(ChatLine(L"fast_move enabled")); chat_lines.push_back(ChatLine(L"fast_move enabled"));
} }
} }
else if(input->wasKeyDown(getKeySetting("keymap_frametime_graph"))) else if(input->wasKeyDown(getKeySetting("keymap_frametime_graph")))
{ {
if(g_settings.getBool("frametime_graph")) if(g_settings->getBool("frametime_graph"))
{ {
g_settings.set("frametime_graph","false"); g_settings->set("frametime_graph","false");
chat_lines.push_back(ChatLine(L"frametime_graph disabled")); chat_lines.push_back(ChatLine(L"frametime_graph disabled"));
} }
else else
{ {
g_settings.set("frametime_graph","true"); g_settings->set("frametime_graph","true");
chat_lines.push_back(ChatLine(L"frametime_graph enabled")); chat_lines.push_back(ChatLine(L"frametime_graph enabled"));
} }
} }
@ -1258,7 +1266,7 @@ void the_game(
if (image) { if (image) {
irr::c8 filename[256]; irr::c8 filename[256];
snprintf(filename, 256, "%s/screenshot_%u.png", snprintf(filename, 256, "%s/screenshot_%u.png",
g_settings.get("screenshot_path").c_str(), g_settings->get("screenshot_path").c_str(),
device->getTimer()->getRealTime()); device->getTimer()->getRealTime());
if (driver->writeImageToFile(image, filename)) { if (driver->writeImageToFile(image, filename)) {
std::wstringstream sstr; std::wstringstream sstr;
@ -1907,7 +1915,7 @@ void the_game(
Fog Fog
*/ */
if(g_settings.getBool("enable_fog") == true) if(g_settings->getBool("enable_fog") == true)
{ {
f32 range; f32 range;
if(farmesh) if(farmesh)
@ -2180,7 +2188,7 @@ void the_game(
/* /*
Frametime log Frametime log
*/ */
if(g_settings.getBool("frametime_graph") == true) if(g_settings->getBool("frametime_graph") == true)
{ {
s32 x = 10; s32 x = 10;
for(core::list<float>::Iterator for(core::list<float>::Iterator

@ -22,6 +22,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "constants.h" #include "constants.h"
#include "keycode.h" #include "keycode.h"
#include "strfnd.h" #include "strfnd.h"
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
void drawInventoryItem(video::IVideoDriver *driver, void drawInventoryItem(video::IVideoDriver *driver,
gui::IGUIFont *font, gui::IGUIFont *font,

@ -24,6 +24,12 @@
#include "serialization.h" #include "serialization.h"
#include "main.h" #include "main.h"
#include <string> #include <string>
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
#include "settings.h"
GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env, GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr) : gui::IGUIElement* parent, s32 id, IMenuManager *menumgr) :
@ -340,20 +346,20 @@ void GUIKeyChangeMenu::drawMenu()
bool GUIKeyChangeMenu::acceptInput() bool GUIKeyChangeMenu::acceptInput()
{ {
g_settings.set("keymap_forward", key_forward.sym()); g_settings->set("keymap_forward", key_forward.sym());
g_settings.set("keymap_backward", key_backward.sym()); g_settings->set("keymap_backward", key_backward.sym());
g_settings.set("keymap_left", key_left.sym()); g_settings->set("keymap_left", key_left.sym());
g_settings.set("keymap_right", key_right.sym()); g_settings->set("keymap_right", key_right.sym());
g_settings.set("keymap_jump", key_jump.sym()); g_settings->set("keymap_jump", key_jump.sym());
g_settings.set("keymap_sneak", key_sneak.sym()); g_settings->set("keymap_sneak", key_sneak.sym());
g_settings.set("keymap_inventory", key_inventory.sym()); g_settings->set("keymap_inventory", key_inventory.sym());
g_settings.set("keymap_chat", key_chat.sym()); g_settings->set("keymap_chat", key_chat.sym());
g_settings.set("keymap_cmd", key_cmd.sym()); g_settings->set("keymap_cmd", key_cmd.sym());
g_settings.set("keymap_rangeselect", key_range.sym()); g_settings->set("keymap_rangeselect", key_range.sym());
g_settings.set("keymap_freemove", key_fly.sym()); g_settings->set("keymap_freemove", key_fly.sym());
g_settings.set("keymap_fastmove", key_fast.sym()); g_settings->set("keymap_fastmove", key_fast.sym());
g_settings.set("keymap_special1", key_use.sym()); g_settings->set("keymap_special1", key_use.sym());
g_settings.set("keymap_print_debug_stacks", key_dump.sym()); g_settings->set("keymap_print_debug_stacks", key_dump.sym());
clearKeyCache(); clearKeyCache();
return true; return true;
} }

@ -22,7 +22,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "debug.h" #include "debug.h"
#include "serialization.h" #include "serialization.h"
#include <string> #include <string>
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
#include "gettext.h" #include "gettext.h"

@ -21,6 +21,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "debug.h" #include "debug.h"
#include "serialization.h" #include "serialization.h"
#include <string> #include <string>
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
#include "gettext.h" #include "gettext.h"

@ -20,6 +20,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "debug.h" #include "debug.h"
#include "serialization.h" #include "serialization.h"
#include <string> #include <string>
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
#include "gettext.h" #include "gettext.h"

@ -23,6 +23,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "porting.h" #include "porting.h"
#include "config.h" #include "config.h"
#include "main.h" #include "main.h"
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
#include "gettext.h" #include "gettext.h"

@ -21,6 +21,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "debug.h" #include "debug.h"
#include "serialization.h" #include "serialization.h"
#include <string> #include <string>
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
#include "gettext.h" #include "gettext.h"

@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "keycode.h" #include "keycode.h"
#include "main.h" // For g_settings #include "main.h" // For g_settings
#include "exceptions.h" #include "exceptions.h"
#include "settings.h"
class UnknownKeycode : public BaseException class UnknownKeycode : public BaseException
{ {
@ -334,7 +335,7 @@ KeyPress getKeySetting(const char *settingname)
if(n) if(n)
return n->getValue(); return n->getValue();
g_key_setting_cache.insert(settingname, g_key_setting_cache.insert(settingname,
g_settings.get(settingname).c_str()); g_settings->get(settingname).c_str());
return g_key_setting_cache.find(settingname)->getValue(); return g_key_setting_cache.find(settingname)->getValue();
} }

@ -411,10 +411,13 @@ Doing currently:
//#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") //#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif #endif
#include "irrlicht.h" // createDevice
#include "main.h"
#include "mainmenumanager.h"
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <locale.h> #include <locale.h>
#include "main.h"
#include "common_irrlicht.h" #include "common_irrlicht.h"
#include "debug.h" #include "debug.h"
#include "test.h" #include "test.h"
@ -431,8 +434,10 @@ Doing currently:
#include "game.h" #include "game.h"
#include "keycode.h" #include "keycode.h"
#include "tile.h" #include "tile.h"
#include "defaultsettings.h"
#include "gettext.h" #include "gettext.h"
#include "settings.h"
#include "profiler.h"
// This makes textures // This makes textures
ITextureSource *g_texturesource = NULL; ITextureSource *g_texturesource = NULL;
@ -441,25 +446,23 @@ ITextureSource *g_texturesource = NULL;
Settings. Settings.
These are loaded from the config file. These are loaded from the config file.
*/ */
Settings main_settings;
Settings g_settings; Settings *g_settings = &main_settings;
// This is located in defaultsettings.cpp
extern void set_default_settings();
// Global profiler // Global profiler
Profiler g_profiler; Profiler main_profiler;
Profiler *g_profiler = &main_profiler;
/* /*
Random stuff Random stuff
*/ */
/* /*
GUI Stuff mainmenumanager.h
*/ */
gui::IGUIEnvironment* guienv = NULL; gui::IGUIEnvironment* guienv = NULL;
gui::IGUIStaticText *guiroot = NULL; gui::IGUIStaticText *guiroot = NULL;
MainMenuManager g_menumgr; MainMenuManager g_menumgr;
bool noMenuActive() bool noMenuActive()
@ -468,7 +471,6 @@ bool noMenuActive()
} }
// Passed to menus to allow disconnecting and exiting // Passed to menus to allow disconnecting and exiting
MainGameCallback *g_gamecallback = NULL; MainGameCallback *g_gamecallback = NULL;
/* /*
@ -1190,7 +1192,7 @@ int main(int argc, char *argv[])
*/ */
// Initialize default settings // Initialize default settings
set_default_settings(); set_default_settings(g_settings);
// Initialize sockets // Initialize sockets
sockets_init(); sockets_init();
@ -1205,7 +1207,7 @@ int main(int argc, char *argv[])
if(cmd_args.exists("config")) if(cmd_args.exists("config"))
{ {
bool r = g_settings.readConfigFile(cmd_args.get("config").c_str()); bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
if(r == false) if(r == false)
{ {
dstream<<"Could not read configuration from \"" dstream<<"Could not read configuration from \""
@ -1224,7 +1226,7 @@ int main(int argc, char *argv[])
for(u32 i=0; i<filenames.size(); i++) for(u32 i=0; i<filenames.size(); i++)
{ {
bool r = g_settings.readConfigFile(filenames[i].c_str()); bool r = g_settings->readConfigFile(filenames[i].c_str());
if(r) if(r)
{ {
configpath = filenames[i]; configpath = filenames[i];
@ -1275,8 +1277,8 @@ int main(int argc, char *argv[])
u16 port = 30000; u16 port = 30000;
if(cmd_args.exists("port")) if(cmd_args.exists("port"))
port = cmd_args.getU16("port"); port = cmd_args.getU16("port");
else if(g_settings.exists("port")) else if(g_settings->exists("port"))
port = g_settings.getU16("port"); port = g_settings->getU16("port");
if(port == 0) if(port == 0)
port = 30000; port = 30000;
@ -1284,8 +1286,8 @@ int main(int argc, char *argv[])
std::string map_dir = porting::path_userdata+"/world"; std::string map_dir = porting::path_userdata+"/world";
if(cmd_args.exists("map-dir")) if(cmd_args.exists("map-dir"))
map_dir = cmd_args.get("map-dir"); map_dir = cmd_args.get("map-dir");
else if(g_settings.exists("map-dir")) else if(g_settings->exists("map-dir"))
map_dir = g_settings.get("map-dir"); map_dir = g_settings->get("map-dir");
// Run dedicated server if asked to // Run dedicated server if asked to
if(cmd_args.getFlag("server")) if(cmd_args.getFlag("server"))
@ -1319,10 +1321,10 @@ int main(int argc, char *argv[])
} }
else else
{ {
address = g_settings.get("address"); address = g_settings->get("address");
} }
std::string playername = g_settings.get("name"); std::string playername = g_settings->get("name");
/* /*
Device initialization Device initialization
@ -1331,14 +1333,14 @@ int main(int argc, char *argv[])
// Resolution selection // Resolution selection
bool fullscreen = false; bool fullscreen = false;
u16 screenW = g_settings.getU16("screenW"); u16 screenW = g_settings->getU16("screenW");
u16 screenH = g_settings.getU16("screenH"); u16 screenH = g_settings->getU16("screenH");
// Determine driver // Determine driver
video::E_DRIVER_TYPE driverType; video::E_DRIVER_TYPE driverType;
std::string driverstring = g_settings.get("video_driver"); std::string driverstring = g_settings->get("video_driver");
if(driverstring == "null") if(driverstring == "null")
driverType = video::EDT_NULL; driverType = video::EDT_NULL;
@ -1397,7 +1399,7 @@ int main(int argc, char *argv[])
device->setResizable(true); device->setResizable(true);
bool random_input = g_settings.getBool("random_input") bool random_input = g_settings->getBool("random_input")
|| cmd_args.getFlag("random-input"); || cmd_args.getFlag("random-input");
InputHandler *input = NULL; InputHandler *input = NULL;
if(random_input) if(random_input)
@ -1508,10 +1510,10 @@ int main(int argc, char *argv[])
menudata.address = narrow_to_wide(address); menudata.address = narrow_to_wide(address);
menudata.name = narrow_to_wide(playername); menudata.name = narrow_to_wide(playername);
menudata.port = narrow_to_wide(itos(port)); menudata.port = narrow_to_wide(itos(port));
menudata.fancy_trees = g_settings.getBool("new_style_leaves"); menudata.fancy_trees = g_settings->getBool("new_style_leaves");
menudata.smooth_lighting = g_settings.getBool("smooth_lighting"); menudata.smooth_lighting = g_settings->getBool("smooth_lighting");
menudata.creative_mode = g_settings.getBool("creative_mode"); menudata.creative_mode = g_settings->getBool("creative_mode");
menudata.enable_damage = g_settings.getBool("enable_damage"); menudata.enable_damage = g_settings->getBool("enable_damage");
GUIMainMenu *menu = GUIMainMenu *menu =
new GUIMainMenu(guienv, guiroot, -1, new GUIMainMenu(guienv, guiroot, -1,
@ -1580,10 +1582,10 @@ int main(int argc, char *argv[])
int newport = stoi(wide_to_narrow(menudata.port)); int newport = stoi(wide_to_narrow(menudata.port));
if(newport != 0) if(newport != 0)
port = newport; port = newport;
g_settings.set("new_style_leaves", itos(menudata.fancy_trees)); g_settings->set("new_style_leaves", itos(menudata.fancy_trees));
g_settings.set("smooth_lighting", itos(menudata.smooth_lighting)); g_settings->set("smooth_lighting", itos(menudata.smooth_lighting));
g_settings.set("creative_mode", itos(menudata.creative_mode)); g_settings->set("creative_mode", itos(menudata.creative_mode));
g_settings.set("enable_damage", itos(menudata.enable_damage)); g_settings->set("enable_damage", itos(menudata.enable_damage));
// NOTE: These are now checked server side; no need to do it // NOTE: These are now checked server side; no need to do it
// here, so let's not do it here. // here, so let's not do it here.
@ -1602,12 +1604,12 @@ int main(int argc, char *argv[])
}*/ }*/
// Save settings // Save settings
g_settings.set("name", playername); g_settings->set("name", playername);
g_settings.set("address", address); g_settings->set("address", address);
g_settings.set("port", itos(port)); g_settings->set("port", itos(port));
// Update configuration file // Update configuration file
if(configpath != "") if(configpath != "")
g_settings.updateConfigFile(configpath.c_str()); g_settings->updateConfigFile(configpath.c_str());
// Continue to game // Continue to game
break; break;

@ -21,16 +21,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MAIN_HEADER #define MAIN_HEADER
// Settings // Settings
#include "utility.h" class Settings;
extern Settings g_settings; extern Settings *g_settings;
// This makes and maps textures // This makes and maps textures
class ITextureSource; class ITextureSource;
extern ITextureSource *g_texturesource; extern ITextureSource *g_texturesource;
// Global profiler // Global profiler
#include "profiler.h" class Profiler;
extern Profiler g_profiler; extern Profiler *g_profiler;
// Debug streams // Debug streams
@ -50,105 +50,5 @@ extern std::ostream *derr_server_ptr;
#define dout_server (*dout_server_ptr) #define dout_server (*dout_server_ptr)
#define derr_server (*derr_server_ptr) #define derr_server (*derr_server_ptr)
/*
All kinds of stuff that needs to be exposed from main.cpp
*/
#include "modalMenu.h"
#include "guiPauseMenu.h" //For IGameCallback
extern gui::IGUIEnvironment* guienv;
extern gui::IGUIStaticText *guiroot;
// Handler for the modal menus
class MainMenuManager : public IMenuManager
{
public:
virtual void createdMenu(GUIModalMenu *menu)
{
for(core::list<GUIModalMenu*>::Iterator
i = m_stack.begin();
i != m_stack.end(); i++)
{
assert(*i != menu);
}
if(m_stack.size() != 0)
(*m_stack.getLast())->setVisible(false);
m_stack.push_back(menu);
}
virtual void deletingMenu(GUIModalMenu *menu)
{
// Remove all entries if there are duplicates
bool removed_entry;
do{
removed_entry = false;
for(core::list<GUIModalMenu*>::Iterator
i = m_stack.begin();
i != m_stack.end(); i++)
{
if(*i == menu)
{
m_stack.erase(i);
removed_entry = true;
break;
}
}
}while(removed_entry);
/*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
assert(*i == menu);
m_stack.erase(i);*/
if(m_stack.size() != 0)
(*m_stack.getLast())->setVisible(true);
}
u32 menuCount()
{
return m_stack.size();
}
core::list<GUIModalMenu*> m_stack;
};
extern MainMenuManager g_menumgr;
extern bool noMenuActive();
class MainGameCallback : public IGameCallback
{
public:
MainGameCallback(IrrlichtDevice *a_device):
disconnect_requested(false),
changepassword_requested(false),
device(a_device)
{
}
virtual void exitToOS()
{
device->closeDevice();
}
virtual void disconnect()
{
disconnect_requested = true;
}
virtual void changePassword()
{
changepassword_requested = true;
}
bool disconnect_requested;
bool changepassword_requested;
IrrlichtDevice *device;
};
extern MainGameCallback *g_gamecallback;
#endif #endif

124
src/mainmenumanager.h Normal file

@ -0,0 +1,124 @@
/*
Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MAINMENUMANAGER_HEADER
#define MAINMENUMANAGER_HEADER
/*
All kinds of stuff that needs to be exposed from main.cpp
*/
#include "debug.h" // assert
#include "modalMenu.h"
#include "guiPauseMenu.h" //For IGameCallback
extern gui::IGUIEnvironment* guienv;
extern gui::IGUIStaticText *guiroot;
// Handler for the modal menus
class MainMenuManager : public IMenuManager
{
public:
virtual void createdMenu(GUIModalMenu *menu)
{
for(core::list<GUIModalMenu*>::Iterator
i = m_stack.begin();
i != m_stack.end(); i++)
{
assert(*i != menu);
}
if(m_stack.size() != 0)
(*m_stack.getLast())->setVisible(false);
m_stack.push_back(menu);
}
virtual void deletingMenu(GUIModalMenu *menu)
{
// Remove all entries if there are duplicates
bool removed_entry;
do{
removed_entry = false;
for(core::list<GUIModalMenu*>::Iterator
i = m_stack.begin();
i != m_stack.end(); i++)
{
if(*i == menu)
{
m_stack.erase(i);
removed_entry = true;
break;
}
}
}while(removed_entry);
/*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
assert(*i == menu);
m_stack.erase(i);*/
if(m_stack.size() != 0)
(*m_stack.getLast())->setVisible(true);
}
u32 menuCount()
{
return m_stack.size();
}
core::list<GUIModalMenu*> m_stack;
};
extern MainMenuManager g_menumgr;
extern bool noMenuActive();
class MainGameCallback : public IGameCallback
{
public:
MainGameCallback(IrrlichtDevice *a_device):
disconnect_requested(false),
changepassword_requested(false),
device(a_device)
{
}
virtual void exitToOS()
{
device->closeDevice();
}
virtual void disconnect()
{
disconnect_requested = true;
}
virtual void changePassword()
{
changepassword_requested = true;
}
bool disconnect_requested;
bool changepassword_requested;
IrrlichtDevice *device;
};
extern MainGameCallback *g_gamecallback;
#endif

@ -29,6 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapgen.h" #include "mapgen.h"
#include "nodemetadata.h" #include "nodemetadata.h"
#include "content_mapnode.h" #include "content_mapnode.h"
#ifndef SERVER
#include <IMaterialRenderer.h>
#endif
#include "settings.h"
/* /*
SQLite format specification: SQLite format specification:
@ -771,7 +775,7 @@ void Map::updateLighting(enum LightBank bank,
generation for testing or whatever generation for testing or whatever
*/ */
#if 0 #if 0
//if(g_settings.get("")) //if(g_settings->get(""))
{ {
core::map<v3s16, MapBlock*>::Iterator i; core::map<v3s16, MapBlock*>::Iterator i;
i = blocks_to_update.getIterator(); i = blocks_to_update.getIterator();
@ -1897,7 +1901,7 @@ ServerMap::ServerMap(std::string savedir):
//m_chunksize = 8; // Takes a few seconds //m_chunksize = 8; // Takes a few seconds
if (g_settings.get("fixed_map_seed").empty()) if (g_settings->get("fixed_map_seed").empty())
{ {
m_seed = (((u64)(myrand()%0xffff)<<0) m_seed = (((u64)(myrand()%0xffff)<<0)
+ ((u64)(myrand()%0xffff)<<16) + ((u64)(myrand()%0xffff)<<16)
@ -1906,7 +1910,7 @@ ServerMap::ServerMap(std::string savedir):
} }
else else
{ {
m_seed = g_settings.getU64("fixed_map_seed"); m_seed = g_settings->getU64("fixed_map_seed");
} }
/* /*
@ -2044,7 +2048,7 @@ ServerMap::~ServerMap()
void ServerMap::initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos) void ServerMap::initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos)
{ {
bool enable_mapgen_debug_info = g_settings.getBool("enable_mapgen_debug_info"); bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
if(enable_mapgen_debug_info) if(enable_mapgen_debug_info)
dstream<<"initBlockMake(): ("<<blockpos.X<<","<<blockpos.Y<<"," dstream<<"initBlockMake(): ("<<blockpos.X<<","<<blockpos.Y<<","
<<blockpos.Z<<")"<<std::endl; <<blockpos.Z<<")"<<std::endl;
@ -2139,7 +2143,7 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
return NULL; return NULL;
} }
bool enable_mapgen_debug_info = g_settings.getBool("enable_mapgen_debug_info"); bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
/*dstream<<"Resulting vmanip:"<<std::endl; /*dstream<<"Resulting vmanip:"<<std::endl;
data->vmanip.print(dstream);*/ data->vmanip.print(dstream);*/
@ -2394,7 +2398,7 @@ MapBlock * ServerMap::generateBlock(
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")" <<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<std::endl;*/ <<std::endl;*/
bool enable_mapgen_debug_info = g_settings.getBool("enable_mapgen_debug_info"); bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
TimeTaker timer("generateBlock"); TimeTaker timer("generateBlock");
@ -3946,7 +3950,7 @@ void ClientMap::renderPostFx()
// - If the player is in liquid, draw a semi-transparent overlay. // - If the player is in liquid, draw a semi-transparent overlay.
ContentFeatures& features = content_features(n); ContentFeatures& features = content_features(n);
video::SColor post_effect_color = features.post_effect_color; video::SColor post_effect_color = features.post_effect_color;
if(features.solidness == 2 && g_settings.getBool("free_move") == false) if(features.solidness == 2 && g_settings->getBool("free_move") == false)
{ {
post_effect_color = video::SColor(255, 0, 0, 0); post_effect_color = video::SColor(255, 0, 0, 0);
} }

@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "map.h" #include "map.h"
#include "main.h" // For g_settings and g_texturesource #include "main.h" // For g_settings and g_texturesource
#include "content_mapblock.h" #include "content_mapblock.h"
#include "settings.h"
void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block) void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block)
{ {
@ -619,9 +620,9 @@ scene::SMesh* makeMapBlockMesh(MeshMakeData *data)
/* /*
Some settings Some settings
*/ */
//bool new_style_water = g_settings.getBool("new_style_water"); //bool new_style_water = g_settings->getBool("new_style_water");
//bool new_style_leaves = g_settings.getBool("new_style_leaves"); //bool new_style_leaves = g_settings->getBool("new_style_leaves");
bool smooth_lighting = g_settings.getBool("smooth_lighting"); bool smooth_lighting = g_settings->getBool("smooth_lighting");
/* /*
We are including the faces of the trailing edges of the block. We are including the faces of the trailing edges of the block.

@ -346,8 +346,10 @@ class SignObject : public MapBlockObject
public: public:
// The constructor of every MapBlockObject should be like this // The constructor of every MapBlockObject should be like this
SignObject(MapBlock *block, s16 id, v3f pos): SignObject(MapBlock *block, s16 id, v3f pos):
MapBlockObject(block, id, pos), MapBlockObject(block, id, pos)
m_node(NULL) #ifndef SERVER
,m_node(NULL)
#endif
{ {
m_selection_box = new core::aabbox3d<f32> m_selection_box = new core::aabbox3d<f32>
(-BS*0.4,-BS*0.5,-BS*0.4, BS*0.4,BS*0.5,BS*0.4); (-BS*0.4,-BS*0.5,-BS*0.4, BS*0.4,BS*0.5,BS*0.4);
@ -534,7 +536,9 @@ public:
} }
protected: protected:
#ifndef SERVER
scene::IMeshSceneNode *m_node; scene::IMeshSceneNode *m_node;
#endif
std::string m_text; std::string m_text;
f32 m_yaw; f32 m_yaw;
}; };
@ -543,8 +547,10 @@ class RatObject : public MovingObject
{ {
public: public:
RatObject(MapBlock *block, s16 id, v3f pos): RatObject(MapBlock *block, s16 id, v3f pos):
MovingObject(block, id, pos), MovingObject(block, id, pos)
m_node(NULL) #ifndef SERVER
,m_node(NULL)
#endif
{ {
m_collision_box = new core::aabbox3d<f32> m_collision_box = new core::aabbox3d<f32>
(-BS*0.3,-BS*.25,-BS*0.3, BS*0.3,BS*0.25,BS*0.3); (-BS*0.3,-BS*.25,-BS*0.3, BS*0.3,BS*0.25,BS*0.3);
@ -681,15 +687,19 @@ public:
void updateNodePos() void updateNodePos()
{ {
#ifndef SERVER
if(m_node == NULL) if(m_node == NULL)
return; return;
m_node->setPosition(getAbsoluteShowPos()); m_node->setPosition(getAbsoluteShowPos());
m_node->setRotation(v3f(0, -m_yaw+180, 0)); m_node->setRotation(v3f(0, -m_yaw+180, 0));
#endif
} }
protected: protected:
#ifndef SERVER
scene::IMeshSceneNode *m_node; scene::IMeshSceneNode *m_node;
#endif
float m_yaw; float m_yaw;
float m_counter1; float m_counter1;
@ -708,8 +718,10 @@ class ItemObject : public MapBlockObject
public: public:
// The constructor of every MapBlockObject should be like this // The constructor of every MapBlockObject should be like this
ItemObject(MapBlock *block, s16 id, v3f pos): ItemObject(MapBlock *block, s16 id, v3f pos):
MapBlockObject(block, id, pos), MapBlockObject(block, id, pos)
m_node(NULL) #ifndef SERVER
,m_node(NULL)
#endif
{ {
/*m_selection_box = new core::aabbox3d<f32> /*m_selection_box = new core::aabbox3d<f32>
(-BS*0.4,-BS*0.5,-BS*0.4, BS*0.4,BS*0.5,BS*0.4);*/ (-BS*0.4,-BS*0.5,-BS*0.4, BS*0.4,BS*0.5,BS*0.4);*/
@ -855,7 +867,9 @@ public:
} }
protected: protected:
#ifndef SERVER
scene::IMeshSceneNode *m_node; scene::IMeshSceneNode *m_node;
#endif
std::string m_itemstring; std::string m_itemstring;
f32 m_yaw; f32 m_yaw;
}; };
@ -868,7 +882,9 @@ class PlayerObject : public MovingObject
public: public:
PlayerObject(MapBlock *block, s16 id, v3f pos): PlayerObject(MapBlock *block, s16 id, v3f pos):
MovingObject(block, id, pos), MovingObject(block, id, pos),
#ifndef SERVER
m_node(NULL), m_node(NULL),
#endif
m_yaw(0) m_yaw(0)
{ {
m_collision_box = new core::aabbox3d<f32> m_collision_box = new core::aabbox3d<f32>
@ -954,15 +970,19 @@ public:
void updateNodePos() void updateNodePos()
{ {
#ifndef SERVER
if(m_node == NULL) if(m_node == NULL)
return; return;
m_node->setPosition(getAbsoluteShowPos()); m_node->setPosition(getAbsoluteShowPos());
m_node->setRotation(v3f(0, -m_yaw+180, 0)); m_node->setRotation(v3f(0, -m_yaw+180, 0));
#endif
} }
protected: protected:
#ifndef SERVER
scene::IMeshSceneNode *m_node; scene::IMeshSceneNode *m_node;
#endif
float m_yaw; float m_yaw;
v3f m_oldpos; v3f m_oldpos;
@ -985,6 +1005,13 @@ struct DistanceSortedObject
} }
}; };
namespace irr{
namespace scene{
class ISceneManager;
}
}
using namespace irr;
class MapBlockObjectList class MapBlockObjectList
{ {
public: public:

@ -19,7 +19,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common_irrlicht.h" #include "common_irrlicht.h"
#include "mapnode.h" #include "mapnode.h"
#ifndef SERVER
#include "tile.h" #include "tile.h"
#endif
#include "porting.h" #include "porting.h"
#include <string> #include <string>
#include "mineral.h" #include "mineral.h"
@ -31,10 +33,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
ContentFeatures::~ContentFeatures() ContentFeatures::~ContentFeatures()
{ {
delete initial_metadata; delete initial_metadata;
#ifndef SERVER
delete special_material; delete special_material;
delete special_atlas; delete special_atlas;
#endif
} }
#ifndef SERVER
void ContentFeatures::setTexture(u16 i, std::string name, u8 alpha) void ContentFeatures::setTexture(u16 i, std::string name, u8 alpha)
{ {
if(g_texturesource) if(g_texturesource)
@ -81,6 +86,7 @@ void ContentFeatures::setInventoryTextureCube(std::string top,
imgname_full += right; imgname_full += right;
inventory_texture = g_texturesource->getTextureRaw(imgname_full); inventory_texture = g_texturesource->getTextureRaw(imgname_full);
} }
#endif
struct ContentFeatures g_content_features[MAX_CONTENT+1]; struct ContentFeatures g_content_features[MAX_CONTENT+1];
@ -119,6 +125,7 @@ void init_mapnode()
Initialize content feature table Initialize content feature table
*/ */
#ifndef SERVER
/* /*
Set initial material type to same in all tiles, so that the Set initial material type to same in all tiles, so that the
same material can be used in more stuff. same material can be used in more stuff.
@ -140,6 +147,7 @@ void init_mapnode()
for(u16 j=0; j<6; j++) for(u16 j=0; j<6; j++)
f->tiles[j].material_type = initial_material_type; f->tiles[j].material_type = initial_material_type;
} }
#endif
/* /*
Initially set every block to be shown as an unknown block. Initially set every block to be shown as an unknown block.
@ -184,6 +192,7 @@ v3s16 facedir_rotate(u8 facedir, v3s16 dir)
return newdir; return newdir;
} }
#ifndef SERVER
TileSpec MapNode::getTile(v3s16 dir) TileSpec MapNode::getTile(v3s16 dir)
{ {
if(content_features(*this).param_type == CPT_FACEDIR_SIMPLE) if(content_features(*this).param_type == CPT_FACEDIR_SIMPLE)
@ -235,6 +244,7 @@ TileSpec MapNode::getTile(v3s16 dir)
return spec; return spec;
} }
#endif
u8 MapNode::getMineral() u8 MapNode::getMineral()
{ {

@ -23,11 +23,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <iostream> #include <iostream>
#include "common_irrlicht.h" #include "common_irrlicht.h"
#include "light.h" #include "light.h"
#include "utility.h"
#include "exceptions.h" #include "exceptions.h"
#include "serialization.h" #include "serialization.h"
#include "tile.h"
#include "materials.h" #include "materials.h"
#ifndef SERVER
#include "tile.h"
#endif
/* /*
Naming scheme: Naming scheme:
@ -101,9 +102,7 @@ class NodeMetadata;
struct ContentFeatures struct ContentFeatures
{ {
// Type of MapNode::param1 #ifndef SERVER
ContentParamType param_type;
/* /*
0: up 0: up
1: down 1: down
@ -116,6 +115,17 @@ struct ContentFeatures
video::ITexture *inventory_texture; video::ITexture *inventory_texture;
// Used currently for flowing liquids
u8 vertex_alpha;
// Post effect color, drawn when the camera is inside the node.
video::SColor post_effect_color;
// Special irrlicht material, used sometimes
video::SMaterial *special_material;
AtlasPointer *special_atlas;
#endif
// Type of MapNode::param1
ContentParamType param_type;
// True for all ground-like things like stone and mud, false for eg. trees // True for all ground-like things like stone and mud, false for eg. trees
bool is_ground_content; bool is_ground_content;
bool light_propagates; bool light_propagates;
@ -162,13 +172,6 @@ struct ContentFeatures
// 1 giving almost instantaneous propagation and 7 being // 1 giving almost instantaneous propagation and 7 being
// the slowest possible // the slowest possible
u8 liquid_viscosity; u8 liquid_viscosity;
// Used currently for flowing liquids
u8 vertex_alpha;
// Post effect color, drawn when the camera is inside the node.
video::SColor post_effect_color;
// Special irrlicht material, used sometimes
video::SMaterial *special_material;
AtlasPointer *special_atlas;
// Amount of light the node emits // Amount of light the node emits
u8 light_source; u8 light_source;
@ -182,8 +185,15 @@ struct ContentFeatures
void reset() void reset()
{ {
param_type = CPT_NONE; #ifndef SERVER
inventory_texture = NULL; inventory_texture = NULL;
vertex_alpha = 255;
post_effect_color = video::SColor(0, 0, 0, 0);
special_material = NULL;
special_atlas = NULL;
#endif
param_type = CPT_NONE;
is_ground_content = false; is_ground_content = false;
light_propagates = false; light_propagates = false;
sunlight_propagates = false; sunlight_propagates = false;
@ -202,10 +212,6 @@ struct ContentFeatures
liquid_alternative_flowing = CONTENT_IGNORE; liquid_alternative_flowing = CONTENT_IGNORE;
liquid_alternative_source = CONTENT_IGNORE; liquid_alternative_source = CONTENT_IGNORE;
liquid_viscosity = 0; liquid_viscosity = 0;
vertex_alpha = 255;
post_effect_color = video::SColor(0, 0, 0, 0);
special_material = NULL;
special_atlas = NULL;
light_source = 0; light_source = 0;
digging_properties.clear(); digging_properties.clear();
damage_per_second = 0; damage_per_second = 0;
@ -222,6 +228,12 @@ struct ContentFeatures
Quickhands for simple materials Quickhands for simple materials
*/ */
#ifdef SERVER
void setTexture(u16 i, std::string name, u8 alpha=255)
{}
void setAllTextures(std::string name, u8 alpha=255)
{}
#else
void setTexture(u16 i, std::string name, u8 alpha=255); void setTexture(u16 i, std::string name, u8 alpha=255);
void setAllTextures(std::string name, u8 alpha=255) void setAllTextures(std::string name, u8 alpha=255)
@ -233,7 +245,9 @@ struct ContentFeatures
// Force inventory texture too // Force inventory texture too
setInventoryTexture(name); setInventoryTexture(name);
} }
#endif
#ifndef SERVER
void setTile(u16 i, const TileSpec &tile) void setTile(u16 i, const TileSpec &tile)
{ {
tiles[i] = tile; tiles[i] = tile;
@ -245,11 +259,20 @@ struct ContentFeatures
setTile(i, tile); setTile(i, tile);
} }
} }
#endif
#ifdef SERVER
void setInventoryTexture(std::string imgname)
{}
void setInventoryTextureCube(std::string top,
std::string left, std::string right)
{}
#else
void setInventoryTexture(std::string imgname); void setInventoryTexture(std::string imgname);
void setInventoryTextureCube(std::string top, void setInventoryTextureCube(std::string top,
std::string left, std::string right); std::string left, std::string right);
#endif
}; };
/* /*
@ -632,6 +655,7 @@ struct MapNode
} }
// In mapnode.cpp // In mapnode.cpp
#ifndef SERVER
/* /*
Get tile of a face of the node. Get tile of a face of the node.
dir: direction of face dir: direction of face
@ -639,6 +663,7 @@ struct MapNode
which must be obeyed so that the texture atlas can be used. which must be obeyed so that the texture atlas can be used.
*/ */
TileSpec getTile(v3s16 dir); TileSpec getTile(v3s16 dir);
#endif
/* /*
Gets mineral content of node, if there is any. Gets mineral content of node, if there is any.

@ -22,7 +22,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "connection.h" #include "connection.h"
#include "constants.h" #include "constants.h"
#include "utility.h" #include "utility.h"
#ifndef SERVER
#include <ITextSceneNode.h>
#endif
#include "settings.h"
Player::Player(): Player::Player():
touching_ground(false), touching_ground(false),
@ -344,7 +347,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
is_frozen = false; is_frozen = false;
// Skip collision detection if a special movement mode is used // Skip collision detection if a special movement mode is used
bool free_move = g_settings.getBool("free_move"); bool free_move = g_settings->getBool("free_move");
if(free_move) if(free_move)
{ {
setPosition(position); setPosition(position);
@ -754,9 +757,9 @@ void LocalPlayer::applyControl(float dtime)
v3f speed = v3f(0,0,0); v3f speed = v3f(0,0,0);
bool free_move = g_settings.getBool("free_move"); bool free_move = g_settings->getBool("free_move");
bool fast_move = g_settings.getBool("fast_move"); bool fast_move = g_settings->getBool("fast_move");
bool continuous_forward = g_settings.getBool("continuous_forward"); bool continuous_forward = g_settings->getBool("continuous_forward");
if(free_move || is_climbing) if(free_move || is_climbing)
{ {

@ -36,6 +36,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_nodemeta.h" #include "content_nodemeta.h"
#include "mapblock.h" #include "mapblock.h"
#include "serverobject.h" #include "serverobject.h"
#include "settings.h"
#include "profiler.h"
#define BLOCK_EMERGE_FLAG_FROMDISK (1<<0) #define BLOCK_EMERGE_FLAG_FROMDISK (1<<0)
@ -107,7 +109,7 @@ void * EmergeThread::Thread()
BEGIN_DEBUG_EXCEPTION_HANDLER BEGIN_DEBUG_EXCEPTION_HANDLER
bool enable_mapgen_debug_info = g_settings.getBool("enable_mapgen_debug_info"); bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
/* /*
Get block info from queue, emerge them and send them Get block info from queue, emerge them and send them
@ -354,7 +356,7 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
} }
// Won't send anything if already sending // Won't send anything if already sending
if(m_blocks_sending.size() >= g_settings.getU16 if(m_blocks_sending.size() >= g_settings->getU16
("max_simultaneous_block_sends_per_client")) ("max_simultaneous_block_sends_per_client"))
{ {
//dstream<<"Not sending any blocks, Queue full."<<std::endl; //dstream<<"Not sending any blocks, Queue full."<<std::endl;
@ -419,7 +421,7 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
//dstream<<"d_start="<<d_start<<std::endl; //dstream<<"d_start="<<d_start<<std::endl;
u16 max_simul_sends_setting = g_settings.getU16 u16 max_simul_sends_setting = g_settings->getU16
("max_simultaneous_block_sends_per_client"); ("max_simultaneous_block_sends_per_client");
u16 max_simul_sends_usually = max_simul_sends_setting; u16 max_simul_sends_usually = max_simul_sends_setting;
@ -429,7 +431,7 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
Decrease send rate if player is building stuff. Decrease send rate if player is building stuff.
*/ */
m_time_from_building += dtime; m_time_from_building += dtime;
if(m_time_from_building < g_settings.getFloat( if(m_time_from_building < g_settings->getFloat(
"full_block_send_enable_min_time_from_building")) "full_block_send_enable_min_time_from_building"))
{ {
max_simul_sends_usually max_simul_sends_usually
@ -450,8 +452,8 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
*/ */
s32 new_nearest_unsent_d = -1; s32 new_nearest_unsent_d = -1;
s16 d_max = g_settings.getS16("max_block_send_distance"); s16 d_max = g_settings->getS16("max_block_send_distance");
s16 d_max_gen = g_settings.getS16("max_block_generate_distance"); s16 d_max_gen = g_settings->getS16("max_block_generate_distance");
// Don't loop very much at a time // Don't loop very much at a time
if(d_max > d_start+1) if(d_max > d_start+1)
@ -735,7 +737,7 @@ queue_full_break:
{ {
m_nothing_to_send_counter++; m_nothing_to_send_counter++;
if((s16)m_nothing_to_send_counter >= if((s16)m_nothing_to_send_counter >=
g_settings.getS16("max_block_send_distance")) g_settings->getS16("max_block_send_distance"))
{ {
// Pause time in seconds // Pause time in seconds
m_nothing_to_send_pause_timer = 1.0; m_nothing_to_send_pause_timer = 1.0;
@ -858,7 +860,7 @@ void RemoteClient::SendObjectData(
v3s16 center_nodepos = floatToInt(playerpos, BS); v3s16 center_nodepos = floatToInt(playerpos, BS);
v3s16 center = getNodeBlockPos(center_nodepos); v3s16 center = getNodeBlockPos(center_nodepos);
s16 d_max = g_settings.getS16("active_object_range"); s16 d_max = g_settings->getS16("active_object_range");
// Number of blocks whose objects were written to bos // Number of blocks whose objects were written to bos
u16 blockcount = 0; u16 blockcount = 0;
@ -1232,7 +1234,7 @@ void Server::AsyncRunStep()
} }
{ {
ScopeProfiler sp(&g_profiler, "Server: selecting and sending " ScopeProfiler sp(g_profiler, "Server: selecting and sending "
"blocks to clients"); "blocks to clients");
// Send blocks to clients // Send blocks to clients
SendBlocks(dtime); SendBlocks(dtime);
@ -1259,14 +1261,14 @@ void Server::AsyncRunStep()
{ {
// Process connection's timeouts // Process connection's timeouts
JMutexAutoLock lock2(m_con_mutex); JMutexAutoLock lock2(m_con_mutex);
ScopeProfiler sp(&g_profiler, "Server: connection timeout processing"); ScopeProfiler sp(g_profiler, "Server: connection timeout processing");
m_con.RunTimeouts(dtime); m_con.RunTimeouts(dtime);
} }
{ {
// This has to be called so that the client list gets synced // This has to be called so that the client list gets synced
// with the peer list of the connection // with the peer list of the connection
ScopeProfiler sp(&g_profiler, "Server: peer change handling"); ScopeProfiler sp(g_profiler, "Server: peer change handling");
handlePeerChanges(); handlePeerChanges();
} }
@ -1277,7 +1279,7 @@ void Server::AsyncRunStep()
JMutexAutoLock envlock(m_env_mutex); JMutexAutoLock envlock(m_env_mutex);
m_time_counter += dtime; m_time_counter += dtime;
f32 speed = g_settings.getFloat("time_speed") * 24000./(24.*3600); f32 speed = g_settings->getFloat("time_speed") * 24000./(24.*3600);
u32 units = (u32)(m_time_counter*speed); u32 units = (u32)(m_time_counter*speed);
m_time_counter -= (f32)units / speed; m_time_counter -= (f32)units / speed;
@ -1292,7 +1294,7 @@ void Server::AsyncRunStep()
m_time_of_day_send_timer -= dtime; m_time_of_day_send_timer -= dtime;
if(m_time_of_day_send_timer < 0.0) if(m_time_of_day_send_timer < 0.0)
{ {
m_time_of_day_send_timer = g_settings.getFloat("time_send_interval"); m_time_of_day_send_timer = g_settings->getFloat("time_send_interval");
//JMutexAutoLock envlock(m_env_mutex); //JMutexAutoLock envlock(m_env_mutex);
JMutexAutoLock conlock(m_con_mutex); JMutexAutoLock conlock(m_con_mutex);
@ -1315,7 +1317,7 @@ void Server::AsyncRunStep()
{ {
JMutexAutoLock lock(m_env_mutex); JMutexAutoLock lock(m_env_mutex);
// Step environment // Step environment
ScopeProfiler sp(&g_profiler, "Server: environment step"); ScopeProfiler sp(g_profiler, "Server: environment step");
m_env.step(dtime); m_env.step(dtime);
} }
@ -1324,9 +1326,9 @@ void Server::AsyncRunStep()
{ {
JMutexAutoLock lock(m_env_mutex); JMutexAutoLock lock(m_env_mutex);
// Run Map's timers and unload unused data // Run Map's timers and unload unused data
ScopeProfiler sp(&g_profiler, "Server: map timer and unload"); ScopeProfiler sp(g_profiler, "Server: map timer and unload");
m_env.getMap().timerUpdate(map_timer_and_unload_dtime, m_env.getMap().timerUpdate(map_timer_and_unload_dtime,
g_settings.getFloat("server_unload_unused_data_timeout")); g_settings->getFloat("server_unload_unused_data_timeout"));
} }
/* /*
@ -1343,7 +1345,7 @@ void Server::AsyncRunStep()
JMutexAutoLock lock(m_env_mutex); JMutexAutoLock lock(m_env_mutex);
ScopeProfiler sp(&g_profiler, "Server: liquid transform"); ScopeProfiler sp(g_profiler, "Server: liquid transform");
core::map<v3s16, MapBlock*> modified_blocks; core::map<v3s16, MapBlock*> modified_blocks;
m_env.getMap().transformLiquids(modified_blocks); m_env.getMap().transformLiquids(modified_blocks);
@ -1409,7 +1411,7 @@ void Server::AsyncRunStep()
} }
} }
//if(g_settings.getBool("enable_experimental")) //if(g_settings->getBool("enable_experimental"))
{ {
/* /*
@ -1420,7 +1422,7 @@ void Server::AsyncRunStep()
JMutexAutoLock envlock(m_env_mutex); JMutexAutoLock envlock(m_env_mutex);
JMutexAutoLock conlock(m_con_mutex); JMutexAutoLock conlock(m_con_mutex);
ScopeProfiler sp(&g_profiler, "Server: checking added and deleted objects"); ScopeProfiler sp(g_profiler, "Server: checking added and deleted objects");
// Radius inside which objects are active // Radius inside which objects are active
s16 radius = 32; s16 radius = 32;
@ -1568,7 +1570,7 @@ void Server::AsyncRunStep()
JMutexAutoLock envlock(m_env_mutex); JMutexAutoLock envlock(m_env_mutex);
JMutexAutoLock conlock(m_con_mutex); JMutexAutoLock conlock(m_con_mutex);
ScopeProfiler sp(&g_profiler, "Server: sending object messages"); ScopeProfiler sp(g_profiler, "Server: sending object messages");
// Key = object id // Key = object id
// Value = data sent by object // Value = data sent by object
@ -1804,12 +1806,12 @@ void Server::AsyncRunStep()
{ {
float &counter = m_objectdata_timer; float &counter = m_objectdata_timer;
counter += dtime; counter += dtime;
if(counter >= g_settings.getFloat("objectdata_interval")) if(counter >= g_settings->getFloat("objectdata_interval"))
{ {
JMutexAutoLock lock1(m_env_mutex); JMutexAutoLock lock1(m_env_mutex);
JMutexAutoLock lock2(m_con_mutex); JMutexAutoLock lock2(m_con_mutex);
ScopeProfiler sp(&g_profiler, "Server: sending mbo positions"); ScopeProfiler sp(g_profiler, "Server: sending mbo positions");
SendObjectData(counter); SendObjectData(counter);
@ -1836,11 +1838,11 @@ void Server::AsyncRunStep()
{ {
float &counter = m_savemap_timer; float &counter = m_savemap_timer;
counter += dtime; counter += dtime;
if(counter >= g_settings.getFloat("server_map_save_interval")) if(counter >= g_settings->getFloat("server_map_save_interval"))
{ {
counter = 0.0; counter = 0.0;
ScopeProfiler sp(&g_profiler, "Server: saving stuff"); ScopeProfiler sp(g_profiler, "Server: saving stuff");
// Auth stuff // Auth stuff
if(m_authmanager.isModified()) if(m_authmanager.isModified())
@ -1855,10 +1857,10 @@ void Server::AsyncRunStep()
/*// Unload unused data (delete from memory) /*// Unload unused data (delete from memory)
m_env.getMap().unloadUnusedData( m_env.getMap().unloadUnusedData(
g_settings.getFloat("server_unload_unused_sectors_timeout")); g_settings->getFloat("server_unload_unused_sectors_timeout"));
*/ */
/*u32 deleted_count = m_env.getMap().unloadUnusedData( /*u32 deleted_count = m_env.getMap().unloadUnusedData(
g_settings.getFloat("server_unload_unused_sectors_timeout")); g_settings->getFloat("server_unload_unused_sectors_timeout"));
*/ */
// Save only changed parts // Save only changed parts
@ -2073,7 +2075,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
} }
else else
{ {
checkpwd = g_settings.get("default_password"); checkpwd = g_settings->get("default_password");
} }
/*dstream<<"Server: Client gave password '"<<password /*dstream<<"Server: Client gave password '"<<password
@ -2096,16 +2098,16 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
m_authmanager.add(playername); m_authmanager.add(playername);
m_authmanager.setPassword(playername, checkpwd); m_authmanager.setPassword(playername, checkpwd);
m_authmanager.setPrivs(playername, m_authmanager.setPrivs(playername,
stringToPrivs(g_settings.get("default_privs"))); stringToPrivs(g_settings->get("default_privs")));
m_authmanager.save(); m_authmanager.save();
} }
// Enforce user limit. // Enforce user limit.
// Don't enforce for users that have some admin right // Don't enforce for users that have some admin right
if(m_clients.size() >= g_settings.getU16("max_users") && if(m_clients.size() >= g_settings->getU16("max_users") &&
(m_authmanager.getPrivs(playername) (m_authmanager.getPrivs(playername)
& (PRIV_SERVER|PRIV_BAN|PRIV_PRIVS)) == 0 && & (PRIV_SERVER|PRIV_BAN|PRIV_PRIVS)) == 0 &&
playername != g_settings.get("name")) playername != g_settings->get("name"))
{ {
SendAccessDenied(m_con, peer_id, L"Too many users."); SendAccessDenied(m_con, peer_id, L"Too many users.");
return; return;
@ -2381,7 +2383,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if(button == 0) if(button == 0)
{ {
InventoryList *ilist = player->inventory.getList("main"); InventoryList *ilist = player->inventory.getList("main");
if(g_settings.getBool("creative_mode") == false && ilist != NULL) if(g_settings->getBool("creative_mode") == false && ilist != NULL)
{ {
// Skip if inventory has no free space // Skip if inventory has no free space
@ -2464,7 +2466,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
InventoryList *ilist = player->inventory.getList("main"); InventoryList *ilist = player->inventory.getList("main");
if(ilist != NULL) if(ilist != NULL)
{ {
if(g_settings.getBool("creative_mode") == false) if(g_settings->getBool("creative_mode") == false)
{ {
// Skip if inventory has no free space // Skip if inventory has no free space
if(ilist->roomForItem(item) == false) if(ilist->roomForItem(item) == false)
@ -2685,7 +2687,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
Update and send inventory Update and send inventory
*/ */
if(g_settings.getBool("creative_mode") == false) if(g_settings->getBool("creative_mode") == false)
{ {
/* /*
Wear out tool Wear out tool
@ -2901,7 +2903,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
Handle inventory Handle inventory
*/ */
InventoryList *ilist = player->inventory.getList("main"); InventoryList *ilist = player->inventory.getList("main");
if(g_settings.getBool("creative_mode") == false && ilist) if(g_settings->getBool("creative_mode") == false && ilist)
{ {
// Remove from inventory and send inventory // Remove from inventory and send inventory
if(mitem->getCount() == 1) if(mitem->getCount() == 1)
@ -2977,7 +2979,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
If in creative mode, item dropping is disabled unless If in creative mode, item dropping is disabled unless
player has build privileges player has build privileges
*/ */
if(g_settings.getBool("creative_mode") && if(g_settings->getBool("creative_mode") &&
(getPlayerPrivs(player) & PRIV_BUILD) == 0) (getPlayerPrivs(player) & PRIV_BUILD) == 0)
{ {
derr_server<<"Not allowing player to drop item: " derr_server<<"Not allowing player to drop item: "
@ -3014,7 +3016,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
dout_server<<"Placed object"<<std::endl; dout_server<<"Placed object"<<std::endl;
if(g_settings.getBool("creative_mode") == false) if(g_settings->getBool("creative_mode") == false)
{ {
// Delete the right amount of items from the slot // Delete the right amount of items from the slot
u16 dropcount = item->getDropCount(); u16 dropcount = item->getDropCount();
@ -3176,7 +3178,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
else if(command == TOSERVER_INVENTORY_ACTION) else if(command == TOSERVER_INVENTORY_ACTION)
{ {
/*// Ignore inventory changes if in creative mode /*// Ignore inventory changes if in creative mode
if(g_settings.getBool("creative_mode") == true) if(g_settings->getBool("creative_mode") == true)
{ {
dstream<<"TOSERVER_INVENTORY_ACTION: ignoring in creative mode" dstream<<"TOSERVER_INVENTORY_ACTION: ignoring in creative mode"
<<std::endl; <<std::endl;
@ -3199,7 +3201,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
*/ */
bool disable_action = false; bool disable_action = false;
if(a->getType() == IACTION_MOVE if(a->getType() == IACTION_MOVE
&& g_settings.getBool("creative_mode") == false) && g_settings->getBool("creative_mode") == false)
{ {
IMoveAction *ma = (IMoveAction*)a; IMoveAction *ma = (IMoveAction*)a;
if(ma->to_inv == "current_player" && if(ma->to_inv == "current_player" &&
@ -3428,7 +3430,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
} }
else if(command == TOSERVER_DAMAGE) else if(command == TOSERVER_DAMAGE)
{ {
if(g_settings.getBool("enable_damage")) if(g_settings->getBool("enable_damage"))
{ {
std::string datastring((char*)&data[2], datasize-2); std::string datastring((char*)&data[2], datasize-2);
std::istringstream is(datastring, std::ios_base::binary); std::istringstream is(datastring, std::ios_base::binary);
@ -4119,7 +4121,7 @@ void Server::SendBlocks(float dtime)
s32 total_sending = 0; s32 total_sending = 0;
{ {
ScopeProfiler sp(&g_profiler, "Server: selecting blocks for sending"); ScopeProfiler sp(g_profiler, "Server: selecting blocks for sending");
for(core::map<u16, RemoteClient*>::Iterator for(core::map<u16, RemoteClient*>::Iterator
i = m_clients.getIterator(); i = m_clients.getIterator();
@ -4145,7 +4147,7 @@ void Server::SendBlocks(float dtime)
for(u32 i=0; i<queue.size(); i++) for(u32 i=0; i<queue.size(); i++)
{ {
//TODO: Calculate limit dynamically //TODO: Calculate limit dynamically
if(total_sending >= g_settings.getS32 if(total_sending >= g_settings->getS32
("max_simultaneous_block_sends_server_total")) ("max_simultaneous_block_sends_server_total"))
break; break;
@ -4185,7 +4187,7 @@ void Server::UpdateCrafting(u16 peer_id)
/* /*
Calculate crafting stuff Calculate crafting stuff
*/ */
if(g_settings.getBool("creative_mode") == false) if(g_settings->getBool("creative_mode") == false)
{ {
InventoryList *clist = player->inventory.getList("craft"); InventoryList *clist = player->inventory.getList("craft");
InventoryList *rlist = player->inventory.getList("craftresult"); InventoryList *rlist = player->inventory.getList("craftresult");
@ -4256,11 +4258,18 @@ std::wstring Server::getStatusString()
os<<L"}"; os<<L"}";
if(((ServerMap*)(&m_env.getMap()))->isSavingEnabled() == false) if(((ServerMap*)(&m_env.getMap()))->isSavingEnabled() == false)
os<<std::endl<<L"# Server: "<<" WARNING: Map saving is disabled."; os<<std::endl<<L"# Server: "<<" WARNING: Map saving is disabled.";
if(g_settings.get("motd") != "") if(g_settings->get("motd") != "")
os<<std::endl<<L"# Server: "<<narrow_to_wide(g_settings.get("motd")); os<<std::endl<<L"# Server: "<<narrow_to_wide(g_settings->get("motd"));
return os.str(); return os.str();
} }
// Saves g_settings to configpath given at initialization
void Server::saveConfig()
{
if(m_configpath != "")
g_settings->updateConfigFile(m_configpath.c_str());
}
v3f findSpawnPos(ServerMap &map) v3f findSpawnPos(ServerMap &map)
{ {
//return v3f(50,50,50)*BS; //return v3f(50,50,50)*BS;
@ -4335,7 +4344,7 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
player->peer_id = peer_id; player->peer_id = peer_id;
// Reset inventory to creative if in creative mode // Reset inventory to creative if in creative mode
if(g_settings.getBool("creative_mode")) if(g_settings->getBool("creative_mode"))
{ {
// Warning: double code below // Warning: double code below
// Backup actual inventory // Backup actual inventory
@ -4370,7 +4379,7 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
m_authmanager.add(name); m_authmanager.add(name);
m_authmanager.setPassword(name, password); m_authmanager.setPassword(name, password);
m_authmanager.setPrivs(name, m_authmanager.setPrivs(name,
stringToPrivs(g_settings.get("default_privs"))); stringToPrivs(g_settings->get("default_privs")));
/* /*
Set player position Set player position
@ -4393,7 +4402,7 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
Add stuff to inventory Add stuff to inventory
*/ */
if(g_settings.getBool("creative_mode")) if(g_settings->getBool("creative_mode"))
{ {
// Warning: double code above // Warning: double code above
// Backup actual inventory // Backup actual inventory
@ -4402,7 +4411,7 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
// Set creative inventory // Set creative inventory
craft_set_creative_inventory(player); craft_set_creative_inventory(player);
} }
else if(g_settings.getBool("give_initial_stuff")) else if(g_settings->getBool("give_initial_stuff"))
{ {
craft_give_initial_stuff(player); craft_give_initial_stuff(player);
} }
@ -4529,7 +4538,7 @@ u64 Server::getPlayerPrivs(Player *player)
std::string playername = player->getName(); std::string playername = player->getName();
// Local player gets all privileges regardless of // Local player gets all privileges regardless of
// what's set on their account. // what's set on their account.
if(g_settings.get("name") == playername) if(g_settings->get("name") == playername)
{ {
return PRIV_ALL; return PRIV_ALL;
} }
@ -4556,7 +4565,7 @@ void dedicated_server_loop(Server &server, bool &kill)
// This is kind of a hack but can be done like this // This is kind of a hack but can be done like this
// because server.step() is very light // because server.step() is very light
{ {
ScopeProfiler sp(&g_profiler, "dedicated server sleep"); ScopeProfiler sp(g_profiler, "dedicated server sleep");
sleep_ms(30); sleep_ms(30);
} }
server.step(0.030); server.step(0.030);
@ -4571,14 +4580,14 @@ void dedicated_server_loop(Server &server, bool &kill)
Profiler Profiler
*/ */
float profiler_print_interval = float profiler_print_interval =
g_settings.getFloat("profiler_print_interval"); g_settings->getFloat("profiler_print_interval");
if(profiler_print_interval != 0) if(profiler_print_interval != 0)
{ {
if(m_profiler_interval.step(0.030, profiler_print_interval)) if(m_profiler_interval.step(0.030, profiler_print_interval))
{ {
dstream<<"Profiler:"<<std::endl; dstream<<"Profiler:"<<std::endl;
g_profiler.print(dstream); g_profiler->print(dstream);
g_profiler.clear(); g_profiler->clear();
} }
} }

@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "environment.h" #include "environment.h"
#include "common_irrlicht.h" #include "common_irrlicht.h"
#include <string> #include <string>
#include "utility.h"
#include "porting.h" #include "porting.h"
#include "map.h" #include "map.h"
#include "inventory.h" #include "inventory.h"
@ -450,11 +449,7 @@ public:
} }
// Saves g_settings to configpath given at initialization // Saves g_settings to configpath given at initialization
void saveConfig() void saveConfig();
{
if(m_configpath != "")
g_settings.updateConfigFile(m_configpath.c_str());
}
void setIpBanned(const std::string &ip, const std::string &name) void setIpBanned(const std::string &ip, const std::string &name)
{ {

@ -18,6 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "servercommand.h" #include "servercommand.h"
#include "utility.h" #include "utility.h"
#include "settings.h"
void cmd_status(std::wostringstream &os, void cmd_status(std::wostringstream &os,
ServerCommandContext *ctx) ServerCommandContext *ctx)
@ -155,7 +156,7 @@ void cmd_setting(std::wostringstream &os,
std::string confline = wide_to_narrow(ctx->paramstring); std::string confline = wide_to_narrow(ctx->paramstring);
g_settings.parseConfigLine(confline); g_settings->parseConfigLine(confline);
ctx->server->saveConfig(); ctx->server->saveConfig();

@ -70,18 +70,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "config.h" #include "config.h"
#include "mineral.h" #include "mineral.h"
#include "filesys.h" #include "filesys.h"
#include "defaultsettings.h"
#include "settings.h"
#include "profiler.h"
/* /*
Settings. Settings.
These are loaded from the config file. These are loaded from the config file.
*/ */
Settings main_settings;
Settings g_settings; Settings *g_settings = &main_settings;
extern void set_default_settings();
// Global profiler // Global profiler
Profiler g_profiler; Profiler main_profiler;
Profiler *g_profiler = &main_profiler;
// A dummy thing // A dummy thing
ITextureSource *g_texturesource = NULL; ITextureSource *g_texturesource = NULL;
@ -221,7 +223,7 @@ int main(int argc, char *argv[])
*/ */
// Initialize default settings // Initialize default settings
set_default_settings(); set_default_settings(g_settings);
// Initialize sockets // Initialize sockets
sockets_init(); sockets_init();
@ -236,7 +238,7 @@ int main(int argc, char *argv[])
if(cmd_args.exists("config")) if(cmd_args.exists("config"))
{ {
bool r = g_settings.readConfigFile(cmd_args.get("config").c_str()); bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
if(r == false) if(r == false)
{ {
dstream<<"Could not read configuration from \"" dstream<<"Could not read configuration from \""
@ -255,7 +257,7 @@ int main(int argc, char *argv[])
for(u32 i=0; i<filenames.size(); i++) for(u32 i=0; i<filenames.size(); i++)
{ {
bool r = g_settings.readConfigFile(filenames[i].c_str()); bool r = g_settings->readConfigFile(filenames[i].c_str());
if(r) if(r)
{ {
configpath = filenames[i]; configpath = filenames[i];
@ -305,9 +307,9 @@ int main(int argc, char *argv[])
{ {
port = cmd_args.getU16("port"); port = cmd_args.getU16("port");
} }
else if(g_settings.exists("port") && g_settings.getU16("port") != 0) else if(g_settings->exists("port") && g_settings->getU16("port") != 0)
{ {
port = g_settings.getU16("port"); port = g_settings->getU16("port");
} }
else else
{ {
@ -319,8 +321,8 @@ int main(int argc, char *argv[])
std::string map_dir = porting::path_userdata+"/world"; std::string map_dir = porting::path_userdata+"/world";
if(cmd_args.exists("map-dir")) if(cmd_args.exists("map-dir"))
map_dir = cmd_args.get("map-dir"); map_dir = cmd_args.get("map-dir");
else if(g_settings.exists("map-dir")) else if(g_settings->exists("map-dir"))
map_dir = g_settings.get("map-dir"); map_dir = g_settings->get("map-dir");
// Create server // Create server
Server server(map_dir.c_str(), configpath); Server server(map_dir.c_str(), configpath);

583
src/settings.h Normal file

@ -0,0 +1,583 @@
/*
Minetest-c55
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef SETTINGS_HEADER
#define SETTINGS_HEADER
#include "common_irrlicht.h"
#include <string>
#include <jthread.h>
#include <jmutex.h>
#include <jmutexautolock.h>
#include "strfnd.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include "debug.h"
#include "utility.h"
enum ValueType
{
VALUETYPE_STRING,
VALUETYPE_FLAG // Doesn't take any arguments
};
struct ValueSpec
{
ValueSpec(ValueType a_type, const char *a_help=NULL)
{
type = a_type;
help = a_help;
}
ValueType type;
const char *help;
};
class Settings
{
public:
Settings()
{
m_mutex.Init();
}
void writeLines(std::ostream &os)
{
JMutexAutoLock lock(m_mutex);
for(core::map<std::string, std::string>::Iterator
i = m_settings.getIterator();
i.atEnd() == false; i++)
{
std::string name = i.getNode()->getKey();
std::string value = i.getNode()->getValue();
os<<name<<" = "<<value<<"\n";
}
}
bool parseConfigLine(const std::string &line)
{
JMutexAutoLock lock(m_mutex);
std::string trimmedline = trim(line);
// Ignore comments
if(trimmedline[0] == '#')
return true;
//dstream<<"trimmedline=\""<<trimmedline<<"\""<<std::endl;
Strfnd sf(trim(line));
std::string name = sf.next("=");
name = trim(name);
if(name == "")
return true;
std::string value = sf.next("\n");
value = trim(value);
/*dstream<<"Config name=\""<<name<<"\" value=\""
<<value<<"\""<<std::endl;*/
m_settings[name] = value;
return true;
}
// Returns false on EOF
bool parseConfigObject(std::istream &is)
{
if(is.eof())
return false;
/*
NOTE: This function might be expanded to allow multi-line
settings.
*/
std::string line;
std::getline(is, line);
//dstream<<"got line: \""<<line<<"\""<<std::endl;
return parseConfigLine(line);
}
/*
Read configuration file
Returns true on success
*/
bool readConfigFile(const char *filename)
{
std::ifstream is(filename);
if(is.good() == false)
{
dstream<<"Error opening configuration file \""
<<filename<<"\""<<std::endl;
return false;
}
dstream<<"Parsing configuration file: \""
<<filename<<"\""<<std::endl;
while(parseConfigObject(is));
return true;
}
/*
Reads a configuration object from stream (usually a single line)
and adds it to dst.
Preserves comments and empty lines.
Settings that were added to dst are also added to updated.
key of updated is setting name, value of updated is dummy.
Returns false on EOF
*/
bool getUpdatedConfigObject(std::istream &is,
core::list<std::string> &dst,
core::map<std::string, bool> &updated)
{
JMutexAutoLock lock(m_mutex);
if(is.eof())
return false;
// NOTE: This function will be expanded to allow multi-line settings
std::string line;
std::getline(is, line);
std::string trimmedline = trim(line);
std::string line_end = "";
if(is.eof() == false)
line_end = "\n";
// Ignore comments
if(trimmedline[0] == '#')
{
dst.push_back(line+line_end);
return true;
}
Strfnd sf(trim(line));
std::string name = sf.next("=");
name = trim(name);
if(name == "")
{
dst.push_back(line+line_end);
return true;
}
std::string value = sf.next("\n");
value = trim(value);
if(m_settings.find(name))
{
std::string newvalue = m_settings[name];
if(newvalue != value)
{
dstream<<"Changing value of \""<<name<<"\" = \""
<<value<<"\" -> \""<<newvalue<<"\""
<<std::endl;
}
dst.push_back(name + " = " + newvalue + line_end);
updated[name] = true;
}
return true;
}
/*
Updates configuration file
Returns true on success
*/
bool updateConfigFile(const char *filename)
{
dstream<<"Updating configuration file: \""
<<filename<<"\""<<std::endl;
core::list<std::string> objects;
core::map<std::string, bool> updated;
// Read and modify stuff
{
std::ifstream is(filename);
if(is.good() == false)
{
dstream<<"INFO: updateConfigFile():"
" Error opening configuration file"
" for reading: \""
<<filename<<"\""<<std::endl;
}
else
{
while(getUpdatedConfigObject(is, objects, updated));
}
}
JMutexAutoLock lock(m_mutex);
// Write stuff back
{
std::ofstream os(filename);
if(os.good() == false)
{
dstream<<"Error opening configuration file"
" for writing: \""
<<filename<<"\""<<std::endl;
return false;
}
/*
Write updated stuff
*/
for(core::list<std::string>::Iterator
i = objects.begin();
i != objects.end(); i++)
{
os<<(*i);
}
/*
Write stuff that was not already in the file
*/
for(core::map<std::string, std::string>::Iterator
i = m_settings.getIterator();
i.atEnd() == false; i++)
{
if(updated.find(i.getNode()->getKey()))
continue;
std::string name = i.getNode()->getKey();
std::string value = i.getNode()->getValue();
dstream<<"Adding \""<<name<<"\" = \""<<value<<"\""
<<std::endl;
os<<name<<" = "<<value<<"\n";
}
}
return true;
}
/*
NOTE: Types of allowed_options are ignored
returns true on success
*/
bool parseCommandLine(int argc, char *argv[],
core::map<std::string, ValueSpec> &allowed_options)
{
int i=1;
for(;;)
{
if(i >= argc)
break;
std::string argname = argv[i];
if(argname.substr(0, 2) != "--")
{
dstream<<"Invalid command-line parameter \""
<<argname<<"\": --<option> expected."<<std::endl;
return false;
}
i++;
std::string name = argname.substr(2);
core::map<std::string, ValueSpec>::Node *n;
n = allowed_options.find(name);
if(n == NULL)
{
dstream<<"Unknown command-line parameter \""
<<argname<<"\""<<std::endl;
return false;
}
ValueType type = n->getValue().type;
std::string value = "";
if(type == VALUETYPE_FLAG)
{
value = "true";
}
else
{
if(i >= argc)
{
dstream<<"Invalid command-line parameter \""
<<name<<"\": missing value"<<std::endl;
return false;
}
value = argv[i];
i++;
}
dstream<<"Valid command-line parameter: \""
<<name<<"\" = \""<<value<<"\""
<<std::endl;
set(name, value);
}
return true;
}
void set(std::string name, std::string value)
{
JMutexAutoLock lock(m_mutex);
m_settings[name] = value;
}
void set(std::string name, const char *value)
{
JMutexAutoLock lock(m_mutex);
m_settings[name] = value;
}
void setDefault(std::string name, std::string value)
{
JMutexAutoLock lock(m_mutex);
m_defaults[name] = value;
}
bool exists(std::string name)
{
JMutexAutoLock lock(m_mutex);
return (m_settings.find(name) || m_defaults.find(name));
}
std::string get(std::string name)
{
JMutexAutoLock lock(m_mutex);
core::map<std::string, std::string>::Node *n;
n = m_settings.find(name);
if(n == NULL)
{
n = m_defaults.find(name);
if(n == NULL)
{
dstream<<"INFO: Settings: Setting not found: \""
<<name<<"\""<<std::endl;
throw SettingNotFoundException("Setting not found");
}
}
return n->getValue();
}
bool getBool(std::string name)
{
return is_yes(get(name));
}
bool getFlag(std::string name)
{
try
{
return getBool(name);
}
catch(SettingNotFoundException &e)
{
return false;
}
}
// Asks if empty
bool getBoolAsk(std::string name, std::string question, bool def)
{
// If it is in settings
if(exists(name))
return getBool(name);
std::string s;
char templine[10];
std::cout<<question<<" [y/N]: ";
std::cin.getline(templine, 10);
s = templine;
if(s == "")
return def;
return is_yes(s);
}
float getFloat(std::string name)
{
return stof(get(name));
}
u16 getU16(std::string name)
{
return stoi(get(name), 0, 65535);
}
u16 getU16Ask(std::string name, std::string question, u16 def)
{
// If it is in settings
if(exists(name))
return getU16(name);
std::string s;
char templine[10];
std::cout<<question<<" ["<<def<<"]: ";
std::cin.getline(templine, 10);
s = templine;
if(s == "")
return def;
return stoi(s, 0, 65535);
}
s16 getS16(std::string name)
{
return stoi(get(name), -32768, 32767);
}
s32 getS32(std::string name)
{
return stoi(get(name));
}
v3f getV3F(std::string name)
{
v3f value;
Strfnd f(get(name));
f.next("(");
value.X = stof(f.next(","));
value.Y = stof(f.next(","));
value.Z = stof(f.next(")"));
return value;
}
u64 getU64(std::string name)
{
u64 value = 0;
std::string s = get(name);
std::istringstream ss(s);
ss>>value;
return value;
}
void setBool(std::string name, bool value)
{
if(value)
set(name, "true");
else
set(name, "false");
}
void setS32(std::string name, s32 value)
{
set(name, itos(value));
}
void setFloat(std::string name, float value)
{
set(name, ftos(value));
}
void setV3F(std::string name, v3f value)
{
std::ostringstream os;
os<<"("<<value.X<<","<<value.Y<<","<<value.Z<<")";
set(name, os.str());
}
void setU64(std::string name, u64 value)
{
std::ostringstream os;
os<<value;
set(name, os.str());
}
void clear()
{
JMutexAutoLock lock(m_mutex);
m_settings.clear();
m_defaults.clear();
}
Settings & operator+=(Settings &other)
{
JMutexAutoLock lock(m_mutex);
JMutexAutoLock lock2(other.m_mutex);
if(&other == this)
return *this;
for(core::map<std::string, std::string>::Iterator
i = other.m_settings.getIterator();
i.atEnd() == false; i++)
{
m_settings.insert(i.getNode()->getKey(),
i.getNode()->getValue());
}
for(core::map<std::string, std::string>::Iterator
i = other.m_defaults.getIterator();
i.atEnd() == false; i++)
{
m_defaults.insert(i.getNode()->getKey(),
i.getNode()->getValue());
}
return *this;
}
Settings & operator=(Settings &other)
{
JMutexAutoLock lock(m_mutex);
JMutexAutoLock lock2(other.m_mutex);
if(&other == this)
return *this;
clear();
(*this) += other;
return *this;
}
private:
core::map<std::string, std::string> m_settings;
core::map<std::string, std::string> m_defaults;
// All methods that access m_settings/m_defaults directly should lock this.
JMutex m_mutex;
};
#endif

@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "porting.h" #include "porting.h"
#include "content_mapnode.h" #include "content_mapnode.h"
#include "mapsector.h" #include "mapsector.h"
#include "settings.h"
/* /*
Asserts that the exception occurs Asserts that the exception occurs

@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "main.h" // for g_settings #include "main.h" // for g_settings
#include "filesys.h" #include "filesys.h"
#include "utility.h" #include "utility.h"
#include "settings.h"
#include <ICameraSceneNode.h>
/* /*
A cache from texture name to texture path A cache from texture name to texture path
@ -112,7 +114,7 @@ std::string getTexturePath(const std::string &filename)
/* /*
Check from texture_path Check from texture_path
*/ */
std::string texture_path = g_settings.get("texture_path"); std::string texture_path = g_settings->get("texture_path");
if(texture_path != "") if(texture_path != "")
{ {
std::string testpath = texture_path + '/' + filename; std::string testpath = texture_path + '/' + filename;
@ -157,7 +159,7 @@ TextureSource::TextureSource(IrrlichtDevice *device):
m_name_to_id[""] = 0; m_name_to_id[""] = 0;
// Build main texture atlas // Build main texture atlas
if(g_settings.getBool("enable_texture_atlas")) if(g_settings->getBool("enable_texture_atlas"))
buildMainAtlas(); buildMainAtlas();
else else
dstream<<"INFO: Not building texture atlas."<<std::endl; dstream<<"INFO: Not building texture atlas."<<std::endl;

@ -156,6 +156,7 @@ void mysrand(unsigned seed)
next = seed; next = seed;
} }
#ifndef SERVER
// Sets the color of all vertices in the mesh // Sets the color of all vertices in the mesh
void setMeshVerticesColor(scene::IMesh* mesh, video::SColor& color) void setMeshVerticesColor(scene::IMesh* mesh, video::SColor& color)
{ {
@ -174,6 +175,7 @@ void setMeshVerticesColor(scene::IMesh* mesh, video::SColor& color)
} }
} }
} }
#endif
/* /*
blockpos: position of block in block coordinates blockpos: position of block in block coordinates

@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <jthread.h> #include <jthread.h>
#include <jmutex.h> #include <jmutex.h>
#include <jmutexautolock.h> #include <jmutexautolock.h>
#include <cstring>
#include "common_irrlicht.h" #include "common_irrlicht.h"
#include "debug.h" #include "debug.h"
@ -553,8 +554,10 @@ private:
u32 *m_result; u32 *m_result;
}; };
#ifndef SERVER
// Sets the color of all vertices in the mesh // Sets the color of all vertices in the mesh
void setMeshVerticesColor(scene::IMesh* mesh, video::SColor& color); void setMeshVerticesColor(scene::IMesh* mesh, video::SColor& color);
#endif
// Calculates the borders of a "d-radius" cube // Calculates the borders of a "d-radius" cube
inline void getFacePositions(core::list<v3s16> &list, u16 d) inline void getFacePositions(core::list<v3s16> &list, u16 d)
@ -938,557 +941,6 @@ public:
} }
}; };
/*
Config stuff
*/
enum ValueType
{
VALUETYPE_STRING,
VALUETYPE_FLAG // Doesn't take any arguments
};
struct ValueSpec
{
ValueSpec(ValueType a_type, const char *a_help=NULL)
{
type = a_type;
help = a_help;
}
ValueType type;
const char *help;
};
class Settings
{
public:
Settings()
{
m_mutex.Init();
}
void writeLines(std::ostream &os)
{
JMutexAutoLock lock(m_mutex);
for(core::map<std::string, std::string>::Iterator
i = m_settings.getIterator();
i.atEnd() == false; i++)
{
std::string name = i.getNode()->getKey();
std::string value = i.getNode()->getValue();
os<<name<<" = "<<value<<"\n";
}
}
bool parseConfigLine(const std::string &line)
{
JMutexAutoLock lock(m_mutex);
std::string trimmedline = trim(line);
// Ignore comments
if(trimmedline[0] == '#')
return true;
//dstream<<"trimmedline=\""<<trimmedline<<"\""<<std::endl;
Strfnd sf(trim(line));
std::string name = sf.next("=");
name = trim(name);
if(name == "")
return true;
std::string value = sf.next("\n");
value = trim(value);
/*dstream<<"Config name=\""<<name<<"\" value=\""
<<value<<"\""<<std::endl;*/
m_settings[name] = value;
return true;
}
// Returns false on EOF
bool parseConfigObject(std::istream &is)
{
if(is.eof())
return false;
/*
NOTE: This function might be expanded to allow multi-line
settings.
*/
std::string line;
std::getline(is, line);
//dstream<<"got line: \""<<line<<"\""<<std::endl;
return parseConfigLine(line);
}
/*
Read configuration file
Returns true on success
*/
bool readConfigFile(const char *filename)
{
std::ifstream is(filename);
if(is.good() == false)
{
dstream<<"Error opening configuration file \""
<<filename<<"\""<<std::endl;
return false;
}
dstream<<"Parsing configuration file: \""
<<filename<<"\""<<std::endl;
while(parseConfigObject(is));
return true;
}
/*
Reads a configuration object from stream (usually a single line)
and adds it to dst.
Preserves comments and empty lines.
Settings that were added to dst are also added to updated.
key of updated is setting name, value of updated is dummy.
Returns false on EOF
*/
bool getUpdatedConfigObject(std::istream &is,
core::list<std::string> &dst,
core::map<std::string, bool> &updated)
{
JMutexAutoLock lock(m_mutex);
if(is.eof())
return false;
// NOTE: This function will be expanded to allow multi-line settings
std::string line;
std::getline(is, line);
std::string trimmedline = trim(line);
std::string line_end = "";
if(is.eof() == false)
line_end = "\n";
// Ignore comments
if(trimmedline[0] == '#')
{
dst.push_back(line+line_end);
return true;
}
Strfnd sf(trim(line));
std::string name = sf.next("=");
name = trim(name);
if(name == "")
{
dst.push_back(line+line_end);
return true;
}
std::string value = sf.next("\n");
value = trim(value);
if(m_settings.find(name))
{
std::string newvalue = m_settings[name];
if(newvalue != value)
{
dstream<<"Changing value of \""<<name<<"\" = \""
<<value<<"\" -> \""<<newvalue<<"\""
<<std::endl;
}
dst.push_back(name + " = " + newvalue + line_end);
updated[name] = true;
}
return true;
}
/*
Updates configuration file
Returns true on success
*/
bool updateConfigFile(const char *filename)
{
dstream<<"Updating configuration file: \""
<<filename<<"\""<<std::endl;
core::list<std::string> objects;
core::map<std::string, bool> updated;
// Read and modify stuff
{
std::ifstream is(filename);
if(is.good() == false)
{
dstream<<"INFO: updateConfigFile():"
" Error opening configuration file"
" for reading: \""
<<filename<<"\""<<std::endl;
}
else
{
while(getUpdatedConfigObject(is, objects, updated));
}
}
JMutexAutoLock lock(m_mutex);
// Write stuff back
{
std::ofstream os(filename);
if(os.good() == false)
{
dstream<<"Error opening configuration file"
" for writing: \""
<<filename<<"\""<<std::endl;
return false;
}
/*
Write updated stuff
*/
for(core::list<std::string>::Iterator
i = objects.begin();
i != objects.end(); i++)
{
os<<(*i);
}
/*
Write stuff that was not already in the file
*/
for(core::map<std::string, std::string>::Iterator
i = m_settings.getIterator();
i.atEnd() == false; i++)
{
if(updated.find(i.getNode()->getKey()))
continue;
std::string name = i.getNode()->getKey();
std::string value = i.getNode()->getValue();
dstream<<"Adding \""<<name<<"\" = \""<<value<<"\""
<<std::endl;
os<<name<<" = "<<value<<"\n";
}
}
return true;
}
/*
NOTE: Types of allowed_options are ignored
returns true on success
*/
bool parseCommandLine(int argc, char *argv[],
core::map<std::string, ValueSpec> &allowed_options)
{
int i=1;
for(;;)
{
if(i >= argc)
break;
std::string argname = argv[i];
if(argname.substr(0, 2) != "--")
{
dstream<<"Invalid command-line parameter \""
<<argname<<"\": --<option> expected."<<std::endl;
return false;
}
i++;
std::string name = argname.substr(2);
core::map<std::string, ValueSpec>::Node *n;
n = allowed_options.find(name);
if(n == NULL)
{
dstream<<"Unknown command-line parameter \""
<<argname<<"\""<<std::endl;
return false;
}
ValueType type = n->getValue().type;
std::string value = "";
if(type == VALUETYPE_FLAG)
{
value = "true";
}
else
{
if(i >= argc)
{
dstream<<"Invalid command-line parameter \""
<<name<<"\": missing value"<<std::endl;
return false;
}
value = argv[i];
i++;
}
dstream<<"Valid command-line parameter: \""
<<name<<"\" = \""<<value<<"\""
<<std::endl;
set(name, value);
}
return true;
}
void set(std::string name, std::string value)
{
JMutexAutoLock lock(m_mutex);
m_settings[name] = value;
}
void set(std::string name, const char *value)
{
JMutexAutoLock lock(m_mutex);
m_settings[name] = value;
}
void setDefault(std::string name, std::string value)
{
JMutexAutoLock lock(m_mutex);
m_defaults[name] = value;
}
bool exists(std::string name)
{
JMutexAutoLock lock(m_mutex);
return (m_settings.find(name) || m_defaults.find(name));
}
std::string get(std::string name)
{
JMutexAutoLock lock(m_mutex);
core::map<std::string, std::string>::Node *n;
n = m_settings.find(name);
if(n == NULL)
{
n = m_defaults.find(name);
if(n == NULL)
{
dstream<<"INFO: Settings: Setting not found: \""
<<name<<"\""<<std::endl;
throw SettingNotFoundException("Setting not found");
}
}
return n->getValue();
}
bool getBool(std::string name)
{
return is_yes(get(name));
}
bool getFlag(std::string name)
{
try
{
return getBool(name);
}
catch(SettingNotFoundException &e)
{
return false;
}
}
// Asks if empty
bool getBoolAsk(std::string name, std::string question, bool def)
{
// If it is in settings
if(exists(name))
return getBool(name);
std::string s;
char templine[10];
std::cout<<question<<" [y/N]: ";
std::cin.getline(templine, 10);
s = templine;
if(s == "")
return def;
return is_yes(s);
}
float getFloat(std::string name)
{
return stof(get(name));
}
u16 getU16(std::string name)
{
return stoi(get(name), 0, 65535);
}
u16 getU16Ask(std::string name, std::string question, u16 def)
{
// If it is in settings
if(exists(name))
return getU16(name);
std::string s;
char templine[10];
std::cout<<question<<" ["<<def<<"]: ";
std::cin.getline(templine, 10);
s = templine;
if(s == "")
return def;
return stoi(s, 0, 65535);
}
s16 getS16(std::string name)
{
return stoi(get(name), -32768, 32767);
}
s32 getS32(std::string name)
{
return stoi(get(name));
}
v3f getV3F(std::string name)
{
v3f value;
Strfnd f(get(name));
f.next("(");
value.X = stof(f.next(","));
value.Y = stof(f.next(","));
value.Z = stof(f.next(")"));
return value;
}
u64 getU64(std::string name)
{
u64 value = 0;
std::string s = get(name);
std::istringstream ss(s);
ss>>value;
return value;
}
void setBool(std::string name, bool value)
{
if(value)
set(name, "true");
else
set(name, "false");
}
void setS32(std::string name, s32 value)
{
set(name, itos(value));
}
void setFloat(std::string name, float value)
{
set(name, ftos(value));
}
void setV3F(std::string name, v3f value)
{
std::ostringstream os;
os<<"("<<value.X<<","<<value.Y<<","<<value.Z<<")";
set(name, os.str());
}
void setU64(std::string name, u64 value)
{
std::ostringstream os;
os<<value;
set(name, os.str());
}
void clear()
{
JMutexAutoLock lock(m_mutex);
m_settings.clear();
m_defaults.clear();
}
Settings & operator+=(Settings &other)
{
JMutexAutoLock lock(m_mutex);
JMutexAutoLock lock2(other.m_mutex);
if(&other == this)
return *this;
for(core::map<std::string, std::string>::Iterator
i = other.m_settings.getIterator();
i.atEnd() == false; i++)
{
m_settings.insert(i.getNode()->getKey(),
i.getNode()->getValue());
}
for(core::map<std::string, std::string>::Iterator
i = other.m_defaults.getIterator();
i.atEnd() == false; i++)
{
m_defaults.insert(i.getNode()->getKey(),
i.getNode()->getValue());
}
return *this;
}
Settings & operator=(Settings &other)
{
JMutexAutoLock lock(m_mutex);
JMutexAutoLock lock2(other.m_mutex);
if(&other == this)
return *this;
clear();
(*this) += other;
return *this;
}
private:
core::map<std::string, std::string> m_settings;
core::map<std::string, std::string> m_defaults;
// All methods that access m_settings/m_defaults directly should lock this.
JMutex m_mutex;
};
/* /*
FIFO queue (well, actually a FILO also) FIFO queue (well, actually a FILO also)
*/ */