content_inventory.cpp
content_nodemeta.cpp
content_craft.cpp
- content_mapblock.cpp
content_mapnode.cpp
auth.cpp
collision.cpp
# Client sources
set(minetest_SRCS
${common_SRCS}
+ content_mapblock.cpp
content_cao.cpp
mapblock_mesh.cpp
farmesh.cpp
#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),
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;
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;
}
#include "inventory.h"
#include "tile.h"
#include "utility.h"
+#include <ICameraSceneNode.h>
+#include <IMeshCache.h>
+#include <IAnimatedMesh.h>
class LocalPlayer;
class MapDrawControl;
#include "mapsector.h"
#include "mapblock_mesh.h"
#include "mapblock.h"
+#include "settings.h"
+#include "profiler.h"
/*
QueuedMeshUpdate
continue;
}
- ScopeProfiler sp(&g_profiler, "mesh make");
+ ScopeProfiler sp(g_profiler, "mesh make");
scene::SMesh *mesh_new = NULL;
mesh_new = makeMapBlockMesh(q->data);
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
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)
}
else if(command == TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD)
{
- //if(g_settings.getBool("enable_experimental"))
+ //if(g_settings->getBool("enable_experimental"))
{
/*
u16 command
}
else if(command == TOCLIENT_ACTIVE_OBJECT_MESSAGES)
{
- //if(g_settings.getBool("enable_experimental"))
+ //if(g_settings->getBool("enable_experimental"))
{
/*
u16 command
#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;
#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.
/*
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)
#include "content_mapnode.h"
#include "mapnode.h"
#include "content_nodemeta.h"
+#include "settings.h"
#define WATER_ALPHA 160
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;
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)
f->special_material->setTexture(0, pa_water1->atlas);
f->special_atlas = pa_water1;
}
+#endif
i = CONTENT_WATERSOURCE;
f = &content_features(i);
else // old style
{
f->solidness = 1;
-
+#ifndef SERVER
TileSpec t;
if(g_texturesource)
t.texture = g_texturesource->getTexture("water.png");
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;
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)
f->special_material->setTexture(0, pa_water1->atlas);
f->special_atlas = pa_water1;
}
+#endif
i = CONTENT_LAVA;
f = &content_features(i);
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)
{
f->special_material->setTexture(0, pa_lava1->atlas);
f->special_atlas = pa_lava1;
}
+#endif
i = CONTENT_LAVASOURCE;
f = &content_features(i);
else // old style
{
f->solidness = 2;
-
+#ifndef SERVER
TileSpec t;
if(g_texturesource)
t.texture = g_texturesource->getTexture("lava.png");
//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;
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)
{
f->special_material->setTexture(0, pa_lava1->atlas);
f->special_atlas = pa_lava1;
}
+#endif
i = CONTENT_TORCH;
f = &content_features(i);
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");
}
--- /dev/null
+/*
+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
+
#include "serverobject.h"
#include "content_sao.h"
#include "mapgen.h"
+#include "settings.h"
Environment::Environment():
m_time_of_day(9000)
//TimeTaker timer("ServerEnv step");
// Get some settings
- bool footprints = g_settings.getBool("footprints");
+ bool footprints = g_settings->getBool("footprints");
/*
Increment game time
removeRemovedObjects();
}
- if(g_settings.getBool("enable_experimental"))
+ if(g_settings->getBool("enable_experimental"))
{
/*
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();
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"
#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
}
/*// Disable skybox if FarMesh is enabled
- if(g_settings.getBool("enable_farmesh"))
+ if(g_settings->getBool("enable_farmesh"))
return;*/
if(brightness >= 0.5)
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));
*/
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);
}
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
*/
{
- 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)
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();
}
}
}
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"));
}
}
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;
Fog
*/
- if(g_settings.getBool("enable_fog") == true)
+ if(g_settings->getBool("enable_fog") == true)
{
f32 range;
if(farmesh)
/*
Frametime log
*/
- if(g_settings.getBool("frametime_graph") == true)
+ if(g_settings->getBool("frametime_graph") == true)
{
s32 x = 10;
for(core::list<float>::Iterator
#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,
#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) :
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;
}
#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"
#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"
#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"
#include "porting.h"\r
#include "config.h"\r
#include "main.h"\r
+#include <IGUICheckBox.h>\r
+#include <IGUIEditBox.h>\r
+#include <IGUIButton.h>\r
+#include <IGUIStaticText.h>\r
+#include <IGUIFont.h>\r
\r
#include "gettext.h"\r
\r
#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"
#include "keycode.h"
#include "main.h" // For g_settings
#include "exceptions.h"
+#include "settings.h"
class UnknownKeycode : public BaseException
{
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();
}
//#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"
#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;
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()
}
// Passed to menus to allow disconnecting and exiting
-
MainGameCallback *g_gamecallback = NULL;
/*
*/
// Initialize default settings
- set_default_settings();
+ set_default_settings(g_settings);
// Initialize sockets
sockets_init();
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 \""
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];
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;
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"))
}
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
// 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;
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)
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,
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.
}*/
// 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;
#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
#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
--- /dev/null
+/*
+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
+
#include "mapgen.h"
#include "nodemetadata.h"
#include "content_mapnode.h"
+#ifndef SERVER
+#include <IMaterialRenderer.h>
+#endif
+#include "settings.h"
/*
SQLite format specification:
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();
//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)
}
else
{
- m_seed = g_settings.getU64("fixed_map_seed");
+ m_seed = g_settings->getU64("fixed_map_seed");
}
/*
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;
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);*/
<<"("<<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");
// - 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);
}
#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)
{
/*
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.
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);
}
protected:
+#ifndef SERVER
scene::IMeshSceneNode *m_node;
+#endif
std::string m_text;
f32 m_yaw;
};
{
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);
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;
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);*/
}
protected:
+#ifndef SERVER
scene::IMeshSceneNode *m_node;
+#endif
std::string m_itemstring;
f32 m_yaw;
};
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>
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;
}
};
+namespace irr{
+namespace scene{
+ class ISceneManager;
+}
+}
+using namespace irr;
+
class MapBlockObjectList
{
public:
#include "common_irrlicht.h"
#include "mapnode.h"
+#ifndef SERVER
#include "tile.h"
+#endif
#include "porting.h"
#include <string>
#include "mineral.h"
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)
imgname_full += right;
inventory_texture = g_texturesource->getTextureRaw(imgname_full);
}
+#endif
struct ContentFeatures g_content_features[MAX_CONTENT+1];
/*
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.
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.
return newdir;
}
+#ifndef SERVER
TileSpec MapNode::getTile(v3s16 dir)
{
if(content_features(*this).param_type == CPT_FACEDIR_SIMPLE)
return spec;
}
+#endif
u8 MapNode::getMineral()
{
#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:
struct ContentFeatures
{
- // Type of MapNode::param1
- ContentParamType param_type;
-
+#ifndef SERVER
/*
0: up
1: down
TileSpec tiles[6];
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;
// Mineral overrides this.
std::string dug_item;
- // Extra dug item and its rarity
- std::string extra_dug_item;
- s32 extra_dug_item_rarity;
-
+ // Extra dug item and its rarity
+ std::string extra_dug_item;
+ s32 extra_dug_item_rarity;
+
// Initial metadata is cloned from this
NodeMetadata *initial_metadata;
// 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;
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;
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;
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)
// Force inventory texture too
setInventoryTexture(name);
}
+#endif
+#ifndef SERVER
void setTile(u16 i, const TileSpec &tile)
{
tiles[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 setInventoryTextureCube(std::string top,
std::string left, std::string right);
+#endif
};
/*
}
// In mapnode.cpp
+#ifndef SERVER
/*
Get tile of a face of the node.
dir: direction of face
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.
#include "connection.h"
#include "constants.h"
#include "utility.h"
-
+#ifndef SERVER
+#include <ITextSceneNode.h>
+#endif
+#include "settings.h"
Player::Player():
touching_ground(false),
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);
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)
{
#include "content_nodemeta.h"
#include "mapblock.h"
#include "serverobject.h"
+#include "settings.h"
+#include "profiler.h"
#define BLOCK_EMERGE_FLAG_FROMDISK (1<<0)
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
}
// 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;
//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;
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
*/
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)
{
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;
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;
}
{
- 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);
{
// 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();
}
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;
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);
{
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);
}
{
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"));
}
/*
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);
}
}
- //if(g_settings.getBool("enable_experimental"))
+ //if(g_settings->getBool("enable_experimental"))
{
/*
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;
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
{
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);
{
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())
/*// 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
}
else
{
- checkpwd = g_settings.get("default_password");
+ checkpwd = g_settings->get("default_password");
}
/*dstream<<"Server: Client gave password '"<<password
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;
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
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)
Update and send inventory
*/
- if(g_settings.getBool("creative_mode") == false)
+ if(g_settings->getBool("creative_mode") == false)
{
/*
Wear out tool
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)
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: "
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();
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;
*/
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" &&
}
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);
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();
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;
/*
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");
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;
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
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
Add stuff to inventory
*/
- if(g_settings.getBool("creative_mode"))
+ if(g_settings->getBool("creative_mode"))
{
// Warning: double code above
// Backup actual inventory
// 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);
}
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;
}
// 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);
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();
}
}
#include "environment.h"
#include "common_irrlicht.h"
#include <string>
-#include "utility.h"
#include "porting.h"
#include "map.h"
#include "inventory.h"
}
// 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)
{
#include "servercommand.h"
#include "utility.h"
+#include "settings.h"
void cmd_status(std::wostringstream &os,
ServerCommandContext *ctx)
std::string confline = wide_to_narrow(ctx->paramstring);
- g_settings.parseConfigLine(confline);
+ g_settings->parseConfigLine(confline);
ctx->server->saveConfig();
#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;
*/
// Initialize default settings
- set_default_settings();
+ set_default_settings(g_settings);
// Initialize sockets
sockets_init();
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 \""
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];
{
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
{
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);
--- /dev/null
+/*
+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
+
#include "porting.h"
#include "content_mapnode.h"
#include "mapsector.h"
+#include "settings.h"
/*
Asserts that the exception occurs
#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
/*
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;
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;
next = seed;
}
+#ifndef SERVER
// Sets the color of all vertices in the mesh
void setMeshVerticesColor(scene::IMesh* mesh, video::SColor& color)
{
}
}
}
+#endif
/*
blockpos: position of block in block coordinates
#include <jthread.h>
#include <jmutex.h>
#include <jmutexautolock.h>
+#include <cstring>
#include "common_irrlicht.h"
#include "debug.h"
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)
}
};
-/*
- 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)
*/