diff options
author | ShadowNinja <shadowninja@minetest.net> | 2017-06-03 14:55:10 -0400 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2017-06-03 14:55:10 -0400 |
commit | caecdb681c428c1aab9c0f7eec2570c0460f995c (patch) | |
tree | e5115982ea59bbf2343ba9b35bc4a0cfbb56f407 /src/client/clientlauncher.cpp | |
parent | 81d56b94919dceb7b2e51d70b21a7ca22f852bd5 (diff) | |
parent | 80dc961d24e1964e25d57039ddb2ba639f9f4d22 (diff) | |
download | minetest-caecdb681c428c1aab9c0f7eec2570c0460f995c.tar.gz minetest-caecdb681c428c1aab9c0f7eec2570c0460f995c.tar.bz2 minetest-caecdb681c428c1aab9c0f7eec2570c0460f995c.zip |
Merge 0.4.16 into stable-0.4
Diffstat (limited to 'src/client/clientlauncher.cpp')
-rw-r--r-- | src/client/clientlauncher.cpp | 108 |
1 files changed, 49 insertions, 59 deletions
diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 6145e3dde..289d1537b 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -42,31 +42,15 @@ gui::IGUIEnvironment *guienv = NULL; gui::IGUIStaticText *guiroot = NULL; MainMenuManager g_menumgr; -bool noMenuActive() +bool isMenuActive() { - return g_menumgr.menuCount() == 0; + return g_menumgr.menuCount() != 0; } // Passed to menus to allow disconnecting and exiting MainGameCallback *g_gamecallback = NULL; -// Instance of the time getter -static TimeGetter *g_timegetter = NULL; - -u32 getTimeMs() -{ - if (g_timegetter == NULL) - return 0; - return g_timegetter->getTime(PRECISION_MILLI); -} - -u32 getTime(TimePrecision prec) { - if (g_timegetter == NULL) - return 0; - return g_timegetter->getTime(prec); -} - ClientLauncher::~ClientLauncher() { if (receiver) @@ -96,9 +80,6 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) return false; } - // Create time getter - g_timegetter = new IrrlichtTimeGetter(device); - // Speed tests (done after irrlicht is loaded to get timer) if (cmd_args.getFlag("speedtests")) { dstream << "Running speed tests" << std::endl; @@ -114,7 +95,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C); - porting::setXorgWindowIcon(device); + porting::setWindowIcon(device); /* This changes the minimum allowed number of vertices in a VBO. @@ -127,10 +108,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) device->setResizable(true); - if (random_input) - input = new RandomInputHandler(); - else - input = new RealInputHandler(device, receiver); + init_input(); smgr = device->getSceneManager(); smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true); @@ -337,6 +315,33 @@ bool ClientLauncher::init_engine() return device != NULL; } +void ClientLauncher::init_input() +{ + if (random_input) + input = new RandomInputHandler(); + else + input = new RealInputHandler(device, receiver); + + if (g_settings->getBool("enable_joysticks")) { + irr::core::array<irr::SJoystickInfo> infos; + std::vector<irr::SJoystickInfo> joystick_infos; + + // Make sure this is called maximum once per + // irrlicht device, otherwise it will give you + // multiple events for the same joystick. + if (device->activateJoysticks(infos)) { + infostream << "Joystick support enabled" << std::endl; + joystick_infos.reserve(infos.size()); + for (u32 i = 0; i < infos.size(); i++) { + joystick_infos.push_back(infos[i]); + } + input->joystick.onJoystickConnect(joystick_infos); + } else { + errorstream << "Could not activate joystick support." << std::endl; + } + } +} + bool ClientLauncher::launch_game(std::string &error_message, bool reconnect_requested, GameParams &game_params, const Settings &cmd_args) @@ -403,15 +408,14 @@ bool ClientLauncher::launch_game(std::string &error_message, return false; } - if (menudata.name == "") - menudata.name = std::string("Guest") + itos(myrand_range(1000, 9999)); - else - playername = menudata.name; + if (menudata.name == "" && !simple_singleplayer_mode) { + error_message = gettext("Please choose a name!"); + return false; + } + playername = menudata.name; password = menudata.password; - g_settings->set("name", playername); - current_playername = playername; current_password = password; current_address = address; @@ -424,13 +428,16 @@ bool ClientLauncher::launch_game(std::string &error_message, 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); + } else { + g_settings->set("name", playername); + if (address != "") { + ServerListSpec server; + server["name"] = menudata.servername; + server["address"] = menudata.address; + server["port"] = menudata.port; + server["description"] = menudata.serverdescription; + ServerList::insert(server); + } } infostream << "Selected world: " << worldspec.name @@ -489,7 +496,7 @@ void ClientLauncher::main_menu(MainMenuData *menudata) infostream << "Waiting for other menus" << std::endl; while (device->run() && *kill == false) { - if (noMenuActive()) + if (!isMenuActive()) break; driver->beginScene(true, true, video::SColor(255, 128, 128, 128)); guienv->drawAll(); @@ -528,7 +535,7 @@ bool ClientLauncher::create_engine_device() // Determine driver video::E_DRIVER_TYPE driverType = video::EDT_OPENGL; - std::string driverstring = g_settings->get("video_driver"); + const std::string &driverstring = g_settings->get("video_driver"); std::vector<video::E_DRIVER_TYPE> drivers = porting::getSupportedVideoDrivers(); u32 i; @@ -564,25 +571,8 @@ bool ClientLauncher::create_engine_device() device = createDeviceEx(params); - if (device) { - if (g_settings->getBool("enable_joysticks")) { - irr::core::array<irr::SJoystickInfo> infos; - std::vector<irr::SJoystickInfo> joystick_infos; - // Make sure this is called maximum once per - // irrlicht device, otherwise it will give you - // multiple events for the same joystick. - if (device->activateJoysticks(infos)) { - infostream << "Joystick support enabled" << std::endl; - joystick_infos.reserve(infos.size()); - for (u32 i = 0; i < infos.size(); i++) { - joystick_infos.push_back(infos[i]); - } - } else { - errorstream << "Could not activate joystick support." << std::endl; - } - } + if (device) porting::initIrrlicht(device); - } return device != NULL; } |