diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2021-06-22 20:31:08 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2021-06-28 22:54:21 +0200 |
commit | b98e2c17e0305c78af3d7581f0bee29ddf26d8f8 (patch) | |
tree | cdb79b6798ae4ddf9b579d8f6d578f0d9d8fb6e3 /src/World.cpp | |
parent | Remove LUA_PLUGIN_NAME_VAR_NAME (diff) | |
download | cuberite-b98e2c17e0305c78af3d7581f0bee29ddf26d8f8.tar cuberite-b98e2c17e0305c78af3d7581f0bee29ddf26d8f8.tar.gz cuberite-b98e2c17e0305c78af3d7581f0bee29ddf26d8f8.tar.bz2 cuberite-b98e2c17e0305c78af3d7581f0bee29ddf26d8f8.tar.lz cuberite-b98e2c17e0305c78af3d7581f0bee29ddf26d8f8.tar.xz cuberite-b98e2c17e0305c78af3d7581f0bee29ddf26d8f8.tar.zst cuberite-b98e2c17e0305c78af3d7581f0bee29ddf26d8f8.zip |
Diffstat (limited to '')
-rw-r--r-- | src/World.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/World.cpp b/src/World.cpp index 10dc909c9..f7647aba3 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1039,6 +1039,12 @@ void cWorld::Tick(std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_La GetSimulatorManager()->Simulate(static_cast<float>(a_Dt.count())); + // Flush out all clients' buffered data: + for (const auto Player : m_Players) + { + Player->GetClientHandle()->ProcessProtocolOut(); + } + if (m_WorldAge - m_LastChunkCheck > std::chrono::seconds(10)) { // Unload every 10 seconds @@ -2282,16 +2288,16 @@ bool cWorld::FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCa size_t NameLength = a_PlayerNameHint.length(); cLock Lock(*this); - for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) + for (const auto Player : m_Players) { - if (!(*itr)->IsTicking()) + if (!Player->IsTicking()) { continue; } - size_t Rating = RateCompareString (a_PlayerNameHint, (*itr)->GetName()); + size_t Rating = RateCompareString (a_PlayerNameHint, Player->GetName()); if (Rating >= BestRating) { - BestMatch = *itr; + BestMatch = Player; BestRating = Rating; } if (Rating == NameLength) // Perfect match @@ -2334,19 +2340,19 @@ bool cWorld::DoWithNearestPlayer(Vector3d a_Pos, double a_RangeLimit, cPlayerLis cPlayer * ClosestPlayer = nullptr; cLock Lock(*this); - for (cPlayerList::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) + for (const auto Player : m_Players) { - if (!(*itr)->IsTicking()) + if (!Player->IsTicking()) { continue; } - if (a_IgnoreSpectator && (*itr)->IsGameModeSpectator()) + if (a_IgnoreSpectator && Player->IsGameModeSpectator()) { continue; } - Vector3f Pos = (*itr)->GetPosition(); + Vector3f Pos = Player->GetPosition(); double Distance = (Pos - a_Pos).Length(); // If the player is too far, skip them: @@ -2365,7 +2371,7 @@ bool cWorld::DoWithNearestPlayer(Vector3d a_Pos, double a_RangeLimit, cPlayerLis } ClosestDistance = Distance; - ClosestPlayer = *itr; + ClosestPlayer = Player; } if (ClosestPlayer) @@ -2749,7 +2755,7 @@ OwnedEntity cWorld::RemoveEntity(cEntity & a_Entity) cLock Lock(*this); const auto Player = static_cast<cPlayer *>(&a_Entity); LOGD("Removing player %s from world \"%s\"", Player->GetName().c_str(), m_WorldName.c_str()); - m_Players.remove(Player); + m_Players.erase(std::remove(m_Players.begin(), m_Players.end(), Player), m_Players.end()); } // Check if the entity is in the chunkmap: @@ -2973,13 +2979,9 @@ void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Resul std::vector<pair_t> UsernamesByWeight; cLock Lock(*this); - for (cPlayerList::iterator itr = m_Players.begin(), end = m_Players.end(); itr != end; ++itr) + for (const auto Player : m_Players) { - AString PlayerName ((*itr)->GetName()); - if ((*itr)->HasCustomName()) - { - PlayerName = (*itr)->GetCustomName(); - } + AString PlayerName = Player->HasCustomName() ? Player->GetCustomName() : Player->GetName(); AString::size_type Found = StrToLower(PlayerName).find(StrToLower(LastWord)); // Try to find last word in playername if (Found == AString::npos) |