]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/game.cpp
Add dtime_s to entity activation
[dragonfireclient.git] / src / game.cpp
index e2e6dd8c1774df7eec004603ae68b5a6e18feab7..a1a197219f4bad5b0c03d013aa0f6a859d17edfd 100644 (file)
@@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "server.h"
 #include "guiPauseMenu.h"
 #include "guiPasswordChange.h"
-#include "guiInventoryMenu.h"
+#include "guiFormSpecMenu.h"
 #include "guiTextInputMenu.h"
 #include "guiDeathScreen.h"
 #include "tool.h"
@@ -77,6 +77,10 @@ struct TextDestChat : public TextDest
        {
                m_client->typeChatMessage(text);
        }
+       void gotText(std::map<std::string, std::string> fields)
+       {
+               m_client->typeChatMessage(narrow_to_wide(fields["text"]));
+       }
 
        Client *m_client;
 };
@@ -88,20 +92,39 @@ struct TextDestNodeMetadata : public TextDest
                m_p = p;
                m_client = client;
        }
+       // This is deprecated I guess? -celeron55
        void gotText(std::wstring text)
        {
                std::string ntext = wide_to_narrow(text);
-               infostream<<"Changing text of a sign node: "
-                               <<ntext<<std::endl;
+               infostream<<"Submitting 'text' field of node at ("<<m_p.X<<","
+                               <<m_p.Y<<","<<m_p.Z<<"): "<<ntext<<std::endl;
                std::map<std::string, std::string> fields;
                fields["text"] = ntext;
                m_client->sendNodemetaFields(m_p, "", fields);
        }
+       void gotText(std::map<std::string, std::string> fields)
+       {
+               m_client->sendNodemetaFields(m_p, "", fields);
+       }
 
        v3s16 m_p;
        Client *m_client;
 };
 
+struct TextDestPlayerInventory : public TextDest
+{
+       TextDestPlayerInventory(Client *client)
+       {
+               m_client = client;
+       }
+       void gotText(std::map<std::string, std::string> fields)
+       {
+               m_client->sendInventoryFields("", fields);
+       }
+
+       Client *m_client;
+};
+
 /* Respawn menu callback */
 
 class MainRespawnInitiator: public IRespawnInitiator
@@ -139,6 +162,13 @@ class NodeMetadataFormSource: public IFormSource
                        return "";
                return meta->getString("formspec");
        }
+       std::string resolveText(std::string str)
+       {
+               NodeMetadata *meta = m_map->getNodeMetadata(m_p);
+               if(!meta)
+                       return str;
+               return meta->resolveString(str);
+       }
 
        ClientMap *m_map;
        v3s16 m_p;
@@ -367,6 +397,14 @@ PointedThing getPointedThing(Client *client, v3f player_position,
        s16 zend = pos_i.Z + (camera_direction.Z>0 ? a : 1);
        s16 xend = pos_i.X + (camera_direction.X>0 ? a : 1);
        
+       // Prevent signed number overflow
+       if(yend==32767)
+               yend=32766;
+       if(zend==32767)
+               zend=32766;
+       if(xend==32767)
+               xend=32766;
+
        for(s16 y = ystart; y <= yend; y++)
        for(s16 z = zstart; z <= zend; z++)
        for(s16 x = xstart; x <= xend; x++)
@@ -1197,6 +1235,9 @@ void the_game(
        float object_hit_delay_timer = 0.0;
        float time_from_last_punch = 10;
 
+       float update_draw_list_timer = 0.0;
+       v3f update_draw_list_last_cam_dir;
+
        bool invert_mouse = g_settings->getBool("invert_mouse");
 
        bool respawn_menu_active = false;
@@ -1471,8 +1512,8 @@ void the_game(
                        infostream<<"the_game: "
                                        <<"Launching inventory"<<std::endl;
                        
-                       GUIInventoryMenu *menu =
-                               new GUIInventoryMenu(guienv, guiroot, -1,
+                       GUIFormSpecMenu *menu =
+                               new GUIFormSpecMenu(guienv, guiroot, -1,
                                        &g_menumgr,
                                        &client, gamedef);
 
@@ -1482,7 +1523,8 @@ void the_game(
                        PlayerInventoryFormSource *src = new PlayerInventoryFormSource(&client);
                        assert(src);
                        menu->setFormSpec(src->getForm(), inventoryloc);
-                       menu->setFormSource(new PlayerInventoryFormSource(&client));
+                       menu->setFormSource(src);
+                       menu->setTextDest(new TextDestPlayerInventory(&client));
                        menu->drop();
                }
                else if(input->wasKeyDown(EscapeKey))
@@ -2211,7 +2253,8 @@ void the_game(
                        {
                                infostream<<"Ground right-clicked"<<std::endl;
                                
-                               // sign special case, at least until formspec is properly implemented
+                               // Sign special case, at least until formspec is properly implemented.
+                               // Deprecated?
                                if(meta && meta->getString("formspec") == "hack:sign_text_input" && !random_input)
                                {
                                        infostream<<"Launching metadata text input"<<std::endl;
@@ -2236,14 +2279,15 @@ void the_game(
                                        
                                        /* Create menu */
 
-                                       GUIInventoryMenu *menu =
-                                               new GUIInventoryMenu(guienv, guiroot, -1,
+                                       GUIFormSpecMenu *menu =
+                                               new GUIFormSpecMenu(guienv, guiroot, -1,
                                                        &g_menumgr,
                                                        &client, gamedef);
                                        menu->setFormSpec(meta->getString("formspec"),
                                                        inventoryloc);
                                        menu->setFormSource(new NodeMetadataFormSource(
                                                        &client.getEnv().getClientMap(), nodepos));
+                                       menu->setTextDest(new TextDestNodeMetadata(nodepos, &client));
                                        menu->drop();
                                }
                                // Otherwise report right click to server
@@ -2263,6 +2307,13 @@ void the_game(
                                                                <<playeritem.name<<" is "
                                                                <<def.node_placement_prediction<<std::endl;
                                                v3s16 p = neighbourpos;
+                                               // Place inside node itself if buildable_to
+                                               try{
+                                                       MapNode n_under = map.getNode(nodepos);
+                                                       if(nodedef->get(n_under).buildable_to)
+                                                               p = nodepos;
+                                               }catch(InvalidPositionException &e){}
+                                               // Find id of predicted node
                                                content_t id;
                                                bool found =
                                                        nodedef->getId(def.node_placement_prediction, id);
@@ -2649,7 +2700,19 @@ void the_game(
                                item = mlist->getItem(client.getPlayerItem());
                        camera.wield(item);
                }
-               
+
+               /*
+                       Update block draw list every 200ms or when camera direction has
+                       changed much
+               */
+               update_draw_list_timer += dtime;
+               if(update_draw_list_timer >= 0.2 ||
+                               update_draw_list_last_cam_dir.getDistanceFrom(camera_direction) > 0.2){
+                       update_draw_list_timer = 0;
+                       client.getEnv().getClientMap().updateDrawList(driver);
+                       update_draw_list_last_cam_dir = camera_direction;
+               }
+
                /*
                        Drawing begins
                */