diff options
Diffstat (limited to 'src/client/clientlauncher.cpp')
-rw-r--r-- | src/client/clientlauncher.cpp | 131 |
1 files changed, 66 insertions, 65 deletions
diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index b96c7e7f6..ce16797e6 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -36,10 +36,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "network/networkexceptions.h" #if USE_SOUND -#include "sound_openal.h" + #include "sound_openal.h" #endif #ifdef __ANDROID__ -#include "porting.h" + #include "porting.h" #endif /* mainmenumanager.h @@ -87,6 +87,7 @@ ClientLauncher::~ClientLauncher() #endif } + bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) { /* This function is called when a client must be started. @@ -94,7 +95,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) * - Singleplayer (address but map provided) * - Join server (no map but address provided) * - Local server (for main menu only) - */ + */ init_args(start_data, cmd_args); @@ -130,7 +131,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) This changes the minimum allowed number of vertices in a VBO. Default is 500. */ - // driver->setMinHardwareBufferVertexCount(50); + //driver->setMinHardwareBufferVertexCount(50); // Create game callback for menus g_gamecallback = new MainGameCallback(); @@ -139,8 +140,8 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) init_input(); - RenderingEngine::get_scene_manager()->getParameters()->setAttribute( - scene::ALLOW_ZWRITE_ON_TRANSPARENT, true); + RenderingEngine::get_scene_manager()->getParameters()-> + setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true); guienv = RenderingEngine::get_gui_env(); skin = RenderingEngine::get_gui_env()->getSkin(); @@ -177,8 +178,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) g_fontengine = new FontEngine(g_settings, guienv); FATAL_ERROR_IF(g_fontengine == NULL, "Font engine creation failed."); -#if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || \ - IRRLICHT_VERSION_MAJOR >= 2 +#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)); @@ -186,13 +186,12 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) // Create the menu clouds if (!g_menucloudsmgr) - g_menucloudsmgr = RenderingEngine::get_scene_manager() - ->createNewSceneManager(); + g_menucloudsmgr = RenderingEngine::get_scene_manager()->createNewSceneManager(); if (!g_menuclouds) g_menuclouds = new Clouds(g_menucloudsmgr, -1, rand()); g_menuclouds->setHeight(100.0f); g_menuclouds->update(v3f(0, 0, 0), video::SColor(255, 240, 240, 255)); - scene::ICameraSceneNode *camera; + scene::ICameraSceneNode* camera; camera = g_menucloudsmgr->addCameraSceneNode(NULL, v3f(0, 0, 0), v3f(0, 60, 100)); camera->setFarValue(10000); @@ -215,17 +214,17 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) bool retval = true; bool *kill = porting::signal_handler_killstatus(); - while (RenderingEngine::run() && !*kill && !g_gamecallback->shutdown_requested) { + while (RenderingEngine::run() && !*kill && + !g_gamecallback->shutdown_requested) { // Set the window caption const wchar_t *text = wgettext("Main Menu"); - RenderingEngine::get_raw_device()->setWindowCaption( - (utf8_to_wide(PROJECT_NAME_C) + L" " + - utf8_to_wide(g_version_hash) + L" [" + - text + L"]") - .c_str()); + RenderingEngine::get_raw_device()-> + setWindowCaption((utf8_to_wide(PROJECT_NAME_C) + + L" " + utf8_to_wide(g_version_hash) + + L" [" + text + L"]").c_str()); delete[] text; - try { // This is used for catching disconnects + try { // This is used for catching disconnects RenderingEngine::get_gui_env()->clear(); @@ -234,11 +233,11 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) custom gui elements directly on the screen. Otherwise they won't be automatically drawn. */ - guiroot = RenderingEngine::get_gui_env()->addStaticText( - L"", core::rect<s32>(0, 0, 10000, 10000)); + guiroot = RenderingEngine::get_gui_env()->addStaticText(L"", + core::rect<s32>(0, 0, 10000, 10000)); - bool game_has_run = launch_game(error_message, - reconnect_requested, start_data, cmd_args); + bool game_has_run = launch_game(error_message, reconnect_requested, + start_data, cmd_args); // Reset the reconnect_requested flag reconnect_requested = false; @@ -259,23 +258,26 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) // Break out of menu-game loop to shut down cleanly if (!RenderingEngine::get_raw_device()->run() || *kill) { if (!g_settings_path.empty()) - g_settings->updateConfigFile( - g_settings_path.c_str()); + g_settings->updateConfigFile(g_settings_path.c_str()); break; } RenderingEngine::get_video_driver()->setTextureCreationFlag( - video::ETCF_CREATE_MIP_MAPS, - g_settings->getBool("mip_map")); + video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map")); #ifdef HAVE_TOUCHSCREENGUI - receiver->m_touchscreengui = new TouchScreenGUI( - RenderingEngine::get_raw_device(), receiver); + receiver->m_touchscreengui = new TouchScreenGUI(RenderingEngine::get_raw_device(), receiver); g_touchscreengui = receiver->m_touchscreengui; #endif - the_game(kill, input, start_data, error_message, chat_backend, - &reconnect_requested); + the_game( + kill, + input, + start_data, + error_message, + chat_backend, + &reconnect_requested + ); RenderingEngine::get_scene_manager()->clear(); #ifdef HAVE_TOUCHSCREENGUI @@ -284,7 +286,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) receiver->m_touchscreengui = NULL; #endif - } // try + } //try catch (con::PeerNotFoundException &e) { error_message = gettext("Connection error (timed out?)"); errorstream << error_message << std::endl; @@ -302,8 +304,8 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) // If no main menu, show error and exit if (skip_main_menu) { if (!error_message.empty()) { - verbosestream << "error_message = " << error_message - << std::endl; + verbosestream << "error_message = " + << error_message << std::endl; retval = false; } break; @@ -337,8 +339,8 @@ void ClientLauncher::init_args(GameStartData &start_data, const Settings &cmd_ar list_video_modes = cmd_args.getFlag("videomodes"); - random_input = g_settings->getBool("random_input") || - cmd_args.getFlag("random-input"); + random_input = g_settings->getBool("random_input") + || cmd_args.getFlag("random-input"); } bool ClientLauncher::init_engine() @@ -370,14 +372,14 @@ void ClientLauncher::init_input() } input->joystick.onJoystickConnect(joystick_infos); } else { - errorstream << "Could not activate joystick support." - << std::endl; + errorstream << "Could not activate joystick support." << std::endl; } } } -bool ClientLauncher::launch_game(std::string &error_message, bool reconnect_requested, - GameStartData &start_data, const Settings &cmd_args) +bool ClientLauncher::launch_game(std::string &error_message, + bool reconnect_requested, GameStartData &start_data, + const Settings &cmd_args) { // Prepare and check the start data to launch a game std::string error_message_lua = error_message; @@ -392,8 +394,8 @@ bool ClientLauncher::launch_game(std::string &error_message, bool reconnect_requ getline(passfile, start_data.password); } else { error_message = gettext("Provided password file " - "failed to open: ") + - cmd_args.get("password-file"); + "failed to open: ") + + cmd_args.get("password-file"); errorstream << error_message << std::endl; return false; } @@ -408,7 +410,7 @@ bool ClientLauncher::launch_game(std::string &error_message, bool reconnect_requ spec.gameid = getWorldGameId(spec.path, true); spec.name = _("[--world parameter]"); - if (spec.gameid.empty()) { // Create new + if (spec.gameid.empty()) { // Create new spec.gameid = g_settings->get("default_game"); spec.name += " [new]"; } @@ -422,11 +424,11 @@ bool ClientLauncher::launch_game(std::string &error_message, bool reconnect_requ // Initialize menu data // TODO: Re-use existing structs (GameStartData) MainMenuData menudata; - menudata.address = start_data.address; - menudata.name = start_data.name; - menudata.password = start_data.password; - menudata.port = itos(start_data.socket_port); - menudata.script_data.errormessage = error_message_lua; + menudata.address = start_data.address; + menudata.name = start_data.name; + menudata.password = start_data.password; + menudata.port = itos(start_data.socket_port); + menudata.script_data.errormessage = error_message_lua; menudata.script_data.reconnect_requested = reconnect_requested; main_menu(&menudata); @@ -436,9 +438,8 @@ bool ClientLauncher::launch_game(std::string &error_message, bool reconnect_requ return false; if (!menudata.script_data.errormessage.empty()) { - /* The calling function will pass this back into this function - * upon the next iteration (if any) causing it to be displayed by - * the GUI + /* The calling function will pass this back into this function upon the + * next iteration (if any) causing it to be displayed by the GUI */ error_message = menudata.script_data.errormessage; return false; @@ -465,7 +466,7 @@ bool ClientLauncher::launch_game(std::string &error_message, bool reconnect_requ server_description = menudata.serverdescription; start_data.local_server = !menudata.simple_singleplayer_mode && - start_data.address.empty(); + start_data.address.empty(); } if (!RenderingEngine::run()) @@ -486,9 +487,9 @@ bool ClientLauncher::launch_game(std::string &error_message, bool reconnect_requ g_settings->set("name", start_data.name); if (!start_data.address.empty()) { ServerListSpec server; - server["name"] = server_name; - server["address"] = start_data.address; - server["port"] = itos(start_data.socket_port); + server["name"] = server_name; + server["address"] = start_data.address; + server["port"] = itos(start_data.socket_port); server["description"] = server_description; ServerList::insert(server); } @@ -502,21 +503,21 @@ bool ClientLauncher::launch_game(std::string &error_message, bool reconnect_requ } auto &worldspec = start_data.world_spec; - infostream << "Selected world: " << worldspec.name << " [" << worldspec.path - << "]" << std::endl; + infostream << "Selected world: " << worldspec.name + << " [" << worldspec.path << "]" << std::endl; if (start_data.address.empty()) { // For singleplayer and local server if (worldspec.path.empty()) { error_message = gettext("No world selected and no address " - "provided. Nothing to do."); + "provided. Nothing to do."); errorstream << error_message << std::endl; return false; } if (!fs::PathExists(worldspec.path)) { - error_message = gettext("Provided world path doesn't exist: ") + - worldspec.path; + error_message = gettext("Provided world path doesn't exist: ") + + worldspec.path; errorstream << error_message << std::endl; return false; } @@ -524,8 +525,8 @@ bool ClientLauncher::launch_game(std::string &error_message, bool reconnect_requ // Load gamespec for required game start_data.game_spec = findWorldSubgame(worldspec.path); if (!start_data.game_spec.isValid()) { - error_message = gettext("Could not find or load game \"") + - worldspec.gameid + "\""; + error_message = gettext("Could not find or load game \"") + + worldspec.gameid + "\""; errorstream << error_message << std::endl; return false; } @@ -600,7 +601,7 @@ void ClientLauncher::speed_tests() for (u32 i = 0; i < ii; i++) { tempstring2 += "asd"; } - for (u32 i = 0; i < ii + 1; i++) { + for (u32 i = 0; i < ii+1; i++) { tempstring += "asd"; if (tempstring == tempstring2) break; @@ -609,7 +610,7 @@ void ClientLauncher::speed_tests() } infostream << "All of the following tests should take around 100ms each." - << std::endl; + << std::endl; { TimeTaker timer("Testing floating-point conversion speed"); @@ -639,7 +640,7 @@ void ClientLauncher::speed_tests() const s16 ii = 300; for (s16 y = 0; y < ii; y++) { for (s16 x = 0; x < ii; x++) { - map1[v2s16(x, y)] = tempf; + map1[v2s16(x, y)] = tempf; tempf += 1; } } @@ -665,7 +666,7 @@ void ClientLauncher::speed_tests() } } // Do at least 10ms - while (timer.getTimerTime() < 10); + while(timer.getTimerTime() < 10); u32 dtime = timer.stop(); u32 per_ms = n / dtime; |