]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/main.cpp
Add emerge.cpp, initial EmergeThread changes
[dragonfireclient.git] / src / main.cpp
index 3352b866c52a41c291c59c5621b5503cb36e1c52..cfd643ac76ba6fb9f7fc6d24c75dc66ba15eb82f 100644 (file)
@@ -1,6 +1,6 @@
 /*
-Minetest-c55
-Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2010-2013 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 Lesser General Public License as published by
@@ -47,7 +47,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <iostream>
 #include <fstream>
 #include <locale.h>
-#include "common_irrlicht.h"
+#include "irrlichttypes_extrabloated.h"
 #include "debug.h"
 #include "test.h"
 #include "server.h"
@@ -68,9 +68,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "profiler.h"
 #include "log.h"
 #include "mods.h"
+#if USE_FREETYPE
+#include "xCGUITTFont.h"
+#endif
 #include "util/string.h"
 #include "subgame.h"
 #include "quicktune.h"
+#include "serverlist.h"
 
 /*
        Settings.
@@ -766,11 +770,19 @@ int main(int argc, char *argv[])
 
        log_register_thread("main");
 
-       // Set locale. This is for forcing '.' as the decimal point.
-       std::locale::global(std::locale("C"));
-       // This enables printing all characters in bitmap font
-       setlocale(LC_CTYPE, "en_US");
+       // This enables internatonal characters input
+       if( setlocale(LC_ALL, "") == NULL )
+       {
+               fprintf( stderr, "%s: warning: could not set default locale\n", argv[0] );
+       }
 
+       // Set locale. This is for forcing '.' as the decimal point.
+       try {
+               std::locale::global(std::locale(std::locale(""), "C", std::locale::numeric));
+               setlocale(LC_NUMERIC, "C");
+       } catch (const std::exception& ex) {
+               errorstream<<"Could not set numeric locale to C"<<std::endl;
+       }
        /*
                Parse command line
        */
@@ -874,23 +886,8 @@ int main(int argc, char *argv[])
        // Create user data directory
        fs::CreateDir(porting::path_user);
 
-       init_gettext((porting::path_share+DIR_DELIM+".."+DIR_DELIM+"locale").c_str());
-       
-       // Initialize debug streams
-#define DEBUGFILE "debug.txt"
-#ifdef RUN_IN_PLACE
-       std::string logfile = DEBUGFILE;
-#else
-       std::string logfile = porting::path_user+DIR_DELIM+DEBUGFILE;
-#endif
-       if(cmd_args.exists("logfile"))
-               logfile = cmd_args.get("logfile");
-       if(logfile != "")
-               debugstreams_init(false, logfile.c_str());
-       else
-               debugstreams_init(false, NULL);
+       init_gettext((porting::path_share + DIR_DELIM + "locale").c_str());
 
-       infostream<<"logfile    = "<<logfile<<std::endl;
        infostream<<"path_share = "<<porting::path_share<<std::endl;
        infostream<<"path_user  = "<<porting::path_user<<std::endl;
 
