Skip to content

Commit

Permalink
Block transfer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron55 committed Sep 2, 2012
1 parent 35b77f2 commit 3d4a138
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
28 changes: 18 additions & 10 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/string.h"
#include "hex.h"

#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"

static std::string getMediaCacheDir()
{
return porting::path_user + DIR_DELIM + "cache" + DIR_DELIM + "media";
Expand Down Expand Up @@ -614,7 +616,8 @@ void Client::step(float dtime)
float interval = 0.5;
float &counter = m_request_blocks_timer;
counter += dtime;
if (counter >= interval)
if (counter >= interval &&
m_con.GetPeerOutgoingQueueSizeSeconds(PEER_ID_SERVER) < interval)
{
counter = 0.0;
sendRequestForBlocks(interval);
Expand Down Expand Up @@ -1062,6 +1065,9 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
if (block && block->getChangeCounter() >= change_counter) {
// We already have a newer version of this block
// Don't need to bother deserializing
/*infostream<<"Client: TOCLIENT_BLOCKDATA: Already have "
<<PP(p)<<" rev. "<<block->getChangeCounter()
<<", server sent rev. "<<change_counter<<std::endl;*/
return;
}

Expand Down Expand Up @@ -1091,6 +1097,9 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
block->setChangeCounter(change_counter);
sector->insertBlock(block);
}

/*infostream<<"Client: TOCLIENT_BLOCKDATA: "
<<analyze_block(block)<<std::endl;*/

// Pre-queue the addition of the task, to spread processing between frames
PreQueuedMeshUpdate pq;
Expand Down Expand Up @@ -1986,7 +1995,7 @@ void Client::sendRequestForBlocks(float timeout)
// Find the coordinate range and change counters of requested blocks
bool first_block = true;
v3s16 req_min_pos, req_max_pos;
core::map<v3s16, u32> request_block_ccs;
core::map<v3s16, bool> request_blocks; // Value is dummy
for (int m = 0; m < 2; ++m)
{
// If mesh generation is fully booked, skip other than adjacent blocks
Expand All @@ -2012,10 +2021,7 @@ void Client::sendRequestForBlocks(float timeout)
if (bpos.Z > req_max_pos.Z) req_max_pos.Z = bpos.Z;
}

MapBlock* b = m_env.getMap().getBlockNoCreateNoEx(bpos);
u32 cc = 0; // Request any by default (allocated blocks start at 1)
if (b != NULL) cc = b->getChangeCounter();
request_block_ccs.set(bpos, cc);
request_blocks.set(bpos, true);
}
}

Expand All @@ -2029,11 +2035,13 @@ void Client::sendRequestForBlocks(float timeout)
for (int y = req_min_pos.Y; y <= req_max_pos.Y; ++y) {
for (int z = req_min_pos.Z; z <= req_max_pos.Z; ++z) {
v3s16 bpos = v3s16(x,y,z);
u32 cc = BLOCK_CHANGECOUNTER_UNDEFINED; // Unrequested block
core::map<v3s16, u32>::Iterator bi = request_block_ccs.find(bpos);
if (bi.getNode()) {
cc = bi->getValue();
u32 cc = BLOCK_CHANGECOUNTER_UNDEFINED; // Don't request
if(request_blocks.find(bpos)){
MapBlock* b = m_env.getMap().getBlockNoCreateNoEx(bpos);
cc = 0; // Request any version unless block exists
if (b != NULL) cc = b->getChangeCounter();
}
//infostream<<"Client: version of "<<PP(bpos)<<" is "<<cc<<std::endl;
writeU32(os, cc);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,13 @@ void Peer::reportRTT(float rtt)
if(rtt < 0.01){
if(m_max_packets_per_second < 400)
m_max_packets_per_second += 10;
} else if(rtt < 0.2){
} else if(rtt < 0.3){
if(m_max_packets_per_second < 100)
m_max_packets_per_second += 2;
} else {
m_max_packets_per_second *= 0.8;
if(m_max_packets_per_second < 10)
m_max_packets_per_second = 10;
if(m_max_packets_per_second < 20)
m_max_packets_per_second = 20;
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,9 @@ void Server::AsyncRunStep()

JMutexAutoLock lock(m_env_mutex);
JMutexAutoLock lock2(m_con_mutex);

m_block_send_queue.send(*this, dtime);
//m_block_send_queue.send(m_con, 100);
// Send stuff enough to fill the outgoing buffer half of the time
m_block_send_queue.send(*this, dtime * 0.5);
}

/*
Expand Down Expand Up @@ -1871,6 +1871,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
{
block->resetUsageTimer();
if (block->getChangeCounter() > client_change_counter) {
/*infostream<<"Server: Client's version of "<<PP(p)
<<" is "<<client_change_counter<<", "
<<"server's version is "<<block->getChangeCounter()
<<std::endl;*/
float priority = -d;
m_block_send_queue.addBlock(peer_id, p, priority, timeout);
}
Expand Down Expand Up @@ -3393,7 +3397,8 @@ void Server::SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver)
g_profiler->add("Server: blocks sent", 1);

/*infostream<<"Server: Sending block ("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<": \tpacket size: "<<replysize<<std::endl;*/
<<": \tpacket size: "<<replysize
<<", content: "<<analyze_block(block)<<std::endl;*/

/*
Send packet
Expand Down

0 comments on commit 3d4a138

Please sign in to comment.