mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Store number of filtered players when filtering
Only update total number of filtered players when the filter is updated instead of calculating it every frame.
This commit is contained in:
parent
3ce669df13
commit
b1d90aaaf2
|
@ -62,6 +62,7 @@ CServerBrowser::CServerBrowser()
|
|||
|
||||
m_NumSortedServers = 0;
|
||||
m_NumSortedServersCapacity = 0;
|
||||
m_NumSortedPlayers = 0;
|
||||
m_NumServers = 0;
|
||||
m_NumServerCapacity = 0;
|
||||
|
||||
|
@ -265,6 +266,7 @@ bool CServerBrowser::SortCompareNumPlayersAndPing(int Index1, int Index2) const
|
|||
void CServerBrowser::Filter()
|
||||
{
|
||||
m_NumSortedServers = 0;
|
||||
m_NumSortedPlayers = 0;
|
||||
|
||||
// allocate the sorted list
|
||||
if(m_NumSortedServersCapacity < m_NumServers)
|
||||
|
@ -411,7 +413,10 @@ void CServerBrowser::Filter()
|
|||
UpdateServerFriends(&Info);
|
||||
|
||||
if(!g_Config.m_BrFilterFriends || Info.m_FriendState != IFriends::FRIEND_NO)
|
||||
{
|
||||
m_NumSortedPlayers += Info.m_NumFilteredPlayers;
|
||||
m_pSortedServerlist[m_NumSortedServers++] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1051,6 +1056,7 @@ void CServerBrowser::CleanUp()
|
|||
m_ServerlistHeap.Reset();
|
||||
m_NumServers = 0;
|
||||
m_NumSortedServers = 0;
|
||||
m_NumSortedPlayers = 0;
|
||||
m_ByAddr.clear();
|
||||
m_pFirstReqServer = nullptr;
|
||||
m_pLastReqServer = nullptr;
|
||||
|
|
|
@ -51,6 +51,7 @@ public:
|
|||
int Players(const CServerInfo &Item) const override;
|
||||
int Max(const CServerInfo &Item) const override;
|
||||
int NumSortedServers() const override { return m_NumSortedServers; }
|
||||
int NumSortedPlayers() const override { return m_NumSortedPlayers; }
|
||||
const CServerInfo *SortedGet(int Index) const override;
|
||||
|
||||
const char *GetTutorialServer() override;
|
||||
|
@ -125,6 +126,7 @@ private:
|
|||
|
||||
int m_NumSortedServers;
|
||||
int m_NumSortedServersCapacity;
|
||||
int m_NumSortedPlayers;
|
||||
int m_NumServers;
|
||||
int m_NumServerCapacity;
|
||||
|
||||
|
|
|
@ -235,6 +235,7 @@ public:
|
|||
virtual int Max(const CServerInfo &Item) const = 0;
|
||||
|
||||
virtual int NumSortedServers() const = 0;
|
||||
virtual int NumSortedPlayers() const = 0;
|
||||
virtual const CServerInfo *SortedGet(int Index) const = 0;
|
||||
|
||||
virtual const std::vector<CCommunity> &Communities() const = 0;
|
||||
|
|
|
@ -517,14 +517,10 @@ void CMenus::RenderServerbrowserStatusBox(CUIRect StatusBox, bool WasListboxItem
|
|||
str_format(aBuf, sizeof(aBuf), Localize("%d of %d server"), ServerBrowser()->NumSortedServers(), ServerBrowser()->NumServers());
|
||||
UI()->DoLabel(&ServersOnline, aBuf, 12.0f, TEXTALIGN_MR);
|
||||
|
||||
int NumPlayers = 0;
|
||||
for(int i = 0; i < ServerBrowser()->NumSortedServers(); i++)
|
||||
NumPlayers += ServerBrowser()->SortedGet(i)->m_NumFilteredPlayers;
|
||||
|
||||
if(NumPlayers != 1)
|
||||
str_format(aBuf, sizeof(aBuf), Localize("%d players"), NumPlayers);
|
||||
if(ServerBrowser()->NumSortedPlayers() != 1)
|
||||
str_format(aBuf, sizeof(aBuf), Localize("%d players"), ServerBrowser()->NumSortedPlayers());
|
||||
else
|
||||
str_format(aBuf, sizeof(aBuf), Localize("%d player"), NumPlayers);
|
||||
str_format(aBuf, sizeof(aBuf), Localize("%d player"), ServerBrowser()->NumSortedPlayers());
|
||||
UI()->DoLabel(&PlayersOnline, aBuf, 12.0f, TEXTALIGN_MR);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue