]> git.lizzy.rs Git - minetest.git/blobdiff - src/game.cpp
Mgvalleys: use standard caves
[minetest.git] / src / game.cpp
index 36945f343aa0ed411deaca7a5bf8cb3f3d1f2652..3902c50bba3d4e863c5e025f428a5968c5cdfaee 100644 (file)
@@ -489,7 +489,7 @@ class ProfilerGraph
                        color(color)
                {}
        };
-       std::vector<Piece> m_log;
+       std::deque<Piece> m_log;
 public:
        u32 m_log_max_size;
 
@@ -512,7 +512,7 @@ class ProfilerGraph
        {
                std::map<std::string, Meta> m_meta;
 
-               for (std::vector<Piece>::const_iterator k = m_log.begin();
+               for (std::deque<Piece>::const_iterator k = m_log.begin();
                                k != m_log.end(); ++k) {
                        const Piece &piece = *k;
 
@@ -600,7 +600,7 @@ class ProfilerGraph
                        float lastscaledvalue = 0.0;
                        bool lastscaledvalue_exists = false;
 
-                       for (std::vector<Piece>::const_iterator j = m_log.begin();
+                       for (std::deque<Piece>::const_iterator j = m_log.begin();
                                        j != m_log.end(); ++j) {
                                const Piece &piece = *j;
                                float value = 0;
@@ -1234,6 +1234,7 @@ struct KeyCache {
                KEYMAP_ID_JUMP,
                KEYMAP_ID_SPECIAL1,
                KEYMAP_ID_SNEAK,
+               KEYMAP_ID_AUTORUN,
 
                // Other
                KEYMAP_ID_DROP,
@@ -1286,6 +1287,8 @@ void KeyCache::populate()
        key[KEYMAP_ID_SPECIAL1]     = getKeySetting("keymap_special1");
        key[KEYMAP_ID_SNEAK]        = getKeySetting("keymap_sneak");
 
+       key[KEYMAP_ID_AUTORUN]      = getKeySetting("keymap_autorun");
+
        key[KEYMAP_ID_DROP]         = getKeySetting("keymap_drop");
        key[KEYMAP_ID_INVENTORY]    = getKeySetting("keymap_inventory");
        key[KEYMAP_ID_CHAT]         = getKeySetting("keymap_chat");
@@ -1493,6 +1496,7 @@ class Game {
        void toggleFast(float *statustext_time);
        void toggleNoClip(float *statustext_time);
        void toggleCinematic(float *statustext_time);
+       void toggleAutorun(float *statustext_time);
 
        void toggleChat(float *statustext_time, bool *flag);
        void toggleHud(float *statustext_time, bool *flag);
@@ -1521,6 +1525,7 @@ class Game {
        void processPlayerInteraction(std::vector<aabb3f> &highlight_boxes,
                        GameRunData *runData, f32 dtime, bool show_hud,
                        bool show_debug);
+       void handlePointingAtNothing(GameRunData *runData, const ItemStack &playerItem);
        void handlePointingAtNode(GameRunData *runData,
                        const PointedThing &pointed, const ItemDefinition &playeritem_def,
                        const ToolCapabilities &playeritem_toolcap, f32 dtime);
@@ -1811,7 +1816,9 @@ void Game::run()
                        && client->checkPrivilege("fast");
 #endif
 
-       while (device->run() && !(*kill || g_gamecallback->shutdown_requested)) {
+       while (device->run()
+                       && !(*kill || g_gamecallback->shutdown_requested
+                       || (server && server->getShutdownRequested()))) {
 
                /* Must be called immediately after a device->run() call because it
                 * uses device->getTimer()->getTime()
@@ -1865,6 +1872,10 @@ void Game::run()
 
 void Game::shutdown()
 {
+       if (g_settings->get("3d_mode") == "pageflip") {
+               driver->setRenderTarget(irr::video::ERT_STEREO_BOTH_BUFFERS);
+       }
+
        showOverlayMessage(wgettext("Shutting down..."), 0, 0, false);
 
        if (clouds)
@@ -2168,7 +2179,7 @@ bool Game::initGui()
 #ifdef HAVE_TOUCHSCREENGUI
 
        if (g_touchscreengui)
-               g_touchscreengui->init(texture_src, porting::getDisplayDensity());
+               g_touchscreengui->init(texture_src);
 
 #endif
 
@@ -2564,7 +2575,17 @@ void Game::processUserInput(VolatileRunFlags *flags,
                        || noMenuActive() == false
                        || guienv->hasFocus(gui_chat_console)) {
                input->clear();
+#ifdef HAVE_TOUCHSCREENGUI
+               g_touchscreengui->hide();
+#endif
+       }
+#ifdef HAVE_TOUCHSCREENGUI
+       else if (g_touchscreengui) {
+               /* on touchscreengui step may generate own input events which ain't
+                * what we want in case we just did clear them */
+               g_touchscreengui->step(dtime);
        }
+#endif
 
        if (!guienv->hasFocus(gui_chat_console) && gui_chat_console->isOpen()) {
                gui_chat_console->closeConsoleAtOnce();
@@ -2573,13 +2594,6 @@ void Game::processUserInput(VolatileRunFlags *flags,
        // Input handler step() (used by the random input generator)
        input->step(dtime);
 
-#ifdef HAVE_TOUCHSCREENGUI
-
-       if (g_touchscreengui) {
-               g_touchscreengui->step(dtime);
-       }
-
-#endif
 #ifdef __ANDROID__
 
        if (current_formspec != 0)
@@ -2615,6 +2629,8 @@ void Game::processKeyboardInput(VolatileRunFlags *flags,
 
        if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_DROP])) {
                dropSelectedItem();
+       } else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_AUTORUN])) {
+               toggleAutorun(statustext_time);
        } else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_INVENTORY])) {
                openInventory();
        } else if (input->wasKeyDown(EscapeKey) || input->wasKeyDown(CancelKey)) {
@@ -2844,6 +2860,16 @@ void Game::toggleCinematic(float *statustext_time)
        statustext = msg[cinematic];
 }
 
+// Add WoW-style autorun by toggling continuous forward.
+void Game::toggleAutorun(float *statustext_time)
+{
+       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));
+
+       *statustext_time = 0;
+       statustext = msg[autorun_enabled ? 1 : 0];
+}
 
 void Game::toggleChat(float *statustext_time, bool *flag)
 {
@@ -3587,6 +3613,8 @@ void Game::processPlayerInteraction(std::vector<aabb3f> &highlight_boxes,
        } else if (input->getLeftState()) {
                // When button is held down in air, show continuous animation
                runData->left_punch = true;
+       } else if (input->getRightClicked()) {
+               handlePointingAtNothing(runData, playeritem);
        }
 
        runData->pointed_old = pointed;
@@ -3602,6 +3630,15 @@ void Game::processPlayerInteraction(std::vector<aabb3f> &highlight_boxes,
 }
 
 
+void Game::handlePointingAtNothing(GameRunData *runData, const ItemStack &playerItem)
+{
+       infostream << "Right Clicked in Air" << std::endl;
+       PointedThing fauxPointed;
+       fauxPointed.type = POINTEDTHING_NOTHING;
+       client->interact(5, fauxPointed);
+}
+
+
 void Game::handlePointingAtNode(GameRunData *runData,
                const PointedThing &pointed, const ItemDefinition &playeritem_def,
                const ToolCapabilities &playeritem_toolcap, f32 dtime)
@@ -3675,8 +3712,12 @@ void Game::handlePointingAtNode(GameRunData *runData,
                                                SimpleSoundSpec();
 
                                if (playeritem_def.node_placement_prediction == "" ||
-                                               nodedef_manager->get(map.getNodeNoEx(nodepos)).rightclickable)
+                                               nodedef_manager->get(map.getNodeNoEx(nodepos)).rightclickable) {
                                        client->interact(3, pointed); // Report to server
+                               } else {
+                                       soundmaker->m_player_rightpunch_sound =
+                                               playeritem_def.sound_place_failed;
+                               }
                        }
                }
        }
@@ -3691,8 +3732,11 @@ void Game::handlePointingAtObject(GameRunData *runData,
 {
        infotext = utf8_to_wide(runData->selected_object->infoText());
 
-       if (infotext == L"" && show_debug) {
-               infotext = utf8_to_wide(runData->selected_object->debugInfoText());
+       if (show_debug) {
+               if (infotext != L"") {
+                       infotext += L"\n";
+               }
+               infotext += utf8_to_wide(runData->selected_object->debugInfoText());
        }
 
        if (input->getLeftState()) {