From: Loïc Blot Date: Fri, 18 Aug 2017 10:17:30 +0000 (+0200) Subject: server.cpp: unroll setting when sending mapblocks (#6265) X-Git-Tag: 5.0.0~931 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=fb196be8cf8606cfab144e2fe62d9c9d1f50932f;p=oweals%2Fminetest.git server.cpp: unroll setting when sending mapblocks (#6265) * server.cpp: unroll setting when sending mapblocks * Improve a little bit performance when sending mapblocks massively * Use a range based for * Code style fixes --- diff --git a/src/server.cpp b/src/server.cpp index 41493a862..685f1f667 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -95,8 +95,6 @@ void *ServerThread::run() while (!stopRequested()) { try { - //TimeTaker timer("AsyncRunStep() + Receive()"); - m_server->AsyncRunStep(); m_server->Receive(); @@ -989,23 +987,17 @@ void Server::Receive() m_con.Receive(&pkt); peer_id = pkt.getPeerId(); ProcessData(&pkt); - } - catch(con::InvalidIncomingDataException &e) { - infostream<<"Server::Receive(): " - "InvalidIncomingDataException: what()=" - <getS32("max_simultaneous_block_sends_server_total"); + + for (const PrioritySortedBlockTransfer &block_to_send : queue) { //TODO: Calculate limit dynamically - if(total_sending >= g_settings->getS32 - ("max_simultaneous_block_sends_server_total")) + if (total_sending >= max_blocks_to_send) break; - PrioritySortedBlockTransfer q = queue[i]; - MapBlock *block = nullptr; try { - block = m_env->getMap().getBlockNoCreate(q.pos); - } catch(const InvalidPositionException &e) { + block = m_env->getMap().getBlockNoCreate(block_to_send.pos); + } catch (const InvalidPositionException &e) { continue; } - RemoteClient *client = m_clients.lockedGetClientNoEx(q.peer_id, CS_Active); + RemoteClient *client = m_clients.lockedGetClientNoEx(block_to_send.peer_id, + CS_Active); if (!client) continue; - SendBlockNoLock(q.peer_id, block, client->serialization_version, client->net_proto_version); + SendBlockNoLock(block_to_send.peer_id, block, client->serialization_version, + client->net_proto_version); - client->SentBlock(q.pos); + client->SentBlock(block_to_send.pos); total_sending++; } m_clients.unlock();