mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 16:13:46 +01:00
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
This commit is contained in:
parent
1d055aad0f
commit
fb196be8cf
@ -95,8 +95,6 @@ void *ServerThread::run()
|
|||||||
|
|
||||||
while (!stopRequested()) {
|
while (!stopRequested()) {
|
||||||
try {
|
try {
|
||||||
//TimeTaker timer("AsyncRunStep() + Receive()");
|
|
||||||
|
|
||||||
m_server->AsyncRunStep();
|
m_server->AsyncRunStep();
|
||||||
|
|
||||||
m_server->Receive();
|
m_server->Receive();
|
||||||
@ -989,23 +987,17 @@ void Server::Receive()
|
|||||||
m_con.Receive(&pkt);
|
m_con.Receive(&pkt);
|
||||||
peer_id = pkt.getPeerId();
|
peer_id = pkt.getPeerId();
|
||||||
ProcessData(&pkt);
|
ProcessData(&pkt);
|
||||||
}
|
} catch (const con::InvalidIncomingDataException &e) {
|
||||||
catch(con::InvalidIncomingDataException &e) {
|
infostream << "Server::Receive(): InvalidIncomingDataException: what()="
|
||||||
infostream<<"Server::Receive(): "
|
<< e.what() << std::endl;
|
||||||
"InvalidIncomingDataException: what()="
|
} catch (const SerializationError &e) {
|
||||||
<<e.what()<<std::endl;
|
infostream << "Server::Receive(): SerializationError: what()="
|
||||||
}
|
<< e.what() << std::endl;
|
||||||
catch(SerializationError &e) {
|
} catch (const ClientStateError &e) {
|
||||||
infostream<<"Server::Receive(): "
|
|
||||||
"SerializationError: what()="
|
|
||||||
<<e.what()<<std::endl;
|
|
||||||
}
|
|
||||||
catch(ClientStateError &e) {
|
|
||||||
errorstream << "ProcessData: peer=" << peer_id << e.what() << std::endl;
|
errorstream << "ProcessData: peer=" << peer_id << e.what() << std::endl;
|
||||||
DenyAccess_Legacy(peer_id, L"Your client sent something server didn't expect."
|
DenyAccess_Legacy(peer_id, L"Your client sent something server didn't expect."
|
||||||
L"Try reconnecting or updating your client");
|
L"Try reconnecting or updating your client");
|
||||||
}
|
} catch (const con::PeerNotFoundException &e) {
|
||||||
catch(con::PeerNotFoundException &e) {
|
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2259,29 +2251,30 @@ void Server::SendBlocks(float dtime)
|
|||||||
std::sort(queue.begin(), queue.end());
|
std::sort(queue.begin(), queue.end());
|
||||||
|
|
||||||
m_clients.lock();
|
m_clients.lock();
|
||||||
for(u32 i=0; i<queue.size(); i++)
|
s32 max_blocks_to_send =
|
||||||
{
|
g_settings->getS32("max_simultaneous_block_sends_server_total");
|
||||||
//TODO: Calculate limit dynamically
|
|
||||||
if(total_sending >= g_settings->getS32
|
|
||||||
("max_simultaneous_block_sends_server_total"))
|
|
||||||
break;
|
|
||||||
|
|
||||||
PrioritySortedBlockTransfer q = queue[i];
|
for (const PrioritySortedBlockTransfer &block_to_send : queue) {
|
||||||
|
//TODO: Calculate limit dynamically
|
||||||
|
if (total_sending >= max_blocks_to_send)
|
||||||
|
break;
|
||||||
|
|
||||||
MapBlock *block = nullptr;
|
MapBlock *block = nullptr;
|
||||||
try {
|
try {
|
||||||
block = m_env->getMap().getBlockNoCreate(q.pos);
|
block = m_env->getMap().getBlockNoCreate(block_to_send.pos);
|
||||||
} catch(const InvalidPositionException &e) {
|
} catch (const InvalidPositionException &e) {
|
||||||
continue;
|
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)
|
if (!client)
|
||||||
continue;
|
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++;
|
total_sending++;
|
||||||
}
|
}
|
||||||
m_clients.unlock();
|
m_clients.unlock();
|
||||||
|
Loading…
Reference in New Issue
Block a user