diff options
author | Lars <larsh@apache.org> | 2020-10-21 14:46:04 -0700 |
---|---|---|
committer | lhofhansl <larsh@apache.org> | 2020-10-27 12:08:44 -0700 |
commit | 68cd93b8657c0c8cad0196e79fb63e3275322e38 (patch) | |
tree | 36f3f84e989fb2d818a2d3547815081bd2d010c7 /src | |
parent | 61a196378ff91411af3245504c5861da026b3b25 (diff) | |
download | minetest-68cd93b8657c0c8cad0196e79fb63e3275322e38.tar.gz minetest-68cd93b8657c0c8cad0196e79fb63e3275322e38.tar.bz2 minetest-68cd93b8657c0c8cad0196e79fb63e3275322e38.zip |
Avoid resending near blocks unnecessarily.
Diffstat (limited to 'src')
-rw-r--r-- | src/clientiface.cpp | 79 | ||||
-rw-r--r-- | src/clientiface.h | 9 |
2 files changed, 42 insertions, 46 deletions
diff --git a/src/clientiface.cpp b/src/clientiface.cpp index a01cba7e0..f5e32469b 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -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); } } diff --git a/src/clientiface.h b/src/clientiface.h index ca2af65fe..eabffb0b6 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -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. */ |