summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-06-22 20:31:08 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2021-06-28 22:54:21 +0200
commitb98e2c17e0305c78af3d7581f0bee29ddf26d8f8 (patch)
treecdb79b6798ae4ddf9b579d8f6d578f0d9d8fb6e3
parentRemove LUA_PLUGIN_NAME_VAR_NAME (diff)
downloadcuberite-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
-rw-r--r--src/Chunk.cpp6
-rw-r--r--src/World.cpp34
-rw-r--r--src/World.h6
3 files changed, 20 insertions, 26 deletions
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index efdce7edc..fac2d37ee 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -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();
}
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)
diff --git a/src/World.h b/src/World.h
index 1a5ac8498..71e23c463 100644
--- a/src/World.h
+++ b/src/World.h
@@ -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;