1
0

Don't flush ClientHandle data multiple times

* Change cWorld::m_Players to a vector
This commit is contained in:
Tiger Wang 2021-06-22 19:31:08 +01:00
parent 8b62245dfb
commit b98e2c17e0
3 changed files with 20 additions and 26 deletions

View File

@ -152,12 +152,6 @@ void cChunk::BroadcastPendingChanges(void)
}
}
// Flush out all buffered data:
for (const auto ClientHandle : m_LoadedByClient)
{
ClientHandle->ProcessProtocolOut();
}
m_PendingSendBlocks.clear();
m_PendingSendBlockEntities.clear();
}

View File

@ -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)

View File

@ -40,8 +40,6 @@ class cUUID;
struct SetChunkData;
typedef std::list< cPlayer * > cPlayerList;
@ -1010,9 +1008,9 @@ private:
cRedstoneSimulator * m_RedstoneSimulator;
// Protect with chunk map CS
cPlayerList m_Players;
std::vector<cPlayer *> m_Players;
cWorldStorage m_Storage;
cWorldStorage m_Storage;
unsigned int m_MaxPlayers;