Avoid resending near blocks unnecessarily.

This commit is contained in:
Lars 2020-10-21 14:46:04 -07:00 committed by lhofhansl
parent 61a196378f
commit 68cd93b865
2 changed files with 42 additions and 46 deletions

@ -138,26 +138,6 @@ void RemoteClient::GetNextBlocks (
camera_dir.rotateYZBy(sao->getLookPitch());
camera_dir.rotateXZBy(sao->getRotation().Y);
/*infostream<<"camera_dir=("<<camera_dir.X<<","<<camera_dir.Y<<","
<<camera_dir.Z<<")"<<std::endl;*/
/*
Get the starting value of the block finder radius.
*/
if (m_last_center != center) {
m_nearest_unsent_d = 0;
m_last_center = center;
}
/*infostream<<"m_nearest_unsent_reset_timer="
<<m_nearest_unsent_reset_timer<<std::endl;*/
//s16 last_nearest_unsent_d = m_nearest_unsent_d;
s16 d_start = m_nearest_unsent_d;
//infostream<<"d_start="<<d_start<<std::endl;
u16 max_simul_sends_usually = m_max_simul_sends;
/*
@ -189,6 +169,29 @@ void RemoteClient::GetNextBlocks (
s16 wanted_range = sao->getWantedRange() + 1;
float camera_fov = sao->getFov();
/*
Get the starting value of the block finder radius.
*/
if (m_last_center != center) {
m_nearest_unsent_d = 0;
m_last_center = center;
}
// reset the unsent distance if the view angle has changed more that 10% of the fov
// (this matches isBlockInSight which allows for an extra 10%)
if (camera_dir.dotProduct(m_last_camera_dir) < std::cos(camera_fov * 0.1f)) {
m_nearest_unsent_d = 0;
m_last_camera_dir = camera_dir;
}
if (m_nearest_unsent_d > 0) {
// make sure any blocks modified since the last time we sent blocks are resent
for (const v3s16 &p : m_blocks_modified) {
m_nearest_unsent_d = std::min(m_nearest_unsent_d, center.getDistanceFrom(p));
}
}
m_blocks_modified.clear();
s16 d_start = m_nearest_unsent_d;
// Distrust client-sent FOV and get server-set player object property
// zoom FOV (degrees) as a check to avoid hacked clients using FOV to load
// distant world.
@ -393,21 +396,18 @@ queue_full_break:
void RemoteClient::GotBlock(v3s16 p)
{
if (m_blocks_modified.find(p) == m_blocks_modified.end()) {
if (m_blocks_sending.find(p) != m_blocks_sending.end())
m_blocks_sending.erase(p);
else
m_excess_gotblocks++;
if (m_blocks_sending.find(p) != m_blocks_sending.end()) {
m_blocks_sending.erase(p);
// only add to sent blocks if it actually was sending
// (it might have been modified since)
m_blocks_sent.insert(p);
} else {
m_excess_gotblocks++;
}
}
void RemoteClient::SentBlock(v3s16 p)
{
if (m_blocks_modified.find(p) != m_blocks_modified.end())
m_blocks_modified.erase(p);
if (m_blocks_sending.find(p) == m_blocks_sending.end())
m_blocks_sending[p] = 0.0f;
else
@ -417,29 +417,24 @@ void RemoteClient::SentBlock(v3s16 p)
void RemoteClient::SetBlockNotSent(v3s16 p)
{
m_nearest_unsent_d = 0;
m_nothing_to_send_pause_timer = 0;
if (m_blocks_sending.find(p) != m_blocks_sending.end())
m_blocks_sending.erase(p);
if (m_blocks_sent.find(p) != m_blocks_sent.end())
m_blocks_sent.erase(p);
m_blocks_modified.insert(p);
// remove the block from sending and sent sets,
// and mark as modified if found
if (m_blocks_sending.erase(p) + m_blocks_sent.erase(p) > 0)
m_blocks_modified.insert(p);
}
void RemoteClient::SetBlocksNotSent(std::map<v3s16, MapBlock*> &blocks)
{
m_nearest_unsent_d = 0;
m_nothing_to_send_pause_timer = 0;
for (auto &block : blocks) {
v3s16 p = block.first;
m_blocks_modified.insert(p);
if (m_blocks_sending.find(p) != m_blocks_sending.end())
m_blocks_sending.erase(p);
if (m_blocks_sent.find(p) != m_blocks_sent.end())
m_blocks_sent.erase(p);
// remove the block from sending and sent sets,
// and mark as modified if found
if (m_blocks_sending.erase(p) + m_blocks_sent.erase(p) > 0)
m_blocks_modified.insert(p);
}
}

@ -364,6 +364,7 @@ private:
std::set<v3s16> m_blocks_sent;
s16 m_nearest_unsent_d = 0;
v3s16 m_last_center;
v3f m_last_camera_dir;
const u16 m_max_simul_sends;
const float m_min_time_from_building;
@ -383,10 +384,10 @@ private:
std::map<v3s16, float> m_blocks_sending;
/*
Blocks that have been modified since last sending them.
These blocks will not be marked as sent, even if the
client reports it has received them to account for blocks
that are being modified while on the line.
Blocks that have been modified since blocks were
sent to the client last (getNextBlocks()).
This is used to reset the unsent distance, so that
modified blocks are resent to the client.
List of block positions.
*/