]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client.cpp
end-of-day.
[dragonfireclient.git] / src / client.cpp
index 4792490f9fd67816782735396d1e27dba3951fcb..915c745b7d6ba135010312d2adfe6d76b9b2dd2f 100644 (file)
@@ -139,37 +139,6 @@ void Client::step(float dtime)
        if(dtime > 2.0)
                dtime = 2.0;
        
-       /*
-               Day/night
-       */
-       {
-               s32 d = 8;
-               s32 t = (((m_time_of_day.get() + 24000/d/2)%24000)/(24000/d));
-               s32 dn = 0;
-               if(t == d/4 || t == (d-d/4))
-                       dn = 1;
-               else if(t < d/4 || t > (d-d/4))
-                       dn = 2;
-               else
-                       dn = 0;
-
-               u32 dr = 1000;
-               if(dn == 0)
-                       dr = 1000;
-               if(dn == 1)
-                       dr = 600;
-               if(dn == 2)
-                       dr = 300;
-               
-               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);
-               }
-       }
-
        
        //dstream<<"Client steps "<<dtime<<std::endl;
 
@@ -599,7 +568,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
                        our_peer_id = m_con.GetPeerID();
                }
                // Cancel if we don't have a peer id
-               if(our_peer_id == PEER_ID_NEW){
+               if(our_peer_id == PEER_ID_INEXISTENT){
                        dout_client<<DTIME<<"TOCLIENT_PLAYERPOS cancelled: "
                                        "we have no peer id"
                                        <<std::endl;
@@ -665,7 +634,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
                        our_peer_id = m_con.GetPeerID();
                }
                // Cancel if we don't have a peer id
-               if(our_peer_id == PEER_ID_NEW){
+               if(our_peer_id == PEER_ID_INEXISTENT){
                        dout_client<<DTIME<<"TOCLIENT_PLAYERINFO cancelled: "
                                        "we have no peer id"
                                        <<std::endl;
@@ -1003,6 +972,42 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
                time = time % 24000;
                m_time_of_day.set(time);
                //dstream<<"Client: time="<<time<<std::endl;
+               
+               /*
+                       Day/night
+
+                       time_of_day:
+                       0 = midnight
+                       12000 = midday
+               */
+               {
+                       const s32 daylength = 16;
+                       const s32 nightlength = 6;
+                       const s32 daytimelength = 8;
+                       s32 d = daylength;
+                       s32 t = (((m_time_of_day.get())%24000)/(24000/d));
+                       u32 dr;
+                       if(t < nightlength/2 || t >= d - nightlength/2)
+                               dr = 400;
+                       else if(t >= d/2 - daytimelength/2 && t < d/2 + daytimelength/2)
+                               dr = 1000;
+                       else
+                               dr = 750;
+
+                       dstream<<"time_of_day="<<m_time_of_day.get()
+                                       <<", t="<<t
+                                       <<", dr="<<dr
+                                       <<std::endl;
+                       
+                       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);
+                       }
+               }
+
        }
        else if(command == TOCLIENT_CHAT_MESSAGE)
        {
@@ -1204,8 +1209,8 @@ bool Client::AsyncProcessPacket()
        } //try
        catch(con::PeerNotFoundException &e)
        {
-               dout_client<<DTIME<<"Client::AsyncProcessData(): Cancelling: The server"
-                               " connection doesn't exist (a timeout or not yet connected?)"<<std::endl;
+               /*dout_client<<DTIME<<"Client::AsyncProcessData(): Cancelling: The server"
+                               " connection doesn't exist (a timeout or not yet connected?)"<<std::endl;*/
                return false;
        }
 }
@@ -1227,25 +1232,6 @@ void Client::Send(u16 channelnum, SharedBuffer<u8> data, bool reliable)
        m_con.Send(PEER_ID_SERVER, channelnum, data, reliable);
 }
 
-bool Client::isFetchingBlocks()
-{
-       JMutexAutoLock conlock(m_con_mutex);
-       con::Peer *peer = m_con.GetPeerNoEx(PEER_ID_SERVER);
-       // Not really fetching but can't fetch more.
-       if(peer == NULL) return true;
-
-       con::Channel *channel = &(peer->channels[1]);
-       /*
-               NOTE: Channel 0 should always be used for fetching blocks,
-                     and for nothing else.
-       */
-       if(channel->incoming_reliables.size() > 0)
-               return true;
-       if(channel->outgoing_reliables.size() > 0)
-               return true;
-       return false;
-}
-
 IncomingPacket Client::getPacket()
 {
        JMutexAutoLock lock(m_incoming_queue_mutex);
@@ -1287,6 +1273,7 @@ void Client::groundAction(u8 action, v3s16 nodepos_undersurface,
                0: start digging
                1: place block
                2: stop digging (all parameters ignored)
+               3: digging completed
        */
        u8 datasize = 2 + 1 + 6 + 6 + 2;
        SharedBuffer<u8> data(datasize);
@@ -1424,7 +1411,7 @@ void Client::sendPlayerPos()
        }
        
        // Set peer id if not set already
-       if(myplayer->peer_id == PEER_ID_NEW)
+       if(myplayer->peer_id == PEER_ID_INEXISTENT)
                myplayer->peer_id = our_peer_id;
        // Check that an existing peer_id is the same as the connection's
        assert(myplayer->peer_id == our_peer_id);