3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #pragma message ("Disabling unit tests")
24 #warning "Disabling unit tests"
27 #define ENABLE_TESTS 0
30 #define ENABLE_TESTS 1
34 #ifndef SERVER // Dedicated server isn't linked with Irrlicht
35 #pragma comment(lib, "Irrlicht.lib")
36 // This would get rid of the console window
37 //#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
39 #pragma comment(lib, "zlibwapi.lib")
40 #pragma comment(lib, "Shell32.lib")
43 #include "irrlicht.h" // createDevice
46 #include "mainmenumanager.h"
50 #include "irrlichttypes_extrabloated.h"
55 #include "constants.h"
58 #include "guiMessageMenu.h"
61 #include "guiMainMenu.h"
66 #include "defaultsettings.h"
73 #include "xCGUITTFont.h"
75 #include "util/string.h"
77 #include "quicktune.h"
78 #include "serverlist.h"
82 These are loaded from the config file.
84 Settings main_settings;
85 Settings *g_settings = &main_settings;
88 Profiler main_profiler;
89 Profiler *g_profiler = &main_profiler;
91 // Menu clouds are created later
92 Clouds *g_menuclouds = 0;
93 irr::scene::ISceneManager *g_menucloudsmgr = 0;
100 std::ostream *dout_con_ptr = &dummyout;
101 std::ostream *derr_con_ptr = &verbosestream;
104 std::ostream *dout_server_ptr = &infostream;
105 std::ostream *derr_server_ptr = &errorstream;
108 std::ostream *dout_client_ptr = &infostream;
109 std::ostream *derr_client_ptr = &errorstream;
116 /* mainmenumanager.h */
118 gui::IGUIEnvironment* guienv = NULL;
119 gui::IGUIStaticText *guiroot = NULL;
120 MainMenuManager g_menumgr;
124 return (g_menumgr.menuCount() == 0);
127 // Passed to menus to allow disconnecting and exiting
128 MainGameCallback *g_gamecallback = NULL;
132 gettime.h implementation
139 /* Use imprecise system calls directly (from porting.h) */
140 return porting::getTime(PRECISION_MILLI);
143 u32 getTime(TimePrecision prec)
145 return porting::getTime(prec);
150 // A small helper class
154 virtual u32 getTime(TimePrecision prec) = 0;
157 // A precise irrlicht one
158 class IrrlichtTimeGetter: public TimeGetter
161 IrrlichtTimeGetter(IrrlichtDevice *device):
164 u32 getTime(TimePrecision prec)
166 if (prec == PRECISION_MILLI) {
169 return m_device->getTimer()->getRealTime();
171 return porting::getTime(prec);
175 IrrlichtDevice *m_device;
177 // Not so precise one which works without irrlicht
178 class SimpleTimeGetter: public TimeGetter
181 u32 getTime(TimePrecision prec)
183 return porting::getTime(prec);
187 // A pointer to a global instance of the time getter
189 TimeGetter *g_timegetter = NULL;
193 if(g_timegetter == NULL)
195 return g_timegetter->getTime(PRECISION_MILLI);
198 u32 getTime(TimePrecision prec) {
199 if (g_timegetter == NULL)
201 return g_timegetter->getTime(prec);
206 class StderrLogOutput: public ILogOutput
209 /* line: Full line with timestamp, level and thread */
210 void printLog(const std::string &line)
212 std::cerr<<line<<std::endl;
214 } main_stderr_log_out;
216 class DstreamNoStderrLogOutput: public ILogOutput
219 /* line: Full line with timestamp, level and thread */
220 void printLog(const std::string &line)
222 dstream_no_stderr<<line<<std::endl;
224 } main_dstream_no_stderr_log_out;
229 Event handler for Irrlicht
231 NOTE: Everything possible should be moved out from here,
232 probably to InputHandler and the_game
235 class MyEventReceiver : public IEventReceiver
238 // This is the one method that we have to implement
239 virtual bool OnEvent(const SEvent& event)
242 React to nothing here if a menu is active
244 if(noMenuActive() == false)
249 // Remember whether each key is down or up
250 if(event.EventType == irr::EET_KEY_INPUT_EVENT)
252 if(event.KeyInput.PressedDown) {
253 keyIsDown.set(event.KeyInput);
254 keyWasDown.set(event.KeyInput);
256 keyIsDown.unset(event.KeyInput);
260 if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
262 if(noMenuActive() == false)
265 middle_active = false;
266 right_active = false;
270 left_active = event.MouseInput.isLeftPressed();
271 middle_active = event.MouseInput.isMiddlePressed();
272 right_active = event.MouseInput.isRightPressed();
274 if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
278 if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
282 if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
286 if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)
288 rightreleased = true;
290 if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)
292 mouse_wheel += event.MouseInput.Wheel;
300 bool IsKeyDown(const KeyPress &keyCode) const
302 return keyIsDown[keyCode];
305 // Checks whether a key was down and resets the state
306 bool WasKeyDown(const KeyPress &keyCode)
308 bool b = keyWasDown[keyCode];
310 keyWasDown.unset(keyCode);
327 rightclicked = false;
328 leftreleased = false;
329 rightreleased = false;
332 middle_active = false;
333 right_active = false;
355 IrrlichtDevice *m_device;
357 // The current state of keys
359 // Whether a key has been pressed or not
364 Separated input handler
367 class RealInputHandler : public InputHandler
370 RealInputHandler(IrrlichtDevice *device, MyEventReceiver *receiver):
375 virtual bool isKeyDown(const KeyPress &keyCode)
377 return m_receiver->IsKeyDown(keyCode);
379 virtual bool wasKeyDown(const KeyPress &keyCode)
381 return m_receiver->WasKeyDown(keyCode);
383 virtual v2s32 getMousePos()
385 return m_device->getCursorControl()->getPosition();
387 virtual void setMousePos(s32 x, s32 y)
389 m_device->getCursorControl()->setPosition(x, y);
392 virtual bool getLeftState()
394 return m_receiver->left_active;
396 virtual bool getRightState()
398 return m_receiver->right_active;
401 virtual bool getLeftClicked()
403 return m_receiver->leftclicked;
405 virtual bool getRightClicked()
407 return m_receiver->rightclicked;
409 virtual void resetLeftClicked()
411 m_receiver->leftclicked = false;
413 virtual void resetRightClicked()
415 m_receiver->rightclicked = false;
418 virtual bool getLeftReleased()
420 return m_receiver->leftreleased;
422 virtual bool getRightReleased()
424 return m_receiver->rightreleased;
426 virtual void resetLeftReleased()
428 m_receiver->leftreleased = false;
430 virtual void resetRightReleased()
432 m_receiver->rightreleased = false;
435 virtual s32 getMouseWheel()
437 return m_receiver->getMouseWheel();
442 m_receiver->clearInput();
445 IrrlichtDevice *m_device;
446 MyEventReceiver *m_receiver;
449 class RandomInputHandler : public InputHandler
457 rightclicked = false;
458 leftreleased = false;
459 rightreleased = false;
462 virtual bool isKeyDown(const KeyPress &keyCode)
464 return keydown[keyCode];
466 virtual bool wasKeyDown(const KeyPress &keyCode)
470 virtual v2s32 getMousePos()
474 virtual void setMousePos(s32 x, s32 y)
476 mousepos = v2s32(x,y);
479 virtual bool getLeftState()
483 virtual bool getRightState()
488 virtual bool getLeftClicked()
492 virtual bool getRightClicked()
496 virtual void resetLeftClicked()
500 virtual void resetRightClicked()
502 rightclicked = false;
505 virtual bool getLeftReleased()
509 virtual bool getRightReleased()
511 return rightreleased;
513 virtual void resetLeftReleased()
515 leftreleased = false;
517 virtual void resetRightReleased()
519 rightreleased = false;
522 virtual s32 getMouseWheel()
527 virtual void step(float dtime)
530 static float counter1 = 0;
534 counter1 = 0.1*Rand(1, 40);
535 keydown.toggle(getKeySetting("keymap_jump"));
539 static float counter1 = 0;
543 counter1 = 0.1*Rand(1, 40);
544 keydown.toggle(getKeySetting("keymap_special1"));
548 static float counter1 = 0;
552 counter1 = 0.1*Rand(1, 40);
553 keydown.toggle(getKeySetting("keymap_forward"));
557 static float counter1 = 0;
561 counter1 = 0.1*Rand(1, 40);
562 keydown.toggle(getKeySetting("keymap_left"));
566 static float counter1 = 0;
570 counter1 = 0.1*Rand(1, 20);
571 mousespeed = v2s32(Rand(-20,20), Rand(-15,20));
575 static float counter1 = 0;
579 counter1 = 0.1*Rand(1, 30);
580 leftdown = !leftdown;
588 static float counter1 = 0;
592 counter1 = 0.1*Rand(1, 15);
593 rightdown = !rightdown;
597 rightreleased = true;
600 mousepos += mousespeed;
603 s32 Rand(s32 min, s32 max)
605 return (myrand()%(max-min+1))+min;
621 std::string current_gameid;
622 video::ITexture *background;
623 video::ITexture *overlay;
624 video::ITexture *header;
625 video::ITexture *footer;
634 static video::ITexture* getMenuTexture(const std::string &tname,
635 video::IVideoDriver* driver, const SubgameSpec *spec)
638 // eg. minetest_menu_background.png (for texture packs)
639 std::string pack_tname = spec->id + "_menu_" + tname + ".png";
640 path = getTexturePath(pack_tname);
642 return driver->getTexture(path.c_str());
643 // eg. games/minetest_game/menu/background.png
644 path = getImagePath(spec->path + DIR_DELIM + "menu" + DIR_DELIM + tname + ".png");
646 return driver->getTexture(path.c_str());
650 void update(video::IVideoDriver* driver, const SubgameSpec *spec)
652 if(spec->id == current_gameid)
654 current_gameid = spec->id;
655 background = getMenuTexture("background", driver, spec);
656 overlay = getMenuTexture("overlay", driver, spec);
657 header = getMenuTexture("header", driver, spec);
658 footer = getMenuTexture("footer", driver, spec);
662 void drawMenuBackground(video::IVideoDriver* driver, const MenuTextures &menutextures)
664 v2u32 screensize = driver->getScreenSize();
665 video::ITexture *texture = menutextures.background;
667 /* If no texture, draw background of solid color */
669 video::SColor color(255,80,58,37);
670 core::rect<s32> rect(0, 0, screensize.X, screensize.Y);
671 driver->draw2DRectangle(color, rect, NULL);
675 /* Draw background texture */
676 v2u32 sourcesize = texture->getSize();
677 driver->draw2DImage(texture,
678 core::rect<s32>(0, 0, screensize.X, screensize.Y),
679 core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
683 void drawMenuOverlay(video::IVideoDriver* driver, const MenuTextures &menutextures)
685 v2u32 screensize = driver->getScreenSize();
686 video::ITexture *texture = menutextures.overlay;
688 /* If no texture, draw nothing */
692 /* Draw overlay texture */
693 v2u32 sourcesize = texture->getSize();
694 driver->draw2DImage(texture,
695 core::rect<s32>(0, 0, screensize.X, screensize.Y),
696 core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
700 void drawMenuHeader(video::IVideoDriver* driver, const MenuTextures &menutextures)
702 core::dimension2d<u32> screensize = driver->getScreenSize();
703 video::ITexture *texture = menutextures.header;
705 /* If no texture, draw nothing */
709 f32 mult = (((f32)screensize.Width / 2)) /
710 ((f32)texture->getOriginalSize().Width);
712 v2s32 splashsize(((f32)texture->getOriginalSize().Width) * mult,
713 ((f32)texture->getOriginalSize().Height) * mult);
715 // Don't draw the header is there isn't enough room
716 s32 free_space = (((s32)screensize.Height)-320)/2;
717 if (free_space > splashsize.Y) {
718 core::rect<s32> splashrect(0, 0, splashsize.X, splashsize.Y);
719 splashrect += v2s32((screensize.Width/2)-(splashsize.X/2),
720 ((free_space/2)-splashsize.Y/2)+10);
722 video::SColor bgcolor(255,50,50,50);
724 driver->draw2DImage(texture, splashrect,
725 core::rect<s32>(core::position2d<s32>(0,0),
726 core::dimension2di(texture->getSize())),
731 void drawMenuFooter(video::IVideoDriver* driver, const MenuTextures &menutextures)
733 core::dimension2d<u32> screensize = driver->getScreenSize();
734 video::ITexture *texture = menutextures.footer;
736 /* If no texture, draw nothing */
740 f32 mult = (((f32)screensize.Width)) /
741 ((f32)texture->getOriginalSize().Width);
743 v2s32 footersize(((f32)texture->getOriginalSize().Width) * mult,
744 ((f32)texture->getOriginalSize().Height) * mult);
746 // Don't draw the footer if there isn't enough room
747 s32 free_space = (((s32)screensize.Height)-320)/2;
748 if (free_space > footersize.Y) {
749 core::rect<s32> rect(0,0,footersize.X,footersize.Y);
750 rect += v2s32(screensize.Width/2,screensize.Height-footersize.Y);
751 rect -= v2s32(footersize.X/2, 0);
753 driver->draw2DImage(texture, rect,
754 core::rect<s32>(core::position2d<s32>(0,0),
755 core::dimension2di(texture->getSize())),
760 static const SubgameSpec* getMenuGame(const MainMenuData &menudata)
762 for(size_t i=0; i<menudata.games.size(); i++){
763 if(menudata.games[i].id == menudata.selected_game){
764 return &menudata.games[i];
772 // These are defined global so that they're not optimized too much.
773 // Can't change them to volatile.
778 std::string tempstring;
779 std::string tempstring2;
784 infostream<<"The following test should take around 20ms."<<std::endl;
785 TimeTaker timer("Testing std::string speed");
786 const u32 jj = 10000;
787 for(u32 j=0; j<jj; j++)
792 for(u32 i=0; i<ii; i++){
793 tempstring2 += "asd";
795 for(u32 i=0; i<ii+1; i++){
797 if(tempstring == tempstring2)
803 infostream<<"All of the following tests should take around 100ms each."
807 TimeTaker timer("Testing floating-point conversion speed");
809 for(u32 i=0; i<4000000; i++){
816 TimeTaker timer("Testing floating-point vector speed");
818 tempv3f1 = v3f(1,2,3);
819 tempv3f2 = v3f(4,5,6);
820 for(u32 i=0; i<10000000; i++){
821 tempf += tempv3f1.dotProduct(tempv3f2);
822 tempv3f2 += v3f(7,8,9);
827 TimeTaker timer("Testing std::map speed");
829 std::map<v2s16, f32> map1;
832 for(s16 y=0; y<ii; y++){
833 for(s16 x=0; x<ii; x++){
834 map1[v2s16(x,y)] = tempf;
838 for(s16 y=ii-1; y>=0; y--){
839 for(s16 x=0; x<ii; x++){
840 tempf = map1[v2s16(x,y)];
846 infostream<<"Around 5000/ms should do well here."<<std::endl;
847 TimeTaker timer("Testing mutex speed");
861 while(timer.getTimerTime() < 10);
863 u32 dtime = timer.stop();
864 u32 per_ms = n / dtime;
865 infostream<<"Done. "<<dtime<<"ms, "
866 <<per_ms<<"/ms"<<std::endl;
870 static void print_worldspecs(const std::vector<WorldSpec> &worldspecs,
873 for(u32 i=0; i<worldspecs.size(); i++){
874 std::string name = worldspecs[i].name;
875 std::string path = worldspecs[i].path;
876 if(name.find(" ") != std::string::npos)
877 name = std::string("'") + name + "'";
878 path = std::string("'") + path + "'";
879 name = padStringRight(name, 14);
880 os<<" "<<name<<" "<<path<<std::endl;
884 int main(int argc, char *argv[])
892 log_add_output_maxlev(&main_stderr_log_out, LMT_ACTION);
893 log_add_output_all_levs(&main_dstream_no_stderr_log_out);
895 log_register_thread("main");
897 // This enables internatonal characters input
898 if( setlocale(LC_ALL, "") == NULL )
900 fprintf( stderr, "%s: warning: could not set default locale\n", argv[0] );
903 // Set locale. This is for forcing '.' as the decimal point.
905 std::locale::global(std::locale(std::locale(""), "C", std::locale::numeric));
906 setlocale(LC_NUMERIC, "C");
907 } catch (const std::exception& ex) {
908 errorstream<<"Could not set numeric locale to C"<<std::endl;
914 // List all allowed options
915 std::map<std::string, ValueSpec> allowed_options;
916 allowed_options.insert(std::make_pair("help", ValueSpec(VALUETYPE_FLAG,
917 _("Show allowed options"))));
918 allowed_options.insert(std::make_pair("config", ValueSpec(VALUETYPE_STRING,
919 _("Load configuration from specified file"))));
920 allowed_options.insert(std::make_pair("port", ValueSpec(VALUETYPE_STRING,
921 _("Set network port (UDP)"))));
922 allowed_options.insert(std::make_pair("disable-unittests", ValueSpec(VALUETYPE_FLAG,
923 _("Disable unit tests"))));
924 allowed_options.insert(std::make_pair("enable-unittests", ValueSpec(VALUETYPE_FLAG,
925 _("Enable unit tests"))));
926 allowed_options.insert(std::make_pair("map-dir", ValueSpec(VALUETYPE_STRING,
927 _("Same as --world (deprecated)"))));
928 allowed_options.insert(std::make_pair("world", ValueSpec(VALUETYPE_STRING,
929 _("Set world path (implies local game) ('list' lists all)"))));
930 allowed_options.insert(std::make_pair("worldname", ValueSpec(VALUETYPE_STRING,
931 _("Set world by name (implies local game)"))));
932 allowed_options.insert(std::make_pair("info", ValueSpec(VALUETYPE_FLAG,
933 _("Print more information to console"))));
934 allowed_options.insert(std::make_pair("verbose", ValueSpec(VALUETYPE_FLAG,
935 _("Print even more information to console"))));
936 allowed_options.insert(std::make_pair("trace", ValueSpec(VALUETYPE_FLAG,
937 _("Print enormous amounts of information to log and console"))));
938 allowed_options.insert(std::make_pair("logfile", ValueSpec(VALUETYPE_STRING,
939 _("Set logfile path ('' = no logging)"))));
940 allowed_options.insert(std::make_pair("gameid", ValueSpec(VALUETYPE_STRING,
941 _("Set gameid (\"--gameid list\" prints available ones)"))));
943 allowed_options.insert(std::make_pair("videomodes", ValueSpec(VALUETYPE_FLAG,
944 _("Show available video modes"))));
945 allowed_options.insert(std::make_pair("speedtests", ValueSpec(VALUETYPE_FLAG,
946 _("Run speed tests"))));
947 allowed_options.insert(std::make_pair("address", ValueSpec(VALUETYPE_STRING,
948 _("Address to connect to. ('' = local game)"))));
949 allowed_options.insert(std::make_pair("random-input", ValueSpec(VALUETYPE_FLAG,
950 _("Enable random user input, for testing"))));
951 allowed_options.insert(std::make_pair("server", ValueSpec(VALUETYPE_FLAG,
952 _("Run dedicated server"))));
953 allowed_options.insert(std::make_pair("name", ValueSpec(VALUETYPE_STRING,
954 _("Set player name"))));
955 allowed_options.insert(std::make_pair("password", ValueSpec(VALUETYPE_STRING,
956 _("Set password"))));
957 allowed_options.insert(std::make_pair("go", ValueSpec(VALUETYPE_FLAG,
958 _("Disable main menu"))));
963 bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);
965 if(ret == false || cmd_args.getFlag("help") || cmd_args.exists("nonopt1"))
967 dstream<<_("Allowed options:")<<std::endl;
968 for(std::map<std::string, ValueSpec>::iterator
969 i = allowed_options.begin();
970 i != allowed_options.end(); ++i)
972 std::ostringstream os1(std::ios::binary);
973 os1<<" --"<<i->first;
974 if(i->second.type == VALUETYPE_FLAG)
978 dstream<<padStringRight(os1.str(), 24);
980 if(i->second.help != NULL)
981 dstream<<i->second.help;
985 return cmd_args.getFlag("help") ? 0 : 1;
989 Low-level initialization
992 // If trace is enabled, enable logging of certain things
993 if(cmd_args.getFlag("trace")){
994 dstream<<_("Enabling trace level debug output")<<std::endl;
995 log_trace_level_enabled = true;
996 dout_con_ptr = &verbosestream; // this is somewhat old crap
997 socket_enable_debug_output = true; // socket doesn't use log.h
999 // In certain cases, output info level on stderr
1000 if(cmd_args.getFlag("info") || cmd_args.getFlag("verbose") ||
1001 cmd_args.getFlag("trace") || cmd_args.getFlag("speedtests"))
1002 log_add_output(&main_stderr_log_out, LMT_INFO);
1003 // In certain cases, output verbose level on stderr
1004 if(cmd_args.getFlag("verbose") || cmd_args.getFlag("trace"))
1005 log_add_output(&main_stderr_log_out, LMT_VERBOSE);
1007 porting::signal_handler_init();
1008 bool &kill = *porting::signal_handler_killstatus();
1010 porting::initializePaths();
1012 // Create user data directory
1013 fs::CreateDir(porting::path_user);
1015 init_gettext((porting::path_share + DIR_DELIM + "locale").c_str());
1017 infostream<<"path_share = "<<porting::path_share<<std::endl;
1018 infostream<<"path_user = "<<porting::path_user<<std::endl;
1020 // Initialize debug stacks
1021 debug_stacks_init();
1022 DSTACK(__FUNCTION_NAME);
1025 BEGIN_DEBUG_EXCEPTION_HANDLER
1027 // List gameids if requested
1028 if(cmd_args.exists("gameid") && cmd_args.get("gameid") == "list")
1030 std::set<std::string> gameids = getAvailableGameIds();
1031 for(std::set<std::string>::const_iterator i = gameids.begin();
1032 i != gameids.end(); i++)
1033 dstream<<(*i)<<std::endl;
1037 // List worlds if requested
1038 if(cmd_args.exists("world") && cmd_args.get("world") == "list"){
1039 dstream<<_("Available worlds:")<<std::endl;
1040 std::vector<WorldSpec> worldspecs = getAvailableWorlds();
1041 print_worldspecs(worldspecs, dstream);
1045 // Print startup message
1046 infostream<<PROJECT_NAME<<
1047 " "<<_("with")<<" SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
1052 Basic initialization
1055 // Initialize default settings
1056 set_default_settings(g_settings);
1058 // Initialize sockets
1060 atexit(sockets_cleanup);
1066 // Path of configuration file in use
1067 std::string configpath = "";
1069 if(cmd_args.exists("config"))
1071 bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
1074 errorstream<<"Could not read configuration from \""
1075 <<cmd_args.get("config")<<"\""<<std::endl;
1078 configpath = cmd_args.get("config");
1082 std::vector<std::string> filenames;
1083 filenames.push_back(porting::path_user +
1084 DIR_DELIM + "minetest.conf");
1085 // Legacy configuration file location
1086 filenames.push_back(porting::path_user +
1087 DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
1089 // Try also from a lower level (to aid having the same configuration
1090 // for many RUN_IN_PLACE installs)
1091 filenames.push_back(porting::path_user +
1092 DIR_DELIM + ".." + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
1095 for(u32 i=0; i<filenames.size(); i++)
1097 bool r = g_settings->readConfigFile(filenames[i].c_str());
1100 configpath = filenames[i];
1105 // If no path found, use the first one (menu creates the file)
1106 if(configpath == "")
1107 configpath = filenames[0];
1110 // Initialize debug streams
1111 #define DEBUGFILE "debug.txt"
1113 std::string logfile = DEBUGFILE;
1115 std::string logfile = porting::path_user+DIR_DELIM+DEBUGFILE;
1117 if(cmd_args.exists("logfile"))
1118 logfile = cmd_args.get("logfile");
1120 log_remove_output(&main_dstream_no_stderr_log_out);
1121 int loglevel = g_settings->getS32("debug_log_level");
1123 if (loglevel == 0) //no logging
1125 else if (loglevel > 0 && loglevel <= LMT_NUM_VALUES)
1126 log_add_output_maxlev(&main_dstream_no_stderr_log_out, (LogMessageLevel)(loglevel - 1));
1129 debugstreams_init(false, logfile.c_str());
1131 debugstreams_init(false, NULL);
1133 infostream<<"logfile = "<<logfile<<std::endl;
1135 // Initialize random seed
1143 if((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false)
1144 || cmd_args.getFlag("enable-unittests") == true)
1155 if(cmd_args.exists("port"))
1156 port = cmd_args.getU16("port");
1157 else if(g_settings->exists("port"))
1158 port = g_settings->getU16("port");
1163 std::string commanded_world = "";
1164 if(cmd_args.exists("world"))
1165 commanded_world = cmd_args.get("world");
1166 else if(cmd_args.exists("map-dir"))
1167 commanded_world = cmd_args.get("map-dir");
1168 else if(cmd_args.exists("nonopt0")) // First nameless argument
1169 commanded_world = cmd_args.get("nonopt0");
1170 else if(g_settings->exists("map-dir"))
1171 commanded_world = g_settings->get("map-dir");
1174 std::string commanded_worldname = "";
1175 if(cmd_args.exists("worldname"))
1176 commanded_worldname = cmd_args.get("worldname");
1178 // Strip world.mt from commanded_world
1180 std::string worldmt = "world.mt";
1181 if(commanded_world.size() > worldmt.size() &&
1182 commanded_world.substr(commanded_world.size()-worldmt.size())
1184 dstream<<_("Supplied world.mt file - stripping it off.")<<std::endl;
1185 commanded_world = commanded_world.substr(
1186 0, commanded_world.size()-worldmt.size());
1190 // If a world name was specified, convert it to a path
1191 if(commanded_worldname != ""){
1192 // Get information about available worlds
1193 std::vector<WorldSpec> worldspecs = getAvailableWorlds();
1195 for(u32 i=0; i<worldspecs.size(); i++){
1196 std::string name = worldspecs[i].name;
1197 if(name == commanded_worldname){
1198 if(commanded_world != ""){
1199 dstream<<_("--worldname takes precedence over previously "
1200 "selected world.")<<std::endl;
1202 commanded_world = worldspecs[i].path;
1208 dstream<<_("World")<<" '"<<commanded_worldname<<_("' not "
1209 "available. Available worlds:")<<std::endl;
1210 print_worldspecs(worldspecs, dstream);
1216 SubgameSpec commanded_gamespec;
1217 if(cmd_args.exists("gameid")){
1218 std::string gameid = cmd_args.get("gameid");
1219 commanded_gamespec = findSubgame(gameid);
1220 if(!commanded_gamespec.isValid()){
1221 errorstream<<"Game \""<<gameid<<"\" not found"<<std::endl;
1227 Run dedicated server if asked to or no other option
1230 bool run_dedicated_server = true;
1232 bool run_dedicated_server = cmd_args.getFlag("server");
1234 g_settings->set("server_dedicated", run_dedicated_server ? "true" : "false");
1235 if(run_dedicated_server)
1237 DSTACK("Dedicated server branch");
1238 // Create time getter if built with Irrlicht
1240 g_timegetter = new SimpleTimeGetter();
1244 std::string world_path;
1245 verbosestream<<_("Determining world path")<<std::endl;
1246 bool is_legacy_world = false;
1247 // If a world was commanded, use it
1248 if(commanded_world != ""){
1249 world_path = commanded_world;
1250 infostream<<"Using commanded world path ["<<world_path<<"]"
1253 // No world was specified; try to select it automatically
1256 // Get information about available worlds
1257 std::vector<WorldSpec> worldspecs = getAvailableWorlds();
1258 // If a world name was specified, select it
1259 if(commanded_worldname != ""){
1261 for(u32 i=0; i<worldspecs.size(); i++){
1262 std::string name = worldspecs[i].name;
1263 if(name == commanded_worldname){
1264 world_path = worldspecs[i].path;
1268 if(world_path == ""){
1269 dstream<<_("World")<<" '"<<commanded_worldname<<"' "<<_("not "
1270 "available. Available worlds:")<<std::endl;
1271 print_worldspecs(worldspecs, dstream);
1275 // If there is only a single world, use it
1276 if(worldspecs.size() == 1){
1277 world_path = worldspecs[0].path;
1278 dstream<<_("Automatically selecting world at")<<" ["
1279 <<world_path<<"]"<<std::endl;
1280 // If there are multiple worlds, list them
1281 } else if(worldspecs.size() > 1){
1282 dstream<<_("Multiple worlds are available.")<<std::endl;
1283 dstream<<_("Please select one using --worldname <name>"
1284 " or --world <path>")<<std::endl;
1285 print_worldspecs(worldspecs, dstream);
1287 // If there are no worlds, automatically create a new one
1289 // This is the ultimate default world path
1290 world_path = porting::path_user + DIR_DELIM + "worlds" +
1291 DIR_DELIM + "world";
1292 infostream<<"Creating default world at ["
1293 <<world_path<<"]"<<std::endl;
1297 if(world_path == ""){
1298 errorstream<<"No world path specified or found."<<std::endl;
1301 verbosestream<<_("Using world path")<<" ["<<world_path<<"]"<<std::endl;
1303 // We need a gamespec.
1304 SubgameSpec gamespec;
1305 verbosestream<<_("Determining gameid/gamespec")<<std::endl;
1306 // If world doesn't exist
1307 if(!getWorldExists(world_path))
1309 // Try to take gamespec from command line
1310 if(commanded_gamespec.isValid()){
1311 gamespec = commanded_gamespec;
1312 infostream<<"Using commanded gameid ["<<gamespec.id<<"]"<<std::endl;
1314 // Otherwise we will be using "minetest"
1316 gamespec = findSubgame(g_settings->get("default_game"));
1317 infostream<<"Using default gameid ["<<gamespec.id<<"]"<<std::endl;
1323 std::string world_gameid = getWorldGameId(world_path, is_legacy_world);
1324 // If commanded to use a gameid, do so
1325 if(commanded_gamespec.isValid()){
1326 gamespec = commanded_gamespec;
1327 if(commanded_gamespec.id != world_gameid){
1328 errorstream<<"WARNING: Using commanded gameid ["
1329 <<gamespec.id<<"]"<<" instead of world gameid ["
1330 <<world_gameid<<"]"<<std::endl;
1333 // If world contains an embedded game, use it;
1334 // Otherwise find world from local system.
1335 gamespec = findWorldSubgame(world_path);
1336 infostream<<"Using world gameid ["<<gamespec.id<<"]"<<std::endl;
1339 if(!gamespec.isValid()){
1340 errorstream<<"Subgame ["<<gamespec.id<<"] could not be found."
1344 verbosestream<<_("Using gameid")<<" ["<<gamespec.id<<"]"<<std::endl;
1347 Server server(world_path, configpath, gamespec, false);
1351 dedicated_server_loop(server, kill);
1356 #ifndef SERVER // Exclude from dedicated server build
1362 std::string address = g_settings->get("address");
1363 if(commanded_world != "")
1365 else if(cmd_args.exists("address"))
1366 address = cmd_args.get("address");
1368 std::string playername = g_settings->get("name");
1369 if(cmd_args.exists("name"))
1370 playername = cmd_args.get("name");
1372 bool skip_main_menu = cmd_args.getFlag("go");
1375 Device initialization
1378 // Resolution selection
1380 bool fullscreen = g_settings->getBool("fullscreen");
1381 u16 screenW = g_settings->getU16("screenW");
1382 u16 screenH = g_settings->getU16("screenH");
1386 bool vsync = g_settings->getBool("vsync");
1387 u16 bits = g_settings->getU16("fullscreen_bpp");
1388 u16 fsaa = g_settings->getU16("fsaa");
1392 video::E_DRIVER_TYPE driverType;
1394 std::string driverstring = g_settings->get("video_driver");
1396 if(driverstring == "null")
1397 driverType = video::EDT_NULL;
1398 else if(driverstring == "software")
1399 driverType = video::EDT_SOFTWARE;
1400 else if(driverstring == "burningsvideo")
1401 driverType = video::EDT_BURNINGSVIDEO;
1402 else if(driverstring == "direct3d8")
1403 driverType = video::EDT_DIRECT3D8;
1404 else if(driverstring == "direct3d9")
1405 driverType = video::EDT_DIRECT3D9;
1406 else if(driverstring == "opengl")
1407 driverType = video::EDT_OPENGL;
1408 #ifdef _IRR_COMPILE_WITH_OGLES1_
1409 else if(driverstring == "ogles1")
1410 driverType = video::EDT_OGLES1;
1412 #ifdef _IRR_COMPILE_WITH_OGLES2_
1413 else if(driverstring == "ogles2")
1414 driverType = video::EDT_OGLES2;
1418 errorstream<<"WARNING: Invalid video_driver specified; defaulting "
1419 "to opengl"<<std::endl;
1420 driverType = video::EDT_OPENGL;
1424 List video modes if requested
1427 MyEventReceiver receiver;
1429 if(cmd_args.getFlag("videomodes")){
1430 IrrlichtDevice *nulldevice;
1432 SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
1433 params.DriverType = video::EDT_NULL;
1434 params.WindowSize = core::dimension2d<u32>(640, 480);
1436 params.AntiAlias = fsaa;
1437 params.Fullscreen = false;
1438 params.Stencilbuffer = false;
1439 params.Vsync = vsync;
1440 params.EventReceiver = &receiver;
1442 nulldevice = createDeviceEx(params);
1447 dstream<<_("Available video modes (WxHxD):")<<std::endl;
1449 video::IVideoModeList *videomode_list =
1450 nulldevice->getVideoModeList();
1452 if(videomode_list == 0){
1457 s32 videomode_count = videomode_list->getVideoModeCount();
1458 core::dimension2d<u32> videomode_res;
1459 s32 videomode_depth;
1460 for (s32 i = 0; i < videomode_count; ++i){
1461 videomode_res = videomode_list->getVideoModeResolution(i);
1462 videomode_depth = videomode_list->getVideoModeDepth(i);
1463 dstream<<videomode_res.Width<<"x"<<videomode_res.Height
1464 <<"x"<<videomode_depth<<std::endl;
1467 dstream<<_("Active video mode (WxHxD):")<<std::endl;
1468 videomode_res = videomode_list->getDesktopResolution();
1469 videomode_depth = videomode_list->getDesktopDepth();
1470 dstream<<videomode_res.Width<<"x"<<videomode_res.Height
1471 <<"x"<<videomode_depth<<std::endl;
1479 Create device and exit if creation failed
1482 IrrlichtDevice *device;
1484 SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
1485 params.DriverType = driverType;
1486 params.WindowSize = core::dimension2d<u32>(screenW, screenH);
1488 params.AntiAlias = fsaa;
1489 params.Fullscreen = fullscreen;
1490 params.Stencilbuffer = false;
1491 params.Vsync = vsync;
1492 params.EventReceiver = &receiver;
1494 device = createDeviceEx(params);
1497 return 1; // could not create selected driver.
1500 Continue initialization
1503 video::IVideoDriver* driver = device->getVideoDriver();
1506 This changes the minimum allowed number of vertices in a VBO.
1509 //driver->setMinHardwareBufferVertexCount(50);
1511 // Create time getter
1512 g_timegetter = new IrrlichtTimeGetter(device);
1514 // Create game callback for menus
1515 g_gamecallback = new MainGameCallback(device);
1518 Speed tests (done after irrlicht is loaded to get timer)
1520 if(cmd_args.getFlag("speedtests"))
1522 dstream<<"Running speed tests"<<std::endl;
1528 device->setResizable(true);
1530 bool random_input = g_settings->getBool("random_input")
1531 || cmd_args.getFlag("random-input");
1532 InputHandler *input = NULL;
1534 input = new RandomInputHandler();
1536 input = new RealInputHandler(device, &receiver);
1538 scene::ISceneManager* smgr = device->getSceneManager();
1540 guienv = device->getGUIEnvironment();
1541 gui::IGUISkin* skin = guienv->getSkin();
1543 std::string font_path = g_settings->get("font_path");
1544 u16 font_size = g_settings->getU16("font_size");
1545 gui::IGUIFont *font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size);
1547 gui::IGUIFont* font = guienv->getFont(getTexturePath("fontlucida.png").c_str());
1550 skin->setFont(font);
1552 errorstream<<"WARNING: Font file was not found."
1553 " Using default font."<<std::endl;
1554 // If font was not found, this will get us one
1555 font = skin->getFont();
1558 u32 text_height = font->getDimension(L"Hello, world!").Height;
1559 infostream<<"text_height="<<text_height<<std::endl;
1561 //skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,0,0,0));
1562 skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,255,255,255));
1563 //skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(0,0,0,0));
1564 //skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(0,0,0,0));
1565 skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255,0,0,0));
1566 skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255,0,0,0));
1567 skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255,70,100,50));
1568 skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255,255,255,255));
1570 #if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
1571 // Irrlicht 1.8 input colours
1572 skin->setColor(gui::EGDC_EDITABLE, video::SColor(255,128,128,128));
1573 skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255,96,134,49));
1577 // Create the menu clouds
1578 if (!g_menucloudsmgr)
1579 g_menucloudsmgr = smgr->createNewSceneManager();
1581 g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(),
1582 g_menucloudsmgr, -1, rand(), 100);
1583 g_menuclouds->update(v2f(0, 0), video::SColor(255,200,200,255));
1584 scene::ICameraSceneNode* camera;
1585 camera = g_menucloudsmgr->addCameraSceneNode(0,
1586 v3f(0,0,0), v3f(0, 60, 100));
1587 camera->setFarValue(10000);
1593 ChatBackend chat_backend;
1596 If an error occurs, this is set to something and the
1597 menu-game loop is restarted. It is then displayed before
1600 std::wstring error_message = L"";
1602 // The password entered during the menu screen,
1603 std::string password;
1605 bool first_loop = true;
1610 while(device->run() && kill == false)
1612 // Set the window caption
1613 wchar_t* text = wgettext("Main Menu");
1614 device->setWindowCaption((std::wstring(L"Minetest [")+text+L"]").c_str());
1617 // This is used for catching disconnects
1622 Clear everything from the GUIEnvironment
1627 We need some kind of a root node to be able to add
1628 custom gui elements directly on the screen.
1629 Otherwise they won't be automatically drawn.
1631 guiroot = guienv->addStaticText(L"",
1632 core::rect<s32>(0, 0, 10000, 10000));
1634 SubgameSpec gamespec;
1635 WorldSpec worldspec;
1636 bool simple_singleplayer_mode = false;
1638 // These are set up based on the menu and other things
1639 std::string current_playername = "inv£lid";
1640 std::string current_password = "";
1641 std::string current_address = "does-not-exist";
1642 int current_port = 0;
1645 Out-of-game menu loop.
1647 Loop quits when menu returns proper parameters.
1649 while(kill == false)
1651 // If skip_main_menu, only go through here once
1652 if(skip_main_menu && !first_loop){
1658 // Cursor can be non-visible when coming from the game
1659 device->getCursorControl()->setVisible(true);
1660 // Some stuff are left to scene manager when coming from the game
1664 // Initialize menu data
1665 MainMenuData menudata;
1666 if(g_settings->exists("selected_mainmenu_tab"))
1667 menudata.selected_tab = g_settings->getS32("selected_mainmenu_tab");
1668 if(g_settings->exists("selected_serverlist"))
1669 menudata.selected_serverlist = g_settings->getS32("selected_serverlist");
1670 if(g_settings->exists("selected_mainmenu_game")){
1671 menudata.selected_game = g_settings->get("selected_mainmenu_game");
1672 menudata.selected_game_name = findSubgame(menudata.selected_game).name;
1674 menudata.address = narrow_to_wide(address);
1675 menudata.name = narrow_to_wide(playername);
1676 menudata.port = narrow_to_wide(itos(port));
1677 if(cmd_args.exists("password"))
1678 menudata.password = narrow_to_wide(cmd_args.get("password"));
1679 menudata.fancy_trees = g_settings->getBool("new_style_leaves");
1680 menudata.smooth_lighting = g_settings->getBool("smooth_lighting");
1681 menudata.clouds_3d = g_settings->getBool("enable_3d_clouds");
1682 menudata.opaque_water = g_settings->getBool("opaque_water");
1683 menudata.mip_map = g_settings->getBool("mip_map");
1684 menudata.anisotropic_filter = g_settings->getBool("anisotropic_filter");
1685 menudata.bilinear_filter = g_settings->getBool("bilinear_filter");
1686 menudata.trilinear_filter = g_settings->getBool("trilinear_filter");
1687 menudata.enable_shaders = g_settings->getS32("enable_shaders");
1688 menudata.preload_item_visuals = g_settings->getBool("preload_item_visuals");
1689 menudata.enable_particles = g_settings->getBool("enable_particles");
1690 menudata.liquid_finite = g_settings->getBool("liquid_finite");
1691 driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, menudata.mip_map);
1692 menudata.creative_mode = g_settings->getBool("creative_mode");
1693 menudata.enable_damage = g_settings->getBool("enable_damage");
1694 menudata.enable_public = g_settings->getBool("server_announce");
1695 // Default to selecting nothing
1696 menudata.selected_world = -1;
1697 // Get world listing for the menu
1698 std::vector<WorldSpec> worldspecs = getAvailableWorlds();
1699 // If there is only one world, select it
1700 if(worldspecs.size() == 1){
1701 menudata.selected_world = 0;
1703 // Otherwise try to select according to selected_world_path
1704 else if(g_settings->exists("selected_world_path")){
1705 std::string trypath = g_settings->get("selected_world_path");
1706 for(u32 i=0; i<worldspecs.size(); i++){
1707 if(worldspecs[i].path == trypath){
1708 menudata.selected_world = i;
1713 // If a world was commanded, append and select it
1714 if(commanded_world != ""){
1715 std::string gameid = getWorldGameId(commanded_world, true);
1716 std::string name = _("[--world parameter]");
1718 gameid = g_settings->get("default_game");
1721 WorldSpec spec(commanded_world, name, gameid);
1722 worldspecs.push_back(spec);
1723 menudata.selected_world = worldspecs.size()-1;
1725 // Copy worldspecs to menu
1726 menudata.worlds = worldspecs;
1728 menudata.games = getAvailableGames();
1729 // If selected game doesn't exist, take first from list
1730 if(findSubgame(menudata.selected_game).id == "" &&
1731 !menudata.games.empty()){
1732 menudata.selected_game = menudata.games[0].id;
1734 const SubgameSpec *menugame = getMenuGame(menudata);
1736 MenuTextures menutextures;
1737 menutextures.update(driver, menugame);
1739 if(skip_main_menu == false)
1741 video::IVideoDriver* driver = device->getVideoDriver();
1742 float fps_max = g_settings->getFloat("fps_max");
1743 infostream<<"Waiting for other menus"<<std::endl;
1744 while(device->run() && kill == false)
1748 driver->beginScene(true, true,
1749 video::SColor(255,128,128,128));
1750 drawMenuBackground(driver, menutextures);
1753 // On some computers framerate doesn't seem to be
1754 // automatically limited
1757 infostream<<"Waited for other menus"<<std::endl;
1760 new GUIMainMenu(guienv, guiroot, -1,
1761 &g_menumgr, &menudata, g_gamecallback);
1762 menu->allowFocusRemoval(true);
1764 if(error_message != L"")
1766 verbosestream<<"error_message = "
1767 <<wide_to_narrow(error_message)<<std::endl;
1769 GUIMessageMenu *menu2 =
1770 new GUIMessageMenu(guienv, guiroot, -1,
1771 &g_menumgr, error_message.c_str());
1773 error_message = L"";
1776 // Time is in milliseconds, for clouds
1777 u32 lasttime = device->getTimer()->getTime();
1779 infostream<<"Created main menu"<<std::endl;
1781 while(device->run() && kill == false)
1783 if(menu->getStatus() == true)
1786 // Game can be selected in the menu
1787 menugame = getMenuGame(menudata);
1788 menutextures.update(driver, menugame);
1789 // Clouds for the main menu
1790 bool cloud_menu_background = g_settings->getBool("menu_clouds");
1792 // If game has regular background and no overlay, don't use clouds
1793 if(cloud_menu_background && menutextures.background &&
1794 !menutextures.overlay){
1795 cloud_menu_background = false;
1797 // If game game has overlay and no regular background, always draw clouds
1798 else if(menutextures.overlay && !menutextures.background){
1799 cloud_menu_background = true;
1803 // Time calc for the clouds
1804 f32 dtime=0; // in seconds
1805 if (cloud_menu_background) {
1806 u32 time = device->getTimer()->getTime();
1808 dtime = (time - lasttime) / 1000.0;
1814 //driver->beginScene(true, true, video::SColor(255,0,0,0));
1815 driver->beginScene(true, true, video::SColor(255,140,186,250));
1817 if (cloud_menu_background) {
1818 // *3 otherwise the clouds would move very slowly
1819 g_menuclouds->step(dtime*3);
1820 g_menuclouds->render();
1821 g_menucloudsmgr->drawAll();
1822 drawMenuOverlay(driver, menutextures);
1823 drawMenuHeader(driver, menutextures);
1824 drawMenuFooter(driver, menutextures);
1826 drawMenuBackground(driver, menutextures);
1827 drawMenuHeader(driver, menutextures);
1828 drawMenuFooter(driver, menutextures);
1835 // On some computers framerate doesn't seem to be
1836 // automatically limited
1837 if (cloud_menu_background) {
1838 // Time of frame without fps limit
1841 // not using getRealTime is necessary for wine
1842 u32 time = device->getTimer()->getTime();
1844 busytime_u32 = time - lasttime;
1847 busytime = busytime_u32 / 1000.0;
1850 u32 frametime_min = 1000./fps_max;
1852 if(busytime_u32 < frametime_min) {
1853 u32 sleeptime = frametime_min - busytime_u32;
1854 device->sleep(sleeptime);
1861 infostream<<"Dropping main menu"<<std::endl;
1866 playername = wide_to_narrow(menudata.name);
1867 if (playername == "")
1868 playername = std::string("Guest") + itos(myrand_range(1000,9999));
1869 password = translatePassword(playername, menudata.password);
1870 //infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
1872 address = wide_to_narrow(menudata.address);
1873 int newport = stoi(wide_to_narrow(menudata.port));
1876 simple_singleplayer_mode = menudata.simple_singleplayer_mode;
1878 g_settings->setS32("selected_mainmenu_tab", menudata.selected_tab);
1879 g_settings->setS32("selected_serverlist", menudata.selected_serverlist);
1880 g_settings->set("selected_mainmenu_game", menudata.selected_game);
1881 g_settings->set("new_style_leaves", itos(menudata.fancy_trees));
1882 g_settings->set("smooth_lighting", itos(menudata.smooth_lighting));
1883 g_settings->set("enable_3d_clouds", itos(menudata.clouds_3d));
1884 g_settings->set("opaque_water", itos(menudata.opaque_water));
1886 g_settings->set("mip_map", itos(menudata.mip_map));
1887 g_settings->set("anisotropic_filter", itos(menudata.anisotropic_filter));
1888 g_settings->set("bilinear_filter", itos(menudata.bilinear_filter));
1889 g_settings->set("trilinear_filter", itos(menudata.trilinear_filter));
1891 g_settings->setS32("enable_shaders", menudata.enable_shaders);
1892 g_settings->set("preload_item_visuals", itos(menudata.preload_item_visuals));
1893 g_settings->set("enable_particles", itos(menudata.enable_particles));
1894 g_settings->set("liquid_finite", itos(menudata.liquid_finite));
1896 g_settings->set("creative_mode", itos(menudata.creative_mode));
1897 g_settings->set("enable_damage", itos(menudata.enable_damage));
1898 g_settings->set("server_announce", itos(menudata.enable_public));
1899 g_settings->set("name", playername);
1900 g_settings->set("address", address);
1901 g_settings->set("port", itos(port));
1902 if(menudata.selected_world != -1)
1903 g_settings->set("selected_world_path",
1904 worldspecs[menudata.selected_world].path);
1906 // Break out of menu-game loop to shut down cleanly
1907 if(device->run() == false || kill == true)
1910 current_playername = playername;
1911 current_password = password;
1912 current_address = address;
1913 current_port = port;
1915 // If using simple singleplayer mode, override
1916 if(simple_singleplayer_mode){
1917 current_playername = "singleplayer";
1918 current_password = "";
1919 current_address = "";
1920 current_port = 30011;
1922 else if (address != "")
1924 ServerListSpec server;
1925 server["name"] = menudata.servername;
1926 server["address"] = wide_to_narrow(menudata.address);
1927 server["port"] = wide_to_narrow(menudata.port);
1928 server["description"] = menudata.serverdescription;
1929 ServerList::insert(server);
1932 // Set world path to selected one
1933 if(menudata.selected_world != -1){
1934 worldspec = worldspecs[menudata.selected_world];
1935 infostream<<"Selected world: "<<worldspec.name
1936 <<" ["<<worldspec.path<<"]"<<std::endl;
1939 // Only refresh if so requested
1940 if(menudata.only_refresh){
1941 infostream<<"Refreshing menu"<<std::endl;
1945 // Create new world if requested
1946 if(menudata.create_world_name != L"")
1948 std::string path = porting::path_user + DIR_DELIM
1949 "worlds" + DIR_DELIM
1950 + wide_to_narrow(menudata.create_world_name);
1951 // Create world if it doesn't exist
1952 if(!initializeWorld(path, menudata.create_world_gameid)){
1953 error_message = wgettext("Failed to initialize world");
1954 errorstream<<wide_to_narrow(error_message)<<std::endl;
1957 g_settings->set("selected_world_path", path);
1958 g_settings->set("selected_mainmenu_game", menudata.create_world_gameid);
1963 if(current_address == "")
1965 if(menudata.selected_world == -1){
1966 error_message = wgettext("No world selected and no address "
1967 "provided. Nothing to do.");
1968 errorstream<<wide_to_narrow(error_message)<<std::endl;
1971 // Load gamespec for required game
1972 gamespec = findWorldSubgame(worldspec.path);
1973 if(!gamespec.isValid() && !commanded_gamespec.isValid()){
1974 error_message = wgettext("Could not find or load game \"")
1975 + narrow_to_wide(worldspec.gameid) + L"\"";
1976 errorstream<<wide_to_narrow(error_message)<<std::endl;
1979 if(commanded_gamespec.isValid() &&
1980 commanded_gamespec.id != worldspec.gameid){
1981 errorstream<<"WARNING: Overriding gamespec from \""
1982 <<worldspec.gameid<<"\" to \""
1983 <<commanded_gamespec.id<<"\""<<std::endl;
1984 gamespec = commanded_gamespec;
1987 if(!gamespec.isValid()){
1988 error_message = wgettext("Invalid gamespec.");
1989 error_message += L" (world_gameid="
1990 +narrow_to_wide(worldspec.gameid)+L")";
1991 errorstream<<wide_to_narrow(error_message)<<std::endl;
2000 // Break out of menu-game loop to shut down cleanly
2001 if(device->run() == false || kill == true)
2022 simple_singleplayer_mode
2027 catch(con::PeerNotFoundException &e)
2029 error_message = wgettext("Connection error (timed out?)");
2030 errorstream<<wide_to_narrow(error_message)<<std::endl;
2033 catch(std::exception &e)
2035 std::string narrow_message = "Some exception: \"";
2036 narrow_message += e.what();
2037 narrow_message += "\"";
2038 errorstream<<narrow_message<<std::endl;
2039 error_message = narrow_to_wide(narrow_message);
2043 // If no main menu, show error and exit
2046 if(error_message != L""){
2047 verbosestream<<"error_message = "
2048 <<wide_to_narrow(error_message)<<std::endl;
2056 g_menuclouds->drop();
2057 g_menucloudsmgr->drop();
2062 In the end, delete the Irrlicht device.
2068 // Update configuration file
2069 if(configpath != "")
2070 g_settings->updateConfigFile(configpath.c_str());
2072 // Print modified quicktune values
2074 bool header_printed = false;
2075 std::vector<std::string> names = getQuicktuneNames();
2076 for(u32 i=0; i<names.size(); i++){
2077 QuicktuneValue val = getQuicktuneValue(names[i]);
2080 if(!header_printed){
2081 dstream<<"Modified quicktune values:"<<std::endl;
2082 header_printed = true;
2084 dstream<<names[i]<<" = "<<val.getString()<<std::endl;
2088 END_DEBUG_EXCEPTION_HANDLER(errorstream)
2090 debugstreams_deinit();