]> git.lizzy.rs Git - minetest.git/blobdiff - src/client/clientlauncher.cpp
Prevent SIGFPE on entity tile loading issue. (#5178)
[minetest.git] / src / client / clientlauncher.cpp
index bad5c384c3cdbd1c138b1fdd28077489898d6e7f..6145e3ddef379aa044fe56a08a5141748ba997dd 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;
@@ -455,7 +465,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 +505,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 +523,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 +551,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 +565,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);
        }
 
@@ -651,14 +667,14 @@ void ClientLauncher::speed_tests()
                infostream << "Around 5000/ms should do well here." << std::endl;
                TimeTaker timer("Testing mutex speed");
 
-               JMutex m;
+               Mutex m;
                u32 n = 0;
                u32 i = 0;
                do {
                        n += 10000;
                        for (; i < n; i++) {
-                               m.Lock();
-                               m.Unlock();
+                               m.lock();
+                               m.unlock();
                        }
                }
                // Do at least 10ms
@@ -696,7 +712,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 +723,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;
 
        }