3 Copyright (C) 2010-2011 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
15 You should have received a copy of the GNU 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 "common_irrlicht.h"
54 #include "constants.h"
57 #include "guiMessageMenu.h"
60 #include "guiMainMenu.h"
65 #include "defaultsettings.h"
71 #include "utility_string.h"
75 These are loaded from the config file.
77 Settings main_settings;
78 Settings *g_settings = &main_settings;
81 Profiler main_profiler;
82 Profiler *g_profiler = &main_profiler;
89 std::ostream *dout_con_ptr = &dummyout;
90 std::ostream *derr_con_ptr = &verbosestream;
91 //std::ostream *dout_con_ptr = &infostream;
92 //std::ostream *derr_con_ptr = &errorstream;
95 std::ostream *dout_server_ptr = &infostream;
96 std::ostream *derr_server_ptr = &errorstream;
99 std::ostream *dout_client_ptr = &infostream;
100 std::ostream *derr_client_ptr = &errorstream;
107 /* mainmenumanager.h */
109 gui::IGUIEnvironment* guienv = NULL;
110 gui::IGUIStaticText *guiroot = NULL;
111 MainMenuManager g_menumgr;
115 return (g_menumgr.menuCount() == 0);
118 // Passed to menus to allow disconnecting and exiting
119 MainGameCallback *g_gamecallback = NULL;
123 gettime.h implementation
130 /* Use imprecise system calls directly (from porting.h) */
131 return porting::getTimeMs();
136 // A small helper class
140 virtual u32 getTime() = 0;
143 // A precise irrlicht one
144 class IrrlichtTimeGetter: public TimeGetter
147 IrrlichtTimeGetter(IrrlichtDevice *device):
154 return m_device->getTimer()->getRealTime();
157 IrrlichtDevice *m_device;
159 // Not so precise one which works without irrlicht
160 class SimpleTimeGetter: public TimeGetter
165 return porting::getTimeMs();
169 // A pointer to a global instance of the time getter
171 TimeGetter *g_timegetter = NULL;
175 if(g_timegetter == NULL)
177 return g_timegetter->getTime();
182 class StderrLogOutput: public ILogOutput
185 /* line: Full line with timestamp, level and thread */
186 void printLog(const std::string &line)
188 std::cerr<<line<<std::endl;
190 } main_stderr_log_out;
192 class DstreamNoStderrLogOutput: public ILogOutput
195 /* line: Full line with timestamp, level and thread */
196 void printLog(const std::string &line)
198 dstream_no_stderr<<line<<std::endl;
200 } main_dstream_no_stderr_log_out;
205 Event handler for Irrlicht
207 NOTE: Everything possible should be moved out from here,
208 probably to InputHandler and the_game
211 class MyEventReceiver : public IEventReceiver
214 // This is the one method that we have to implement
215 virtual bool OnEvent(const SEvent& event)
218 React to nothing here if a menu is active
220 if(noMenuActive() == false)
225 // Remember whether each key is down or up
226 if(event.EventType == irr::EET_KEY_INPUT_EVENT)
228 if(event.KeyInput.PressedDown) {
229 keyIsDown.set(event.KeyInput);
230 keyWasDown.set(event.KeyInput);
232 keyIsDown.unset(event.KeyInput);
236 if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
238 if(noMenuActive() == false)
241 middle_active = false;
242 right_active = false;
246 left_active = event.MouseInput.isLeftPressed();
247 middle_active = event.MouseInput.isMiddlePressed();
248 right_active = event.MouseInput.isRightPressed();
250 if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
254 if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
258 if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
262 if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)
264 rightreleased = true;
266 if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)
268 mouse_wheel += event.MouseInput.Wheel;
276 bool IsKeyDown(const KeyPress &keyCode) const
278 return keyIsDown[keyCode];
281 // Checks whether a key was down and resets the state
282 bool WasKeyDown(const KeyPress &keyCode)
284 bool b = keyWasDown[keyCode];
286 keyWasDown.unset(keyCode);
303 rightclicked = false;
304 leftreleased = false;
305 rightreleased = false;
308 middle_active = false;
309 right_active = false;
331 IrrlichtDevice *m_device;
333 // The current state of keys
335 // Whether a key has been pressed or not
340 Separated input handler
343 class RealInputHandler : public InputHandler
346 RealInputHandler(IrrlichtDevice *device, MyEventReceiver *receiver):
351 virtual bool isKeyDown(const KeyPress &keyCode)
353 return m_receiver->IsKeyDown(keyCode);
355 virtual bool wasKeyDown(const KeyPress &keyCode)
357 return m_receiver->WasKeyDown(keyCode);
359 virtual v2s32 getMousePos()
361 return m_device->getCursorControl()->getPosition();
363 virtual void setMousePos(s32 x, s32 y)
365 m_device->getCursorControl()->setPosition(x, y);
368 virtual bool getLeftState()
370 return m_receiver->left_active;
372 virtual bool getRightState()
374 return m_receiver->right_active;
377 virtual bool getLeftClicked()
379 return m_receiver->leftclicked;
381 virtual bool getRightClicked()
383 return m_receiver->rightclicked;
385 virtual void resetLeftClicked()
387 m_receiver->leftclicked = false;
389 virtual void resetRightClicked()
391 m_receiver->rightclicked = false;
394 virtual bool getLeftReleased()
396 return m_receiver->leftreleased;
398 virtual bool getRightReleased()
400 return m_receiver->rightreleased;
402 virtual void resetLeftReleased()
404 m_receiver->leftreleased = false;
406 virtual void resetRightReleased()
408 m_receiver->rightreleased = false;
411 virtual s32 getMouseWheel()
413 return m_receiver->getMouseWheel();
418 m_receiver->clearInput();
421 IrrlichtDevice *m_device;
422 MyEventReceiver *m_receiver;
425 class RandomInputHandler : public InputHandler
433 rightclicked = false;
434 leftreleased = false;
435 rightreleased = false;
438 virtual bool isKeyDown(const KeyPress &keyCode)
440 return keydown[keyCode];
442 virtual bool wasKeyDown(const KeyPress &keyCode)
446 virtual v2s32 getMousePos()
450 virtual void setMousePos(s32 x, s32 y)
452 mousepos = v2s32(x,y);
455 virtual bool getLeftState()
459 virtual bool getRightState()
464 virtual bool getLeftClicked()
468 virtual bool getRightClicked()
472 virtual void resetLeftClicked()
476 virtual void resetRightClicked()
478 rightclicked = false;
481 virtual bool getLeftReleased()
485 virtual bool getRightReleased()
487 return rightreleased;
489 virtual void resetLeftReleased()
491 leftreleased = false;
493 virtual void resetRightReleased()
495 rightreleased = false;
498 virtual s32 getMouseWheel()
503 virtual void step(float dtime)
506 static float counter1 = 0;
510 counter1 = 0.1*Rand(1, 40);
511 keydown.toggle(getKeySetting("keymap_jump"));
515 static float counter1 = 0;
519 counter1 = 0.1*Rand(1, 40);
520 keydown.toggle(getKeySetting("keymap_special1"));
524 static float counter1 = 0;
528 counter1 = 0.1*Rand(1, 40);
529 keydown.toggle(getKeySetting("keymap_forward"));
533 static float counter1 = 0;
537 counter1 = 0.1*Rand(1, 40);
538 keydown.toggle(getKeySetting("keymap_left"));
542 static float counter1 = 0;
546 counter1 = 0.1*Rand(1, 20);
547 mousespeed = v2s32(Rand(-20,20), Rand(-15,20));
551 static float counter1 = 0;
555 counter1 = 0.1*Rand(1, 30);
556 leftdown = !leftdown;
564 static float counter1 = 0;
568 counter1 = 0.1*Rand(1, 15);
569 rightdown = !rightdown;
573 rightreleased = true;
576 mousepos += mousespeed;
579 s32 Rand(s32 min, s32 max)
581 return (myrand()%(max-min+1))+min;
595 void drawMenuBackground(video::IVideoDriver* driver)
597 core::dimension2d<u32> screensize = driver->getScreenSize();
599 video::ITexture *bgtexture =
600 driver->getTexture(getTexturePath("menubg.png").c_str());
603 s32 scaledsize = 128;
605 // The important difference between destsize and screensize is
606 // that destsize is rounded to whole scaled pixels.
607 // These formulas use component-wise multiplication and division of v2u32.
608 v2u32 texturesize = bgtexture->getSize();
609 v2u32 sourcesize = texturesize * screensize / scaledsize + v2u32(1,1);
610 v2u32 destsize = scaledsize * sourcesize / texturesize;
612 // Default texture wrapping mode in Irrlicht is ETC_REPEAT.
613 driver->draw2DImage(bgtexture,
614 core::rect<s32>(0, 0, destsize.X, destsize.Y),
615 core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
619 video::ITexture *logotexture =
620 driver->getTexture(getTexturePath("menulogo.png").c_str());
623 v2s32 logosize(logotexture->getOriginalSize().Width,
624 logotexture->getOriginalSize().Height);
627 video::SColor bgcolor(255,50,50,50);
628 core::rect<s32> bgrect(0, screensize.Height-logosize.Y-20,
629 screensize.Width, screensize.Height);
630 driver->draw2DRectangle(bgcolor, bgrect, NULL);
632 core::rect<s32> rect(0,0,logosize.X,logosize.Y);
633 rect += v2s32(screensize.Width/2,screensize.Height-10-logosize.Y);
634 rect -= v2s32(logosize.X/2, 0);
635 driver->draw2DImage(logotexture, rect,
636 core::rect<s32>(core::position2d<s32>(0,0),
637 core::dimension2di(logotexture->getSize())),
644 // These are defined global so that they're not optimized too much.
645 // Can't change them to volatile.
650 std::string tempstring;
651 std::string tempstring2;
656 infostream<<"The following test should take around 20ms."<<std::endl;
657 TimeTaker timer("Testing std::string speed");
658 const u32 jj = 10000;
659 for(u32 j=0; j<jj; j++)
664 for(u32 i=0; i<ii; i++){
665 tempstring2 += "asd";
667 for(u32 i=0; i<ii+1; i++){
669 if(tempstring == tempstring2)
675 infostream<<"All of the following tests should take around 100ms each."
679 TimeTaker timer("Testing floating-point conversion speed");
681 for(u32 i=0; i<4000000; i++){
688 TimeTaker timer("Testing floating-point vector speed");
690 tempv3f1 = v3f(1,2,3);
691 tempv3f2 = v3f(4,5,6);
692 for(u32 i=0; i<10000000; i++){
693 tempf += tempv3f1.dotProduct(tempv3f2);
694 tempv3f2 += v3f(7,8,9);
699 TimeTaker timer("Testing core::map speed");
701 core::map<v2s16, f32> map1;
704 for(s16 y=0; y<ii; y++){
705 for(s16 x=0; x<ii; x++){
706 map1.insert(v2s16(x,y), tempf);
710 for(s16 y=ii-1; y>=0; y--){
711 for(s16 x=0; x<ii; x++){
712 tempf = map1[v2s16(x,y)];
718 infostream<<"Around 5000/ms should do well here."<<std::endl;
719 TimeTaker timer("Testing mutex speed");
733 while(timer.getTime() < 10);
735 u32 dtime = timer.stop();
736 u32 per_ms = n / dtime;
737 infostream<<"Done. "<<dtime<<"ms, "
738 <<per_ms<<"/ms"<<std::endl;
742 int main(int argc, char *argv[])
750 log_add_output_maxlev(&main_stderr_log_out, LMT_ACTION);
751 log_add_output_all_levs(&main_dstream_no_stderr_log_out);
753 log_register_thread("main");
755 // Set locale. This is for forcing '.' as the decimal point.
756 std::locale::global(std::locale("C"));
757 // This enables printing all characters in bitmap font
758 setlocale(LC_CTYPE, "en_US");
764 // List all allowed options
765 core::map<std::string, ValueSpec> allowed_options;
766 allowed_options.insert("help", ValueSpec(VALUETYPE_FLAG,
767 "Show allowed options"));
768 allowed_options.insert("config", ValueSpec(VALUETYPE_STRING,
769 "Load configuration from specified file"));
770 allowed_options.insert("port", ValueSpec(VALUETYPE_STRING,
771 "Set network port (UDP)"));
772 allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG,
773 "Disable unit tests"));
774 allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG,
775 "Enable unit tests"));
776 allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING,
777 "Same as --world (deprecated)"));
778 allowed_options.insert("world", ValueSpec(VALUETYPE_STRING,
780 allowed_options.insert("verbose", ValueSpec(VALUETYPE_FLAG,
781 "Print more information to console"));
782 allowed_options.insert("logfile", ValueSpec(VALUETYPE_STRING,
783 "Set logfile path (debug.txt)"));
785 allowed_options.insert("speedtests", ValueSpec(VALUETYPE_FLAG,
787 allowed_options.insert("address", ValueSpec(VALUETYPE_STRING,
788 "Address to connect to. ('' = local game)"));
789 allowed_options.insert("random-input", ValueSpec(VALUETYPE_FLAG,
790 "Enable random user input, for testing"));
791 allowed_options.insert("server", ValueSpec(VALUETYPE_FLAG,
792 "Run dedicated server"));
793 allowed_options.insert("name", ValueSpec(VALUETYPE_STRING,
795 allowed_options.insert("password", ValueSpec(VALUETYPE_STRING,
797 allowed_options.insert("go", ValueSpec(VALUETYPE_FLAG,
798 "Disable main menu"));
803 bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);
805 if(ret == false || cmd_args.getFlag("help"))
807 dstream<<"Allowed options:"<<std::endl;
808 for(core::map<std::string, ValueSpec>::Iterator
809 i = allowed_options.getIterator();
810 i.atEnd() == false; i++)
812 std::ostringstream os1(std::ios::binary);
813 os1<<" --"<<i.getNode()->getKey();
814 if(i.getNode()->getValue().type == VALUETYPE_FLAG)
818 dstream<<padStringRight(os1.str(), 24);
820 if(i.getNode()->getValue().help != NULL)
821 dstream<<i.getNode()->getValue().help;
825 return cmd_args.getFlag("help") ? 0 : 1;
829 Low-level initialization
832 // In certain cases, output info level on stderr
833 if(cmd_args.getFlag("verbose") || cmd_args.getFlag("speedtests"))
834 log_add_output(&main_stderr_log_out, LMT_INFO);
836 porting::signal_handler_init();
837 bool &kill = *porting::signal_handler_killstatus();
839 porting::initializePaths();
841 // Create user data directory
842 fs::CreateDir(porting::path_user);
844 init_gettext((porting::path_share+DIR_DELIM+".."+DIR_DELIM+"locale").c_str());
846 // Initialize debug streams
848 std::string logfile = DEBUGFILE;
850 std::string logfile = porting::path_user+DIR_DELIM+DEBUGFILE;
852 if(cmd_args.exists("logfile"))
853 logfile = cmd_args.get("logfile");
854 bool disable_stderr = false;
855 debugstreams_init(disable_stderr, logfile.c_str());
856 // Initialize debug stacks
859 DSTACK(__FUNCTION_NAME);
861 dstream<<"logfile = "<<logfile<<std::endl;
862 dstream<<"path_share = "<<porting::path_share<<std::endl;
863 dstream<<"path_user = "<<porting::path_user<<std::endl;
866 BEGIN_DEBUG_EXCEPTION_HANDLER
868 // Print startup message
869 actionstream<<PROJECT_NAME<<
870 " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
878 // Initialize default settings
879 set_default_settings(g_settings);
881 // Initialize sockets
883 atexit(sockets_cleanup);
889 // Path of configuration file in use
890 std::string configpath = "";
892 if(cmd_args.exists("config"))
894 bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
897 errorstream<<"Could not read configuration from \""
898 <<cmd_args.get("config")<<"\""<<std::endl;
901 configpath = cmd_args.get("config");
905 core::array<std::string> filenames;
906 filenames.push_back(porting::path_user +
907 DIR_DELIM + "minetest.conf");
908 // Legacy configuration file location
909 filenames.push_back(porting::path_user +
910 DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
912 // Try also from a lower level (to aid having the same configuration
913 // for many RUN_IN_PLACE installs)
914 filenames.push_back(porting::path_user +
915 DIR_DELIM + ".." + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
918 for(u32 i=0; i<filenames.size(); i++)
920 bool r = g_settings->readConfigFile(filenames[i].c_str());
923 configpath = filenames[i];
928 // If no path found, use the first one (menu creates the file)
930 configpath = filenames[0];
933 // Initialize random seed
941 if((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false)
942 || cmd_args.getFlag("enable-unittests") == true)
953 if(cmd_args.exists("port"))
954 port = cmd_args.getU16("port");
955 else if(g_settings->exists("port"))
956 port = g_settings->getU16("port");
961 std::string map_dir = porting::path_user + DIR_DELIM + "server" + DIR_DELIM + "worlds" + DIR_DELIM + "world";
962 if(cmd_args.exists("map-dir"))
963 map_dir = cmd_args.get("map-dir");
964 else if(g_settings->exists("map-dir"))
965 map_dir = g_settings->get("map-dir");
967 // No map-dir option was specified.
968 // Check if the world is found from the default directory, and if
969 // not, see if the legacy world directory exists.
970 std::string legacy_map_dir = porting::path_user+DIR_DELIM+".."+DIR_DELIM+"world";
971 if(!fs::PathExists(map_dir) && fs::PathExists(legacy_map_dir)){
972 errorstream<<"Warning: Using legacy world directory \""
973 <<legacy_map_dir<<"\""<<std::endl;
974 map_dir = legacy_map_dir;
978 // Run dedicated server if asked to or no other option
980 bool run_dedicated_server = true;
982 bool run_dedicated_server = cmd_args.getFlag("server");
984 if(run_dedicated_server)
986 DSTACK("Dedicated server branch");
988 // Create time getter if built with Irrlicht
990 g_timegetter = new SimpleTimeGetter();
994 Server server(map_dir, configpath, "mesetint");
998 dedicated_server_loop(server, kill);
1003 #ifndef SERVER // Exclude from dedicated server build
1009 std::string address = g_settings->get("address");
1010 if(cmd_args.exists("address"))
1011 address = cmd_args.get("address");
1013 std::string playername = g_settings->get("name");
1014 if(cmd_args.exists("name"))
1015 playername = cmd_args.get("name");
1017 bool skip_main_menu = cmd_args.getFlag("go");
1020 Device initialization
1023 // Resolution selection
1025 bool fullscreen = false;
1026 u16 screenW = g_settings->getU16("screenW");
1027 u16 screenH = g_settings->getU16("screenH");
1031 video::E_DRIVER_TYPE driverType;
1033 std::string driverstring = g_settings->get("video_driver");
1035 if(driverstring == "null")
1036 driverType = video::EDT_NULL;
1037 else if(driverstring == "software")
1038 driverType = video::EDT_SOFTWARE;
1039 else if(driverstring == "burningsvideo")
1040 driverType = video::EDT_BURNINGSVIDEO;
1041 else if(driverstring == "direct3d8")
1042 driverType = video::EDT_DIRECT3D8;
1043 else if(driverstring == "direct3d9")
1044 driverType = video::EDT_DIRECT3D9;
1045 else if(driverstring == "opengl")
1046 driverType = video::EDT_OPENGL;
1049 errorstream<<"WARNING: Invalid video_driver specified; defaulting "
1050 "to opengl"<<std::endl;
1051 driverType = video::EDT_OPENGL;
1055 Create device and exit if creation failed
1058 MyEventReceiver receiver;
1060 IrrlichtDevice *device;
1061 device = createDevice(driverType,
1062 core::dimension2d<u32>(screenW, screenH),
1063 16, fullscreen, false, false, &receiver);
1066 return 1; // could not create selected driver.
1069 Continue initialization
1072 video::IVideoDriver* driver = device->getVideoDriver();
1074 // Disable mipmaps (because some of them look ugly)
1075 driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
1078 This changes the minimum allowed number of vertices in a VBO.
1081 //driver->setMinHardwareBufferVertexCount(50);
1083 // Set the window caption
1084 device->setWindowCaption(L"Minetest [Main Menu]");
1086 // Create time getter
1087 g_timegetter = new IrrlichtTimeGetter(device);
1089 // Create game callback for menus
1090 g_gamecallback = new MainGameCallback(device);
1093 Speed tests (done after irrlicht is loaded to get timer)
1095 if(cmd_args.getFlag("speedtests"))
1097 dstream<<"Running speed tests"<<std::endl;
1102 device->setResizable(true);
1104 bool random_input = g_settings->getBool("random_input")
1105 || cmd_args.getFlag("random-input");
1106 InputHandler *input = NULL;
1108 input = new RandomInputHandler();
1110 input = new RealInputHandler(device, &receiver);
1112 scene::ISceneManager* smgr = device->getSceneManager();
1114 guienv = device->getGUIEnvironment();
1115 gui::IGUISkin* skin = guienv->getSkin();
1116 gui::IGUIFont* font = guienv->getFont(getTexturePath("fontlucida.png").c_str());
1118 skin->setFont(font);
1120 errorstream<<"WARNING: Font file was not found."
1121 " Using default font."<<std::endl;
1122 // If font was not found, this will get us one
1123 font = skin->getFont();
1126 u32 text_height = font->getDimension(L"Hello, world!").Height;
1127 infostream<<"text_height="<<text_height<<std::endl;
1129 //skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,0,0,0));
1130 skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,255,255,255));
1131 //skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(0,0,0,0));
1132 //skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(0,0,0,0));
1133 skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255,0,0,0));
1134 skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255,0,0,0));
1140 ChatBackend chat_backend;
1143 If an error occurs, this is set to something and the
1144 menu-game loop is restarted. It is then displayed before
1147 std::wstring error_message = L"";
1149 // The password entered during the menu screen,
1150 std::string password;
1155 while(device->run() && kill == false)
1158 // This is used for catching disconnects
1163 Clear everything from the GUIEnvironment
1168 We need some kind of a root node to be able to add
1169 custom gui elements directly on the screen.
1170 Otherwise they won't be automatically drawn.
1172 guiroot = guienv->addStaticText(L"",
1173 core::rect<s32>(0, 0, 10000, 10000));
1176 Out-of-game menu loop.
1178 Loop quits when menu returns proper parameters.
1180 while(kill == false)
1182 // Cursor can be non-visible when coming from the game
1183 device->getCursorControl()->setVisible(true);
1184 // Some stuff are left to scene manager when coming from the game
1187 // Reset or hide the debug gui texts
1188 /*guitext->setText(L"Minetest-c55");
1189 guitext2->setVisible(false);
1190 guitext_info->setVisible(false);
1191 guitext_chat->setVisible(false);*/
1193 // Initialize menu data
1194 MainMenuData menudata;
1195 menudata.address = narrow_to_wide(address);
1196 menudata.name = narrow_to_wide(playername);
1197 menudata.port = narrow_to_wide(itos(port));
1198 menudata.fancy_trees = g_settings->getBool("new_style_leaves");
1199 menudata.smooth_lighting = g_settings->getBool("smooth_lighting");
1200 menudata.clouds_3d = g_settings->getBool("enable_3d_clouds");
1201 menudata.opaque_water = g_settings->getBool("opaque_water");
1202 menudata.creative_mode = g_settings->getBool("creative_mode");
1203 menudata.enable_damage = g_settings->getBool("enable_damage");
1204 if(cmd_args.exists("password"))
1205 menudata.password = narrow_to_wide(cmd_args.get("password"));
1207 if(skip_main_menu == false)
1210 new GUIMainMenu(guienv, guiroot, -1,
1211 &g_menumgr, &menudata, g_gamecallback);
1212 menu->allowFocusRemoval(true);
1214 if(error_message != L"")
1216 verbosestream<<"error_message = "
1217 <<wide_to_narrow(error_message)<<std::endl;
1219 GUIMessageMenu *menu2 =
1220 new GUIMessageMenu(guienv, guiroot, -1,
1221 &g_menumgr, error_message.c_str());
1223 error_message = L"";
1226 video::IVideoDriver* driver = device->getVideoDriver();
1228 infostream<<"Created main menu"<<std::endl;
1230 while(device->run() && kill == false)
1232 if(menu->getStatus() == true)
1235 //driver->beginScene(true, true, video::SColor(255,0,0,0));
1236 driver->beginScene(true, true, video::SColor(255,128,128,128));
1238 drawMenuBackground(driver);
1244 // On some computers framerate doesn't seem to be
1245 // automatically limited
1249 // Break out of menu-game loop to shut down cleanly
1250 if(device->run() == false || kill == true)
1253 infostream<<"Dropping main menu"<<std::endl;
1257 // Delete map if requested
1258 if(menudata.delete_map)
1260 bool r = fs::RecursiveDeleteContent(map_dir);
1262 error_message = L"Delete failed";
1267 playername = wide_to_narrow(menudata.name);
1268 password = translatePassword(playername, menudata.password);
1269 //infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
1271 address = wide_to_narrow(menudata.address);
1272 int newport = stoi(wide_to_narrow(menudata.port));
1276 g_settings->set("new_style_leaves", itos(menudata.fancy_trees));
1277 g_settings->set("smooth_lighting", itos(menudata.smooth_lighting));
1278 g_settings->set("enable_3d_clouds", itos(menudata.clouds_3d));
1279 g_settings->set("opaque_water", itos(menudata.opaque_water));
1280 g_settings->set("creative_mode", itos(menudata.creative_mode));
1281 g_settings->set("enable_damage", itos(menudata.enable_damage));
1282 g_settings->set("name", playername);
1283 g_settings->set("address", address);
1284 g_settings->set("port", itos(port));
1285 // Update configuration file
1286 if(configpath != "")
1287 g_settings->updateConfigFile(configpath.c_str());
1293 // Break out of menu-game loop to shut down cleanly
1294 if(device->run() == false || kill == true)
1317 catch(con::PeerNotFoundException &e)
1319 errorstream<<"Connection error (timed out?)"<<std::endl;
1320 error_message = L"Connection error (timed out?)";
1322 catch(SocketException &e)
1324 errorstream<<"Socket error (port already in use?)"<<std::endl;
1325 error_message = L"Socket error (port already in use?)";
1329 errorstream<<e.what()<<std::endl;
1330 error_message = narrow_to_wide(e.what()) + L"\nCheck debug.txt for details.";
1333 catch(std::exception &e)
1335 std::string narrow_message = "Some exception, what()=\"";
1336 narrow_message += e.what();
1337 narrow_message += "\"";
1338 errorstream<<narrow_message<<std::endl;
1339 error_message = narrow_to_wide(narrow_message);
1343 // If no main menu, show error and exit
1346 if(error_message != L""){
1347 verbosestream<<"error_message = "
1348 <<wide_to_narrow(error_message)<<std::endl;
1358 In the end, delete the Irrlicht device.
1364 // Update configuration file
1365 if(configpath != "")
1366 g_settings->updateConfigFile(configpath.c_str());
1368 END_DEBUG_EXCEPTION_HANDLER(errorstream)
1370 debugstreams_deinit();