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_nodemeta.cpp
content_craft.cpp
content_mapblock.cpp
content_mapnode.cpp
auth.cpp
collision.cpp
@ -138,6 +137,7 @@ endif()
# Client sources
set(minetest_SRCS
${common_SRCS}
content_mapblock.cpp
content_cao.cpp
mapblock_mesh.cpp
farmesh.cpp

@ -25,6 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "player.h"
#include "tile.h"
#include <cmath>
#include <SAnimatedMesh.h>
#include "settings.h"
Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control):
m_smgr(smgr),
@ -299,8 +301,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize)
v3f speed = player->getSpeed();
if ((hypot(speed.X, speed.Z) > BS) &&
(player->touching_ground) &&
(g_settings.getBool("view_bobbing") == true) &&
(g_settings.getBool("free_move") == false))
(g_settings->getBool("view_bobbing") == true) &&
(g_settings->getBool("free_move") == false))
{
// Start animation
m_view_bobbing_state = 1;
@ -427,18 +429,18 @@ void Camera::updateViewingRange(f32 frametime_in)
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_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);
f32 fov_degrees = g_settings.getFloat("fov");
f32 fov_degrees = g_settings->getFloat("fov");
fov_degrees = MYMAX(fov_degrees, 10.0);
fov_degrees = MYMIN(fov_degrees, 170.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);
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 "tile.h"
#include "utility.h"
#include <ICameraSceneNode.h>
#include <IMeshCache.h>
#include <IAnimatedMesh.h>
class LocalPlayer;
class MapDrawControl;

