fixed crack animation timing in client
authorPerttu Ahola <celeron55@gmail.com>
Thu, 23 Dec 2010 10:10:46 +0000 (12:10 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Thu, 23 Dec 2010 10:10:46 +0000 (12:10 +0200)
src/client.cpp
src/client.h
src/constants.h
src/main.cpp

index 32f62e3babdd17206405446b8b958ee411288922..23f9d2a555948ed5cfd3fe0ae1e0a42071858d4d 100644 (file)
@@ -176,6 +176,7 @@ void Client::step(float dtime)
                if(dr != m_env.getDayNightRatio())
                {
                        //dstream<<"dr="<<dr<<std::endl;
+                       dout_client<<DTIME<<"Client: changing day-night ratio"<<std::endl;
                        m_env.setDayNightRatio(dr);
                        m_env.expireMeshes(true);
                }
@@ -1037,6 +1038,9 @@ bool Client::AsyncProcessPacket(LazyMeshUpdater &mesh_updater)
                p.Z = readS16(&data[6]);
                
                //TimeTaker t1("TOCLIENT_REMOVENODE", g_device);
+               
+               // This will clear the cracking animation after digging
+               ((ClientMap&)m_env.getMap()).clearTempMod(p);
 
                core::map<v3s16, MapBlock*> modified_blocks;
 
index bfec7730ddccfa3e8fc92e9923f2b5f5151af293..3c8bbfaf6206e5872d6a6dc8f10c9cc0bd77494c 100644 (file)
@@ -251,6 +251,15 @@ public:
                v3s16 blockpos = ((ClientMap&)m_env.getMap()).clearTempMod(p);
                m_env.getMap().updateMeshes(blockpos, m_env.getDayNightRatio());
        }
+
+       float getAvgRtt()
+       {
+               JMutexAutoLock lock(m_con_mutex);
+               con::Peer *peer = m_con.GetPeerNoEx(PEER_ID_SERVER);
+               if(peer == NULL)
+                       return 0.0;
+               return peer->avg_rtt;
+       }
        
 private:
        
index 8b7e77c4240c16c8f7a351220138d4fa4c82539e..cf394ca02101a2e44f7ba2721bd913aae86f3cc1 100644 (file)
@@ -79,5 +79,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #define WATER_LEVEL (0)
 
+// Length of cracking animation in count of images
+#define CRACK_ANIMATION_LENGTH 4
+
 #endif
 
index 5d6712df6e1fbc6e819d39a61da8d214631e77ee..aacf4d7757e9dbc4994225eef7f50e8b67daea37 100644 (file)
@@ -2114,6 +2114,7 @@ int main(int argc, char *argv[])
                        static v3s16 nodepos_old(-32768,-32768,-32768);\r
 \r
                        static float dig_time = 0.0;\r
+                       static u16 dig_index = 0;\r
 \r
                        if(nodepos != nodepos_old)\r
                        {\r
@@ -2146,19 +2147,25 @@ int main(int argc, char *argv[])
                        }\r
                        if(g_input->getLeftState())\r
                        {\r
-                               dig_time += dtime;\r
-                               \r
                                float dig_time_complete = 0.5;\r
                                MapNode n = client.getNode(nodepos);\r
                                if(n.d == CONTENT_STONE)\r
                                        dig_time_complete = 1.5;\r
+                               \r
+                               float dig_time_complete0 = dig_time_complete+client.getAvgRtt()*2;\r
+                               if(dig_time_complete0 < 0.0)\r
+                                       dig_time_complete0 = 0.0;\r
 \r
-                               u16 dig_index = (u16)(3.99*dig_time/dig_time_complete);\r
-                               if(dig_time > 0.125)\r
+                               dig_index = (u16)((float)CRACK_ANIMATION_LENGTH\r
+                                               * dig_time/dig_time_complete0);\r
+\r
+                               if(dig_time > 0.125 && dig_index < CRACK_ANIMATION_LENGTH)\r
                                {\r
                                        //dstream<<"dig_index="<<dig_index<<std::endl;\r
                                        client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, dig_index));\r
                                }\r
+\r
+                               dig_time += dtime;\r
                        }\r
                        \r
                        if(g_input->getRightClicked())\r