Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/wip5.8.0' into wip5.8.0webport
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Sep 30, 2024
2 parents a010026 + 7a0582a commit 94b51ff
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/client/fm_client.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <exception>
#include "client.h"
#include "clientmap.h"
#include "emerge.h"
Expand All @@ -9,6 +10,7 @@
#include "map.h"
#include "mapgen/mapgen.h"
#include "network/networkpacket.h"
#include "threading/lock.h"
#include "util/directiontables.h"
#include "util/hex.h"

Expand Down Expand Up @@ -49,7 +51,9 @@ void Client::sendGetBlocks()
if (!farmesh_server)
return;

const auto &far_blocks = *m_env.getClientMap().m_far_blocks_use;
auto &far_blocks = *m_env.getClientMap().m_far_blocks_use;
const auto lock = far_blocks.lock_unique_rec();

if (far_blocks.empty()) {
return;
}
Expand All @@ -61,6 +65,8 @@ void Client::sendGetBlocks()
PACK(TOSERVER_GET_BLOCKS_BLOCKS,
static_cast<std::remove_reference_t<decltype(far_blocks)>::full_type>(
far_blocks));
far_blocks.clear();
lock->unlock();

NetworkPacket pkt(TOSERVER_GET_BLOCKS, buffer.size());
pkt.putLongString({buffer.data(), buffer.size()});
Expand Down Expand Up @@ -172,7 +178,7 @@ void Client::handleCommand_BlockDatas(NetworkPacket *pkt)

if (block->content_only == CONTENT_IGNORE) {
try {
block->deSerialize(istr, m_server_ser_ver, false);
block->deSerialize(istr, m_server_ser_ver, false);
} catch (const std::exception &ex) {
errorstream << "fm block deSerialize fail " << bpos << " " << block->far_step
<< " : " << ex.what() << " : " << pkt->getSize() << " "
Expand Down Expand Up @@ -218,4 +224,4 @@ void Client::handleCommand_BlockDatas(NetworkPacket *pkt)
}
}
}
}
}
7 changes: 6 additions & 1 deletion src/client/fm_farmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ void FarMesh::update(v3opos_t camera_pos,
//timestamp_complete = m_client->m_uptime;
complete_set = true;
++m_client->m_new_meshes;
}
/*
{
auto &clientMap = m_client->getEnv().getClientMap();
if (clientMap.m_far_blocks_use != clientMap.m_far_blocks_fill)
clientMap.m_far_blocks_use = clientMap.m_far_blocks_currrent
? &clientMap.m_far_blocks_1
Expand All @@ -471,7 +475,8 @@ void FarMesh::update(v3opos_t camera_pos,
clientMap.m_far_blocks_currrent = !clientMap.m_far_blocks_currrent;
clientMap.m_far_blocks_fill->clear();
clientMap.m_far_blocks_created = m_client->m_uptime;
clientMap.far_blocks_sent_timer = 0;
//clientMap.far_blocks_sent_timer = 0;
}
*/
}
}
2 changes: 1 addition & 1 deletion src/clientiface.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class RemoteClient
void SetBlocksNotSent();
void SetBlockDeleted(v3bpos_t p);
std::unordered_map<v3bpos_t, uint8_t> far_blocks_requested;
std::shared_mutex far_blocks_requested_mutex;
std::mutex far_blocks_requested_mutex;
std::array<std::unordered_set<v3bpos_t>, FARMESH_STEP_MAX> far_blocks_sent;
int GetNextBlocksFm(ServerEnvironment *env, EmergeManager* emerge,
float dtime, std::vector<PrioritySortedBlockTransfer> &dest, double m_uptime, u64 max_ms);
Expand Down
3 changes: 2 additions & 1 deletion src/fm_clientiface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ int RemoteClient::GetNextBlocksFm(ServerEnvironment *env, EmergeManager *emerge,
}
}

TRY_SHARED_LOCK(far_blocks_requested_mutex)
TRY_UNIQUE_LOCK(far_blocks_requested_mutex)
{
for (const auto &[bp, step] : far_blocks_requested) {
if (step >= FARMESH_STEP_MAX - 1) {
Expand All @@ -583,6 +583,7 @@ int RemoteClient::GetNextBlocksFm(ServerEnvironment *env, EmergeManager *emerge,
peer_id, block, serialization_version, net_proto_version);
far_blocks_sent[step].emplace(bp);
}
far_blocks_requested.clear();
}

return num_blocks_selected - num_blocks_sending;
Expand Down
6 changes: 5 additions & 1 deletion src/fm_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,11 @@ void Server::handleCommand_GetBlocks(NetworkPacket *pkt)
auto &packet = *(pkt->packet);
WITH_UNIQUE_LOCK(client->far_blocks_requested_mutex)
{
packet[TOSERVER_GET_BLOCKS_BLOCKS].convert(client->far_blocks_requested);
std::unordered_map<v3bpos_t, MapBlock::block_step_t> blocks;
packet[TOSERVER_GET_BLOCKS_BLOCKS].convert(blocks);
for (const auto &[bpos, step] : blocks) {
client->far_blocks_requested.insert_or_assign(bpos, step);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ class Map : public NodeContainer
far_blocks_list_type m_far_blocks_1, m_far_blocks_2;
far_blocks_list_type *m_far_blocks_use = &m_far_blocks_1,
*m_far_blocks_fill = &m_far_blocks_1;
double m_far_blocks_created = 0, m_far_blocks_sent = 0;
//double m_far_blocks_created = 0;
//double m_far_blocks_sent = 0;
float far_blocks_sent_timer = 1;
v3pos_t m_far_blocks_last_cam_pos;
std::vector<std::shared_ptr<MapBlock>> m_far_blocks_delete_1, m_far_blocks_delete_2;
Expand Down

0 comments on commit 94b51ff

Please sign in to comment.