@ -28,6 +28,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapsector.h"
#include "mapblock_mesh.h"
#include "mapblock.h"
#include "settings.h"
#include "profiler.h"
/*
QueuedMeshUpdate
@ -151,7 +153,7 @@ void * MeshUpdateThread::Thread()
continue;
}
ScopeProfiler sp(&g_profiler, "mesh make");
ScopeProfiler sp(g_profiler, "mesh make");
scene::SMesh *mesh_new = NULL;
mesh_new = makeMapBlockMesh(q->data);
@ -327,7 +329,7 @@ void Client::step(float dtime)
core::list<v3s16> deleted_blocks;
float delete_unused_sectors_timeout =
g_settings.getFloat("client_delete_unused_sectors_timeout");
g_settings->getFloat("client_delete_unused_sectors_timeout");
// Delete sector blocks
/*u32 num = m_env.getMap().unloadUnusedData
@ -449,10 +451,10 @@ void Client::step(float dtime)
const float map_timer_and_unload_dtime = 5.25;
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;
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);
/*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)
{
//if(g_settings.getBool("enable_experimental"))
//if(g_settings->getBool("enable_experimental"))
{
/*
u16 command
@ -1462,7 +1464,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
}
else if(command == TOCLIENT_ACTIVE_OBJECT_MESSAGES)
{
//if(g_settings.getBool("enable_experimental"))
//if(g_settings->getBool("enable_experimental"))
{
/*
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),\
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;
typedef core::vector3df v3f;
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 "mineral.h"
#include "mapblock_mesh.h" // For MapBlock_LightColor()
#include "settings.h"
#ifndef SERVER
// Create a cuboid.
@ -128,10 +129,10 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
/*
Some settings
*/
bool new_style_water = g_settings.getBool("new_style_water");
bool new_style_leaves = g_settings.getBool("new_style_leaves");
//bool smooth_lighting = g_settings.getBool("smooth_lighting");
bool invisible_stone = g_settings.getBool("invisible_stone");
bool new_style_water = g_settings->getBool("new_style_water");
bool new_style_leaves = g_settings->getBool("new_style_leaves");
//bool smooth_lighting = g_settings->getBool("smooth_lighting");
bool invisible_stone = g_settings->getBool("invisible_stone");
float node_liquid_level = 1.0;
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 "mapnode.h"
#include "content_nodemeta.h"
#include "settings.h"
#define WATER_ALPHA 160
@ -103,9 +104,9 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version)
void content_mapnode_init()
{
// Read some settings
bool new_style_water = g_settings.getBool("new_style_water");
bool new_style_leaves = g_settings.getBool("new_style_leaves");
bool invisible_stone = g_settings.getBool("invisible_stone");
bool new_style_water = g_settings->getBool("new_style_water");
bool new_style_leaves = g_settings->getBool("new_style_leaves");
bool invisible_stone = g_settings->getBool("invisible_stone");
content_t i;
ContentFeatures *f = NULL;
@ -390,6 +391,7 @@ void content_mapnode_init()
f->liquid_alternative_flowing = CONTENT_WATER;
f->liquid_alternative_source = CONTENT_WATERSOURCE;
f->liquid_viscosity = WATER_VISC;
#ifndef SERVER
f->vertex_alpha = WATER_ALPHA;
f->post_effect_color = video::SColor(64, 100, 100, 200);
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_atlas = pa_water1;
}
#endif
i = CONTENT_WATERSOURCE;
f = &content_features(i);
@ -418,7 +421,7 @@ void content_mapnode_init()
else // old style
{
f->solidness = 1;
#ifndef SERVER
TileSpec t;
if(g_texturesource)
t.texture = g_texturesource->getTexture("water.png");
@ -427,6 +430,7 @@ void content_mapnode_init()
t.material_type = MATERIAL_ALPHA_VERTEX;
t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
f->setAllTiles(t);
#endif
}
f->param_type = CPT_LIGHT;
f->light_propagates = true;
@ -439,6 +443,7 @@ void content_mapnode_init()
f->liquid_alternative_flowing = CONTENT_WATER;
f->liquid_alternative_source = CONTENT_WATERSOURCE;
f->liquid_viscosity = WATER_VISC;
#ifndef SERVER
f->vertex_alpha = WATER_ALPHA;
f->post_effect_color = video::SColor(64, 100, 100, 200);
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_atlas = pa_water1;
}
#endif
i = CONTENT_LAVA;
f = &content_features(i);
@ -473,6 +479,7 @@ void content_mapnode_init()
f->liquid_alternative_source = CONTENT_LAVASOURCE;
f->liquid_viscosity = LAVA_VISC;
f->damage_per_second = 4*2;
#ifndef SERVER
f->post_effect_color = video::SColor(192, 255, 64, 0);
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_atlas = pa_lava1;
}
#endif
i = CONTENT_LAVASOURCE;
f = &content_features(i);
@ -500,7 +508,7 @@ void content_mapnode_init()
else // old style
{
f->solidness = 2;
#ifndef SERVER
TileSpec t;
if(g_texturesource)
t.texture = g_texturesource->getTexture("lava.png");
@ -509,6 +517,7 @@ void content_mapnode_init()
//t.material_type = MATERIAL_ALPHA_VERTEX;
//t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
f->setAllTiles(t);
#endif
}
f->param_type = CPT_LIGHT;
f->light_propagates = false;
@ -523,6 +532,7 @@ void content_mapnode_init()
f->liquid_alternative_source = CONTENT_LAVASOURCE;
f->liquid_viscosity = LAVA_VISC;
f->damage_per_second = 4*2;
#ifndef SERVER
f->post_effect_color = video::SColor(192, 255, 64, 0);
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_atlas = pa_lava1;
}
#endif
i = CONTENT_TORCH;
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.
*/
#include "utility.h"
#include "settings.h"
extern Settings g_settings;
void set_default_settings()
void set_default_settings(Settings *settings)
{
// Client and server
g_settings.setDefault("port", "");
g_settings.setDefault("name", "");
g_settings.setDefault("footprints", "false");
settings->setDefault("port", "");
settings->setDefault("name", "");
settings->setDefault("footprints", "false");
// Client stuff
g_settings.setDefault("keymap_forward", "KEY_KEY_W");
g_settings.setDefault("keymap_backward", "KEY_KEY_S");
g_settings.setDefault("keymap_left", "KEY_KEY_A");
g_settings.setDefault("keymap_right", "KEY_KEY_D");
g_settings.setDefault("keymap_jump", "KEY_SPACE");
g_settings.setDefault("keymap_sneak", "KEY_LSHIFT");
g_settings.setDefault("keymap_inventory", "KEY_KEY_I");
g_settings.setDefault("keymap_chat", "KEY_KEY_T");
g_settings.setDefault("keymap_cmd", "/");
g_settings.setDefault("keymap_rangeselect", "KEY_KEY_R");
g_settings.setDefault("keymap_freemove", "KEY_KEY_K");
g_settings.setDefault("keymap_fastmove", "KEY_KEY_J");
g_settings.setDefault("keymap_frametime_graph", "KEY_F1");
g_settings.setDefault("keymap_screenshot", "KEY_F12");
settings->setDefault("keymap_forward", "KEY_KEY_W");
settings->setDefault("keymap_backward", "KEY_KEY_S");
settings->setDefault("keymap_left", "KEY_KEY_A");
settings->setDefault("keymap_right", "KEY_KEY_D");
settings->setDefault("keymap_jump", "KEY_SPACE");
settings->setDefault("keymap_sneak", "KEY_LSHIFT");
settings->setDefault("keymap_inventory", "KEY_KEY_I");
settings->setDefault("keymap_chat", "KEY_KEY_T");
settings->setDefault("keymap_cmd", "/");
settings->setDefault("keymap_rangeselect", "KEY_KEY_R");
settings->setDefault("keymap_freemove", "KEY_KEY_K");
settings->setDefault("keymap_fastmove", "KEY_KEY_J");
settings->setDefault("keymap_frametime_graph", "KEY_F1");
settings->setDefault("keymap_screenshot", "KEY_F12");
// Some (temporary) keys for debugging
g_settings.setDefault("keymap_special1", "KEY_KEY_E");
g_settings.setDefault("keymap_print_debug_stacks", "KEY_KEY_P");
settings->setDefault("keymap_special1", "KEY_KEY_E");
settings->setDefault("keymap_print_debug_stacks", "KEY_KEY_P");
g_settings.setDefault("wanted_fps", "30");
g_settings.setDefault("fps_max", "60");
g_settings.setDefault("viewing_range_nodes_max", "300");
g_settings.setDefault("viewing_range_nodes_min", "15");
g_settings.setDefault("screenW", "800");
g_settings.setDefault("screenH", "600");
g_settings.setDefault("address", "");
g_settings.setDefault("random_input", "false");
g_settings.setDefault("client_unload_unused_data_timeout", "600");
g_settings.setDefault("enable_fog", "true");
g_settings.setDefault("fov", "72");
g_settings.setDefault("view_bobbing", "true");
g_settings.setDefault("new_style_water", "false");
g_settings.setDefault("new_style_leaves", "true");
g_settings.setDefault("smooth_lighting", "true");
g_settings.setDefault("frametime_graph", "false");
g_settings.setDefault("enable_texture_atlas", "true");
g_settings.setDefault("texture_path", "");
g_settings.setDefault("video_driver", "opengl");
g_settings.setDefault("free_move", "false");
g_settings.setDefault("continuous_forward", "false");
g_settings.setDefault("fast_move", "false");
g_settings.setDefault("invert_mouse", "false");
g_settings.setDefault("enable_farmesh", "false");
g_settings.setDefault("enable_clouds", "true");
g_settings.setDefault("invisible_stone", "false");
g_settings.setDefault("screenshot_path", ".");
settings->setDefault("wanted_fps", "30");
settings->setDefault("fps_max", "60");
settings->setDefault("viewing_range_nodes_max", "300");
settings->setDefault("viewing_range_nodes_min", "15");
settings->setDefault("screenW", "800");
settings->setDefault("screenH", "600");
settings->setDefault("address", "");
settings->setDefault("random_input", "false");
settings->setDefault("client_unload_unused_data_timeout", "600");
settings->setDefault("enable_fog", "true");
settings->setDefault("fov", "72");
settings->setDefault("view_bobbing", "true");
settings->setDefault("new_style_water", "false");
settings->setDefault("new_style_leaves", "true");
settings->setDefault("smooth_lighting", "true");
settings->setDefault("frametime_graph", "false");
settings->setDefault("enable_texture_atlas", "true");
settings->setDefault("texture_path", "");
settings->setDefault("video_driver", "opengl");
settings->setDefault("free_move", "false");
settings->setDefault("continuous_forward", "false");
settings->setDefault("fast_move", "false");
settings->setDefault("invert_mouse", "false");
settings->setDefault("enable_farmesh", "false");
settings->setDefault("enable_clouds", "true");
settings->setDefault("invisible_stone", "false");
settings->setDefault("screenshot_path", ".");
// Server stuff
g_settings.setDefault("motd", "");
g_settings.setDefault("max_users", "20");
g_settings.setDefault("enable_experimental", "false");
g_settings.setDefault("creative_mode", "false");
g_settings.setDefault("enable_damage", "true");
g_settings.setDefault("give_initial_stuff", "false");
g_settings.setDefault("default_password", "");
g_settings.setDefault("default_privs", "build, shout");
g_settings.setDefault("profiler_print_interval", "0");
g_settings.setDefault("enable_mapgen_debug_info", "false");
g_settings.setDefault("fixed_map_seed", "");
settings->setDefault("motd", "");
settings->setDefault("max_users", "20");
settings->setDefault("enable_experimental", "false");
settings->setDefault("creative_mode", "false");
settings->setDefault("enable_damage", "true");
settings->setDefault("give_initial_stuff", "false");
settings->setDefault("default_password", "");
settings->setDefault("default_privs", "build, shout");
settings->setDefault("profiler_print_interval", "0");
settings->setDefault("enable_mapgen_debug_info", "false");
settings->setDefault("fixed_map_seed", "");
g_settings.setDefault("objectdata_interval", "0.2");
g_settings.setDefault("active_object_range", "2");
//g_settings.setDefault("max_simultaneous_block_sends_per_client", "1");
settings->setDefault("objectdata_interval", "0.2");
settings->setDefault("active_object_range", "2");
//settings->setDefault("max_simultaneous_block_sends_per_client", "1");
// This causes frametime jitter on client side, or does it?
g_settings.setDefault("max_simultaneous_block_sends_per_client", "2");
g_settings.setDefault("max_simultaneous_block_sends_server_total", "8");
g_settings.setDefault("max_block_send_distance", "8");
g_settings.setDefault("max_block_generate_distance", "8");
g_settings.setDefault("time_send_interval", "20");
g_settings.setDefault("time_speed", "96");
g_settings.setDefault("server_unload_unused_data_timeout", "60");
g_settings.setDefault("server_map_save_interval", "60");
g_settings.setDefault("full_block_send_enable_min_time_from_building", "2.0");
//g_settings.setDefault("dungeon_rarity", "0.025");
settings->setDefault("max_simultaneous_block_sends_per_client", "2");
settings->setDefault("max_simultaneous_block_sends_server_total", "8");
settings->setDefault("max_block_send_distance", "8");
settings->setDefault("max_block_generate_distance", "8");
settings->setDefault("time_send_interval", "20");
settings->setDefault("time_speed", "96");
settings->setDefault("server_unload_unused_data_timeout", "60");
settings->setDefault("server_map_save_interval", "60");
settings->setDefault("full_block_send_enable_min_time_from_building", "2.0");
//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 "content_sao.h"
#include "mapgen.h"
#include "settings.h"
Environment::Environment():
m_time_of_day(9000)
@ -649,7 +650,7 @@ void ServerEnvironment::step(float dtime)
//TimeTaker timer("ServerEnv step");
// Get some settings
bool footprints = g_settings.getBool("footprints");
bool footprints = g_settings->getBool("footprints");
/*
Increment game time
@ -1013,7 +1014,7 @@ void ServerEnvironment::step(float dtime)
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);
// Get some settings
bool free_move = g_settings.getBool("free_move");
bool footprints = g_settings.getBool("footprints");
bool free_move = g_settings->getBool("free_move");
bool footprints = g_settings->getBool("footprints");
// Get local player
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.
*/
#include "common_irrlicht.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 "server.h"
#include "guiPauseMenu.h"
@ -31,6 +36,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "camera.h"
#include "farmesh.h"
#include "mapblock.h"
#include "settings.h"
#include "profiler.h"
#include "mainmenumanager.h"
/*
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
if(g_settings.getBool("enable_farmesh"))
if(g_settings->getBool("enable_farmesh"))
return;*/
if(brightness >= 0.5)
@ -825,7 +833,7 @@ void the_game(
float cloud_height = BS*100;
Clouds *clouds = NULL;
if(g_settings.getBool("enable_clouds"))
if(g_settings->getBool("enable_clouds"))
{
clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
cloud_height, time(0));
@ -836,7 +844,7 @@ void the_game(
*/
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);
}
@ -919,7 +927,7 @@ void the_game(
float damage_flash_timer = 0;
s16 farmesh_range = 20*MAP_BLOCKSIZE;
bool invert_mouse = g_settings.getBool("invert_mouse");
bool invert_mouse = g_settings->getBool("invert_mouse");
/*
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;
if(busytime_u32 < frametime_min)
@ -1133,14 +1141,14 @@ void the_game(
Profiler
*/
float profiler_print_interval =
g_settings.getFloat("profiler_print_interval");
g_settings->getFloat("profiler_print_interval");
if(profiler_print_interval != 0)
{
if(m_profiler_interval.step(0.030, profiler_print_interval))
{
dstream<<"Profiler:"<<std::endl;
g_profiler.print(dstream);
g_profiler.clear();
g_profiler->print(dstream);
g_profiler->clear();
}
}
@ -1215,40 +1223,40 @@ void the_game(
}
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"));
}
else
{
g_settings.set("free_move","true");
g_settings->set("free_move","true");
chat_lines.push_back(ChatLine(L"free_move enabled"));
}
}
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"));
}
else
{
g_settings.set("fast_move","true");
g_settings->set("fast_move","true");
chat_lines.push_back(ChatLine(L"fast_move enabled"));
}
}
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"));
}
else
{
g_settings.set("frametime_graph","true");
g_settings->set("frametime_graph","true");
chat_lines.push_back(ChatLine(L"frametime_graph enabled"));
}
}
@ -1258,7 +1266,7 @@ void the_game(
if (image) {
irr::c8 filename[256];
snprintf(filename, 256, "%s/screenshot_%u.png",
g_settings.get("screenshot_path").c_str(),
g_settings->get("screenshot_path").c_str(),
device->getTimer()->getRealTime());
if (driver->writeImageToFile(image, filename)) {
std::wstringstream sstr;
@ -1907,7 +1915,7 @@ void the_game(
Fog
*/
if(g_settings.getBool("enable_fog") == true)
if(g_settings->getBool("enable_fog") == true)
{
f32 range;
if(farmesh)
@ -2180,7 +2188,7 @@ void the_game(
/*
Frametime log
*/
if(g_settings.getBool("frametime_graph") == true)
if(g_settings->getBool("frametime_graph") == true)
{
s32 x = 10;
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 "keycode.h"
#include "strfnd.h"
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
void drawInventoryItem(video::IVideoDriver *driver,
gui::IGUIFont *font,

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

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

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

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

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

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

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

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

@ -21,16 +21,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MAIN_HEADER
// Settings
#include "utility.h"
extern Settings g_settings;
class Settings;
extern Settings *g_settings;
// This makes and maps textures
class ITextureSource;
extern ITextureSource *g_texturesource;
// Global profiler
#include "profiler.h"
extern Profiler g_profiler;
class Profiler;
extern Profiler *g_profiler;
// Debug streams
@ -50,105 +50,5 @@ extern std::ostream *derr_server_ptr;
#define dout_server (*dout_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

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 "nodemetadata.h"
#include "content_mapnode.h"
#ifndef SERVER
#include <IMaterialRenderer.h>
#endif
#include "settings.h"
/*
SQLite format specification:
@ -771,7 +775,7 @@ void Map::updateLighting(enum LightBank bank,
generation for testing or whatever
*/
#if 0
//if(g_settings.get(""))
//if(g_settings->get(""))
{
core::map<v3s16, MapBlock*>::Iterator i;
i = blocks_to_update.getIterator();
@ -1897,7 +1901,7 @@ ServerMap::ServerMap(std::string savedir):
//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)
+ ((u64)(myrand()%0xffff)<<16)
@ -1906,7 +1910,7 @@ ServerMap::ServerMap(std::string savedir):
}
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)
{
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)
dstream<<"initBlockMake(): ("<<blockpos.X<<","<<blockpos.Y<<","
<<blockpos.Z<<")"<<std::endl;
@ -2139,7 +2143,7 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
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;
data->vmanip.print(dstream);*/
@ -2394,7 +2398,7 @@ MapBlock * ServerMap::generateBlock(
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<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");
@ -3946,7 +3950,7 @@ void ClientMap::renderPostFx()
// - If the player is in liquid, draw a semi-transparent overlay.
ContentFeatures& features = content_features(n);
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);
}

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

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

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

@ -23,11 +23,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <iostream>
#include "common_irrlicht.h"
#include "light.h"
#include "utility.h"
#include "exceptions.h"
#include "serialization.h"
#include "tile.h"
#include "materials.h"
#ifndef SERVER
#include "tile.h"
#endif
/*
Naming scheme:
@ -101,9 +102,7 @@ class NodeMetadata;
struct ContentFeatures
{
// Type of MapNode::param1
ContentParamType param_type;
#ifndef SERVER
/*
0: up
1: down
@ -116,6 +115,17 @@ struct ContentFeatures
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
bool is_ground_content;
bool light_propagates;
@ -162,13 +172,6 @@ struct ContentFeatures
// 1 giving almost instantaneous propagation and 7 being
// the slowest possible
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
u8 light_source;
@ -182,8 +185,15 @@ struct ContentFeatures
void reset()
{
param_type = CPT_NONE;
#ifndef SERVER
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;
light_propagates = false;
sunlight_propagates = false;
@ -202,10 +212,6 @@ struct ContentFeatures
liquid_alternative_flowing = CONTENT_IGNORE;
liquid_alternative_source = CONTENT_IGNORE;
liquid_viscosity = 0;
vertex_alpha = 255;
post_effect_color = video::SColor(0, 0, 0, 0);
special_material = NULL;
special_atlas = NULL;
light_source = 0;
digging_properties.clear();
damage_per_second = 0;
@ -222,6 +228,12 @@ struct ContentFeatures
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 setAllTextures(std::string name, u8 alpha=255)
@ -233,7 +245,9 @@ struct ContentFeatures
// Force inventory texture too
setInventoryTexture(name);
}
#endif
#ifndef SERVER
void setTile(u16 i, const TileSpec &tile)
{
tiles[i] = tile;
@ -245,11 +259,20 @@ struct ContentFeatures
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 setInventoryTextureCube(std::string top,
std::string left, std::string right);
#endif
};
/*
@ -632,6 +655,7 @@ struct MapNode
}
// In mapnode.cpp
#ifndef SERVER
/*
Get tile of a face of the node.
dir: direction of face
@ -639,6 +663,7 @@ struct MapNode
which must be obeyed so that the texture atlas can be used.
*/
TileSpec getTile(v3s16 dir);
#endif
/*
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 "constants.h"
#include "utility.h"
#ifndef SERVER
#include <ITextSceneNode.h>
#endif
#include "settings.h"
Player::Player():
touching_ground(false),
@ -344,7 +347,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
is_frozen = false;
// 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)
{
setPosition(position);
@ -754,9 +757,9 @@ void LocalPlayer::applyControl(float dtime)
v3f speed = v3f(0,0,0);
bool free_move = g_settings.getBool("free_move");
bool fast_move = g_settings.getBool("fast_move");
bool continuous_forward = g_settings.getBool("continuous_forward");
bool free_move = g_settings->getBool("free_move");
bool fast_move = g_settings->getBool("fast_move");
bool continuous_forward = g_settings->getBool("continuous_forward");
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 "mapblock.h"
#include "serverobject.h"
#include "settings.h"
#include "profiler.h"
#define BLOCK_EMERGE_FLAG_FROMDISK (1<<0)
@ -107,7 +109,7 @@ void * EmergeThread::Thread()
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
@ -354,7 +356,7 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
}
// 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"))
{
//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;
u16 max_simul_sends_setting = g_settings.getU16
u16 max_simul_sends_setting = g_settings->getU16
("max_simultaneous_block_sends_per_client");
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.
*/
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"))
{
max_simul_sends_usually
@ -450,8 +452,8 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
*/
s32 new_nearest_unsent_d = -1;
s16 d_max = g_settings.getS16("max_block_send_distance");
s16 d_max_gen = g_settings.getS16("max_block_generate_distance");
s16 d_max = g_settings->getS16("max_block_send_distance");
s16 d_max_gen = g_settings->getS16("max_block_generate_distance");
// Don't loop very much at a time
if(d_max > d_start+1)
@ -735,7 +737,7 @@ queue_full_break:
{
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
m_nothing_to_send_pause_timer = 1.0;
@ -858,7 +860,7 @@ void RemoteClient::SendObjectData(
v3s16 center_nodepos = floatToInt(playerpos, BS);
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
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");
// Send blocks to clients
SendBlocks(dtime);
@ -1259,14 +1261,14 @@ void Server::AsyncRunStep()
{
// Process connection's timeouts
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);
}
{
// This has to be called so that the client list gets synced
// with the peer list of the connection
ScopeProfiler sp(&g_profiler, "Server: peer change handling");
ScopeProfiler sp(g_profiler, "Server: peer change handling");
handlePeerChanges();
}
@ -1277,7 +1279,7 @@ void Server::AsyncRunStep()
JMutexAutoLock envlock(m_env_mutex);
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);
m_time_counter -= (f32)units / speed;
@ -1292,7 +1294,7 @@ void Server::AsyncRunStep()
m_time_of_day_send_timer -= dtime;
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 conlock(m_con_mutex);
@ -1315,7 +1317,7 @@ void Server::AsyncRunStep()
{
JMutexAutoLock lock(m_env_mutex);
// Step environment
ScopeProfiler sp(&g_profiler, "Server: environment step");
ScopeProfiler sp(g_profiler, "Server: environment step");
m_env.step(dtime);
}
@ -1324,9 +1326,9 @@ void Server::AsyncRunStep()
{
JMutexAutoLock lock(m_env_mutex);
// 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,
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);
ScopeProfiler sp(&g_profiler, "Server: liquid transform");
ScopeProfiler sp(g_profiler, "Server: liquid transform");
core::map<v3s16, MapBlock*> 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 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
s16 radius = 32;
@ -1568,7 +1570,7 @@ void Server::AsyncRunStep()
JMutexAutoLock envlock(m_env_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
// Value = data sent by object
@ -1804,12 +1806,12 @@ void Server::AsyncRunStep()
{
float &counter = m_objectdata_timer;
counter += dtime;
if(counter >= g_settings.getFloat("objectdata_interval"))
if(counter >= g_settings->getFloat("objectdata_interval"))
{
JMutexAutoLock lock1(m_env_mutex);
JMutexAutoLock lock2(m_con_mutex);
ScopeProfiler sp(&g_profiler, "Server: sending mbo positions");
ScopeProfiler sp(g_profiler, "Server: sending mbo positions");
SendObjectData(counter);
@ -1836,11 +1838,11 @@ void Server::AsyncRunStep()
{
float &counter = m_savemap_timer;
counter += dtime;
if(counter >= g_settings.getFloat("server_map_save_interval"))
if(counter >= g_settings->getFloat("server_map_save_interval"))
{
counter = 0.0;
ScopeProfiler sp(&g_profiler, "Server: saving stuff");
ScopeProfiler sp(g_profiler, "Server: saving stuff");
// Auth stuff
if(m_authmanager.isModified())
@ -1855,10 +1857,10 @@ void Server::AsyncRunStep()
/*// Unload unused data (delete from memory)
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(
g_settings.getFloat("server_unload_unused_sectors_timeout"));
g_settings->getFloat("server_unload_unused_sectors_timeout"));
*/
// Save only changed parts
@ -2073,7 +2075,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
else
{
checkpwd = g_settings.get("default_password");
checkpwd = g_settings->get("default_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.setPassword(playername, checkpwd);
m_authmanager.setPrivs(playername,
stringToPrivs(g_settings.get("default_privs")));
stringToPrivs(g_settings->get("default_privs")));
m_authmanager.save();
}
// Enforce user limit.
// 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)
& (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.");
return;
@ -2381,7 +2383,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if(button == 0)
{
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
@ -2464,7 +2466,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
InventoryList *ilist = player->inventory.getList("main");
if(ilist != NULL)
{
if(g_settings.getBool("creative_mode") == false)
if(g_settings->getBool("creative_mode") == false)
{
// Skip if inventory has no free space
if(ilist->roomForItem(item) == false)
@ -2685,7 +2687,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
Update and send inventory
*/
if(g_settings.getBool("creative_mode") == false)
if(g_settings->getBool("creative_mode") == false)
{
/*
Wear out tool
@ -2901,7 +2903,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
Handle inventory
*/
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
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
player has build privileges
*/
if(g_settings.getBool("creative_mode") &&
if(g_settings->getBool("creative_mode") &&
(getPlayerPrivs(player) & PRIV_BUILD) == 0)
{
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;
if(g_settings.getBool("creative_mode") == false)
if(g_settings->getBool("creative_mode") == false)
{
// Delete the right amount of items from the slot
u16 dropcount = item->getDropCount();
@ -3176,7 +3178,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
else if(command == TOSERVER_INVENTORY_ACTION)
{
/*// 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"
<<std::endl;
@ -3199,7 +3201,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
*/
bool disable_action = false;
if(a->getType() == IACTION_MOVE
&& g_settings.getBool("creative_mode") == false)
&& g_settings->getBool("creative_mode") == false)
{
IMoveAction *ma = (IMoveAction*)a;
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)
{
if(g_settings.getBool("enable_damage"))
if(g_settings->getBool("enable_damage"))
{
std::string datastring((char*)&data[2], datasize-2);
std::istringstream is(datastring, std::ios_base::binary);
@ -4119,7 +4121,7 @@ void Server::SendBlocks(float dtime)
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
i = m_clients.getIterator();
@ -4145,7 +4147,7 @@ void Server::SendBlocks(float dtime)
for(u32 i=0; i<queue.size(); i++)
{
//TODO: Calculate limit dynamically
if(total_sending >= g_settings.getS32
if(total_sending >= g_settings->getS32
("max_simultaneous_block_sends_server_total"))
break;
@ -4185,7 +4187,7 @@ void Server::UpdateCrafting(u16 peer_id)
/*
Calculate crafting stuff
*/
if(g_settings.getBool("creative_mode") == false)
if(g_settings->getBool("creative_mode") == false)
{
InventoryList *clist = player->inventory.getList("craft");
InventoryList *rlist = player->inventory.getList("craftresult");
@ -4256,11 +4258,18 @@ std::wstring Server::getStatusString()
os<<L"}";
if(((ServerMap*)(&m_env.getMap()))->isSavingEnabled() == false)
os<<std::endl<<L"# Server: "<<" WARNING: Map saving is disabled.";
if(g_settings.get("motd") != "")
os<<std::endl<<L"# Server: "<<narrow_to_wide(g_settings.get("motd"));
if(g_settings->get("motd") != "")
os<<std::endl<<L"# Server: "<<narrow_to_wide(g_settings->get("motd"));
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)
{
//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;
// Reset inventory to creative if in creative mode
if(g_settings.getBool("creative_mode"))
if(g_settings->getBool("creative_mode"))
{
// Warning: double code below
// 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.setPassword(name, password);
m_authmanager.setPrivs(name,
stringToPrivs(g_settings.get("default_privs")));
stringToPrivs(g_settings->get("default_privs")));
/*
Set player position
@ -4393,7 +4402,7 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
Add stuff to inventory
*/
if(g_settings.getBool("creative_mode"))
if(g_settings->getBool("creative_mode"))
{
// Warning: double code above
// Backup actual inventory
@ -4402,7 +4411,7 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
// Set creative inventory
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);
}
@ -4529,7 +4538,7 @@ u64 Server::getPlayerPrivs(Player *player)
std::string playername = player->getName();
// Local player gets all privileges regardless of
// what's set on their account.
if(g_settings.get("name") == playername)
if(g_settings->get("name") == playername)
{
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
// because server.step() is very light
{
ScopeProfiler sp(&g_profiler, "dedicated server sleep");
ScopeProfiler sp(g_profiler, "dedicated server sleep");
sleep_ms(30);
}
server.step(0.030);
@ -4571,14 +4580,14 @@ void dedicated_server_loop(Server &server, bool &kill)
Profiler
*/
float profiler_print_interval =
g_settings.getFloat("profiler_print_interval");
g_settings->getFloat("profiler_print_interval");
if(profiler_print_interval != 0)
{
if(m_profiler_interval.step(0.030, profiler_print_interval))
{
dstream<<"Profiler:"<<std::endl;
g_profiler.print(dstream);
g_profiler.clear();
g_profiler->print(dstream);
g_profiler->clear();
}
}

@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "environment.h"
#include "common_irrlicht.h"
#include <string>
#include "utility.h"
#include "porting.h"
#include "map.h"
#include "inventory.h"
@ -450,11 +449,7 @@ public:
}
// Saves g_settings to configpath given at initialization
void saveConfig()
{
if(m_configpath != "")
g_settings.updateConfigFile(m_configpath.c_str());
}
void saveConfig();
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 "utility.h"
#include "settings.h"
void cmd_status(std::wostringstream &os,
ServerCommandContext *ctx)
@ -155,7 +156,7 @@ void cmd_setting(std::wostringstream &os,
std::string confline = wide_to_narrow(ctx->paramstring);
g_settings.parseConfigLine(confline);
g_settings->parseConfigLine(confline);
ctx->server->saveConfig();

@ -70,18 +70,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "config.h"
#include "mineral.h"
#include "filesys.h"
#include "defaultsettings.h"
#include "settings.h"
#include "profiler.h"
/*
Settings.
These are loaded from the config file.
*/
Settings g_settings;
extern void set_default_settings();
Settings main_settings;
Settings *g_settings = &main_settings;
// Global profiler
Profiler g_profiler;
Profiler main_profiler;
Profiler *g_profiler = &main_profiler;
// A dummy thing
ITextureSource *g_texturesource = NULL;
@ -221,7 +223,7 @@ int main(int argc, char *argv[])
*/
// Initialize default settings
set_default_settings();
set_default_settings(g_settings);
// Initialize sockets
sockets_init();
@ -236,7 +238,7 @@ int main(int argc, char *argv[])
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)
{
dstream<<"Could not read configuration from \""
@ -255,7 +257,7 @@ int main(int argc, char *argv[])
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)
{
configpath = filenames[i];
@ -305,9 +307,9 @@ int main(int argc, char *argv[])
{
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
{
@ -319,8 +321,8 @@ int main(int argc, char *argv[])
std::string map_dir = porting::path_userdata+"/world";
if(cmd_args.exists("map-dir"))
map_dir = cmd_args.get("map-dir");
else if(g_settings.exists("map-dir"))
map_dir = g_settings.get("map-dir");
else if(g_settings->exists("map-dir"))
map_dir = g_settings->get("map-dir");
// Create server
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 "content_mapnode.h"
#include "mapsector.h"
#include "settings.h"
/*
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 "filesys.h"
#include "utility.h"
#include "settings.h"
#include <ICameraSceneNode.h>
/*
A cache from texture name to texture path
@ -112,7 +114,7 @@ std::string getTexturePath(const std::string &filename)
/*
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 != "")
{
std::string testpath = texture_path + '/' + filename;
@ -157,7 +159,7 @@ TextureSource::TextureSource(IrrlichtDevice *device):
m_name_to_id[""] = 0;
// Build main texture atlas
if(g_settings.getBool("enable_texture_atlas"))
if(g_settings->getBool("enable_texture_atlas"))
buildMainAtlas();
else
dstream<<"INFO: Not building texture atlas."<<std::endl;

@ -156,6 +156,7 @@ void mysrand(unsigned seed)
next = seed;
}
#ifndef SERVER
// Sets the color of all vertices in the mesh
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

@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <jthread.h>
#include <jmutex.h>
#include <jmutexautolock.h>
#include <cstring>
#include "common_irrlicht.h"
#include "debug.h"
@ -553,8 +554,10 @@ private:
u32 *m_result;
};
#ifndef SERVER
// Sets the color of all vertices in the mesh
void setMeshVerticesColor(scene::IMesh* mesh, video::SColor& color);
#endif
// Calculates the borders of a "d-radius" cube
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)
*/