]> git.lizzy.rs Git - minetest.git/blobdiff - src/client/clientlauncher.cpp
Clean up getTime helpers
[minetest.git] / src / client / clientlauncher.cpp
index ee8662ed697c0a1ea2f3fad2bee7e72fa5d8a87f..be4e82134a4e3a93eb3ca147efe7f80d70702408 100644 (file)
@@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "fontengine.h"
 #include "joystick_controller.h"
 #include "clientlauncher.h"
+#include "version.h"
 
 /* mainmenumanager.h
  */
@@ -50,22 +51,6 @@ bool noMenuActive()
 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)
@@ -95,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;
@@ -113,6 +95,8 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
 
        porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C);
 
+       porting::setWindowIcon(device);
+
        /*
                This changes the minimum allowed number of vertices in a VBO.
                Default is 500.
@@ -124,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);
@@ -185,7 +166,9 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
        {
                // Set the window caption
                const wchar_t *text = wgettext("Main Menu");
-               device->setWindowCaption((utf8_to_wide(PROJECT_NAME_C) + L" [" + text + L"]").c_str());
+               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
@@ -332,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)
@@ -398,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;
@@ -419,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
@@ -523,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;
@@ -559,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;
 }