Translated using Weblate (Japanese)
[oweals/minetest.git] / src / game.cpp
index ef3cb9044aaae5b28c916dfa0b1f3f665bdcaa4d..840d627b6796916716d2ac0d0514068a2cc72f06 100644 (file)
@@ -375,7 +375,7 @@ PointedThing getPointedThing(Client *client, v3f player_position,
 
                                for (std::vector<aabb3f>::const_iterator
                                                i = boxes.begin();
-                                               i != boxes.end(); i++) {
+                                               i != boxes.end(); ++i) {
                                        aabb3f box = *i;
                                        box.MinEdge += npf;
                                        box.MaxEdge += npf;
@@ -420,7 +420,7 @@ PointedThing getPointedThing(Client *client, v3f player_position,
                                                if (!g_settings->getBool("enable_node_highlighting")) {
                                                        for (std::vector<aabb3f>::const_iterator
                                                                        i2 = boxes.begin();
-                                                                       i2 != boxes.end(); i2++) {
+                                                                       i2 != boxes.end(); ++i2) {
                                                                aabb3f box = *i2;
                                                                box.MinEdge += npf + v3f(-d, -d, -d) - intToFloat(camera_offset, BS);
                                                                box.MaxEdge += npf + v3f(d, d, d) - intToFloat(camera_offset, BS);
@@ -514,11 +514,11 @@ public:
                std::map<std::string, Meta> m_meta;
 
                for (std::vector<Piece>::const_iterator k = m_log.begin();
-                               k != m_log.end(); k++) {
+                               k != m_log.end(); ++k) {
                        const Piece &piece = *k;
 
                        for (Profiler::GraphValues::const_iterator i = piece.values.begin();
-                                       i != piece.values.end(); i++) {
+                                       i != piece.values.end(); ++i) {
                                const std::string &id = i->first;
                                const float &value = i->second;
                                std::map<std::string, Meta>::iterator j =
@@ -550,7 +550,7 @@ public:
                u32 next_color_i = 0;
 
                for (std::map<std::string, Meta>::iterator i = m_meta.begin();
-                               i != m_meta.end(); i++) {
+                               i != m_meta.end(); ++i) {
                        Meta &meta = i->second;
                        video::SColor color(255, 200, 200, 200);
 
@@ -566,7 +566,7 @@ public:
                s32 meta_i = 0;
 
                for (std::map<std::string, Meta>::const_iterator i = m_meta.begin();
-                               i != m_meta.end(); i++) {
+                               i != m_meta.end(); ++i) {
                        const std::string &id = i->first;
                        const Meta &meta = i->second;
                        s32 x = x_left;
@@ -602,7 +602,7 @@ public:
                        bool lastscaledvalue_exists = false;
 
                        for (std::vector<Piece>::const_iterator j = m_log.begin();
-                                       j != m_log.end(); j++) {
+                                       j != m_log.end(); ++j) {
                                const Piece &piece = *j;
                                float value = 0;
                                bool value_exists = false;
@@ -806,7 +806,7 @@ public:
                        m_fogEnabled = g_settings->getBool("enable_fog");
        }
 
-       static void SettingsCallback(const std::string name, void *userdata)
+       static void SettingsCallback(const std::string &name, void *userdata)
        {
                reinterpret_cast<GameGlobalShaderConstantSetter*>(userdata)->onSettingsChange(name);
        }
@@ -878,11 +878,11 @@ public:
 #if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
                services->setPixelShaderConstant("baseTexture" , (irr::f32 *)&layer0, 1);
                services->setPixelShaderConstant("normalTexture" , (irr::f32 *)&layer1, 1);
-               services->setPixelShaderConstant("useNormalmap" , (irr::f32 *)&layer2, 1);
+               services->setPixelShaderConstant("textureFlags" , (irr::f32 *)&layer2, 1);
 #else
                services->setPixelShaderConstant("baseTexture" , (irr::s32 *)&layer0, 1);
                services->setPixelShaderConstant("normalTexture" , (irr::s32 *)&layer1, 1);
-               services->setPixelShaderConstant("useNormalmap" , (irr::s32 *)&layer2, 1);
+               services->setPixelShaderConstant("textureFlags" , (irr::s32 *)&layer2, 1);
 #endif
        }
 };
@@ -1417,8 +1417,7 @@ struct VolatileRunFlags {
  * hides most of the stuff in this class (nothing in this class is required
  * by any other file) but exposes the public methods/data only.
  */
-class Game
-{
+class Game {
 public:
        Game();
        ~Game();
@@ -1434,6 +1433,7 @@ public:
                        std::string *address,
                        u16 port,
                        std::string &error_message,
+                       bool *reconnect,
                        ChatBackend *chat_backend,
                        const SubgameSpec &gamespec,    // Used for local game
                        bool simple_singleplayer_mode);
@@ -1497,7 +1497,7 @@ protected:
 
        void toggleChat(float *statustext_time, bool *flag);
        void toggleHud(float *statustext_time, bool *flag);
-       void toggleMinimap(float *statustext_time, bool *flag1, bool *flag2,
+       void toggleMinimap(float *statustext_time, bool *flag, bool show_hud,
                        bool shift_pressed);
        void toggleFog(float *statustext_time, bool *flag);
        void toggleDebug(float *statustext_time, bool *show_debug,
@@ -1545,6 +1545,9 @@ protected:
        void showOverlayMessage(const wchar_t *msg, float dtime, int percent,
                        bool draw_clouds = true);
 
+       static void settingChangedCallback(const std::string &setting_name, void *data);
+       void readSettings();
+
 private:
        InputHandler *input;
 
@@ -1588,6 +1591,7 @@ private:
        scene::ISceneManager *smgr;
        bool *kill;
        std::string *error_message;
+       bool *reconnect_requested;
        IGameDef *gamedef;                     // Convenience (same as *client)
        scene::ISceneNode *skybox;
 
@@ -1615,10 +1619,7 @@ private:
 
        IntervalLimiter profiler_interval;
 
-       /* TODO: Add a callback function so these can be updated when a setting
-        *       changes.  At this point in time it doesn't matter (e.g. /set
-        *       is documented to change server settings only)
-        *
+       /*
         * TODO: Local caching of settings is not optimal and should at some stage
         *       be updated to use a global settings object for getting thse values
         *       (as opposed to the this local caching). This can be addressed in
@@ -1661,15 +1662,22 @@ Game::Game() :
        hud(NULL),
        mapper(NULL)
 {
-       m_cache_doubletap_jump            = g_settings->getBool("doubletap_jump");
-       m_cache_enable_node_highlighting  = g_settings->getBool("enable_node_highlighting");
-       m_cache_enable_clouds             = g_settings->getBool("enable_clouds");
-       m_cache_enable_particles          = g_settings->getBool("enable_particles");
-       m_cache_enable_fog                = g_settings->getBool("enable_fog");
-       m_cache_mouse_sensitivity         = g_settings->getFloat("mouse_sensitivity");
-       m_repeat_right_click_time         = g_settings->getFloat("repeat_rightclick_time");
-
-       m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);
+       g_settings->registerChangedCallback("doubletap_jump",
+               &settingChangedCallback, this);
+       g_settings->registerChangedCallback("enable_node_highlighting",
+               &settingChangedCallback, this);
+       g_settings->registerChangedCallback("enable_clouds",
+               &settingChangedCallback, this);
+       g_settings->registerChangedCallback("enable_particles",
+               &settingChangedCallback, this);
+       g_settings->registerChangedCallback("enable_fog",
+               &settingChangedCallback, this);
+       g_settings->registerChangedCallback("mouse_sensitivity",
+               &settingChangedCallback, this);
+       g_settings->registerChangedCallback("repeat_rightclick_time",
+               &settingChangedCallback, this);
+
+       readSettings();
 
 #ifdef __ANDROID__
        m_cache_hold_aux1 = false;      // This is initialised properly later
@@ -1704,6 +1712,21 @@ Game::~Game()
        delete draw_control;
 
        extendedResourceCleanup();
+
+       g_settings->deregisterChangedCallback("doubletap_jump",
+               &settingChangedCallback, this);
+       g_settings->deregisterChangedCallback("enable_node_highlighting",
+               &settingChangedCallback, this);
+       g_settings->deregisterChangedCallback("enable_clouds",
+               &settingChangedCallback, this);
+       g_settings->deregisterChangedCallback("enable_particles",
+               &settingChangedCallback, this);
+       g_settings->deregisterChangedCallback("enable_fog",
+               &settingChangedCallback, this);
+       g_settings->deregisterChangedCallback("mouse_sensitivity",
+               &settingChangedCallback, this);
+       g_settings->deregisterChangedCallback("repeat_rightclick_time",
+               &settingChangedCallback, this);
 }
 
 bool Game::startup(bool *kill,
@@ -1716,17 +1739,19 @@ bool Game::startup(bool *kill,
                std::string *address,     // can change if simple_singleplayer_mode
                u16 port,
                std::string &error_message,
+               bool *reconnect,
                ChatBackend *chat_backend,
                const SubgameSpec &gamespec,
                bool simple_singleplayer_mode)
 {
        // "cache"
-       this->device        = device;
-       this->kill          = kill;
-       this->error_message = &error_message;
-       this->random_input  = random_input;
-       this->input         = input;
-       this->chat_backend  = chat_backend;
+       this->device              = device;
+       this->kill                = kill;
+       this->error_message       = &error_message;
+       this->reconnect_requested = reconnect;
+       this->random_input        = random_input;
+       this->input               = input;
+       this->chat_backend        = chat_backend;
        this->simple_singleplayer_mode = simple_singleplayer_mode;
 
        driver              = device->getVideoDriver();
@@ -1832,6 +1857,9 @@ void Game::run()
                updateFrame(highlight_boxes, &graph, &stats, &runData, dtime,
                                flags, cam_view);
                updateProfilerGraphs(&graph);
+
+               // Update if minimap has been disabled by the server
+               flags.show_minimap &= !client->isMinimapDisabledByServer();
        }
 }
 
@@ -2239,6 +2267,7 @@ bool Game::connectToServer(const std::string &playername,
                        if (client->accessDenied()) {
                                *error_message = "Access denied. Reason: "
                                                + client->accessDeniedReason();
+                               *reconnect_requested = client->reconnectRequested();
                                errorstream << *error_message << std::endl;
                                break;
                        }
@@ -2376,6 +2405,7 @@ inline bool Game::checkConnection()
        if (client->accessDenied()) {
                *error_message = "Access denied. Reason: "
                                + client->accessDeniedReason();
+               *reconnect_requested = client->reconnectRequested();
                errorstream << *error_message << std::endl;
                return false;
        }
@@ -2615,7 +2645,7 @@ void Game::processKeyboardInput(VolatileRunFlags *flags,
        } else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_TOGGLE_HUD])) {
                toggleHud(statustext_time, &flags->show_hud);
        } else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_MINIMAP])) {
-               toggleMinimap(statustext_time, &flags->show_minimap, &flags->show_hud,
+               toggleMinimap(statustext_time, &flags->show_minimap, flags->show_hud,
                        input->isKeyDown(keycache.key[KeyCache::KEYMAP_ID_SNEAK]));
        } else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_TOGGLE_CHAT])) {
                toggleChat(statustext_time, &flags->show_chat);
@@ -2837,43 +2867,54 @@ void Game::toggleHud(float *statustext_time, bool *flag)
                client->setHighlighted(client->getHighlighted(), *flag);
 }
 
-void Game::toggleMinimap(float *statustext_time, bool *flag, bool *show_hud, bool shift_pressed)
+void Game::toggleMinimap(float *statustext_time, bool *flag,
+       bool show_hud, bool shift_pressed)
 {
-       if (*show_hud && g_settings->getBool("enable_minimap")) {
-               if (shift_pressed) {
-                       mapper->toggleMinimapShape();
-                       return;
-               }
-               MinimapMode mode = mapper->getMinimapMode();
-               mode = (MinimapMode)((int)(mode) + 1);
-               *flag = true;
-               switch (mode) {
-                       case MINIMAP_MODE_SURFACEx1:
-                               statustext = L"Minimap in surface mode, Zoom x1";
-                               break;
-                       case MINIMAP_MODE_SURFACEx2:
-                               statustext = L"Minimap in surface mode, Zoom x2";
-                               break;
-                       case MINIMAP_MODE_SURFACEx4:
-                               statustext = L"Minimap in surface mode, Zoom x4";
-                               break;
-                       case MINIMAP_MODE_RADARx1:
-                               statustext = L"Minimap in radar mode, Zoom x1";
-                               break;
-                       case MINIMAP_MODE_RADARx2:
-                               statustext = L"Minimap in radar mode, Zoom x2";
-                               break;
-                       case MINIMAP_MODE_RADARx4:
-                               statustext = L"Minimap in radar mode, Zoom x4";
-                               break;
-                       default:
-                               mode = MINIMAP_MODE_OFF;
-                               *flag = false;
-                               statustext = L"Minimap hidden";
-               }
-               *statustext_time = 0;
-               mapper->setMinimapMode(mode);
+       if (!show_hud || !g_settings->getBool("enable_minimap"))
+               return;
+
+       if (shift_pressed) {
+               mapper->toggleMinimapShape();
+               return;
        }
+
+       u32 hud_flags = client->getEnv().getLocalPlayer()->hud_flags;
+
+       MinimapMode mode = MINIMAP_MODE_OFF;
+       if (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) {
+               mode = mapper->getMinimapMode();
+               mode = (MinimapMode)((int)mode + 1);
+       }
+
+       *flag = true;
+       switch (mode) {
+               case MINIMAP_MODE_SURFACEx1:
+                       statustext = L"Minimap in surface mode, Zoom x1";
+                       break;
+               case MINIMAP_MODE_SURFACEx2:
+                       statustext = L"Minimap in surface mode, Zoom x2";
+                       break;
+               case MINIMAP_MODE_SURFACEx4:
+                       statustext = L"Minimap in surface mode, Zoom x4";
+                       break;
+               case MINIMAP_MODE_RADARx1:
+                       statustext = L"Minimap in radar mode, Zoom x1";
+                       break;
+               case MINIMAP_MODE_RADARx2:
+                       statustext = L"Minimap in radar mode, Zoom x2";
+                       break;
+               case MINIMAP_MODE_RADARx4:
+                       statustext = L"Minimap in radar mode, Zoom x4";
+                       break;
+               default:
+                       mode = MINIMAP_MODE_OFF;
+                       *flag = false;
+                       statustext = (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) ?
+                               L"Minimap hidden" : L"Minimap disabled by server";
+       }
+
+       *statustext_time = 0;
+       mapper->setMinimapMode(mode);
 }
 
 void Game::toggleFog(float *statustext_time, bool *flag)
@@ -4282,6 +4323,23 @@ void Game::showOverlayMessage(const wchar_t *msg, float dtime,
        delete[] msg;
 }
 
+void Game::settingChangedCallback(const std::string &setting_name, void *data)
+{
+       ((Game *)data)->readSettings();
+}
+
+void Game::readSettings()
+{
+       m_cache_doubletap_jump            = g_settings->getBool("doubletap_jump");
+       m_cache_enable_node_highlighting  = g_settings->getBool("enable_node_highlighting");
+       m_cache_enable_clouds             = g_settings->getBool("enable_clouds");
+       m_cache_enable_particles          = g_settings->getBool("enable_particles");
+       m_cache_enable_fog                = g_settings->getBool("enable_fog");
+       m_cache_mouse_sensitivity         = g_settings->getFloat("mouse_sensitivity");
+       m_repeat_right_click_time         = g_settings->getFloat("repeat_rightclick_time");
+
+       m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);
+}
 
 /****************************************************************************/
 /****************************************************************************
@@ -4330,6 +4388,7 @@ void the_game(bool *kill,
 
                std::string &error_message,
                ChatBackend &chat_backend,
+               bool *reconnect_requested,
                const SubgameSpec &gamespec,        // Used for local game
                bool simple_singleplayer_mode)
 {
@@ -4344,8 +4403,8 @@ void the_game(bool *kill,
        try {
 
                if (game.startup(kill, random_input, input, device, map_dir,
-                               playername, password, &server_address, port,
-                               error_message, &chat_backend, gamespec,
+                               playername, password, &server_address, port, error_message,
+                               reconnect_requested, &chat_backend, gamespec,
                                simple_singleplayer_mode)) {
                        game.run();
                        game.shutdown();