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;
96 std::ostream *dout_con_ptr = &dummyout;
97 std::ostream *derr_con_ptr = &verbosestream;
100 std::ostream *dout_server_ptr = &infostream;
101 std::ostream *derr_server_ptr = &errorstream;
104 std::ostream *dout_client_ptr = &infostream;
105 std::ostream *derr_client_ptr = &errorstream;
112 /* mainmenumanager.h */
114 gui::IGUIEnvironment* guienv = NULL;
115 gui::IGUIStaticText *guiroot = NULL;
116 MainMenuManager g_menumgr;
120 return (g_menumgr.menuCount() == 0);
123 // Passed to menus to allow disconnecting and exiting
124 MainGameCallback *g_gamecallback = NULL;
128 gettime.h implementation
135 /* Use imprecise system calls directly (from porting.h) */
136 return porting::getTime(PRECISION_MILLI);
139 u32 getTime(TimePrecision prec)
141 return porting::getTime(prec);
146 // A small helper class
150 virtual u32 getTime(TimePrecision prec) = 0;
153 // A precise irrlicht one
154 class IrrlichtTimeGetter: public TimeGetter
157 IrrlichtTimeGetter(IrrlichtDevice *device):
160 u32 getTime(TimePrecision prec)
162 if (prec == PRECISION_MILLI) {
165 return m_device->getTimer()->getRealTime();
167 return porting::getTime(prec);
171 IrrlichtDevice *m_device;
173 // Not so precise one which works without irrlicht
174 class SimpleTimeGetter: public TimeGetter
177 u32 getTime(TimePrecision prec)
179 return porting::getTime(prec);
183 // A pointer to a global instance of the time getter
185 TimeGetter *g_timegetter = NULL;
189 if(g_timegetter == NULL)
191 return g_timegetter->getTime(PRECISION_MILLI);
194 u32 getTime(TimePrecision prec) {
195 if (g_timegetter == NULL)
197 return g_timegetter->getTime(prec);
202 class StderrLogOutput: public ILogOutput
205 /* line: Full line with timestamp, level and thread */
206 void printLog(const std::string &line)
208 std::cerr<<line<<std::endl;
210 } main_stderr_log_out;
212 class DstreamNoStderrLogOutput: public ILogOutput
215 /* line: Full line with timestamp, level and thread */
216 void printLog(const std::string &line)
218 dstream_no_stderr<<line<<std::endl;
220 } main_dstream_no_stderr_log_out;
225 Event handler for Irrlicht
227 NOTE: Everything possible should be moved out from here,
228 probably to InputHandler and the_game
231 class MyEventReceiver : public IEventReceiver
234 // This is the one method that we have to implement
235 virtual bool OnEvent(const SEvent& event)
238 React to nothing here if a menu is active
240 if(noMenuActive() == false)
245 // Remember whether each key is down or up
246 if(event.EventType == irr::EET_KEY_INPUT_EVENT)
248 if(event.KeyInput.PressedDown) {
249 keyIsDown.set(event.KeyInput);
250 keyWasDown.set(event.KeyInput);
252 keyIsDown.unset(event.KeyInput);
256 if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
258 if(noMenuActive() == false)
261 middle_active = false;
262 right_active = false;
266 left_active = event.MouseInput.isLeftPressed();
267 middle_active = event.MouseInput.isMiddlePressed();
268 right_active = event.MouseInput.isRightPressed();
270 if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
274 if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
278 if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
282 if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)
284 rightreleased = true;
286 if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)
288 mouse_wheel += event.MouseInput.Wheel;
296 bool IsKeyDown(const KeyPress &keyCode) const
298 return keyIsDown[keyCode];
301 // Checks whether a key was down and resets the state
302 bool WasKeyDown(const KeyPress &keyCode)
304 bool b = keyWasDown[keyCode];
306 keyWasDown.unset(keyCode);
323 rightclicked = false;
324 leftreleased = false;
325 rightreleased = false;
328 middle_active = false;
329 right_active = false;
351 IrrlichtDevice *m_device;
353 // The current state of keys
355 // Whether a key has been pressed or not
360 Separated input handler
363 class RealInputHandler : public InputHandler
366 RealInputHandler(IrrlichtDevice *device, MyEventReceiver *receiver):
371 virtual bool isKeyDown(const KeyPress &keyCode)
373 return m_receiver->IsKeyDown(keyCode);
375 virtual bool wasKeyDown(const KeyPress &keyCode)
377 return m_receiver->WasKeyDown(keyCode);
379 virtual v2s32 getMousePos()
381 return m_device->getCursorControl()->getPosition();
383 virtual void setMousePos(s32 x, s32 y)
385 m_device->getCursorControl()->setPosition(x, y);
388 virtual bool getLeftState()
390 return m_receiver->left_active;
392 virtual bool getRightState()
394 return m_receiver->right_active;
397 virtual bool getLeftClicked()
399 return m_receiver->leftclicked;
401 virtual bool getRightClicked()
403 return m_receiver->rightclicked;
405 virtual void resetLeftClicked()
407 m_receiver->leftclicked = false;
409 virtual void resetRightClicked()
411 m_receiver->rightclicked = false;
414 virtual bool getLeftReleased()
416 return m_receiver->leftreleased;
418 virtual bool getRightReleased()
420 return m_receiver->rightreleased;
422 virtual void resetLeftReleased()
424 m_receiver->leftreleased = false;
426 virtual void resetRightReleased()
428 m_receiver->rightreleased = false;
431 virtual s32 getMouseWheel()
433 return m_receiver->getMouseWheel();
438 m_receiver->clearInput();
441 IrrlichtDevice *m_device;
442 MyEventReceiver *m_receiver;
445 class RandomInputHandler : public InputHandler
453 rightclicked = false;
454 leftreleased = false;
455 rightreleased = false;
458 virtual bool isKeyDown(const KeyPress &keyCode)
460 return keydown[keyCode];
462 virtual bool wasKeyDown(const KeyPress &keyCode)
466 virtual v2s32 getMousePos()
470 virtual void setMousePos(s32 x, s32 y)
472 mousepos = v2s32(x,y);
475 virtual bool getLeftState()
479 virtual bool getRightState()
484 virtual bool getLeftClicked()
488 virtual bool getRightClicked()
492 virtual void resetLeftClicked()
496 virtual void resetRightClicked()
498 rightclicked = false;
501 virtual bool getLeftReleased()
505 virtual bool getRightReleased()
507 return rightreleased;
509 virtual void resetLeftReleased()
511 leftreleased = false;
513 virtual void resetRightReleased()
515 rightreleased = false;
518 virtual s32 getMouseWheel()
523 virtual void step(float dtime)
526 static float counter1 = 0;
530 counter1 = 0.1*Rand(1, 40);
531 keydown.toggle(getKeySetting("keymap_jump"));
535 static float counter1 = 0;
539 counter1 = 0.1*Rand(1, 40);
540 keydown.toggle(getKeySetting("keymap_special1"));
544 static float counter1 = 0;
548 counter1 = 0.1*Rand(1, 40);
549 keydown.toggle(getKeySetting("keymap_forward"));
553 static float counter1 = 0;
557 counter1 = 0.1*Rand(1, 40);
558 keydown.toggle(getKeySetting("keymap_left"));
562 static float counter1 = 0;
566 counter1 = 0.1*Rand(1, 20);
567 mousespeed = v2s32(Rand(-20,20), Rand(-15,20));
571 static float counter1 = 0;
575 counter1 = 0.1*Rand(1, 30);
576 leftdown = !leftdown;
584 static float counter1 = 0;
588 counter1 = 0.1*Rand(1, 15);
589 rightdown = !rightdown;
593 rightreleased = true;
596 mousepos += mousespeed;
599 s32 Rand(s32 min, s32 max)
601 return (myrand()%(max-min+1))+min;
617 std::string current_gameid;
618 video::ITexture *background;
619 video::ITexture *overlay;
620 video::ITexture *header;
621 video::ITexture *footer;
630 static video::ITexture* getMenuTexture(const std::string &tname,
631 video::IVideoDriver* driver, const SubgameSpec *spec)
634 // eg. minetest_menu_background.png (for texture packs)
635 std::string pack_tname = spec->id + "_menu_" + tname + ".png";
636 path = getTexturePath(pack_tname);
638 return driver->getTexture(path.c_str());
639 // eg. games/minetest_game/menu/background.png
640 path = getImagePath(spec->path + DIR_DELIM + "menu" + DIR_DELIM + tname + ".png");
642 return driver->getTexture(path.c_str());
646 void update(video::IVideoDriver* driver, const SubgameSpec *spec)
648 if(spec->id == current_gameid)
650 current_gameid = spec->id;
651 background = getMenuTexture("background", driver, spec);
652 overlay = getMenuTexture("overlay", driver, spec);
653 header = getMenuTexture("header", driver, spec);
654 footer = getMenuTexture("footer", driver, spec);
658 void drawMenuBackground(video::IVideoDriver* driver, const MenuTextures &menutextures)
660 v2u32 screensize = driver->getScreenSize();
661 video::ITexture *texture = menutextures.background;
663 /* If no texture, draw background of solid color */
665 video::SColor color(255,80,58,37);
666 core::rect<s32> rect(0, 0, screensize.X, screensize.Y);
667 driver->draw2DRectangle(color, rect, NULL);
671 /* Draw background texture */
672 v2u32 sourcesize = texture->getSize();
673 driver->draw2DImage(texture,
674 core::rect<s32>(0, 0, screensize.X, screensize.Y),
675 core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
679 void drawMenuOverlay(video::IVideoDriver* driver, const MenuTextures &menutextures)
681 v2u32 screensize = driver->getScreenSize();
682 video::ITexture *texture = menutextures.overlay;
684 /* If no texture, draw nothing */
688 /* Draw overlay texture */
689 v2u32 sourcesize = texture->getSize();
690 driver->draw2DImage(texture,
691 core::rect<s32>(0, 0, screensize.X, screensize.Y),
692 core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
696 void drawMenuHeader(video::IVideoDriver* driver, const MenuTextures &menutextures)
698 core::dimension2d<u32> screensize = driver->getScreenSize();
699 video::ITexture *texture = menutextures.header;
701 /* If no texture, draw nothing */
705 f32 mult = (((f32)screensize.Width / 2)) /
706 ((f32)texture->getOriginalSize().Width);
708 v2s32 splashsize(((f32)texture->getOriginalSize().Width) * mult,
709 ((f32)texture->getOriginalSize().Height) * mult);
711 // Don't draw the header is there isn't enough room
712 s32 free_space = (((s32)screensize.Height)-320)/2;
713 if (free_space > splashsize.Y) {
714 core::rect<s32> splashrect(0, 0, splashsize.X, splashsize.Y);
715 splashrect += v2s32((screensize.Width/2)-(splashsize.X/2),
716 ((free_space/2)-splashsize.Y/2)+10);
718 video::SColor bgcolor(255,50,50,50);
720 driver->draw2DImage(texture, splashrect,
721 core::rect<s32>(core::position2d<s32>(0,0),
722 core::dimension2di(texture->getSize())),
727 void drawMenuFooter(video::IVideoDriver* driver, const MenuTextures &menutextures)
729 core::dimension2d<u32> screensize = driver->getScreenSize();
730 video::ITexture *texture = menutextures.footer;
732 /* If no texture, draw nothing */
736 f32 mult = (((f32)screensize.Width)) /
737 ((f32)texture->getOriginalSize().Width);
739 v2s32 footersize(((f32)texture->getOriginalSize().Width) * mult,
740 ((f32)texture->getOriginalSize().Height) * mult);
742 // Don't draw the footer if there isn't enough room
743 s32 free_space = (((s32)screensize.Height)-320)/2;
744 if (free_space > footersize.Y) {
745 core::rect<s32> rect(0,0,footersize.X,footersize.Y);
746 rect += v2s32(screensize.Width/2,screensize.Height-footersize.Y);
747 rect -= v2s32(footersize.X/2, 0);
749 driver->draw2DImage(texture, rect,
750 core::rect<s32>(core::position2d<s32>(0,0),
751 core::dimension2di(texture->getSize())),
756 static const SubgameSpec* getMenuGame(const MainMenuData &menudata)
758 for(size_t i=0; i<menudata.games.size(); i++){
759 if(menudata.games[i].id == menudata.selected_game){
760 return &menudata.games[i];
768 // These are defined global so that they're not optimized too much.
769 // Can't change them to volatile.
774 std::string tempstring;
775 std::string tempstring2;
780 infostream<<"The following test should take around 20ms."<<std::endl;
781 TimeTaker timer("Testing std::string speed");
782 const u32 jj = 10000;
783 for(u32 j=0; j<jj; j++)
788 for(u32 i=0; i<ii; i++){
789 tempstring2 += "asd";
791 for(u32 i=0; i<ii+1; i++){
793 if(tempstring == tempstring2)
799 infostream<<"All of the following tests should take around 100ms each."
803 TimeTaker timer("Testing floating-point conversion speed");
805 for(u32 i=0; i<4000000; i++){
812 TimeTaker timer("Testing floating-point vector speed");
814 tempv3f1 = v3f(1,2,3);
815 tempv3f2 = v3f(4,5,6);
816 for(u32 i=0; i<10000000; i++){
817 tempf += tempv3f1.dotProduct(tempv3f2);
818 tempv3f2 += v3f(7,8,9);
823 TimeTaker timer("Testing std::map speed");
825 std::map<v2s16, f32> map1;
828 for(s16 y=0; y<ii; y++){
829 for(s16 x=0; x<ii; x++){
830 map1[v2s16(x,y)] = tempf;
834 for(s16 y=ii-1; y>=0; y--){
835 for(s16 x=0; x<ii; x++){
836 tempf = map1[v2s16(x,y)];
842 infostream<<"Around 5000/ms should do well here."<<std::endl;
843 TimeTaker timer("Testing mutex speed");
857 while(timer.getTimerTime() < 10);
859 u32 dtime = timer.stop();
860 u32 per_ms = n / dtime;
861 infostream<<"Done. "<<dtime<<"ms, "
862 <<per_ms<<"/ms"<<std::endl;
866 static void print_worldspecs(const std::vector<WorldSpec> &worldspecs,
869 for(u32 i=0; i<worldspecs.size(); i++){
870 std::string name = worldspecs[i].name;
871 std::string path = worldspecs[i].path;
872 if(name.find(" ") != std::string::npos)
873 name = std::string("'") + name + "'";
874 path = std::string("'") + path + "'";
875 name = padStringRight(name, 14);
876 os<<" "<<name<<" "<<path<<std::endl;
880 int main(int argc, char *argv[])
888 log_add_output_maxlev(&main_stderr_log_out, LMT_ACTION);
889 log_add_output_all_levs(&main_dstream_no_stderr_log_out);
891 log_register_thread("main");
893 // This enables internatonal characters input
894 if( setlocale(LC_ALL, "") == NULL )
896 fprintf( stderr, "%s: warning: could not set default locale\n", argv[0] );
899 // Set locale. This is for forcing '.' as the decimal point.
901 std::locale::global(std::locale(std::locale(""), "C", std::locale::numeric));
902 setlocale(LC_NUMERIC, "C");
903 } catch (const std::exception& ex) {
904 errorstream<<"Could not set numeric locale to C"<<std::endl;
910 // List all allowed options
911 std::map<std::string, ValueSpec> allowed_options;
912 allowed_options.insert(std::make_pair("help", ValueSpec(VALUETYPE_FLAG,
913 _("Show allowed options"))));
914 allowed_options.insert(std::make_pair("config", ValueSpec(VALUETYPE_STRING,
915 _("Load configuration from specified file"))));
916 allowed_options.insert(std::make_pair("port", ValueSpec(VALUETYPE_STRING,
917 _("Set network port (UDP)"))));
918 allowed_options.insert(std::make_pair("disable-unittests", ValueSpec(VALUETYPE_FLAG,
919 _("Disable unit tests"))));
920 allowed_options.insert(std::make_pair("enable-unittests", ValueSpec(VALUETYPE_FLAG,
921 _("Enable unit tests"))));
922 allowed_options.insert(std::make_pair("map-dir", ValueSpec(VALUETYPE_STRING,
923 _("Same as --world (deprecated)"))));
924 allowed_options.insert(std::make_pair("world", ValueSpec(VALUETYPE_STRING,
925 _("Set world path (implies local game) ('list' lists all)"))));
926 allowed_options.insert(std::make_pair("worldname", ValueSpec(VALUETYPE_STRING,
927 _("Set world by name (implies local game)"))));
928 allowed_options.insert(std::make_pair("info", ValueSpec(VALUETYPE_FLAG,
929 _("Print more information to console"))));
930 allowed_options.insert(std::make_pair("verbose", ValueSpec(VALUETYPE_FLAG,
931 _("Print even more information to console"))));
932 allowed_options.insert(std::make_pair("trace", ValueSpec(VALUETYPE_FLAG,
933 _("Print enormous amounts of information to log and console"))));
934 allowed_options.insert(std::make_pair("logfile", ValueSpec(VALUETYPE_STRING,
935 _("Set logfile path ('' = no logging)"))));
936 allowed_options.insert(std::make_pair("gameid", ValueSpec(VALUETYPE_STRING,
937 _("Set gameid (\"--gameid list\" prints available ones)"))));
939 allowed_options.insert(std::make_pair("speedtests", ValueSpec(VALUETYPE_FLAG,
940 _("Run speed tests"))));
941 allowed_options.insert(std::make_pair("address", ValueSpec(VALUETYPE_STRING,
942 _("Address to connect to. ('' = local game)"))));
943 allowed_options.insert(std::make_pair("random-input", ValueSpec(VALUETYPE_FLAG,
944 _("Enable random user input, for testing"))));
945 allowed_options.insert(std::make_pair("server", ValueSpec(VALUETYPE_FLAG,
946 _("Run dedicated server"))));
947 allowed_options.insert(std::make_pair("name", ValueSpec(VALUETYPE_STRING,
948 _("Set player name"))));
949 allowed_options.insert(std::make_pair("password", ValueSpec(VALUETYPE_STRING,
950 _("Set password"))));
951 allowed_options.insert(std::make_pair("go", ValueSpec(VALUETYPE_FLAG,
952 _("Disable main menu"))));
957 bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);
959 if(ret == false || cmd_args.getFlag("help") || cmd_args.exists("nonopt1"))
961 dstream<<_("Allowed options:")<<std::endl;
962 for(std::map<std::string, ValueSpec>::iterator
963 i = allowed_options.begin();
964 i != allowed_options.end(); ++i)
966 std::ostringstream os1(std::ios::binary);
967 os1<<" --"<<i->first;
968 if(i->second.type == VALUETYPE_FLAG)
972 dstream<<padStringRight(os1.str(), 24);
974 if(i->second.help != NULL)
975 dstream<<i->second.help;
979 return cmd_args.getFlag("help") ? 0 : 1;
983 Low-level initialization
986 // If trace is enabled, enable logging of certain things
987 if(cmd_args.getFlag("trace")){
988 dstream<<_("Enabling trace level debug output")<<std::endl;
989 log_trace_level_enabled = true;
990 dout_con_ptr = &verbosestream; // this is somewhat old crap
991 socket_enable_debug_output = true; // socket doesn't use log.h
993 // In certain cases, output info level on stderr
994 if(cmd_args.getFlag("info") || cmd_args.getFlag("verbose") ||
995 cmd_args.getFlag("trace") || cmd_args.getFlag("speedtests"))
996 log_add_output(&main_stderr_log_out, LMT_INFO);
997 // In certain cases, output verbose level on stderr
998 if(cmd_args.getFlag("verbose") || cmd_args.getFlag("trace"))
999 log_add_output(&main_stderr_log_out, LMT_VERBOSE);
1001 porting::signal_handler_init();
1002 bool &kill = *porting::signal_handler_killstatus();
1004 porting::initializePaths();
1006 // Create user data directory
1007 fs::CreateDir(porting::path_user);
1009 init_gettext((porting::path_share + DIR_DELIM + "locale").c_str());
1011 infostream<<"path_share = "<<porting::path_share<<std::endl;
1012 infostream<<"path_user = "<<porting::path_user<<std::endl;
1014 // Initialize debug stacks
1015 debug_stacks_init();
1016 DSTACK(__FUNCTION_NAME);
1019 BEGIN_DEBUG_EXCEPTION_HANDLER
1021 // List gameids if requested
1022 if(cmd_args.exists("gameid") && cmd_args.get("gameid") == "list")
1024 std::set<std::string> gameids = getAvailableGameIds();
1025 for(std::set<std::string>::const_iterator i = gameids.begin();
1026 i != gameids.end(); i++)
1027 dstream<<(*i)<<std::endl;
1031 // List worlds if requested
1032 if(cmd_args.exists("world") && cmd_args.get("world") == "list"){
1033 dstream<<_("Available worlds:")<<std::endl;
1034 std::vector<WorldSpec> worldspecs = getAvailableWorlds();
1035 print_worldspecs(worldspecs, dstream);
1039 // Print startup message
1040 infostream<<PROJECT_NAME<<
1041 " "<<_("with")<<" SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
1046 Basic initialization
1049 // Initialize default settings
1050 set_default_settings(g_settings);
1052 // Initialize sockets
1054 atexit(sockets_cleanup);
1060 // Path of configuration file in use
1061 std::string configpath = "";
1063 if(cmd_args.exists("config"))
1065 bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
1068 errorstream<<"Could not read configuration from \""
1069 <<cmd_args.get("config")<<"\""<<std::endl;
1072 configpath = cmd_args.get("config");
1076 std::vector<std::string> filenames;
1077 filenames.push_back(porting::path_user +
1078 DIR_DELIM + "minetest.conf");
1079 // Legacy configuration file location
1080 filenames.push_back(porting::path_user +
1081 DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
1083 // Try also from a lower level (to aid having the same configuration
1084 // for many RUN_IN_PLACE installs)
1085 filenames.push_back(porting::path_user +
1086 DIR_DELIM + ".." + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
1089 for(u32 i=0; i<filenames.size(); i++)
1091 bool r = g_settings->readConfigFile(filenames[i].c_str());
1094 configpath = filenames[i];
1099 // If no path found, use the first one (menu creates the file)
1100 if(configpath == "")
1101 configpath = filenames[0];
1104 // Initialize debug streams
1105 #define DEBUGFILE "debug.txt"
1107 std::string logfile = DEBUGFILE;
1109 std::string logfile = porting::path_user+DIR_DELIM+DEBUGFILE;
1111 if(cmd_args.exists("logfile"))
1112 logfile = cmd_args.get("logfile");
1114 log_remove_output(&main_dstream_no_stderr_log_out);
1115 int loglevel = g_settings->getS32("debug_log_level");
1117 if (loglevel == 0) //no logging
1119 else if (loglevel > 0 && loglevel <= LMT_NUM_VALUES)
1120 log_add_output_maxlev(&main_dstream_no_stderr_log_out, (LogMessageLevel)(loglevel - 1));
1123 debugstreams_init(false, logfile.c_str());
1125 debugstreams_init(false, NULL);
1127 infostream<<"logfile = "<<logfile<<std::endl;
1129 // Initialize random seed
1137 if((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false)
1138 || cmd_args.getFlag("enable-unittests") == true)
1149 if(cmd_args.exists("port"))
1150 port = cmd_args.getU16("port");
1151 else if(g_settings->exists("port"))
1152 port = g_settings->getU16("port");
1157 std::string commanded_world = "";
1158 if(cmd_args.exists("world"))
1159 commanded_world = cmd_args.get("world");
1160 else if(cmd_args.exists("map-dir"))
1161 commanded_world = cmd_args.get("map-dir");
1162 else if(cmd_args.exists("nonopt0")) // First nameless argument
1163 commanded_world = cmd_args.get("nonopt0");
1164 else if(g_settings->exists("map-dir"))
1165 commanded_world = g_settings->get("map-dir");
1168 std::string commanded_worldname = "";
1169 if(cmd_args.exists("worldname"))
1170 commanded_worldname = cmd_args.get("worldname");
1172 // Strip world.mt from commanded_world
1174 std::string worldmt = "world.mt";
1175 if(commanded_world.size() > worldmt.size() &&
1176 commanded_world.substr(commanded_world.size()-worldmt.size())
1178 dstream<<_("Supplied world.mt file - stripping it off.")<<std::endl;
1179 commanded_world = commanded_world.substr(
1180 0, commanded_world.size()-worldmt.size());
1184 // If a world name was specified, convert it to a path
1185 if(commanded_worldname != ""){
1186 // Get information about available worlds
1187 std::vector<WorldSpec> worldspecs = getAvailableWorlds();
1189 for(u32 i=0; i<worldspecs.size(); i++){
1190 std::string name = worldspecs[i].name;
1191 if(name == commanded_worldname){
1192 if(commanded_world != ""){
1193 dstream<<_("--worldname takes precedence over previously "
1194 "selected world.")<<std::endl;
1196 commanded_world = worldspecs[i].path;
1202 dstream<<_("World")<<" '"<<commanded_worldname<<_("' not "
1203 "available. Available worlds:")<<std::endl;
1204 print_worldspecs(worldspecs, dstream);
1210 SubgameSpec commanded_gamespec;
1211 if(cmd_args.exists("gameid")){
1212 std::string gameid = cmd_args.get("gameid");
1213 commanded_gamespec = findSubgame(gameid);
1214 if(!commanded_gamespec.isValid()){
1215 errorstream<<"Game \""<<gameid<<"\" not found"<<std::endl;
1221 Run dedicated server if asked to or no other option
1224 bool run_dedicated_server = true;
1226 bool run_dedicated_server = cmd_args.getFlag("server");
1228 g_settings->set("server_dedicated", run_dedicated_server ? "true" : "false");
1229 if(run_dedicated_server)
1231 DSTACK("Dedicated server branch");
1232 // Create time getter if built with Irrlicht
1234 g_timegetter = new SimpleTimeGetter();
1238 std::string world_path;
1239 verbosestream<<_("Determining world path")<<std::endl;
1240 bool is_legacy_world = false;
1241 // If a world was commanded, use it
1242 if(commanded_world != ""){
1243 world_path = commanded_world;
1244 infostream<<"Using commanded world path ["<<world_path<<"]"
1247 // No world was specified; try to select it automatically
1250 // Get information about available worlds
1251 std::vector<WorldSpec> worldspecs = getAvailableWorlds();
1252 // If a world name was specified, select it
1253 if(commanded_worldname != ""){
1255 for(u32 i=0; i<worldspecs.size(); i++){
1256 std::string name = worldspecs[i].name;
1257 if(name == commanded_worldname){
1258 world_path = worldspecs[i].path;
1262 if(world_path == ""){
1263 dstream<<_("World")<<" '"<<commanded_worldname<<"' "<<_("not "
1264 "available. Available worlds:")<<std::endl;
1265 print_worldspecs(worldspecs, dstream);
1269 // If there is only a single world, use it
1270 if(worldspecs.size() == 1){
1271 world_path = worldspecs[0].path;
1272 dstream<<_("Automatically selecting world at")<<" ["
1273 <<world_path<<"]"<<std::endl;
1274 // If there are multiple worlds, list them
1275 } else if(worldspecs.size() > 1){
1276 dstream<<_("Multiple worlds are available.")<<std::endl;
1277 dstream<<_("Please select one using --worldname <name>"
1278 " or --world <path>")<<std::endl;
1279 print_worldspecs(worldspecs, dstream);
1281 // If there are no worlds, automatically create a new one
1283 // This is the ultimate default world path
1284 world_path = porting::path_user + DIR_DELIM + "worlds" +
1285 DIR_DELIM + "world";
1286 infostream<<"Creating default world at ["
1287 <<world_path<<"]"<<std::endl;
1291 if(world_path == ""){
1292 errorstream<<"No world path specified or found."<<std::endl;
1295 verbosestream<<_("Using world path")<<" ["<<world_path<<"]"<<std::endl;
1297 // We need a gamespec.
1298 SubgameSpec gamespec;
1299 verbosestream<<_("Determining gameid/gamespec")<<std::endl;
1300 // If world doesn't exist
1301 if(!getWorldExists(world_path))
1303 // Try to take gamespec from command line
1304 if(commanded_gamespec.isValid()){
1305 gamespec = commanded_gamespec;
1306 infostream<<"Using commanded gameid ["<<gamespec.id<<"]"<<std::endl;
1308 // Otherwise we will be using "minetest"
1310 gamespec = findSubgame(g_settings->get("default_game"));
1311 infostream<<"Using default gameid ["<<gamespec.id<<"]"<<std::endl;
1317 std::string world_gameid = getWorldGameId(world_path, is_legacy_world);
1318 // If commanded to use a gameid, do so
1319 if(commanded_gamespec.isValid()){
1320 gamespec = commanded_gamespec;
1321 if(commanded_gamespec.id != world_gameid){
1322 errorstream<<"WARNING: Using commanded gameid ["
1323 <<gamespec.id<<"]"<<" instead of world gameid ["
1324 <<world_gameid<<"]"<<std::endl;
1327 // If world contains an embedded game, use it;
1328 // Otherwise find world from local system.
1329 gamespec = findWorldSubgame(world_path);
1330 infostream<<"Using world gameid ["<<gamespec.id<<"]"<<std::endl;
1333 if(!gamespec.isValid()){
1334 errorstream<<"Subgame ["<<gamespec.id<<"] could not be found."
1338 verbosestream<<_("Using gameid")<<" ["<<gamespec.id<<"]"<<std::endl;
1341 Server server(world_path, configpath, gamespec, false);
1345 dedicated_server_loop(server, kill);
1350 #ifndef SERVER // Exclude from dedicated server build
1356 std::string address = g_settings->get("address");
1357 if(commanded_world != "")
1359 else if(cmd_args.exists("address"))
1360 address = cmd_args.get("address");
1362 std::string playername = g_settings->get("name");
1363 if(cmd_args.exists("name"))
1364 playername = cmd_args.get("name");
1366 bool skip_main_menu = cmd_args.getFlag("go");
1369 Device initialization
1372 // Resolution selection
1374 bool fullscreen = g_settings->getBool("fullscreen");
1375 u16 screenW = g_settings->getU16("screenW");
1376 u16 screenH = g_settings->getU16("screenH");
1380 bool vsync = g_settings->getBool("vsync");
1381 u16 bits = g_settings->getU16("fullscreen_bpp");
1382 u16 fsaa = g_settings->getU16("fsaa");
1386 video::E_DRIVER_TYPE driverType;
1388 std::string driverstring = g_settings->get("video_driver");
1390 if(driverstring == "null")
1391 driverType = video::EDT_NULL;
1392 else if(driverstring == "software")
1393 driverType = video::EDT_SOFTWARE;
1394 else if(driverstring == "burningsvideo")
1395 driverType = video::EDT_BURNINGSVIDEO;
1396 else if(driverstring == "direct3d8")
1397 driverType = video::EDT_DIRECT3D8;
1398 else if(driverstring == "direct3d9")
1399 driverType = video::EDT_DIRECT3D9;
1400 else if(driverstring == "opengl")
1401 driverType = video::EDT_OPENGL;
1402 #ifdef _IRR_COMPILE_WITH_OGLES1_
1403 else if(driverstring == "ogles1")
1404 driverType = video::EDT_OGLES1;
1406 #ifdef _IRR_COMPILE_WITH_OGLES2_
1407 else if(driverstring == "ogles2")
1408 driverType = video::EDT_OGLES2;
1412 errorstream<<"WARNING: Invalid video_driver specified; defaulting "
1413 "to opengl"<<std::endl;
1414 driverType = video::EDT_OPENGL;
1418 Create device and exit if creation failed
1421 MyEventReceiver receiver;
1423 IrrlichtDevice *device;
1425 SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
1426 params.DriverType = driverType;
1427 params.WindowSize = core::dimension2d<u32>(screenW, screenH);
1429 params.AntiAlias = fsaa;
1430 params.Fullscreen = fullscreen;
1431 params.Stencilbuffer = false;
1432 params.Vsync = vsync;
1433 params.EventReceiver = &receiver;
1435 device = createDeviceEx(params);
1438 return 1; // could not create selected driver.
1441 Continue initialization
1444 video::IVideoDriver* driver = device->getVideoDriver();
1447 This changes the minimum allowed number of vertices in a VBO.
1450 //driver->setMinHardwareBufferVertexCount(50);
1452 // Create time getter
1453 g_timegetter = new IrrlichtTimeGetter(device);
1455 // Create game callback for menus
1456 g_gamecallback = new MainGameCallback(device);
1459 Speed tests (done after irrlicht is loaded to get timer)
1461 if(cmd_args.getFlag("speedtests"))
1463 dstream<<"Running speed tests"<<std::endl;
1469 device->setResizable(true);
1471 bool random_input = g_settings->getBool("random_input")
1472 || cmd_args.getFlag("random-input");
1473 InputHandler *input = NULL;
1475 input = new RandomInputHandler();
1477 input = new RealInputHandler(device, &receiver);
1479 scene::ISceneManager* smgr = device->getSceneManager();
1481 guienv = device->getGUIEnvironment();
1482 gui::IGUISkin* skin = guienv->getSkin();
1484 std::string font_path = g_settings->get("font_path");
1485 u16 font_size = g_settings->getU16("font_size");
1486 gui::IGUIFont *font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size);
1488 gui::IGUIFont* font = guienv->getFont(getTexturePath("fontlucida.png").c_str());
1491 skin->setFont(font);
1493 errorstream<<"WARNING: Font file was not found."
1494 " Using default font."<<std::endl;
1495 // If font was not found, this will get us one
1496 font = skin->getFont();
1499 u32 text_height = font->getDimension(L"Hello, world!").Height;
1500 infostream<<"text_height="<<text_height<<std::endl;
1502 //skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,0,0,0));
1503 skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,255,255,255));
1504 //skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(0,0,0,0));
1505 //skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(0,0,0,0));
1506 skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255,0,0,0));
1507 skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255,0,0,0));
1508 skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255,70,100,50));
1509 skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255,255,255,255));
1511 #if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
1512 // Irrlicht 1.8 input colours
1513 skin->setColor(gui::EGDC_EDITABLE, video::SColor(255,128,128,128));
1514 skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255,96,134,49));
1521 ChatBackend chat_backend;
1524 If an error occurs, this is set to something and the
1525 menu-game loop is restarted. It is then displayed before
1528 std::wstring error_message = L"";
1530 // The password entered during the menu screen,
1531 std::string password;
1533 bool first_loop = true;
1538 while(device->run() && kill == false)
1540 // Set the window caption
1541 wchar_t* text = wgettext("Main Menu");
1542 device->setWindowCaption((std::wstring(L"Minetest [")+text+L"]").c_str());
1545 // This is used for catching disconnects
1550 Clear everything from the GUIEnvironment
1555 We need some kind of a root node to be able to add
1556 custom gui elements directly on the screen.
1557 Otherwise they won't be automatically drawn.
1559 guiroot = guienv->addStaticText(L"",
1560 core::rect<s32>(0, 0, 10000, 10000));
1562 SubgameSpec gamespec;
1563 WorldSpec worldspec;
1564 bool simple_singleplayer_mode = false;
1566 // These are set up based on the menu and other things
1567 std::string current_playername = "inv£lid";
1568 std::string current_password = "";
1569 std::string current_address = "does-not-exist";
1570 int current_port = 0;
1573 Out-of-game menu loop.
1575 Loop quits when menu returns proper parameters.
1577 while(kill == false)
1579 // If skip_main_menu, only go through here once
1580 if(skip_main_menu && !first_loop){
1586 // Cursor can be non-visible when coming from the game
1587 device->getCursorControl()->setVisible(true);
1588 // Some stuff are left to scene manager when coming from the game
1592 // Initialize menu data
1593 MainMenuData menudata;
1594 if(g_settings->exists("selected_mainmenu_tab"))
1595 menudata.selected_tab = g_settings->getS32("selected_mainmenu_tab");
1596 if(g_settings->exists("selected_serverlist"))
1597 menudata.selected_serverlist = g_settings->getS32("selected_serverlist");
1598 if(g_settings->exists("selected_mainmenu_game")){
1599 menudata.selected_game = g_settings->get("selected_mainmenu_game");
1600 menudata.selected_game_name = findSubgame(menudata.selected_game).name;
1602 menudata.address = narrow_to_wide(address);
1603 menudata.name = narrow_to_wide(playername);
1604 menudata.port = narrow_to_wide(itos(port));
1605 if(cmd_args.exists("password"))
1606 menudata.password = narrow_to_wide(cmd_args.get("password"));
1607 menudata.fancy_trees = g_settings->getBool("new_style_leaves");
1608 menudata.smooth_lighting = g_settings->getBool("smooth_lighting");
1609 menudata.clouds_3d = g_settings->getBool("enable_3d_clouds");
1610 menudata.opaque_water = g_settings->getBool("opaque_water");
1611 menudata.mip_map = g_settings->getBool("mip_map");
1612 menudata.anisotropic_filter = g_settings->getBool("anisotropic_filter");
1613 menudata.bilinear_filter = g_settings->getBool("bilinear_filter");
1614 menudata.trilinear_filter = g_settings->getBool("trilinear_filter");
1615 menudata.enable_shaders = g_settings->getS32("enable_shaders");
1616 menudata.preload_item_visuals = g_settings->getBool("preload_item_visuals");
1617 menudata.enable_particles = g_settings->getBool("enable_particles");
1618 menudata.liquid_finite = g_settings->getBool("liquid_finite");
1619 driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, menudata.mip_map);
1620 menudata.creative_mode = g_settings->getBool("creative_mode");
1621 menudata.enable_damage = g_settings->getBool("enable_damage");
1622 menudata.enable_public = g_settings->getBool("server_announce");
1623 // Default to selecting nothing
1624 menudata.selected_world = -1;
1625 // Get world listing for the menu
1626 std::vector<WorldSpec> worldspecs = getAvailableWorlds();
1627 // If there is only one world, select it
1628 if(worldspecs.size() == 1){
1629 menudata.selected_world = 0;
1631 // Otherwise try to select according to selected_world_path
1632 else if(g_settings->exists("selected_world_path")){
1633 std::string trypath = g_settings->get("selected_world_path");
1634 for(u32 i=0; i<worldspecs.size(); i++){
1635 if(worldspecs[i].path == trypath){
1636 menudata.selected_world = i;
1641 // If a world was commanded, append and select it
1642 if(commanded_world != ""){
1643 std::string gameid = getWorldGameId(commanded_world, true);
1644 std::string name = _("[--world parameter]");
1646 gameid = g_settings->get("default_game");
1649 WorldSpec spec(commanded_world, name, gameid);
1650 worldspecs.push_back(spec);
1651 menudata.selected_world = worldspecs.size()-1;
1653 // Copy worldspecs to menu
1654 menudata.worlds = worldspecs;
1656 menudata.games = getAvailableGames();
1657 // If selected game doesn't exist, take first from list
1658 if(findSubgame(menudata.selected_game).id == "" &&
1659 !menudata.games.empty()){
1660 menudata.selected_game = menudata.games[0].id;
1662 const SubgameSpec *menugame = getMenuGame(menudata);
1664 MenuTextures menutextures;
1665 menutextures.update(driver, menugame);
1667 if(skip_main_menu == false)
1669 video::IVideoDriver* driver = device->getVideoDriver();
1670 float fps_max = g_settings->getFloat("fps_max");
1671 infostream<<"Waiting for other menus"<<std::endl;
1672 while(device->run() && kill == false)
1676 driver->beginScene(true, true,
1677 video::SColor(255,128,128,128));
1678 drawMenuBackground(driver, menutextures);
1681 // On some computers framerate doesn't seem to be
1682 // automatically limited
1685 infostream<<"Waited for other menus"<<std::endl;
1688 new GUIMainMenu(guienv, guiroot, -1,
1689 &g_menumgr, &menudata, g_gamecallback);
1690 menu->allowFocusRemoval(true);
1692 // Always create clouds because they may or may not be
1693 // needed based on the game selected
1694 Clouds *clouds = new Clouds(smgr->getRootSceneNode(),
1695 smgr, -1, rand(), 100);
1696 clouds->update(v2f(0, 0), video::SColor(255,200,200,255));
1698 // A camera to see the clouds
1699 scene::ICameraSceneNode* camera;
1700 camera = smgr->addCameraSceneNode(0,
1701 v3f(0,0,0), v3f(0, 60, 100));
1702 camera->setFarValue(10000);
1704 if(error_message != L"")
1706 verbosestream<<"error_message = "
1707 <<wide_to_narrow(error_message)<<std::endl;
1709 GUIMessageMenu *menu2 =
1710 new GUIMessageMenu(guienv, guiroot, -1,
1711 &g_menumgr, error_message.c_str());
1713 error_message = L"";
1716 // Time is in milliseconds, for clouds
1717 u32 lasttime = device->getTimer()->getTime();
1719 infostream<<"Created main menu"<<std::endl;
1721 while(device->run() && kill == false)
1723 if(menu->getStatus() == true)
1726 // Game can be selected in the menu
1727 menugame = getMenuGame(menudata);
1728 menutextures.update(driver, menugame);
1729 // Clouds for the main menu
1730 bool cloud_menu_background = g_settings->getBool("menu_clouds");
1732 // If game has regular background and no overlay, don't use clouds
1733 if(cloud_menu_background && menutextures.background &&
1734 !menutextures.overlay){
1735 cloud_menu_background = false;
1737 // If game game has overlay and no regular background, always draw clouds
1738 else if(menutextures.overlay && !menutextures.background){
1739 cloud_menu_background = true;
1743 // Time calc for the clouds
1744 f32 dtime; // in seconds
1745 if (cloud_menu_background) {
1746 u32 time = device->getTimer()->getTime();
1748 dtime = (time - lasttime) / 1000.0;
1754 //driver->beginScene(true, true, video::SColor(255,0,0,0));
1755 driver->beginScene(true, true, video::SColor(255,140,186,250));
1757 if (cloud_menu_background) {
1758 // *3 otherwise the clouds would move very slowly
1759 clouds->step(dtime*3);
1762 drawMenuOverlay(driver, menutextures);
1763 drawMenuHeader(driver, menutextures);
1764 drawMenuFooter(driver, menutextures);
1766 drawMenuBackground(driver, menutextures);
1767 drawMenuHeader(driver, menutextures);
1768 drawMenuFooter(driver, menutextures);
1775 // On some computers framerate doesn't seem to be
1776 // automatically limited
1777 if (cloud_menu_background) {
1778 // Time of frame without fps limit
1781 // not using getRealTime is necessary for wine
1782 u32 time = device->getTimer()->getTime();
1784 busytime_u32 = time - lasttime;
1787 busytime = busytime_u32 / 1000.0;
1790 u32 frametime_min = 1000./fps_max;
1792 if(busytime_u32 < frametime_min) {
1793 u32 sleeptime = frametime_min - busytime_u32;
1794 device->sleep(sleeptime);
1801 infostream<<"Dropping main menu"<<std::endl;
1808 playername = wide_to_narrow(menudata.name);
1809 if (playername == "")
1810 playername = std::string("Guest") + itos(myrand_range(1000,9999));
1811 password = translatePassword(playername, menudata.password);
1812 //infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
1814 address = wide_to_narrow(menudata.address);
1815 int newport = stoi(wide_to_narrow(menudata.port));
1818 simple_singleplayer_mode = menudata.simple_singleplayer_mode;
1820 g_settings->setS32("selected_mainmenu_tab", menudata.selected_tab);
1821 g_settings->setS32("selected_serverlist", menudata.selected_serverlist);
1822 g_settings->set("selected_mainmenu_game", menudata.selected_game);
1823 g_settings->set("new_style_leaves", itos(menudata.fancy_trees));
1824 g_settings->set("smooth_lighting", itos(menudata.smooth_lighting));
1825 g_settings->set("enable_3d_clouds", itos(menudata.clouds_3d));
1826 g_settings->set("opaque_water", itos(menudata.opaque_water));
1828 g_settings->set("mip_map", itos(menudata.mip_map));
1829 g_settings->set("anisotropic_filter", itos(menudata.anisotropic_filter));
1830 g_settings->set("bilinear_filter", itos(menudata.bilinear_filter));
1831 g_settings->set("trilinear_filter", itos(menudata.trilinear_filter));
1833 g_settings->setS32("enable_shaders", menudata.enable_shaders);
1834 g_settings->set("preload_item_visuals", itos(menudata.preload_item_visuals));
1835 g_settings->set("enable_particles", itos(menudata.enable_particles));
1836 g_settings->set("liquid_finite", itos(menudata.liquid_finite));
1838 g_settings->set("creative_mode", itos(menudata.creative_mode));
1839 g_settings->set("enable_damage", itos(menudata.enable_damage));
1840 g_settings->set("server_announce", itos(menudata.enable_public));
1841 g_settings->set("name", playername);
1842 g_settings->set("address", address);
1843 g_settings->set("port", itos(port));
1844 if(menudata.selected_world != -1)
1845 g_settings->set("selected_world_path",
1846 worldspecs[menudata.selected_world].path);
1848 // Break out of menu-game loop to shut down cleanly
1849 if(device->run() == false || kill == true)
1852 current_playername = playername;
1853 current_password = password;
1854 current_address = address;
1855 current_port = port;
1857 // If using simple singleplayer mode, override
1858 if(simple_singleplayer_mode){
1859 current_playername = "singleplayer";
1860 current_password = "";
1861 current_address = "";
1862 current_port = 30011;
1864 else if (address != "")
1866 ServerListSpec server;
1867 server["name"] = menudata.servername;
1868 server["address"] = wide_to_narrow(menudata.address);
1869 server["port"] = wide_to_narrow(menudata.port);
1870 server["description"] = menudata.serverdescription;
1871 ServerList::insert(server);
1874 // Set world path to selected one
1875 if(menudata.selected_world != -1){
1876 worldspec = worldspecs[menudata.selected_world];
1877 infostream<<"Selected world: "<<worldspec.name
1878 <<" ["<<worldspec.path<<"]"<<std::endl;
1881 // Only refresh if so requested
1882 if(menudata.only_refresh){
1883 infostream<<"Refreshing menu"<<std::endl;
1887 // Create new world if requested
1888 if(menudata.create_world_name != L"")
1890 std::string path = porting::path_user + DIR_DELIM
1891 "worlds" + DIR_DELIM
1892 + wide_to_narrow(menudata.create_world_name);
1893 // Create world if it doesn't exist
1894 if(!initializeWorld(path, menudata.create_world_gameid)){
1895 error_message = wgettext("Failed to initialize world");
1896 errorstream<<wide_to_narrow(error_message)<<std::endl;
1899 g_settings->set("selected_world_path", path);
1900 g_settings->set("selected_mainmenu_game", menudata.create_world_gameid);
1905 if(current_address == "")
1907 if(menudata.selected_world == -1){
1908 error_message = wgettext("No world selected and no address "
1909 "provided. Nothing to do.");
1910 errorstream<<wide_to_narrow(error_message)<<std::endl;
1913 // Load gamespec for required game
1914 gamespec = findWorldSubgame(worldspec.path);
1915 if(!gamespec.isValid() && !commanded_gamespec.isValid()){
1916 error_message = wgettext("Could not find or load game \"")
1917 + narrow_to_wide(worldspec.gameid) + L"\"";
1918 errorstream<<wide_to_narrow(error_message)<<std::endl;
1921 if(commanded_gamespec.isValid() &&
1922 commanded_gamespec.id != worldspec.gameid){
1923 errorstream<<"WARNING: Overriding gamespec from \""
1924 <<worldspec.gameid<<"\" to \""
1925 <<commanded_gamespec.id<<"\""<<std::endl;
1926 gamespec = commanded_gamespec;
1929 if(!gamespec.isValid()){
1930 error_message = wgettext("Invalid gamespec.");
1931 error_message += L" (world_gameid="
1932 +narrow_to_wide(worldspec.gameid)+L")";
1933 errorstream<<wide_to_narrow(error_message)<<std::endl;
1942 // Break out of menu-game loop to shut down cleanly
1943 if(device->run() == false || kill == true)
1964 simple_singleplayer_mode
1968 catch(con::PeerNotFoundException &e)
1970 error_message = wgettext("Connection error (timed out?)");
1971 errorstream<<wide_to_narrow(error_message)<<std::endl;
1974 catch(std::exception &e)
1976 std::string narrow_message = "Some exception: \"";
1977 narrow_message += e.what();
1978 narrow_message += "\"";
1979 errorstream<<narrow_message<<std::endl;
1980 error_message = narrow_to_wide(narrow_message);
1984 // If no main menu, show error and exit
1987 if(error_message != L""){
1988 verbosestream<<"error_message = "
1989 <<wide_to_narrow(error_message)<<std::endl;
1999 In the end, delete the Irrlicht device.
2005 // Update configuration file
2006 if(configpath != "")
2007 g_settings->updateConfigFile(configpath.c_str());
2009 // Print modified quicktune values
2011 bool header_printed = false;
2012 std::vector<std::string> names = getQuicktuneNames();
2013 for(u32 i=0; i<names.size(); i++){
2014 QuicktuneValue val = getQuicktuneValue(names[i]);
2017 if(!header_printed){
2018 dstream<<"Modified quicktune values:"<<std::endl;
2019 header_printed = true;
2021 dstream<<names[i]<<" = "<<val.getString()<<std::endl;
2025 END_DEBUG_EXCEPTION_HANDLER(errorstream)
2027 debugstreams_deinit();