]> git.lizzy.rs Git - minetest.git/blobdiff - src/client.cpp
Add hack to avoid 2s startup delay on local games
[minetest.git] / src / client.cpp
index 4f392ad7a9c1afef8d17a4112dd5d9c0b2637b9e..50162b1e9822129be1ae1d668689de56fe4da26b 100644 (file)
@@ -221,6 +221,11 @@ Client::Client(
                MtEventManager *event,
                bool ipv6
 ):
+       m_packetcounter_timer(0.0),
+       m_connection_reinit_timer(0.1),
+       m_avg_rtt_timer(0.0),
+       m_playerpos_send_timer(0.0),
+       m_ignore_damage_timer(0.0),
        m_tsrc(tsrc),
        m_shsrc(shsrc),
        m_itemdef(itemdef),
@@ -258,13 +263,6 @@ Client::Client(
        m_removed_sounds_check_timer(0),
        m_state(LC_Created)
 {
-       m_packetcounter_timer = 0.0;
-       //m_delete_unused_sectors_timer = 0.0;
-       m_connection_reinit_timer = 0.0;
-       m_avg_rtt_timer = 0.0;
-       m_playerpos_send_timer = 0.0;
-       m_ignore_damage_timer = 0.0;
-
        /*
                Add local player
        */
@@ -332,11 +330,11 @@ void Client::connect(Address address)
 void Client::step(float dtime)
 {
        DSTACK(__FUNCTION_NAME);
-       
+
        // Limit a bit
        if(dtime > 2.0)
                dtime = 2.0;
-       
+
        if(m_ignore_damage_timer > dtime)
                m_ignore_damage_timer -= dtime;
        else
@@ -360,7 +358,8 @@ void Client::step(float dtime)
                {
                        counter = 20.0;
                        
-                       infostream<<"Client packetcounter (20s):"<<std::endl;
+                       infostream << "Client packetcounter (" << m_packetcounter_timer
+                                       << "):"<<std::endl;
                        m_packetcounter.print(infostream);
                        m_packetcounter.clear();
                }
@@ -456,8 +455,13 @@ void Client::step(float dtime)
                }
        }
 #endif
-
-       if(m_state == LC_Created)
+       // UGLY hack to fix 2 second startup delay caused by non existent
+       // server client startup synchronization in local server or singleplayer mode
+       static bool initial_step = true;
+       if (initial_step) {
+               initial_step = false;
+       }
+       else if(m_state == LC_Created)
        {
                float &counter = m_connection_reinit_timer;
                counter -= dtime;
@@ -469,7 +473,6 @@ void Client::step(float dtime)
                        
                        Player *myplayer = m_env.getLocalPlayer();
                        assert(myplayer != NULL);
-       
                        // Send TOSERVER_INIT
                        // [0] u16 TOSERVER_INIT
                        // [2] u8 SER_FMT_VER_HIGHEST_READ
@@ -1922,12 +1925,23 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
                LocalPlayer *player = m_env.getLocalPlayer();
                assert(player != NULL);
 
-               player->local_animations[0] = readV2F1000(is);
-               player->local_animations[1] = readV2F1000(is);
-               player->local_animations[2] = readV2F1000(is);
-               player->local_animations[3] = readV2F1000(is);
+               player->local_animations[0] = readV2S32(is);
+               player->local_animations[1] = readV2S32(is);
+               player->local_animations[2] = readV2S32(is);
+               player->local_animations[3] = readV2S32(is);
                player->local_animation_speed = readF1000(is);
        }
+       else if(command == TOCLIENT_EYE_OFFSET)
+       {
+               std::string datastring((char *)&data[2], datasize - 2);
+               std::istringstream is(datastring, std::ios_base::binary);
+
+               LocalPlayer *player = m_env.getLocalPlayer();
+               assert(player != NULL);
+
+               player->eye_offset_first = readV3F1000(is);
+               player->eye_offset_third = readV3F1000(is);
+       }
        else
        {
                infostream<<"Client: Ignoring unknown command "
@@ -2687,6 +2701,18 @@ float Client::getRTT(void)
        return m_con.getPeerStat(PEER_ID_SERVER,con::AVG_RTT);
 }
 
+float Client::getCurRate(void)
+{
+       return ( m_con.getLocalStat(con::CUR_INC_RATE) +
+                       m_con.getLocalStat(con::CUR_DL_RATE));
+}
+
+float Client::getAvgRate(void)
+{
+       return ( m_con.getLocalStat(con::AVG_INC_RATE) +
+                       m_con.getLocalStat(con::AVG_DL_RATE));
+}
+
 // IGameDef interface
 // Under envlock
 IItemDefManager* Client::getItemDefManager()