@@ -962,7 +959,7 @@ int main(int argc, char *argv[])
                // Legacy configuration file location
                filenames.push_back(porting::path_user +
                                DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
-#ifdef RUN_IN_PLACE
+#if RUN_IN_PLACE
                // Try also from a lower level (to aid having the same configuration
                // for many RUN_IN_PLACE installs)
                filenames.push_back(porting::path_user +
@@ -983,6 +980,31 @@ int main(int argc, char *argv[])
                if(configpath == "")
                        configpath = filenames[0];
        }
+       
+       // Initialize debug streams
+#define DEBUGFILE "debug.txt"
+#if RUN_IN_PLACE
+       std::string logfile = DEBUGFILE;
+#else
+       std::string logfile = porting::path_user+DIR_DELIM+DEBUGFILE;
+#endif
+       if(cmd_args.exists("logfile"))
+               logfile = cmd_args.get("logfile");
+       
+       log_remove_output(&main_dstream_no_stderr_log_out);
+       int loglevel = g_settings->getS32("debug_log_level");
+
+       if (loglevel == 0) //no logging
+               logfile = "";
+       else if (loglevel > 0 && loglevel <= LMT_NUM_VALUES)
+               log_add_output_maxlev(&main_dstream_no_stderr_log_out, (LogMessageLevel)(loglevel - 1));
+
+       if(logfile != "")
+               debugstreams_init(false, logfile.c_str());
+       else
+               debugstreams_init(false, NULL);
+               
+       infostream<<"logfile    = "<<logfile<<std::endl;
 
        // Initialize random seed
        srand(time(0));
@@ -1083,6 +1105,7 @@ int main(int argc, char *argv[])
 #else
        bool run_dedicated_server = cmd_args.getFlag("server");
 #endif
+       g_settings->set("server_dedicated", run_dedicated_server ? "true" : "false");
        if(run_dedicated_server)
        {
                DSTACK("Dedicated server branch");
@@ -1292,9 +1315,6 @@ int main(int argc, char *argv[])
 
        video::IVideoDriver* driver = device->getVideoDriver();
 
-       // Disable mipmaps (because some of them look ugly)
-       driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
-
        /*
                This changes the minimum allowed number of vertices in a VBO.
                Default is 500.
@@ -1331,7 +1351,13 @@ int main(int argc, char *argv[])
 
        guienv = device->getGUIEnvironment();
        gui::IGUISkin* skin = guienv->getSkin();
+       #if USE_FREETYPE
+       std::string font_path = g_settings->get("font_path");
+       u16 font_size = g_settings->getU16("font_size");
+       gui::IGUIFont *font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size);
+       #else
        gui::IGUIFont* font = guienv->getFont(getTexturePath("fontlucida.png").c_str());
+       #endif
        if(font)
                skin->setFont(font);
        else
@@ -1352,7 +1378,13 @@ int main(int argc, char *argv[])
        skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255,0,0,0));
        skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255,70,100,50));
        skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255,255,255,255));
-       
+
+#if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
+       // Irrlicht 1.8 input colours
+       skin->setColor(gui::EGDC_EDITABLE, video::SColor(255,128,128,128));
+       skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255,96,134,49));
+#endif
+
        /*
                GUI stuff
        */
@@ -1439,8 +1471,17 @@ int main(int argc, char *argv[])
                                menudata.smooth_lighting = g_settings->getBool("smooth_lighting");
                                menudata.clouds_3d = g_settings->getBool("enable_3d_clouds");
                                menudata.opaque_water = g_settings->getBool("opaque_water");
+                               menudata.mip_map = g_settings->getBool("mip_map");
+                               menudata.anisotropic_filter = g_settings->getBool("anisotropic_filter");
+                               menudata.bilinear_filter = g_settings->getBool("bilinear_filter");
+                               menudata.trilinear_filter = g_settings->getBool("trilinear_filter");
+                               menudata.enable_shaders = g_settings->getS32("enable_shaders");
+                               menudata.preload_item_visuals = g_settings->getBool("preload_item_visuals");
+                               menudata.enable_particles = g_settings->getBool("enable_particles");
+                               driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, menudata.mip_map);
                                menudata.creative_mode = g_settings->getBool("creative_mode");
                                menudata.enable_damage = g_settings->getBool("enable_damage");
+                               menudata.enable_public = g_settings->getBool("server_announce");
                                // Default to selecting nothing
                                menudata.selected_world = -1;
                                // Get world listing for the menu
@@ -1552,15 +1593,26 @@ int main(int argc, char *argv[])
                                g_settings->set("smooth_lighting", itos(menudata.smooth_lighting));
                                g_settings->set("enable_3d_clouds", itos(menudata.clouds_3d));
                                g_settings->set("opaque_water", itos(menudata.opaque_water));
+
+                               g_settings->set("mip_map", itos(menudata.mip_map));
+                               g_settings->set("anisotropic_filter", itos(menudata.anisotropic_filter));
+                               g_settings->set("bilinear_filter", itos(menudata.bilinear_filter));
+                               g_settings->set("trilinear_filter", itos(menudata.trilinear_filter));
+
+                               g_settings->setS32("enable_shaders", menudata.enable_shaders);
+                               g_settings->set("preload_item_visuals", itos(menudata.preload_item_visuals));
+                               g_settings->set("enable_particles", itos(menudata.enable_particles));
+
                                g_settings->set("creative_mode", itos(menudata.creative_mode));
                                g_settings->set("enable_damage", itos(menudata.enable_damage));
+                               g_settings->set("server_announce", itos(menudata.enable_public));
                                g_settings->set("name", playername);
                                g_settings->set("address", address);
                                g_settings->set("port", itos(port));
                                if(menudata.selected_world != -1)
                                        g_settings->set("selected_world_path",
                                                        worldspecs[menudata.selected_world].path);
-                               
+
                                // Break out of menu-game loop to shut down cleanly
                                if(device->run() == false || kill == true)
                                        break;
@@ -1577,6 +1629,15 @@ int main(int argc, char *argv[])
                                        current_address = "";
                                        current_port = 30011;
                                }
+                               else if (address != "")
+                               {
+                                       ServerListSpec server;
+                                       server["name"] = menudata.servername;
+                                       server["address"] = wide_to_narrow(menudata.address);
+                                       server["port"] = wide_to_narrow(menudata.port);
+                                       server["description"] = menudata.serverdescription;
+                                       ServerList::insert(server);
+                               }
                                
                                // Set world path to selected one
                                if(menudata.selected_world != -1){