clientlauncher.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "mainmenumanager.h"
  17. #include "debug.h"
  18. #include "clouds.h"
  19. #include "server.h"
  20. #include "filesys.h"
  21. #include "guiMainMenu.h"
  22. #include "game.h"
  23. #include "chat.h"
  24. #include "gettext.h"
  25. #include "profiler.h"
  26. #include "log.h"
  27. #include "serverlist.h"
  28. #include "guiEngine.h"
  29. #include "player.h"
  30. #include "fontengine.h"
  31. #include "joystick_controller.h"
  32. #include "clientlauncher.h"
  33. #include "version.h"
  34. /* mainmenumanager.h
  35. */
  36. gui::IGUIEnvironment *guienv = NULL;
  37. gui::IGUIStaticText *guiroot = NULL;
  38. MainMenuManager g_menumgr;
  39. bool noMenuActive()
  40. {
  41. return g_menumgr.menuCount() == 0;
  42. }
  43. // Passed to menus to allow disconnecting and exiting
  44. MainGameCallback *g_gamecallback = NULL;
  45. // Instance of the time getter
  46. static TimeGetter *g_timegetter = NULL;
  47. u32 getTimeMs()
  48. {
  49. if (g_timegetter == NULL)
  50. return 0;
  51. return g_timegetter->getTime(PRECISION_MILLI);
  52. }
  53. u32 getTime(TimePrecision prec) {
  54. if (g_timegetter == NULL)
  55. return 0;
  56. return g_timegetter->getTime(prec);
  57. }
  58. ClientLauncher::~ClientLauncher()
  59. {
  60. if (receiver)
  61. delete receiver;
  62. if (input)
  63. delete input;
  64. if (g_fontengine)
  65. delete g_fontengine;
  66. if (device)
  67. device->drop();
  68. }
  69. bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
  70. {
  71. init_args(game_params, cmd_args);
  72. // List video modes if requested
  73. if (list_video_modes)
  74. return print_video_modes();
  75. if (!init_engine()) {
  76. errorstream << "Could not initialize game engine." << std::endl;
  77. return false;
  78. }
  79. // Create time getter
  80. g_timegetter = new IrrlichtTimeGetter(device);
  81. // Speed tests (done after irrlicht is loaded to get timer)
  82. if (cmd_args.getFlag("speedtests")) {
  83. dstream << "Running speed tests" << std::endl;
  84. speed_tests();
  85. return true;
  86. }
  87. video::IVideoDriver *video_driver = device->getVideoDriver();
  88. if (video_driver == NULL) {
  89. errorstream << "Could not initialize video driver." << std::endl;
  90. return false;
  91. }
  92. porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C);
  93. porting::setXorgWindowIcon(device,
  94. porting::path_share + "/misc/minetest-xorg-icon-128.png");
  95. /*
  96. This changes the minimum allowed number of vertices in a VBO.
  97. Default is 500.
  98. */
  99. //driver->setMinHardwareBufferVertexCount(50);
  100. // Create game callback for menus
  101. g_gamecallback = new MainGameCallback(device);
  102. device->setResizable(true);
  103. if (random_input)
  104. input = new RandomInputHandler();
  105. else
  106. input = new RealInputHandler(device, receiver);
  107. smgr = device->getSceneManager();
  108. smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
  109. guienv = device->getGUIEnvironment();
  110. skin = guienv->getSkin();
  111. skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255));
  112. skin->setColor(gui::EGDC_3D_LIGHT, video::SColor(0, 0, 0, 0));
  113. skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 30, 30, 30));
  114. skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255, 0, 0, 0));
  115. skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 120, 50));
  116. skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255));
  117. g_fontengine = new FontEngine(g_settings, guienv);
  118. FATAL_ERROR_IF(g_fontengine == NULL, "Font engine creation failed.");
  119. #if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
  120. // Irrlicht 1.8 input colours
  121. skin->setColor(gui::EGDC_EDITABLE, video::SColor(255, 128, 128, 128));
  122. skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 96, 134, 49));
  123. #endif
  124. // Create the menu clouds
  125. if (!g_menucloudsmgr)
  126. g_menucloudsmgr = smgr->createNewSceneManager();
  127. if (!g_menuclouds)
  128. g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(),
  129. g_menucloudsmgr, -1, rand(), 100);
  130. g_menuclouds->update(v2f(0, 0), video::SColor(255, 200, 200, 255));
  131. scene::ICameraSceneNode* camera;
  132. camera = g_menucloudsmgr->addCameraSceneNode(0,
  133. v3f(0, 0, 0), v3f(0, 60, 100));
  134. camera->setFarValue(10000);
  135. /*
  136. GUI stuff
  137. */
  138. ChatBackend chat_backend;
  139. // If an error occurs, this is set to something by menu().
  140. // It is then displayed before the menu shows on the next call to menu()
  141. std::string error_message;
  142. bool reconnect_requested = false;
  143. bool first_loop = true;
  144. /*
  145. Menu-game loop
  146. */
  147. bool retval = true;
  148. bool *kill = porting::signal_handler_killstatus();
  149. while (device->run() && !*kill && !g_gamecallback->shutdown_requested)
  150. {
  151. // Set the window caption
  152. const wchar_t *text = wgettext("Main Menu");
  153. device->setWindowCaption((utf8_to_wide(PROJECT_NAME_C) +
  154. L" " + utf8_to_wide(g_version_hash) +
  155. L" [" + text + L"]").c_str());
  156. delete[] text;
  157. try { // This is used for catching disconnects
  158. guienv->clear();
  159. /*
  160. We need some kind of a root node to be able to add
  161. custom gui elements directly on the screen.
  162. Otherwise they won't be automatically drawn.
  163. */
  164. guiroot = guienv->addStaticText(L"", core::rect<s32>(0, 0, 10000, 10000));
  165. bool game_has_run = launch_game(error_message, reconnect_requested,
  166. game_params, cmd_args);
  167. // Reset the reconnect_requested flag
  168. reconnect_requested = false;
  169. // If skip_main_menu, we only want to startup once
  170. if (skip_main_menu && !first_loop)
  171. break;
  172. first_loop = false;
  173. if (!game_has_run) {
  174. if (skip_main_menu)
  175. break;
  176. else
  177. continue;
  178. }
  179. // Break out of menu-game loop to shut down cleanly
  180. if (!device->run() || *kill) {
  181. if (g_settings_path != "")
  182. g_settings->updateConfigFile(g_settings_path.c_str());
  183. break;
  184. }
  185. if (current_playername.length() > PLAYERNAME_SIZE-1) {
  186. error_message = gettext("Player name too long.");
  187. playername = current_playername.substr(0, PLAYERNAME_SIZE-1);
  188. g_settings->set("name", playername);
  189. continue;
  190. }
  191. device->getVideoDriver()->setTextureCreationFlag(
  192. video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));
  193. #ifdef HAVE_TOUCHSCREENGUI
  194. receiver->m_touchscreengui = new TouchScreenGUI(device, receiver);
  195. g_touchscreengui = receiver->m_touchscreengui;
  196. #endif
  197. the_game(
  198. kill,
  199. random_input,
  200. input,
  201. device,
  202. worldspec.path,
  203. current_playername,
  204. current_password,
  205. current_address,
  206. current_port,
  207. error_message,
  208. chat_backend,
  209. &reconnect_requested,
  210. gamespec,
  211. simple_singleplayer_mode
  212. );
  213. smgr->clear();
  214. #ifdef HAVE_TOUCHSCREENGUI
  215. delete g_touchscreengui;
  216. g_touchscreengui = NULL;
  217. receiver->m_touchscreengui = NULL;
  218. #endif
  219. } //try
  220. catch (con::PeerNotFoundException &e) {
  221. error_message = gettext("Connection error (timed out?)");
  222. errorstream << error_message << std::endl;
  223. }
  224. #ifdef NDEBUG
  225. catch (std::exception &e) {
  226. std::string error_message = "Some exception: \"";
  227. error_message += e.what();
  228. error_message += "\"";
  229. errorstream << error_message << std::endl;
  230. }
  231. #endif
  232. // If no main menu, show error and exit
  233. if (skip_main_menu) {
  234. if (!error_message.empty()) {
  235. verbosestream << "error_message = "
  236. << error_message << std::endl;
  237. retval = false;
  238. }
  239. break;
  240. }
  241. } // Menu-game loop
  242. g_menuclouds->drop();
  243. g_menucloudsmgr->drop();
  244. return retval;
  245. }
  246. void ClientLauncher::init_args(GameParams &game_params, const Settings &cmd_args)
  247. {
  248. skip_main_menu = cmd_args.getFlag("go");
  249. // FIXME: This is confusing (but correct)
  250. /* If world_path is set then override it unless skipping the main menu using
  251. * the --go command line param. Else, give preference to the address
  252. * supplied on the command line
  253. */
  254. address = g_settings->get("address");
  255. if (game_params.world_path != "" && !skip_main_menu)
  256. address = "";
  257. else if (cmd_args.exists("address"))
  258. address = cmd_args.get("address");
  259. playername = g_settings->get("name");
  260. if (cmd_args.exists("name"))
  261. playername = cmd_args.get("name");
  262. list_video_modes = cmd_args.getFlag("videomodes");
  263. use_freetype = g_settings->getBool("freetype");
  264. random_input = g_settings->getBool("random_input")
  265. || cmd_args.getFlag("random-input");
  266. }
  267. bool ClientLauncher::init_engine()
  268. {
  269. receiver = new MyEventReceiver();
  270. create_engine_device();
  271. return device != NULL;
  272. }
  273. bool ClientLauncher::launch_game(std::string &error_message,
  274. bool reconnect_requested, GameParams &game_params,
  275. const Settings &cmd_args)
  276. {
  277. // Initialize menu data
  278. MainMenuData menudata;
  279. menudata.address = address;
  280. menudata.name = playername;
  281. menudata.password = password;
  282. menudata.port = itos(game_params.socket_port);
  283. menudata.script_data.errormessage = error_message;
  284. menudata.script_data.reconnect_requested = reconnect_requested;
  285. error_message.clear();
  286. if (cmd_args.exists("password"))
  287. menudata.password = cmd_args.get("password");
  288. menudata.enable_public = g_settings->getBool("server_announce");
  289. // If a world was commanded, append and select it
  290. if (game_params.world_path != "") {
  291. worldspec.gameid = getWorldGameId(game_params.world_path, true);
  292. worldspec.name = _("[--world parameter]");
  293. if (worldspec.gameid == "") { // Create new
  294. worldspec.gameid = g_settings->get("default_game");
  295. worldspec.name += " [new]";
  296. }
  297. worldspec.path = game_params.world_path;
  298. }
  299. /* Show the GUI menu
  300. */
  301. if (!skip_main_menu) {
  302. main_menu(&menudata);
  303. // Skip further loading if there was an exit signal.
  304. if (*porting::signal_handler_killstatus())
  305. return false;
  306. address = menudata.address;
  307. int newport = stoi(menudata.port);
  308. if (newport != 0)
  309. game_params.socket_port = newport;
  310. simple_singleplayer_mode = menudata.simple_singleplayer_mode;
  311. std::vector<WorldSpec> worldspecs = getAvailableWorlds();
  312. if (menudata.selected_world >= 0
  313. && menudata.selected_world < (int)worldspecs.size()) {
  314. g_settings->set("selected_world_path",
  315. worldspecs[menudata.selected_world].path);
  316. worldspec = worldspecs[menudata.selected_world];
  317. }
  318. }
  319. if (!menudata.script_data.errormessage.empty()) {
  320. /* The calling function will pass this back into this function upon the
  321. * next iteration (if any) causing it to be displayed by the GUI
  322. */
  323. error_message = menudata.script_data.errormessage;
  324. return false;
  325. }
  326. if (menudata.name == "")
  327. menudata.name = std::string("Guest") + itos(myrand_range(1000, 9999));
  328. else
  329. playername = menudata.name;
  330. password = menudata.password;
  331. g_settings->set("name", playername);
  332. current_playername = playername;
  333. current_password = password;
  334. current_address = address;
  335. current_port = game_params.socket_port;
  336. // If using simple singleplayer mode, override
  337. if (simple_singleplayer_mode) {
  338. assert(skip_main_menu == false);
  339. current_playername = "singleplayer";
  340. current_password = "";
  341. current_address = "";
  342. current_port = myrand_range(49152, 65535);
  343. } else if (address != "") {
  344. ServerListSpec server;
  345. server["name"] = menudata.servername;
  346. server["address"] = menudata.address;
  347. server["port"] = menudata.port;
  348. server["description"] = menudata.serverdescription;
  349. ServerList::insert(server);
  350. }
  351. infostream << "Selected world: " << worldspec.name
  352. << " [" << worldspec.path << "]" << std::endl;
  353. if (current_address == "") { // If local game
  354. if (worldspec.path == "") {
  355. error_message = gettext("No world selected and no address "
  356. "provided. Nothing to do.");
  357. errorstream << error_message << std::endl;
  358. return false;
  359. }
  360. if (!fs::PathExists(worldspec.path)) {
  361. error_message = gettext("Provided world path doesn't exist: ")
  362. + worldspec.path;
  363. errorstream << error_message << std::endl;
  364. return false;
  365. }
  366. // Load gamespec for required game
  367. gamespec = findWorldSubgame(worldspec.path);
  368. if (!gamespec.isValid() && !game_params.game_spec.isValid()) {
  369. error_message = gettext("Could not find or load game \"")
  370. + worldspec.gameid + "\"";
  371. errorstream << error_message << std::endl;
  372. return false;
  373. }
  374. if (porting::signal_handler_killstatus())
  375. return true;
  376. if (game_params.game_spec.isValid() &&
  377. game_params.game_spec.id != worldspec.gameid) {
  378. warningstream << "Overriding gamespec from \""
  379. << worldspec.gameid << "\" to \""
  380. << game_params.game_spec.id << "\"" << std::endl;
  381. gamespec = game_params.game_spec;
  382. }
  383. if (!gamespec.isValid()) {
  384. error_message = gettext("Invalid gamespec.");
  385. error_message += " (world.gameid=" + worldspec.gameid + ")";
  386. errorstream << error_message << std::endl;
  387. return false;
  388. }
  389. }
  390. return true;
  391. }
  392. void ClientLauncher::main_menu(MainMenuData *menudata)
  393. {
  394. bool *kill = porting::signal_handler_killstatus();
  395. video::IVideoDriver *driver = device->getVideoDriver();
  396. infostream << "Waiting for other menus" << std::endl;
  397. while (device->run() && *kill == false) {
  398. if (noMenuActive())
  399. break;
  400. driver->beginScene(true, true, video::SColor(255, 128, 128, 128));
  401. guienv->drawAll();
  402. driver->endScene();
  403. // On some computers framerate doesn't seem to be automatically limited
  404. sleep_ms(25);
  405. }
  406. infostream << "Waited for other menus" << std::endl;
  407. // Cursor can be non-visible when coming from the game
  408. #ifndef ANDROID
  409. device->getCursorControl()->setVisible(true);
  410. #endif
  411. /* show main menu */
  412. GUIEngine mymenu(device, &input->joystick, guiroot,
  413. &g_menumgr, smgr, menudata, *kill);
  414. smgr->clear(); /* leave scene manager in a clean state */
  415. }
  416. bool ClientLauncher::create_engine_device()
  417. {
  418. // Resolution selection
  419. bool fullscreen = g_settings->getBool("fullscreen");
  420. u16 screenW = g_settings->getU16("screenW");
  421. u16 screenH = g_settings->getU16("screenH");
  422. // bpp, fsaa, vsync
  423. bool vsync = g_settings->getBool("vsync");
  424. u16 bits = g_settings->getU16("fullscreen_bpp");
  425. u16 fsaa = g_settings->getU16("fsaa");
  426. // stereo buffer required for pageflip stereo
  427. bool stereo_buffer = g_settings->get("3d_mode") == "pageflip";
  428. // Determine driver
  429. video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
  430. std::string driverstring = g_settings->get("video_driver");
  431. std::vector<video::E_DRIVER_TYPE> drivers
  432. = porting::getSupportedVideoDrivers();
  433. u32 i;
  434. for (i = 0; i != drivers.size(); i++) {
  435. if (!strcasecmp(driverstring.c_str(),
  436. porting::getVideoDriverName(drivers[i]))) {
  437. driverType = drivers[i];
  438. break;
  439. }
  440. }
  441. if (i == drivers.size()) {
  442. errorstream << "Invalid video_driver specified; "
  443. "defaulting to opengl" << std::endl;
  444. }
  445. SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
  446. params.DriverType = driverType;
  447. params.WindowSize = core::dimension2d<u32>(screenW, screenH);
  448. params.Bits = bits;
  449. params.AntiAlias = fsaa;
  450. params.Fullscreen = fullscreen;
  451. params.Stencilbuffer = false;
  452. params.Stereobuffer = stereo_buffer;
  453. params.Vsync = vsync;
  454. params.EventReceiver = receiver;
  455. params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
  456. params.ZBufferBits = 24;
  457. #ifdef __ANDROID__
  458. params.PrivateData = porting::app_global;
  459. params.OGLES2ShaderPath = std::string(porting::path_user + DIR_DELIM +
  460. "media" + DIR_DELIM + "Shaders" + DIR_DELIM).c_str();
  461. #endif
  462. device = createDeviceEx(params);
  463. if (device) {
  464. if (g_settings->getBool("enable_joysticks")) {
  465. irr::core::array<irr::SJoystickInfo> infos;
  466. std::vector<irr::SJoystickInfo> joystick_infos;
  467. // Make sure this is called maximum once per
  468. // irrlicht device, otherwise it will give you
  469. // multiple events for the same joystick.
  470. if (device->activateJoysticks(infos)) {
  471. infostream << "Joystick support enabled" << std::endl;
  472. joystick_infos.reserve(infos.size());
  473. for (u32 i = 0; i < infos.size(); i++) {
  474. joystick_infos.push_back(infos[i]);
  475. }
  476. } else {
  477. errorstream << "Could not activate joystick support." << std::endl;
  478. }
  479. }
  480. porting::initIrrlicht(device);
  481. }
  482. return device != NULL;
  483. }
  484. void ClientLauncher::speed_tests()
  485. {
  486. // volatile to avoid some potential compiler optimisations
  487. volatile static s16 temp16;
  488. volatile static f32 tempf;
  489. static v3f tempv3f1;
  490. static v3f tempv3f2;
  491. static std::string tempstring;
  492. static std::string tempstring2;
  493. tempv3f1 = v3f();
  494. tempv3f2 = v3f();
  495. tempstring = std::string();
  496. tempstring2 = std::string();
  497. {
  498. infostream << "The following test should take around 20ms." << std::endl;
  499. TimeTaker timer("Testing std::string speed");
  500. const u32 jj = 10000;
  501. for (u32 j = 0; j < jj; j++) {
  502. tempstring = "";
  503. tempstring2 = "";
  504. const u32 ii = 10;
  505. for (u32 i = 0; i < ii; i++) {
  506. tempstring2 += "asd";
  507. }
  508. for (u32 i = 0; i < ii+1; i++) {
  509. tempstring += "asd";
  510. if (tempstring == tempstring2)
  511. break;
  512. }
  513. }
  514. }
  515. infostream << "All of the following tests should take around 100ms each."
  516. << std::endl;
  517. {
  518. TimeTaker timer("Testing floating-point conversion speed");
  519. tempf = 0.001;
  520. for (u32 i = 0; i < 4000000; i++) {
  521. temp16 += tempf;
  522. tempf += 0.001;
  523. }
  524. }
  525. {
  526. TimeTaker timer("Testing floating-point vector speed");
  527. tempv3f1 = v3f(1, 2, 3);
  528. tempv3f2 = v3f(4, 5, 6);
  529. for (u32 i = 0; i < 10000000; i++) {
  530. tempf += tempv3f1.dotProduct(tempv3f2);
  531. tempv3f2 += v3f(7, 8, 9);
  532. }
  533. }
  534. {
  535. TimeTaker timer("Testing std::map speed");
  536. std::map<v2s16, f32> map1;
  537. tempf = -324;
  538. const s16 ii = 300;
  539. for (s16 y = 0; y < ii; y++) {
  540. for (s16 x = 0; x < ii; x++) {
  541. map1[v2s16(x, y)] = tempf;
  542. tempf += 1;
  543. }
  544. }
  545. for (s16 y = ii - 1; y >= 0; y--) {
  546. for (s16 x = 0; x < ii; x++) {
  547. tempf = map1[v2s16(x, y)];
  548. }
  549. }
  550. }
  551. {
  552. infostream << "Around 5000/ms should do well here." << std::endl;
  553. TimeTaker timer("Testing mutex speed");
  554. Mutex m;
  555. u32 n = 0;
  556. u32 i = 0;
  557. do {
  558. n += 10000;
  559. for (; i < n; i++) {
  560. m.lock();
  561. m.unlock();
  562. }
  563. }
  564. // Do at least 10ms
  565. while(timer.getTimerTime() < 10);
  566. u32 dtime = timer.stop();
  567. u32 per_ms = n / dtime;
  568. infostream << "Done. " << dtime << "ms, " << per_ms << "/ms" << std::endl;
  569. }
  570. }
  571. bool ClientLauncher::print_video_modes()
  572. {
  573. IrrlichtDevice *nulldevice;
  574. bool vsync = g_settings->getBool("vsync");
  575. u16 fsaa = g_settings->getU16("fsaa");
  576. MyEventReceiver* receiver = new MyEventReceiver();
  577. SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
  578. params.DriverType = video::EDT_NULL;
  579. params.WindowSize = core::dimension2d<u32>(640, 480);
  580. params.Bits = 24;
  581. params.AntiAlias = fsaa;
  582. params.Fullscreen = false;
  583. params.Stencilbuffer = false;
  584. params.Vsync = vsync;
  585. params.EventReceiver = receiver;
  586. params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
  587. nulldevice = createDeviceEx(params);
  588. if (nulldevice == NULL) {
  589. delete receiver;
  590. return false;
  591. }
  592. std::cout << _("Available video modes (WxHxD):") << std::endl;
  593. video::IVideoModeList *videomode_list = nulldevice->getVideoModeList();
  594. if (videomode_list != NULL) {
  595. s32 videomode_count = videomode_list->getVideoModeCount();
  596. core::dimension2d<u32> videomode_res;
  597. s32 videomode_depth;
  598. for (s32 i = 0; i < videomode_count; ++i) {
  599. videomode_res = videomode_list->getVideoModeResolution(i);
  600. videomode_depth = videomode_list->getVideoModeDepth(i);
  601. std::cout << videomode_res.Width << "x" << videomode_res.Height
  602. << "x" << videomode_depth << std::endl;
  603. }
  604. std::cout << _("Active video mode (WxHxD):") << std::endl;
  605. videomode_res = videomode_list->getDesktopResolution();
  606. videomode_depth = videomode_list->getDesktopDepth();
  607. std::cout << videomode_res.Width << "x" << videomode_res.Height
  608. << "x" << videomode_depth << std::endl;
  609. }
  610. nulldevice->drop();
  611. delete receiver;
  612. return videomode_list != NULL;
  613. }