X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmain.cpp;h=9d336825ec3a25b69b59b3d11b9a7be92cf43bf3;hb=fb2183b61da9298e78b483da5a6ad79779eac64b;hp=ddd55d1a42622e72de6b8aebd68fdc13434df84d;hpb=5b1bd2fb4760e7d6f4a47e59839aa1b52c6c0f7a;p=dragonfireclient.git diff --git a/src/main.cpp b/src/main.cpp index ddd55d1a4..9d336825e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,15 +79,20 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "httpfetch.h" #include "guiEngine.h" #include "mapsector.h" +#include "player.h" #include "database-sqlite3.h" #ifdef USE_LEVELDB #include "database-leveldb.h" #endif + #if USE_REDIS #include "database-redis.h" #endif +#ifdef HAVE_TOUCHSCREENGUI +#include "touchscreengui.h" +#endif /* Settings. These are loaded from the config file. @@ -176,7 +181,7 @@ class IrrlichtTimeGetter: public TimeGetter u32 getTime(TimePrecision prec) { if (prec == PRECISION_MILLI) { - if(m_device == NULL) + if (m_device == NULL) return 0; return m_device->getTimer()->getRealTime(); } else { @@ -202,7 +207,7 @@ TimeGetter *g_timegetter = NULL; u32 getTimeMs() { - if(g_timegetter == NULL) + if (g_timegetter == NULL) return 0; return g_timegetter->getTime(PRECISION_MILLI); } @@ -220,7 +225,7 @@ class StderrLogOutput: public ILogOutput /* line: Full line with timestamp, level and thread */ void printLog(const std::string &line) { - std::cerr<Toggle(false); + } +#endif return g_menumgr.preprocessEvent(event); } // Remember whether each key is down or up - if(event.EventType == irr::EET_KEY_INPUT_EVENT) - { - if(event.KeyInput.PressedDown) { + if (event.EventType == irr::EET_KEY_INPUT_EVENT) { + if (event.KeyInput.PressedDown) { keyIsDown.set(event.KeyInput); keyWasDown.set(event.KeyInput); } else { @@ -268,42 +276,46 @@ class MyEventReceiver : public IEventReceiver } } - if(event.EventType == irr::EET_MOUSE_INPUT_EVENT) - { - if(noMenuActive() == false) - { +#ifdef HAVE_TOUCHSCREENGUI + // case of touchscreengui we have to handle different events + if ((m_touchscreengui != 0) && + (event.EventType == irr::EET_TOUCH_INPUT_EVENT)) { + m_touchscreengui->translateEvent(event); + return true; + } +#endif + // handle mouse events + if(event.EventType == irr::EET_MOUSE_INPUT_EVENT) { + if (noMenuActive() == false) { left_active = false; middle_active = false; right_active = false; - } - else - { + } else { left_active = event.MouseInput.isLeftPressed(); middle_active = event.MouseInput.isMiddlePressed(); right_active = event.MouseInput.isRightPressed(); - if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) - { + if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) { leftclicked = true; } - if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN) - { + if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN) { rightclicked = true; } - if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) - { + if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) { leftreleased = true; } - if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP) - { + if (event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP) { rightreleased = true; } - if(event.MouseInput.Event == EMIE_MOUSE_WHEEL) - { + if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) { mouse_wheel += event.MouseInput.Wheel; } } } + if(event.EventType == irr::EET_LOG_TEXT_EVENT) { + dstream<< std::string("Irrlicht log: ") + std::string(event.LogEvent.Text)<getCursorControl()->getPosition(); + if (m_device->getCursorControl()) { + return m_device->getCursorControl()->getPosition(); + } + else { + return m_mousepos; + } } virtual void setMousePos(s32 x, s32 y) { - m_device->getCursorControl()->setPosition(x, y); + if (m_device->getCursorControl()) { + m_device->getCursorControl()->setPosition(x, y); + } + else { + m_mousepos = v2s32(x,y); + } } virtual bool getLeftState() @@ -452,8 +481,9 @@ class RealInputHandler : public InputHandler m_receiver->clearInput(); } private: - IrrlichtDevice *m_device; + IrrlichtDevice *m_device; MyEventReceiver *m_receiver; + v2s32 m_mousepos; }; class RandomInputHandler : public InputHandler @@ -483,7 +513,7 @@ class RandomInputHandler : public InputHandler } virtual void setMousePos(s32 x, s32 y) { - mousepos = v2s32(x,y); + mousepos = v2s32(x, y); } virtual bool getLeftState() @@ -539,71 +569,64 @@ class RandomInputHandler : public InputHandler { static float counter1 = 0; counter1 -= dtime; - if(counter1 < 0.0) - { - counter1 = 0.1*Rand(1, 40); + if (counter1 < 0.0) { + counter1 = 0.1 * Rand(1, 40); keydown.toggle(getKeySetting("keymap_jump")); } } { static float counter1 = 0; counter1 -= dtime; - if(counter1 < 0.0) - { - counter1 = 0.1*Rand(1, 40); + if (counter1 < 0.0) { + counter1 = 0.1 * Rand(1, 40); keydown.toggle(getKeySetting("keymap_special1")); } } { static float counter1 = 0; counter1 -= dtime; - if(counter1 < 0.0) - { - counter1 = 0.1*Rand(1, 40); + if (counter1 < 0.0) { + counter1 = 0.1 * Rand(1, 40); keydown.toggle(getKeySetting("keymap_forward")); } } { static float counter1 = 0; counter1 -= dtime; - if(counter1 < 0.0) - { - counter1 = 0.1*Rand(1, 40); + if (counter1 < 0.0) { + counter1 = 0.1 * Rand(1, 40); keydown.toggle(getKeySetting("keymap_left")); } } { static float counter1 = 0; counter1 -= dtime; - if(counter1 < 0.0) - { - counter1 = 0.1*Rand(1, 20); - mousespeed = v2s32(Rand(-20,20), Rand(-15,20)); + if (counter1 < 0.0) { + counter1 = 0.1 * Rand(1, 20); + mousespeed = v2s32(Rand(-20, 20), Rand(-15, 20)); } } { static float counter1 = 0; counter1 -= dtime; - if(counter1 < 0.0) - { - counter1 = 0.1*Rand(1, 30); + if (counter1 < 0.0) { + counter1 = 0.1 * Rand(1, 30); leftdown = !leftdown; - if(leftdown) + if (leftdown) leftclicked = true; - if(!leftdown) + if (!leftdown) leftreleased = true; } } { static float counter1 = 0; counter1 -= dtime; - if(counter1 < 0.0) - { - counter1 = 0.1*Rand(1, 15); + if (counter1 < 0.0) { + counter1 = 0.1 * Rand(1, 15); rightdown = !rightdown; - if(rightdown) + if (rightdown) rightclicked = true; - if(!rightdown) + if (!rightdown) rightreleased = true; } } @@ -640,32 +663,31 @@ std::string tempstring2; void SpeedTests() { { - infostream<<"The following test should take around 20ms."< map1; tempf = -324; - const s16 ii=300; - for(s16 y=0; y=0; y--){ - for(s16 x=0; x= 0; y--) { + for(s16 x = 0; x < ii; x++) { + tempf = map1[v2s16(x, y)]; } } } { - infostream<<"Around 5000/ms should do well here."< &worldspecs, - std::ostream &os) +static void print_worldspecs(const std::vector &worldspecs, std::ostream &os) { - for(u32 i=0; i::iterator i = allowed_options.begin(); - i != allowed_options.end(); ++i) - { + i != allowed_options.end(); ++i) { std::ostringstream os1(std::ios::binary); - os1<<" --"<first; - if(i->second.type == VALUETYPE_FLAG) - {} - else - os1<<_(" "); - dstream<second.help != NULL) - dstream<second.help; - dstream<first; + if (i->second.type == VALUETYPE_FLAG) { + } else + os1 << _(" "); + dstream << padStringRight(os1.str(), 24); + + if (i->second.help != NULL) + dstream << i->second.help; + dstream << std::endl; } return cmd_args.getFlag("help") ? 0 : 1; } - if(cmd_args.getFlag("version")) - { + if (cmd_args.getFlag("version")) { #ifdef SERVER - dstream<<"minetestserver "< gameids = getAvailableGameIds(); for(std::set::const_iterator i = gameids.begin(); i != gameids.end(); i++) @@ -893,18 +925,16 @@ int main(int argc, char *argv[]) } // List worlds if requested - if(cmd_args.exists("world") && cmd_args.get("world") == "list"){ - dstream<<_("Available worlds:")< worldspecs = getAvailableWorlds(); print_worldspecs(worldspecs, dstream); return 0; } // Print startup message - infostream<readConfigFile(cmd_args.get("config").c_str()); - if(r == false) - { - errorstream<<"Could not read configuration from \"" - < filenames; filenames.push_back(porting::path_user + DIR_DELIM + "minetest.conf"); @@ -950,18 +976,16 @@ int main(int argc, char *argv[]) DIR_DELIM + ".." + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf"); #endif - for(u32 i=0; ireadConfigFile(filenames[i].c_str()); - if(r) - { + if (r) { g_settings_path = filenames[i]; break; } } // If no path found, use the first one (menu creates the file) - if(g_settings_path == "") + if (g_settings_path == "") g_settings_path = filenames[0]; } @@ -972,7 +996,7 @@ int main(int argc, char *argv[]) #else std::string logfile = porting::path_user+DIR_DELIM+DEBUGFILE; #endif - if(cmd_args.exists("logfile")) + if (cmd_args.exists("logfile")) logfile = cmd_args.get("logfile"); log_remove_output(&main_dstream_no_stderr_log_out); @@ -981,14 +1005,15 @@ int main(int argc, char *argv[]) if (loglevel == 0) //no logging logfile = ""; else if (loglevel > 0 && loglevel <= LMT_NUM_VALUES) - log_add_output_maxlev(&main_dstream_no_stderr_log_out, (LogMessageLevel)(loglevel - 1)); + log_add_output_maxlev(&main_dstream_no_stderr_log_out, + (LogMessageLevel)(loglevel - 1)); - if(logfile != "") + if (logfile != "") debugstreams_init(false, logfile.c_str()); else debugstreams_init(false, NULL); - infostream<<"logfile = "<get("language"),argc,argv); + init_gettext((porting::path_share + DIR_DELIM + "locale").c_str(), + g_settings->get("language"), argc, argv); #else - init_gettext((porting::path_share + DIR_DELIM + "locale").c_str(),g_settings->get("language")); + init_gettext((porting::path_share + DIR_DELIM + "locale").c_str(), + g_settings->get("language")); #endif /* @@ -1018,61 +1045,61 @@ int main(int argc, char *argv[]) // Port u16 port = 30000; - if(cmd_args.exists("port")) + if (cmd_args.exists("port")) port = cmd_args.getU16("port"); - else if(g_settings->exists("port")) + else if (g_settings->exists("port")) port = g_settings->getU16("port"); - if(port == 0) + if (port == 0) port = 30000; // World directory std::string commanded_world = ""; - if(cmd_args.exists("world")) + if (cmd_args.exists("world")) commanded_world = cmd_args.get("world"); - else if(cmd_args.exists("map-dir")) + else if (cmd_args.exists("map-dir")) commanded_world = cmd_args.get("map-dir"); - else if(cmd_args.exists("nonopt0")) // First nameless argument + else if (cmd_args.exists("nonopt0")) // First nameless argument commanded_world = cmd_args.get("nonopt0"); - else if(g_settings->exists("map-dir")) + else if (g_settings->exists("map-dir")) commanded_world = g_settings->get("map-dir"); // World name std::string commanded_worldname = ""; - if(cmd_args.exists("worldname")) + if (cmd_args.exists("worldname")) commanded_worldname = cmd_args.get("worldname"); // Strip world.mt from commanded_world { std::string worldmt = "world.mt"; - if(commanded_world.size() > worldmt.size() && - commanded_world.substr(commanded_world.size()-worldmt.size()) - == worldmt){ - dstream<<_("Supplied world.mt file - stripping it off.")< worldmt.size() && + commanded_world.substr(commanded_world.size() - worldmt.size()) + == worldmt) { + dstream << _("Supplied world.mt file - stripping it off.") << std::endl; + commanded_world = commanded_world.substr(0, + commanded_world.size() - worldmt.size()); } } // If a world name was specified, convert it to a path - if(commanded_worldname != ""){ + if (commanded_worldname != "") { // Get information about available worlds std::vector worldspecs = getAvailableWorlds(); bool found = false; - for(u32 i=0; iset("server_dedicated", run_dedicated_server ? "true" : "false"); - if(run_dedicated_server) + if (run_dedicated_server) { DSTACK("Dedicated server branch"); // Create time getter if built with Irrlicht @@ -1109,46 +1136,43 @@ int main(int argc, char *argv[]) // World directory std::string world_path; - verbosestream<<_("Determining world path")< worldspecs = getAvailableWorlds(); // If a world name was specified, select it - if(commanded_worldname != ""){ + if (commanded_worldname != "") { world_path = ""; - for(u32 i=0; i 1){ - dstream<<_("Multiple worlds are available.")<" - " or --world ")< 1) { + dstream << _("Multiple worlds are available.") << std::endl; + dstream << _("Please select one using --worldname " + " or --world ") << std::endl; print_worldspecs(worldspecs, dstream); return 1; // If there are no worlds, automatically create a new one @@ -1156,63 +1180,57 @@ int main(int argc, char *argv[]) // This is the ultimate default world path world_path = porting::path_user + DIR_DELIM + "worlds" + DIR_DELIM + "world"; - infostream<<"Creating default world at [" - <get("default_game")); - infostream<<"Using default gameid ["<get("bind_address"); - Address bind_addr(0,0,0,0, port); + Address bind_addr(0, 0, 0, 0, port); if (g_settings->getBool("ipv6_server")) { bind_addr.setAddress((IPv6AddressBytes*) NULL); @@ -1224,7 +1242,7 @@ int main(int argc, char *argv[]) << "\" failed: " << e.what() << " -- Listening on all addresses." << std::endl; } - if(bind_addr.isIPv6() && !g_settings->getBool("enable_ipv6")) { + if (bind_addr.isIPv6() && !g_settings->getBool("enable_ipv6")) { errorstream << "Unable to listen on " << bind_addr.serializeString() << L" because IPv6 is disabled" << std::endl; @@ -1238,7 +1256,8 @@ int main(int argc, char *argv[]) if (cmd_args.exists("migrate")) { std::string migrate_to = cmd_args.get("migrate"); Settings world_mt; - bool success = world_mt.readConfigFile((world_path + DIR_DELIM + "world.mt").c_str()); + bool success = world_mt.readConfigFile((world_path + DIR_DELIM + + "world.mt").c_str()); if (!success) { errorstream << "Cannot read world.mt" << std::endl; return 1; @@ -1251,7 +1270,8 @@ int main(int argc, char *argv[]) std::string backend = world_mt.get("backend"); Database *new_db; if (backend == migrate_to) { - errorstream << "Cannot migrate: new backend is same as the old one" << std::endl; + errorstream << "Cannot migrate: new backend is same" + <<" as the old one" << std::endl; return 1; } if (migrate_to == "sqlite3") @@ -1265,7 +1285,8 @@ int main(int argc, char *argv[]) new_db = new Database_Redis(&(ServerMap&)server.getMap(), world_path); #endif else { - errorstream << "Migration to " << migrate_to << " is not supported" << std::endl; + errorstream << "Migration to " << migrate_to + << " is not supported" << std::endl; return 1; } @@ -1274,11 +1295,15 @@ int main(int argc, char *argv[]) old_map.listAllLoadableBlocks(blocks); int count = 0; new_db->beginSave(); - for (std::list::iterator i = blocks.begin(); i != blocks.end(); ++i) { + for (std::list::iterator i = blocks.begin(); i != blocks.end(); i++) { MapBlock *block = old_map.loadBlock(*i); - new_db->saveBlock(block); - MapSector *sector = old_map.getSectorNoGenerate(v2s16(i->X, i->Z)); - sector->deleteBlock(block); + if (!block) { + errorstream << "Failed to load block " << PP(*i) << ", skipping it."; + } else { + old_map.saveBlock(block, new_db); + MapSector *sector = old_map.getSectorNoGenerate(v2s16(i->X, i->Z)); + sector->deleteBlock(block); + } ++count; if (count % 500 == 0) actionstream << "Migrated " << count << " blocks " @@ -1289,10 +1314,10 @@ int main(int argc, char *argv[]) actionstream << "Successfully migrated " << count << " blocks" << std::endl; world_mt.set("backend", migrate_to); - if(!world_mt.updateConfigFile((world_path + DIR_DELIM + "world.mt").c_str())) - errorstream<<"Failed to update world.mt!"<get("address"); - if(commanded_world != "") + if (commanded_world != "") address = ""; - else if(cmd_args.exists("address")) + else if (cmd_args.exists("address")) address = cmd_args.get("address"); std::string playername = g_settings->get("name"); - if(cmd_args.exists("name")) + if (cmd_args.exists("name")) playername = cmd_args.get("name"); bool skip_main_menu = cmd_args.getFlag("go"); @@ -1340,45 +1365,46 @@ int main(int argc, char *argv[]) u16 fsaa = g_settings->getU16("fsaa"); // Determine driver - - video::E_DRIVER_TYPE driverType; - - std::string driverstring = g_settings->get("video_driver"); - - if(driverstring == "null") - driverType = video::EDT_NULL; - else if(driverstring == "software") - driverType = video::EDT_SOFTWARE; - else if(driverstring == "burningsvideo") - driverType = video::EDT_BURNINGSVIDEO; - else if(driverstring == "direct3d8") - driverType = video::EDT_DIRECT3D8; - else if(driverstring == "direct3d9") - driverType = video::EDT_DIRECT3D9; - else if(driverstring == "opengl") - driverType = video::EDT_OPENGL; + video::E_DRIVER_TYPE driverType = video::EDT_OPENGL; + static const char* driverids[] = { + "null", + "software", + "burningsvideo", + "direct3d8", + "direct3d9", + "opengl" #ifdef _IRR_COMPILE_WITH_OGLES1_ - else if(driverstring == "ogles1") - driverType = video::EDT_OGLES1; + ,"ogles1" #endif #ifdef _IRR_COMPILE_WITH_OGLES2_ - else if(driverstring == "ogles2") - driverType = video::EDT_OGLES2; + ,"ogles2" #endif - else + ,"invalid" + }; + + std::string driverstring = g_settings->get("video_driver"); + for (unsigned int i = 0; + i < (sizeof(driverids)/sizeof(driverids[0])); + i++) { - errorstream<<"WARNING: Invalid video_driver specified; defaulting " - "to opengl"<getBool("high_precision_fpu"); nulldevice = createDeviceEx(params); - if(nulldevice == 0) + if (nulldevice == 0) return 1; - dstream<<_("Available video modes (WxHxD):")<getVideoModeList(); - if(videomode_list == 0){ + if (videomode_list == 0) { nulldevice->drop(); return 1; } @@ -1410,30 +1436,28 @@ int main(int argc, char *argv[]) s32 videomode_count = videomode_list->getVideoModeCount(); core::dimension2d videomode_res; s32 videomode_depth; - for (s32 i = 0; i < videomode_count; ++i){ + for (s32 i = 0; i < videomode_count; ++i) { videomode_res = videomode_list->getVideoModeResolution(i); videomode_depth = videomode_list->getVideoModeDepth(i); - dstream<getDesktopResolution(); videomode_depth = videomode_list->getDesktopDepth(); - dstream<drop(); + delete receiver; return 0; } /* Create device and exit if creation failed */ - - IrrlichtDevice *device; - SIrrlichtCreationParameters params = SIrrlichtCreationParameters(); params.DriverType = driverType; params.WindowSize = core::dimension2d(screenW, screenH); @@ -1442,13 +1466,39 @@ int main(int argc, char *argv[]) params.Fullscreen = fullscreen; params.Stencilbuffer = false; params.Vsync = vsync; - params.EventReceiver = &receiver; + params.EventReceiver = receiver; params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu"); +#ifdef __ANDROID__ + params.PrivateData = porting::app_global; + params.OGLES2ShaderPath = std::string(porting::path_user + DIR_DELIM + + "media" + DIR_DELIM + "Shaders" + DIR_DELIM).c_str(); +#endif - device = createDeviceEx(params); + IrrlichtDevice * device = createDeviceEx(params); - if (device == 0) + if (device == 0) { + delete receiver; return 1; // could not create selected driver. + } + + // Map our log level to irrlicht engine one. + static const irr::ELOG_LEVEL irr_log_level[5] = { + ELL_NONE, + ELL_ERROR, + ELL_WARNING, + ELL_INFORMATION, +#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8) + ELL_INFORMATION +#else + ELL_DEBUG +#endif + }; + + ILogger* irr_logger = device->getLogger(); + irr_logger->setLogLevel(irr_log_level[loglevel]); + + porting::initIrrlicht(device); + late_init_default_settings(g_settings); /* Continue initialization @@ -1471,9 +1521,9 @@ int main(int argc, char *argv[]) /* Speed tests (done after irrlicht is loaded to get timer) */ - if(cmd_args.getFlag("speedtests")) + if (cmd_args.getFlag("speedtests")) { - dstream<<"Running speed tests"<drop(); return 0; @@ -1484,10 +1534,11 @@ int main(int argc, char *argv[]) bool random_input = g_settings->getBool("random_input") || cmd_args.getFlag("random-input"); InputHandler *input = NULL; - if(random_input) { + + if (random_input) { input = new RandomInputHandler(); } else { - input = new RealInputHandler(device, &receiver); + input = new RealInputHandler(device,receiver); } scene::ISceneManager* smgr = device->getSceneManager(); @@ -1506,38 +1557,36 @@ int main(int argc, char *argv[]) font_path = g_settings->get(fallback + "font_path"); u32 font_shadow = g_settings->getU16(fallback + "font_shadow"); u32 font_shadow_alpha = g_settings->getU16(fallback + "font_shadow_alpha"); - font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size, true, true, font_shadow, font_shadow_alpha); + font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size, + true, true, font_shadow, font_shadow_alpha); } else { font = guienv->getFont(font_path.c_str()); } #else font = guienv->getFont(font_path.c_str()); #endif - if(font) + if (font) skin->setFont(font); else - errorstream<<"WARNING: Font file was not found." - " Using default font."<getFont(); assert(font); u32 text_height = font->getDimension(L"Hello, world!").Height; - infostream<<"text_height="<setWindowCaption((std::wstring(L"Minetest [")+text+L"]").c_str()); + device->setWindowCaption((std::wstring(L"Minetest [") + text + L"]").c_str()); delete[] text; // This is used for catching disconnects @@ -1596,7 +1646,7 @@ int main(int argc, char *argv[]) Otherwise they won't be automatically drawn. */ guiroot = guienv->addStaticText(L"", - core::rect(0, 0, 10000, 10000)); + core::rect(0, 0, 10000, 10000)); SubgameSpec gamespec; WorldSpec worldspec; @@ -1613,17 +1663,18 @@ int main(int argc, char *argv[]) Loop quits when menu returns proper parameters. */ - while(kill == false) - { + while (kill == false) { // If skip_main_menu, only go through here once - if(skip_main_menu && !first_loop){ + if (skip_main_menu && !first_loop) { kill = true; break; } first_loop = false; // Cursor can be non-visible when coming from the game + #ifndef ANDROID device->getCursorControl()->setVisible(true); + #endif // Some stuff are left to scene manager when coming from the game // (map at least?) smgr->clear(); @@ -1635,7 +1686,7 @@ int main(int argc, char *argv[]) menudata.port = itos(port); menudata.errormessage = wide_to_narrow(error_message); error_message = L""; - if(cmd_args.exists("password")) + if (cmd_args.exists("password")) menudata.password = cmd_args.get("password"); driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map")); @@ -1645,44 +1696,41 @@ int main(int argc, char *argv[]) std::vector 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]"; + if(commanded_world != "") { + worldspec.gameid = getWorldGameId(commanded_world, true); + worldspec.name = _("[--world parameter]"); + if(worldspec.gameid == "") { + worldspec.gameid = g_settings->get("default_game"); + worldspec.name += " [new]"; } - //TODO find within worldspecs and set config + worldspec.path = commanded_world; } - if(skip_main_menu == false) - { + if (skip_main_menu == false) { video::IVideoDriver* driver = device->getVideoDriver(); - infostream<<"Waiting for other menus"<run() && kill == false) - { - if(noMenuActive()) + 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)); + 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"<clear(); } - if(menudata.errormessage != ""){ + if (menudata.errormessage != "") { error_message = narrow_to_wide(menudata.errormessage); continue; } @@ -1700,7 +1748,7 @@ int main(int argc, char *argv[]) address = menudata.address; int newport = stoi(menudata.port); - if(newport != 0) + if (newport != 0) port = newport; simple_singleplayer_mode = menudata.simple_singleplayer_mode; @@ -1708,13 +1756,8 @@ int main(int argc, char *argv[]) // Save settings g_settings->set("name", playername); - if((menudata.selected_world >= 0) && - (menudata.selected_world < (int)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) + if (device->run() == false || kill == true) break; current_playername = playername; @@ -1723,14 +1766,12 @@ int main(int argc, char *argv[]) current_port = port; // If using simple singleplayer mode, override - if(simple_singleplayer_mode){ + if (simple_singleplayer_mode) { current_playername = "singleplayer"; current_password = ""; current_address = ""; current_port = myrand_range(49152, 65535); - } - else if (address != "") - { + } else if (address != "") { ServerListSpec server; server["name"] = menudata.servername; server["address"] = menudata.address; @@ -1739,44 +1780,56 @@ int main(int argc, char *argv[]) ServerList::insert(server); } - // Set world path to selected one - if ((menudata.selected_world >= 0) && - (menudata.selected_world < (int)worldspecs.size())) { + if ((!skip_main_menu) && + (menudata.selected_world >= 0) && + (menudata.selected_world < (int)worldspecs.size())) { + g_settings->set("selected_world_path", + worldspecs[menudata.selected_world].path); worldspec = worldspecs[menudata.selected_world]; - infostream<<"Selected world: "<run() == false || kill == true) { - if(g_settings_path != "") { - g_settings->updateConfigFile( - g_settings_path.c_str()); + if (device->run() == false || kill == true) { + if (g_settings_path != "") { + g_settings->updateConfigFile(g_settings_path.c_str()); } break; } + if (current_playername.length() > PLAYERNAME_SIZE-1) { + error_message = wgettext("Player name too long."); + playername = current_playername.substr(0,PLAYERNAME_SIZE-1); + g_settings->set("name", playername); + continue; + } + /* Run game */ +#ifdef HAVE_TOUCHSCREENGUI + receiver->m_touchscreengui = new TouchScreenGUI(device, receiver); + g_touchscreengui = receiver->m_touchscreengui; +#endif the_game( kill, random_input, @@ -1814,12 +1877,17 @@ int main(int argc, char *argv[]) simple_singleplayer_mode ); smgr->clear(); +#ifdef HAVE_TOUCHSCREENGUI + delete g_touchscreengui; + g_touchscreengui = NULL; + receiver->m_touchscreengui = NULL; +#endif } //try catch(con::PeerNotFoundException &e) { error_message = wgettext("Connection error (timed out?)"); - errorstream<updateConfigFile(g_settings_path.c_str()); // Print modified quicktune values { bool header_printed = false; std::vector names = getQuicktuneNames(); - for(u32 i=0; i