]> git.lizzy.rs Git - minetest.git/blobdiff - src/game.cpp
Remove legacy unused define DIGGING_PARTICLES_AMOUNT
[minetest.git] / src / game.cpp
index 6ef471c9e6e4be78cfcdf1088c5350c3ff297efe..12fe6a6e9480b6ecfb73ec25755379ed7de2cf2f 100644 (file)
@@ -60,7 +60,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "version.h"
 #include "minimap.h"
 #include "mapblock_mesh.h"
-#include "script/clientscripting.h"
+#include "script/scripting_client.h"
 
 #include "sound.h"
 
@@ -79,14 +79,15 @@ extern Profiler *g_profiler;
        Text input system
 */
 
-struct TextDestNodeMetadata : public TextDest {
+struct TextDestNodeMetadata : public TextDest
+{
        TextDestNodeMetadata(v3s16 p, Client *client)
        {
                m_p = p;
                m_client = client;
        }
        // This is deprecated I guess? -celeron55
-       void gotText(std::wstring text)
+       void gotText(const std::wstring &text)
        {
                std::string ntext = wide_to_utf8(text);
                infostream << "Submitting 'text' field of node at (" << m_p.X << ","
@@ -104,13 +105,14 @@ struct TextDestNodeMetadata : public TextDest {
        Client *m_client;
 };
 
-struct TextDestPlayerInventory : public TextDest {
+struct TextDestPlayerInventory : public TextDest
+{
        TextDestPlayerInventory(Client *client)
        {
                m_client = client;
                m_formname = "";
        }
-       TextDestPlayerInventory(Client *client, std::string formname)
+       TextDestPlayerInventory(Client *client, const std::string &formname)
        {
                m_client = client;
                m_formname = formname;
@@ -125,23 +127,18 @@ struct TextDestPlayerInventory : public TextDest {
 
 struct LocalFormspecHandler : public TextDest
 {
-       LocalFormspecHandler(std::string formname):
-               m_client(0)
+       LocalFormspecHandler(const std::string &formname):
+               m_client(NULL)
        {
                m_formname = formname;
        }
 
-       LocalFormspecHandler(std::string formname, Client *client):
+       LocalFormspecHandler(const std::string &formname, Client *client):
                m_client(client)
        {
                m_formname = formname;
        }
 
-       void gotText(std::wstring message)
-       {
-               errorstream << "LocalFormspecHandler::gotText old style message received" << std::endl;
-       }
-
        void gotText(const StringMap &fields)
        {
                if (m_formname == "MT_PAUSE_MENU") {
@@ -205,7 +202,8 @@ class NodeMetadataFormSource: public IFormSource
 
                return meta->getString("formspec");
        }
-       std::string resolveText(std::string str)
+
+       virtual std::string resolveText(const std::string &str)
        {
                NodeMetadata *meta = m_map->getNodeMetadata(m_p);
 
@@ -569,27 +567,35 @@ class SoundMaker
 class GameOnDemandSoundFetcher: public OnDemandSoundFetcher
 {
        std::set<std::string> m_fetched;
+private:
+       void paths_insert(std::set<std::string> &dst_paths,
+               const std::string &base,
+               const std::string &name)
+       {
+               dst_paths.insert(base + DIR_DELIM + "sounds" + DIR_DELIM + name + ".ogg");
+               dst_paths.insert(base + DIR_DELIM + "sounds" + DIR_DELIM + name + ".0.ogg");
+               dst_paths.insert(base + DIR_DELIM + "sounds" + DIR_DELIM + name + ".1.ogg");
+               dst_paths.insert(base + DIR_DELIM + "sounds" + DIR_DELIM + name + ".2.ogg");
+               dst_paths.insert(base + DIR_DELIM + "sounds" + DIR_DELIM + name + ".3.ogg");
+               dst_paths.insert(base + DIR_DELIM + "sounds" + DIR_DELIM + name + ".4.ogg");
+               dst_paths.insert(base + DIR_DELIM + "sounds" + DIR_DELIM + name + ".5.ogg");
+               dst_paths.insert(base + DIR_DELIM + "sounds" + DIR_DELIM + name + ".6.ogg");
+               dst_paths.insert(base + DIR_DELIM + "sounds" + DIR_DELIM + name + ".7.ogg");
+               dst_paths.insert(base + DIR_DELIM + "sounds" + DIR_DELIM + name + ".8.ogg");
+               dst_paths.insert(base + DIR_DELIM + "sounds" + DIR_DELIM + name + ".9.ogg");
+       }
 public:
        void fetchSounds(const std::string &name,
-                       std::set<std::string> &dst_paths,
-                       std::set<std::string> &dst_datas)
+               std::set<std::string> &dst_paths,
+               std::set<std::string> &dst_datas)
        {
                if (m_fetched.count(name))
                        return;
 
                m_fetched.insert(name);
-               std::string base = porting::path_share + DIR_DELIM + "sounds";
-               dst_paths.insert(base + DIR_DELIM + name + ".ogg");
-               dst_paths.insert(base + DIR_DELIM + name + ".0.ogg");
-               dst_paths.insert(base + DIR_DELIM + name + ".1.ogg");
-               dst_paths.insert(base + DIR_DELIM + name + ".2.ogg");
-               dst_paths.insert(base + DIR_DELIM + name + ".3.ogg");
-               dst_paths.insert(base + DIR_DELIM + name + ".4.ogg");
-               dst_paths.insert(base + DIR_DELIM + name + ".5.ogg");
-               dst_paths.insert(base + DIR_DELIM + name + ".6.ogg");
-               dst_paths.insert(base + DIR_DELIM + name + ".7.ogg");
-               dst_paths.insert(base + DIR_DELIM + name + ".8.ogg");
-               dst_paths.insert(base + DIR_DELIM + name + ".9.ogg");
+
+               paths_insert(dst_paths, porting::path_share, name);
+               paths_insert(dst_paths, porting::path_user,  name);
        }
 };
 
@@ -1111,6 +1117,7 @@ struct GameRunData {
        PointedThing pointed_old;
        bool digging;
        bool ldown_for_dig;
+       bool dig_instantly;
        bool left_punch;
        bool update_wielded_item_trigger;
        bool reset_jump_timer;
@@ -1190,7 +1197,7 @@ class Game {
                        u16 port,
                        const SubgameSpec &gamespec);
        bool initSound();
-       bool createSingleplayerServer(const std::string map_dir,
+       bool createSingleplayerServer(const std::string &map_dir,
                        const SubgameSpec &gamespec, u16 port, std::string *address);
 
        // Client creation
@@ -1725,9 +1732,10 @@ bool Game::init(
                u16 port,
                const SubgameSpec &gamespec)
 {
+       texture_src = createTextureSource(device);
+
        showOverlayMessage(wgettext("Loading..."), 0, 0);
 
-       texture_src = createTextureSource(device);
        shader_src = createShaderSource(device);
 
        itemdef_manager = createItemDefManager();
@@ -1779,7 +1787,7 @@ bool Game::initSound()
        return true;
 }
 
-bool Game::createSingleplayerServer(const std::string map_dir,
+bool Game::createSingleplayerServer(const std::string &map_dir,
                const SubgameSpec &gamespec, u16 port, std::string *address)
 {
        showOverlayMessage(wgettext("Creating server..."), 0, 5);
@@ -2183,12 +2191,14 @@ bool Game::getServerContent(bool *aborted)
                if (!client->itemdefReceived()) {
                        const wchar_t *text = wgettext("Item definitions...");
                        progress = 25;
-                       draw_load_screen(text, device, guienv, dtime, progress);
+                       draw_load_screen(text, device, guienv, texture_src,
+                               dtime, progress);
                        delete[] text;
                } else if (!client->nodedefReceived()) {
                        const wchar_t *text = wgettext("Node definitions...");
                        progress = 30;
-                       draw_load_screen(text, device, guienv, dtime, progress);
+                       draw_load_screen(text, device, guienv, texture_src,
+                               dtime, progress);
                        delete[] text;
                } else {
                        std::stringstream message;
@@ -2212,7 +2222,7 @@ bool Game::getServerContent(bool *aborted)
 
                        progress = 30 + client->mediaReceiveProgress() * 35 + 0.5;
                        draw_load_screen(utf8_to_wide(message.str()), device,
-                                       guienv, dtime, progress);
+                                       guienv, texture_src, dtime, progress);
                }
        }
 
@@ -3486,6 +3496,10 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
                        client->setCrack(-1, v3s16(0, 0, 0));
                        runData.dig_time = 0.0;
                }
+       } else if (runData.dig_instantly && getLeftReleased()) {
+               // Remove e.g. torches faster when clicking instead of holding LMB
+               runData.nodig_delay_timer = 0;
+               runData.dig_instantly = false;
        }
 
        if (!runData.digging && runData.ldown_for_dig && !isLeftPressed()) {
@@ -3716,6 +3730,9 @@ void Game::handlePointingAtNode(const PointedThing &pointed, const ItemDefinitio
                                // Read the sound
                                soundmaker->m_player_rightpunch_sound =
                                                playeritem_def.sound_place;
+
+                               if (client->moddingEnabled())
+                                       client->getScript()->on_placenode(pointed, playeritem_def);
                        } else {
                                soundmaker->m_player_rightpunch_sound =
                                                SimpleSoundSpec();
@@ -3798,15 +3815,6 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
        ClientMap &map = client->getEnv().getClientMap();
        MapNode n = client->getEnv().getClientMap().getNodeNoEx(nodepos);
 
-       if (!runData.digging) {
-               infostream << "Started digging" << std::endl;
-               if (client->moddingEnabled() && client->getScript()->on_punchnode(nodepos, n))
-                       return;
-               client->interact(0, pointed);
-               runData.digging = true;
-               runData.ldown_for_dig = true;
-       }
-
        // NOTE: Similar piece of code exists on the server side for
        // cheat detection.
        // Get digging parameters
@@ -3824,6 +3832,16 @@ 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;
@@ -3838,12 +3856,12 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
                }
        }
 
-       if (runData.dig_time_complete >= 0.001) {
+       if (!runData.dig_instantly) {
                runData.dig_index = (float)crack_animation_length
                                * runData.dig_time
                                / runData.dig_time_complete;
        } else {
-               // This is for torches
+               // This is for e.g. torches
                runData.dig_index = crack_animation_length;
        }
 
@@ -3878,17 +3896,12 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
                runData.nodig_delay_timer =
                                runData.dig_time_complete / (float)crack_animation_length;
 
-               // We don't want a corresponding delay to
-               // very time consuming nodes
+               // We don't want a corresponding delay to very time consuming nodes
+               // and nodes without digging time (e.g. torches) get a fixed delay.
                if (runData.nodig_delay_timer > 0.3)
                        runData.nodig_delay_timer = 0.3;
-
-               // We want a slight delay to very little
-               // time consuming nodes
-               const float mindelay = 0.15;
-
-               if (runData.nodig_delay_timer < mindelay)
-                       runData.nodig_delay_timer = mindelay;
+               else if (runData.dig_instantly)
+                       runData.nodig_delay_timer = 0.15;
 
                bool is_valid_position;
                MapNode wasnode = map.getNodeNoEx(nodepos, &is_valid_position);
@@ -4357,7 +4370,8 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime)
 void Game::showOverlayMessage(const wchar_t *msg, float dtime,
                int percent, bool draw_clouds)
 {
-       draw_load_screen(msg, device, guienv, dtime, percent, draw_clouds);
+       draw_load_screen(msg, device, guienv, texture_src, dtime, percent,
+               draw_clouds);
        delete[] msg;
 }