[CSM] Add `on_dignode` callback (#5140)
[oweals/minetest.git] / src / client / clientlauncher.cpp
index 60eb216741988afdc3a20ef614cff23bdb3d2d98..2adac53c2d55d8e79275423abb7596d87da8a4d8 100644 (file)
@@ -32,7 +32,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "guiEngine.h"
 #include "player.h"
 #include "fontengine.h"
+#include "joystick_controller.h"
 #include "clientlauncher.h"
+#include "version.h"
 
 /* mainmenumanager.h
  */
@@ -89,7 +91,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
        if (list_video_modes)
                return print_video_modes();
 
-       if (!init_engine(game_params.log_level)) {
+       if (!init_engine()) {
                errorstream << "Could not initialize game engine." << std::endl;
                return false;
        }
@@ -112,6 +114,8 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
 
        porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C);
 
+       porting::setXorgWindowIcon(device);
+
        /*
                This changes the minimum allowed number of vertices in a VBO.
                Default is 500.
@@ -184,7 +188,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
@@ -201,6 +207,9 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
                        bool game_has_run = launch_game(error_message, reconnect_requested,
                                game_params, cmd_args);
 
+                       // Reset the reconnect_requested flag
+                       reconnect_requested = false;
+
                        // If skip_main_menu, we only want to startup once
                        if (skip_main_menu && !first_loop)
                                break;
@@ -321,10 +330,10 @@ void ClientLauncher::init_args(GameParams &game_params, const Settings &cmd_args
                        || cmd_args.getFlag("random-input");
 }
 
-bool ClientLauncher::init_engine(int log_level)
+bool ClientLauncher::init_engine()
 {
        receiver = new MyEventReceiver();
-       create_engine_device(log_level);
+       create_engine_device();
        return device != NULL;
 }
 
@@ -336,6 +345,7 @@ bool ClientLauncher::launch_game(std::string &error_message,
        MainMenuData menudata;
        menudata.address                         = address;
        menudata.name                            = playername;
+       menudata.password                        = password;
        menudata.port                            = itos(game_params.socket_port);
        menudata.script_data.errormessage        = error_message;
        menudata.script_data.reconnect_requested = reconnect_requested;
@@ -393,15 +403,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;
@@ -414,13 +423,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
@@ -455,7 +467,7 @@ bool ClientLauncher::launch_game(std::string &error_message,
 
                if (game_params.game_spec.isValid() &&
                                game_params.game_spec.id != worldspec.gameid) {
-                       errorstream << "WARNING: Overriding gamespec from \""
+                       warningstream << "Overriding gamespec from \""
                                    << worldspec.gameid << "\" to \""
                                    << game_params.game_spec.id << "\"" << std::endl;
                        gamespec = game_params.game_spec;
@@ -495,25 +507,14 @@ void ClientLauncher::main_menu(MainMenuData *menudata)
 #endif
 
        /* show main menu */
-       GUIEngine mymenu(device, guiroot, &g_menumgr, smgr, menudata, *kill);
+       GUIEngine mymenu(device, &input->joystick, guiroot,
+               &g_menumgr, smgr, menudata, *kill);
 
        smgr->clear();  /* leave scene manager in a clean state */
 }
 
-bool ClientLauncher::create_engine_device(int log_level)
+bool ClientLauncher::create_engine_device()
 {
-       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
-       };
-
        // Resolution selection
        bool fullscreen = g_settings->getBool("fullscreen");
        u16 screenW = g_settings->getU16("screenW");
@@ -524,6 +525,9 @@ bool ClientLauncher::create_engine_device(int log_level)
        u16 bits = g_settings->getU16("fullscreen_bpp");
        u16 fsaa = g_settings->getU16("fsaa");
 
+       // stereo buffer required for pageflip stereo
+       bool stereo_buffer = g_settings->get("3d_mode") == "pageflip";
+
        // Determine driver
        video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
        std::string driverstring = g_settings->get("video_driver");
@@ -549,9 +553,11 @@ bool ClientLauncher::create_engine_device(int log_level)
        params.AntiAlias     = fsaa;
        params.Fullscreen    = fullscreen;
        params.Stencilbuffer = false;
+       params.Stereobuffer  = stereo_buffer;
        params.Vsync         = vsync;
        params.EventReceiver = receiver;
        params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
+       params.ZBufferBits   = 24;
 #ifdef __ANDROID__
        params.PrivateData = porting::app_global;
        params.OGLES2ShaderPath = std::string(porting::path_user + DIR_DELIM +
@@ -561,10 +567,22 @@ bool ClientLauncher::create_engine_device(int log_level)
        device = createDeviceEx(params);
 
        if (device) {
-               // Map our log level to irrlicht engine one.
-               ILogger* irr_logger = device->getLogger();
-               irr_logger->setLogLevel(irr_log_level[log_level]);
-
+               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;
+                       }
+               }
                porting::initIrrlicht(device);
        }
 
@@ -696,7 +714,7 @@ bool ClientLauncher::print_video_modes()
                return false;
        }
 
-       dstream << _("Available video modes (WxHxD):") << std::endl;
+       std::cout << _("Available video modes (WxHxD):") << std::endl;
 
        video::IVideoModeList *videomode_list = nulldevice->getVideoModeList();
 
@@ -707,14 +725,14 @@ bool ClientLauncher::print_video_modes()
                for (s32 i = 0; i < videomode_count; ++i) {
                        videomode_res = videomode_list->getVideoModeResolution(i);
                        videomode_depth = videomode_list->getVideoModeDepth(i);
-                       dstream << videomode_res.Width << "x" << videomode_res.Height
+                       std::cout << videomode_res.Width << "x" << videomode_res.Height
                                << "x" << videomode_depth << std::endl;
                }
 
-               dstream << _("Active video mode (WxHxD):") << std::endl;
+               std::cout << _("Active video mode (WxHxD):") << std::endl;
                videomode_res = videomode_list->getDesktopResolution();
                videomode_depth = videomode_list->getDesktopDepth();
-               dstream << videomode_res.Width << "x" << videomode_res.Height
+               std::cout << videomode_res.Width << "x" << videomode_res.Height
                        << "x" << videomode_depth << std::endl;
 
        }