]> git.lizzy.rs Git - minetest.git/blobdiff - src/client.cpp
Add download rate to media progress bar (non http mode only!)
[minetest.git] / src / client.cpp
index 4d6c0cb9907337c6dc56d95e4935d64636640fa4..a4fabfa619f675785052a5f5c690fe8aaca97ef2 100644 (file)
@@ -47,6 +47,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "serialization.h"
 #include "util/serialize.h"
 #include "config.h"
+#include "cmake_config_githash.h"
 #include "util/directiontables.h"
 #include "util/pointedthing.h"
 #include "version.h"
@@ -168,6 +169,8 @@ void * MeshUpdateThread::Thread()
        
        BEGIN_DEBUG_EXCEPTION_HANDLER
 
+       porting::setThreadName("MeshUpdateThread");
+
        while(!StopRequested())
        {
                QueuedMeshUpdate *q = m_queue_in.pop();
@@ -252,7 +255,8 @@ Client::Client(
        m_last_time_of_day_f(-1),
        m_time_of_day_update_timer(0),
        m_recommended_send_interval(0.1),
-       m_removed_sounds_check_timer(0)
+       m_removed_sounds_check_timer(0),
+       m_state(LC_Created)
 {
        m_packetcounter_timer = 0.0;
        //m_delete_unused_sectors_timer = 0.0;
@@ -325,17 +329,6 @@ void Client::connect(Address address)
        m_con.Connect(address);
 }
 
-bool Client::connectedAndInitialized()
-{
-       if(m_con.Connected() == false)
-               return false;
-       
-       if(m_server_ser_ver == SER_FMT_VER_INVALID)
-               return false;
-       
-       return true;
-}
-
 void Client::step(float dtime)
 {
        DSTACK(__FUNCTION_NAME);
@@ -372,9 +365,6 @@ void Client::step(float dtime)
                        m_packetcounter.clear();
                }
        }
-       
-       // Get connection status
-       bool connected = connectedAndInitialized();
 
 #if 0
        {
@@ -467,7 +457,7 @@ void Client::step(float dtime)
        }
 #endif
 
-       if(connected == false)
+       if(m_state == LC_Created)
        {
                float &counter = m_connection_reinit_timer;
                counter -= dtime;
@@ -632,7 +622,7 @@ void Client::step(float dtime)
                {
                        counter = 0.0;
                        // connectedAndInitialized() is true, peer exists.
-                       float avg_rtt = m_con.GetPeerAvgRTT(PEER_ID_SERVER);
+                       float avg_rtt = getRTT();
                        infostream<<"Client: avg_rtt="<<avg_rtt<<std::endl;
                }
        }
@@ -643,7 +633,7 @@ void Client::step(float dtime)
        {
                float &counter = m_playerpos_send_timer;
                counter += dtime;
-               if(counter >= m_recommended_send_interval)
+               if((m_state == LC_Ready) && (counter >= m_recommended_send_interval))
                {
                        counter = 0.0;
                        sendPlayerPos();
@@ -1051,6 +1041,8 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
                // Send as reliable
                m_con.Send(PEER_ID_SERVER, 1, reply, true);
 
+               m_state = LC_Init;
+
                return;
        }
 
@@ -1222,7 +1214,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
                m_time_of_day_set = true;
 
                u32 dr = m_env.getDayNightRatio();
-               verbosestream<<"Client: time_of_day="<<time_of_day
+               infostream<<"Client: time_of_day="<<time_of_day
                                <<" time_speed="<<time_speed
                                <<" dr="<<dr<<std::endl;
        }
@@ -1922,6 +1914,31 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
                event.override_day_night_ratio.ratio_f     = day_night_ratio_f;
                m_client_event_queue.push_back(event);
        }
+       else if(command == TOCLIENT_LOCAL_PLAYER_ANIMATIONS)
+       {
+               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->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 "
@@ -1937,7 +1954,7 @@ void Client::Send(u16 channelnum, SharedBuffer<u8> data, bool reliable)
 
 void Client::interact(u8 action, const PointedThing& pointed)
 {
-       if(connectedAndInitialized() == false){
+       if(m_state != LC_Ready){
                infostream<<"Client::interact() "
                                "cancelled (not connected)"
                                <<std::endl;
@@ -2072,8 +2089,8 @@ void Client::sendChatMessage(const std::wstring &message)
        Send(0, data, true);
 }
 
-void Client::sendChangePassword(const std::wstring oldpassword,
-               const std::wstring newpassword)
+void Client::sendChangePassword(const std::wstring &oldpassword,
+                                const std::wstring &newpassword)
 {
        Player *player = m_env.getLocalPlayer();
        if(player == NULL)
@@ -2152,6 +2169,27 @@ void Client::sendRespawn()
        Send(0, data, true);
 }
 
+void Client::sendReady()
+{
+       DSTACK(__FUNCTION_NAME);
+       std::ostringstream os(std::ios_base::binary);
+
+       writeU16(os, TOSERVER_CLIENT_READY);
+       writeU8(os,VERSION_MAJOR);
+       writeU8(os,VERSION_MINOR);
+       writeU8(os,VERSION_PATCH_ORIG);
+       writeU8(os,0);
+
+       writeU16(os,strlen(CMAKE_VERSION_GITHASH));
+       os.write(CMAKE_VERSION_GITHASH,strlen(CMAKE_VERSION_GITHASH));
+
+       // Make data buffer
+       std::string s = os.str();
+       SharedBuffer<u8> data((u8*)s.c_str(), s.size());
+       // Send as reliable
+       Send(0, data, true);
+}
+
 void Client::sendPlayerPos()
 {
        LocalPlayer *myplayer = m_env.getLocalPlayer();
@@ -2650,16 +2688,26 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
        infostream<<"- Starting mesh update thread"<<std::endl;
        m_mesh_update_thread.Start();
        
+       m_state = LC_Ready;
+       sendReady();
        infostream<<"Client::afterContentReceived() done"<<std::endl;
 }
 
 float Client::getRTT(void)
 {
-       try{
-               return m_con.GetPeerAvgRTT(PEER_ID_SERVER);
-       } catch(con::PeerNotFoundException &e){
-               return 1337;
-       }
+       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