]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/game.cpp
Use thread_local instead from some static settings (#5955)
[dragonfireclient.git] / src / game.cpp
index f967e349cd7885361fee659dd732d22de32b6665..c32ab6f30d48dd4044a677f275bc06421cea39eb 100644 (file)
@@ -1033,7 +1033,7 @@ void KeyCache::populate()
        key[KeyType::SPECIAL1]     = getKeySetting("keymap_special1");
        key[KeyType::SNEAK]        = getKeySetting("keymap_sneak");
 
-       key[KeyType::AUTORUN]      = getKeySetting("keymap_autorun");
+       key[KeyType::AUTOFORWARD]  = getKeySetting("keymap_autoforward");
 
        key[KeyType::DROP]         = getKeySetting("keymap_drop");
        key[KeyType::INVENTORY]    = getKeySetting("keymap_inventory");
@@ -1238,7 +1238,7 @@ class Game {
        void toggleFast();
        void toggleNoClip();
        void toggleCinematic();
-       void toggleAutorun();
+       void toggleAutoforward();
 
        void toggleChat();
        void toggleHud();
@@ -1633,8 +1633,8 @@ void Game::run()
                        && client->checkPrivilege("fast");
 #endif
 
-       irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screenW"),
-               g_settings->getU16("screenH"));
+       irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screen_w"),
+               g_settings->getU16("screen_h"));
 
        while (device->run()
                        && !(*kill || g_gamecallback->shutdown_requested
@@ -1648,8 +1648,8 @@ void Game::run()
                if (previous_screen_size != current_screen_size &&
                                current_screen_size != irr::core::dimension2d<u32>(0,0) &&
                                g_settings->getBool("autosave_screensize")) {
-                       g_settings->setU16("screenW", current_screen_size.Width);
-                       g_settings->setU16("screenH", current_screen_size.Height);
+                       g_settings->setU16("screen_w", current_screen_size.Width);
+                       g_settings->setU16("screen_h", current_screen_size.Height);
                        previous_screen_size = current_screen_size;
                }
 
@@ -1701,6 +1701,8 @@ void Game::shutdown()
                driver->setRenderTarget(irr::video::ERT_STEREO_BOTH_BUFFERS);
        }
 #endif
+       if (current_formspec)
+               current_formspec->quitMenu();
 
        showOverlayMessage(wgettext("Shutting down..."), 0, 0, false);
 
@@ -2471,8 +2473,8 @@ void Game::processKeyInput()
 {
        if (wasKeyDown(KeyType::DROP)) {
                dropSelectedItem();
-       } else if (wasKeyDown(KeyType::AUTORUN)) {
-               toggleAutorun();
+       } else if (wasKeyDown(KeyType::AUTOFORWARD)) {
+               toggleAutoforward();
        } else if (wasKeyDown(KeyType::INVENTORY)) {
                openInventory();
        } else if (wasKeyDown(KeyType::ESC) || input->wasKeyDown(CancelKey)) {
@@ -2753,15 +2755,15 @@ void Game::toggleCinematic()
        m_statustext = msg[cinematic];
 }
 
-// Add WoW-style autorun by toggling continuous forward.
-void Game::toggleAutorun()
+// Autoforward by toggling continuous forward.
+void Game::toggleAutoforward()
 {
-       static const wchar_t *msg[] = { L"autorun disabled", L"autorun enabled" };
-       bool autorun_enabled = !g_settings->getBool("continuous_forward");
-       g_settings->set("continuous_forward", bool_to_cstr(autorun_enabled));
+       static const wchar_t *msg[] = { L"autoforward disabled", L"autoforward enabled" };
+       bool autoforward_enabled = !g_settings->getBool("continuous_forward");
+       g_settings->set("continuous_forward", bool_to_cstr(autoforward_enabled));
 
        runData.statustext_time = 0;
-       m_statustext = msg[autorun_enabled ? 1 : 0];
+       m_statustext = msg[autoforward_enabled ? 1 : 0];
 }
 
 void Game::toggleChat()
@@ -3229,8 +3231,7 @@ void Game::processClientEvents(CameraOrientation *cam)
                        {
                                HudElement *e = player->removeHud(event.hudrm.id);
 
-                               if (e != NULL)
-                                       delete e;
+                               delete e;
                        }
                        break;
 
@@ -3595,7 +3596,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
        } else if (pointed.type == POINTEDTHING_NODE) {
                ToolCapabilities playeritem_toolcap =
                                playeritem.getToolCapabilities(itemdef_manager);
-               if (playeritem.name.empty()) {
+               if (playeritem.name.empty() && hand_def.tool_capabilities != NULL) {
                        playeritem_toolcap = *hand_def.tool_capabilities;
                }
                handlePointingAtNode(pointed, playeritem_def, playeritem_toolcap, dtime);
@@ -3636,7 +3637,7 @@ PointedThing Game::updatePointedThing(
        std::vector<aabb3f> *selectionboxes = hud->getSelectionBoxes();
        selectionboxes->clear();
        hud->setSelectedFaceNormal(v3f(0.0, 0.0, 0.0));
-       static const bool show_entity_selectionbox = g_settings->getBool(
+       static thread_local const bool show_entity_selectionbox = g_settings->getBool(
                "show_entity_selectionbox");
 
        ClientMap &map = client->getEnv().getClientMap();
@@ -3744,6 +3745,13 @@ void Game::handlePointingAtNode(const PointedThing &pointed, const ItemDefinitio
        */
 
        ClientMap &map = client->getEnv().getClientMap();
+
+       if (runData.nodig_delay_timer <= 0.0 && isLeftPressed()
+                       && client->checkPrivilege("interact")) {
+               handleDigging(pointed, nodepos, playeritem_toolcap, dtime);
+       }
+
+       // This should be done after digging handling
        NodeMetadata *meta = map.getNodeMetadata(nodepos);
 
        if (meta) {
@@ -3757,11 +3765,6 @@ void Game::handlePointingAtNode(const PointedThing &pointed, const ItemDefinitio
                }
        }
 
-       if (runData.nodig_delay_timer <= 0.0 && isLeftPressed()
-                       && client->checkPrivilege("interact")) {
-               handleDigging(pointed, nodepos, playeritem_toolcap, dtime);
-       }
-
        if ((getRightClicked() ||
                        runData.repeat_rightclick_timer >= m_repeat_right_click_time) &&
                        client->checkPrivilege("interact")) {
@@ -3903,16 +3906,6 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
                        params = getDigParams(nodedef_manager->get(n).groups, tp);
        }
 
-       if (!runData.digging) {
-               infostream << "Started digging" << std::endl;
-               runData.dig_instantly = params.time == 0;
-               if (client->moddingEnabled() && client->getScript()->on_punchnode(nodepos, n))
-                       return;
-               client->interact(0, pointed);
-               runData.digging = true;
-               runData.ldown_for_dig = true;
-       }
-
        if (!params.diggable) {
                // I guess nobody will wait for this long
                runData.dig_time_complete = 10000000.0;
@@ -3927,6 +3920,16 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
                }
        }
 
+       if (!runData.digging) {
+               infostream << "Started digging" << std::endl;
+               runData.dig_instantly = runData.dig_time_complete == 0;
+               if (client->moddingEnabled() && client->getScript()->on_punchnode(nodepos, n))
+                       return;
+               client->interact(0, pointed);
+               runData.digging = true;
+               runData.ldown_for_dig = true;
+       }
+
        if (!runData.dig_instantly) {
                runData.dig_index = (float)crack_animation_length
                                * runData.dig_time
@@ -3977,10 +3980,9 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
                bool is_valid_position;
                MapNode wasnode = map.getNodeNoEx(nodepos, &is_valid_position);
                if (is_valid_position) {
-                       if (client->moddingEnabled()) {
-                               if (client->getScript()->on_dignode(nodepos, wasnode)) {
-                                       return;
-                               }
+                       if (client->moddingEnabled() &&
+                                       client->getScript()->on_dignode(nodepos, wasnode)) {
+                               return;
                        }
                        client->removeNode(nodepos);
                }