- /*
- Create device and exit if creation failed
- */
-
- IrrlichtDevice *device;
-
- SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
- params.DriverType = driverType;
- params.WindowSize = core::dimension2d<u32>(screenW, screenH);
- params.Bits = bits;
- params.AntiAlias = fsaa;
- params.Fullscreen = fullscreen;
- params.Stencilbuffer = false;
- params.Vsync = vsync;
- params.EventReceiver = &receiver;
-
- device = createDeviceEx(params);
-
- if (device == 0)
- return 1; // could not create selected driver.
-
- /*
- Continue initialization
- */
-
- video::IVideoDriver* driver = device->getVideoDriver();
-
- /*
- This changes the minimum allowed number of vertices in a VBO.
- Default is 500.
- */
- //driver->setMinHardwareBufferVertexCount(50);
-
- // Create time getter
- g_timegetter = new IrrlichtTimeGetter(device);
-
- // Create game callback for menus
- g_gamecallback = new MainGameCallback(device);
-
- /*
- Speed tests (done after irrlicht is loaded to get timer)
- */
- if(cmd_args.getFlag("speedtests"))
- {
- dstream<<"Running speed tests"<<std::endl;
- SpeedTests();
- device->drop();
- return 0;
- }
-
- device->setResizable(true);
-
- bool random_input = g_settings->getBool("random_input")
- || cmd_args.getFlag("random-input");
- InputHandler *input = NULL;
- if(random_input)
- input = new RandomInputHandler();
- else
- input = new RealInputHandler(device, &receiver);
-
- scene::ISceneManager* smgr = device->getSceneManager();
-
- guienv = device->getGUIEnvironment();
- gui::IGUISkin* skin = guienv->getSkin();
- #if USE_FREETYPE
- std::string font_path = g_settings->get("font_path");
- u16 font_size = g_settings->getU16("font_size");
- gui::IGUIFont *font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size);
- #else
- gui::IGUIFont* font = guienv->getFont(getTexturePath("fontlucida.png").c_str());
- #endif
- if(font)
- skin->setFont(font);
- else
- errorstream<<"WARNING: Font file was not found."
- " Using default font."<<std::endl;
- // If font was not found, this will get us one
- font = skin->getFont();
- assert(font);
-
- u32 text_height = font->getDimension(L"Hello, world!").Height;
- infostream<<"text_height="<<text_height<<std::endl;
-
- //skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,0,0,0));
- skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,255,255,255));
- //skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(0,0,0,0));
- //skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(0,0,0,0));
- skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255,0,0,0));
- skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255,0,0,0));
- skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255,70,100,50));
- skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255,255,255,255));
-
-#if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
- // Irrlicht 1.8 input colours
- skin->setColor(gui::EGDC_EDITABLE, video::SColor(255,128,128,128));
- skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255,96,134,49));
-#endif
-
-
- // Create the menu clouds
- if (!g_menucloudsmgr)
- g_menucloudsmgr = smgr->createNewSceneManager();
- if (!g_menuclouds)
- g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(),
- g_menucloudsmgr, -1, rand(), 100);
- g_menuclouds->update(v2f(0, 0), video::SColor(255,200,200,255));
- scene::ICameraSceneNode* camera;
- camera = g_menucloudsmgr->addCameraSceneNode(0,
- v3f(0,0,0), v3f(0, 60, 100));
- camera->setFarValue(10000);
-
- /*
- GUI stuff
- */
-
- ChatBackend chat_backend;
-
- /*
- If an error occurs, this is set to something and the
- menu-game loop is restarted. It is then displayed before
- the menu.
- */
- std::wstring error_message = L"";
-
- // The password entered during the menu screen,
- std::string password;
-
- bool first_loop = true;
-
- /*
- Menu-game loop
- */
- while(device->run() && kill == false)
- {
- // Set the window caption
- wchar_t* text = wgettext("Main Menu");
- device->setWindowCaption((std::wstring(L"Minetest [")+text+L"]").c_str());
- delete[] text;
-
- // This is used for catching disconnects
- try
- {
-
- /*
- Clear everything from the GUIEnvironment
- */
- guienv->clear();
-
- /*
- We need some kind of a root node to be able to add
- custom gui elements directly on the screen.
- Otherwise they won't be automatically drawn.
- */
- guiroot = guienv->addStaticText(L"",
- core::rect<s32>(0, 0, 10000, 10000));
-
- SubgameSpec gamespec;
- WorldSpec worldspec;
- bool simple_singleplayer_mode = false;
-
- // These are set up based on the menu and other things
- std::string current_playername = "inv£lid";
- std::string current_password = "";
- std::string current_address = "does-not-exist";
- int current_port = 0;
-
- /*
- Out-of-game menu loop.
-
- Loop quits when menu returns proper parameters.
- */
- while(kill == false)
- {
- // If skip_main_menu, only go through here once
- if(skip_main_menu && !first_loop){
- kill = true;
- break;
- }
- first_loop = false;
-
- // Cursor can be non-visible when coming from the game
- device->getCursorControl()->setVisible(true);
- // Some stuff are left to scene manager when coming from the game
- // (map at least?)
- smgr->clear();
-
- // Initialize menu data
- MainMenuData menudata;
- menudata.kill = kill;
- menudata.address = address;
- menudata.name = playername;
- menudata.port = itos(port);
- menudata.errormessage = wide_to_narrow(error_message);
- error_message = L"";
- if(cmd_args.exists("password"))
- menudata.password = cmd_args.get("password");
-
- driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));
-
- menudata.enable_public = g_settings->getBool("server_announce");
-
- std::vector<WorldSpec> worldspecs = getAvailableWorlds();
-
- // If a world was commanded, append and select it
- if(commanded_world != ""){
-
- std::string gameid = getWorldGameId(commanded_world, true);
- std::string name = _("[--world parameter]");
- if(gameid == ""){
- gameid = g_settings->get("default_game");
- name += " [new]";
- }
- //TODO find within worldspecs and set config
- }
-
- if(skip_main_menu == false)
- {
- video::IVideoDriver* driver = device->getVideoDriver();
-
- infostream<<"Waiting for other menus"<<std::endl;
- while(device->run() && kill == false)
- {
- if(noMenuActive())
- break;
- driver->beginScene(true, true,
- video::SColor(255,128,128,128));
- guienv->drawAll();
- driver->endScene();
- // On some computers framerate doesn't seem to be
- // automatically limited
- sleep_ms(25);
- }
- infostream<<"Waited for other menus"<<std::endl;
-
- GUIEngine* temp = new GUIEngine(device, guiroot, &g_menumgr,smgr,&menudata);
-
- delete temp;
- //once finished you'll never end up here
- smgr->clear();
- kill = menudata.kill;
-
- }
-
- //update worldspecs (necessary as new world may have been created)
- worldspecs = getAvailableWorlds();
-
- if (menudata.name == "")
- menudata.name = std::string("Guest") + itos(myrand_range(1000,9999));
- else
- playername = menudata.name;
-
- password = translatePassword(playername, narrow_to_wide(menudata.password));
- //infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
-
- address = menudata.address;
- int newport = stoi(menudata.port);
- if(newport != 0)
- port = newport;
-
- simple_singleplayer_mode = menudata.simple_singleplayer_mode;
-
- // Save settings
- g_settings->set("name", playername);
- g_settings->set("address", address);
- g_settings->set("port", itos(port));
-
- if((menudata.selected_world >= 0) &&
- (menudata.selected_world < worldspecs.size()))
- g_settings->set("selected_world_path",
- worldspecs[menudata.selected_world].path);
-
- // Break out of menu-game loop to shut down cleanly
- if(device->run() == false || kill == true)
- break;
-
- current_playername = playername;
- current_password = password;
- current_address = address;
- current_port = port;
-
- // If using simple singleplayer mode, override
- if(simple_singleplayer_mode){
- current_playername = "singleplayer";
- current_password = "";
- current_address = "";
- current_port = myrand_range(49152, 65535);
- }
- else if (address != "")
- {
- ServerListSpec server;
- server["name"] = menudata.servername;
- server["address"] = menudata.address;
- server["port"] = menudata.port;
- server["description"] = menudata.serverdescription;
- ServerList::insert(server);
- }
-
- // Set world path to selected one
- if ((menudata.selected_world >= 0) &&
- (menudata.selected_world < worldspecs.size())) {
- worldspec = worldspecs[menudata.selected_world];
- infostream<<"Selected world: "<<worldspec.name
- <<" ["<<worldspec.path<<"]"<<std::endl;
- }
-
- // If local game
- if(current_address == "")
- {
- if(menudata.selected_world == -1){
- error_message = wgettext("No world selected and no address "
- "provided. Nothing to do.");
- errorstream<<wide_to_narrow(error_message)<<std::endl;
- continue;
- }
- // Load gamespec for required game
- gamespec = findWorldSubgame(worldspec.path);
- if(!gamespec.isValid() && !commanded_gamespec.isValid()){
- error_message = wgettext("Could not find or load game \"")
- + narrow_to_wide(worldspec.gameid) + L"\"";
- errorstream<<wide_to_narrow(error_message)<<std::endl;
- continue;
- }
- if(commanded_gamespec.isValid() &&
- commanded_gamespec.id != worldspec.gameid){
- errorstream<<"WARNING: Overriding gamespec from \""
- <<worldspec.gameid<<"\" to \""
- <<commanded_gamespec.id<<"\""<<std::endl;
- gamespec = commanded_gamespec;
- }
-
- if(!gamespec.isValid()){
- error_message = wgettext("Invalid gamespec.");
- error_message += L" (world_gameid="
- +narrow_to_wide(worldspec.gameid)+L")";
- errorstream<<wide_to_narrow(error_message)<<std::endl;
- continue;
- }
- }
-
- // Continue to game
- break;
- }