From faf388b853f04946cd31fbe8ba5f5a147ed2fcb4 Mon Sep 17 00:00:00 2001 From: def Date: Mon, 29 Oct 2018 22:03:57 +0100 Subject: [PATCH] Fix #1350 --- src/engine/client/serverbrowser.cpp | 57 ++++++++++---------- src/engine/client/serverbrowser.h | 2 - src/engine/serverbrowser.h | 2 +- src/game/client/components/menus_browser.cpp | 4 +- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index e0b8d87ae..7068f5c99 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -147,7 +147,7 @@ bool CServerBrowser::SortCompareNumPlayers(int Index1, int Index2) const { CServerEntry *a = m_ppServerlist[Index1]; CServerEntry *b = m_ppServerlist[Index2]; - return FilteredPlayers(a->m_Info) < FilteredPlayers(b->m_Info); + return a->m_Info.m_NumFilteredPlayers < b->m_Info.m_NumFilteredPlayers; } bool CServerBrowser::SortCompareNumClients(int Index1, int Index2) const @@ -157,32 +157,6 @@ bool CServerBrowser::SortCompareNumClients(int Index1, int Index2) const return a->m_Info.m_NumClients < b->m_Info.m_NumClients; } -int CServerBrowser::FilteredPlayers(const CServerInfo &Item) const -{ - int NumPlayers = 0; - - for(int i = 0; i < MAX_CLIENTS; i++) - { - const CServerInfo::CClient &Client = Item.m_aClients[i]; - - if(Client.m_aName[0] == '\0') - continue; - - if(g_Config.m_BrFilterSpectators && !Client.m_Player) - continue; - - if(g_Config.m_BrFilterFriends && Client.m_FriendState == IFriends::FRIEND_NO) - continue; - - if(g_Config.m_BrFilterConnectingPlayers && str_comp(Client.m_aName, "(connecting)") == 0 && Client.m_aClan[0] == '\0' && Client.m_Country == -1 && Client.m_Score == 0) - continue; - - NumPlayers++; - } - - return NumPlayers; -} - void CServerBrowser::Filter() { int i = 0, p = 0; @@ -202,7 +176,7 @@ void CServerBrowser::Filter() { int Filtered = 0; - if(g_Config.m_BrFilterEmpty && FilteredPlayers(m_ppServerlist[i]->m_Info) == 0) + if(g_Config.m_BrFilterEmpty && m_ppServerlist[i]->m_Info.m_NumFilteredPlayers == 0) Filtered = 1; else if(g_Config.m_BrFilterFull && Players(m_ppServerlist[i]->m_Info) == Max(m_ppServerlist[i]->m_Info)) Filtered = 1; @@ -360,10 +334,37 @@ int CServerBrowser::SortHash() const return i; } +void SetFilteredPlayers(const CServerInfo &Item) +{ + Item.m_NumFilteredPlayers = 0; + + for(int i = 0; i < MAX_CLIENTS; i++) + { + const CServerInfo::CClient &Client = Item.m_aClients[i]; + + if(Client.m_aName[0] == '\0') + continue; + + if(g_Config.m_BrFilterSpectators && !Client.m_Player) + continue; + + if(g_Config.m_BrFilterConnectingPlayers && str_comp(Client.m_aName, "(connecting)") == 0 && Client.m_aClan[0] == '\0' && Client.m_Country == -1 && Client.m_Score == 0) + continue; + + Item.m_NumFilteredPlayers++; + } +} + void CServerBrowser::Sort() { int i; + // fill m_NumFilteredPlayers + for(i = 0; i < m_NumServers; i++) + { + SetFilteredPlayers(m_ppServerlist[i]->m_Info); + } + // create filtered list Filter(); diff --git a/src/engine/client/serverbrowser.h b/src/engine/client/serverbrowser.h index ec2e8acc9..f78e1a1d8 100644 --- a/src/engine/client/serverbrowser.h +++ b/src/engine/client/serverbrowser.h @@ -68,8 +68,6 @@ public: int NumServers() const { return m_NumServers; } - int FilteredPlayers(const CServerInfo &Item) const; - int Players(const CServerInfo &Item) const { return g_Config.m_BrFilterSpectators ? Item.m_NumPlayers : Item.m_NumClients; diff --git a/src/engine/serverbrowser.h b/src/engine/serverbrowser.h index 617a0feae..1b01812d7 100644 --- a/src/engine/serverbrowser.h +++ b/src/engine/serverbrowser.h @@ -59,6 +59,7 @@ public: char m_aVersion[32]; char m_aAddress[NETADDR_MAXSTRSIZE]; CClient m_aClients[MAX_CLIENTS]; + mutable int m_NumFilteredPlayers; }; bool IsVanilla(const CServerInfo *pInfo); @@ -116,7 +117,6 @@ public: virtual int NumServers() const = 0; - virtual int FilteredPlayers(const CServerInfo &Item) const = 0; virtual int Players(const CServerInfo &Item) const = 0; virtual int Max(const CServerInfo &Item) const = 0; diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 9ca6099b4..464a0ae30 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -243,7 +243,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) { int ItemIndex = i; const CServerInfo *pItem = ServerBrowser()->SortedGet(ItemIndex); - NumPlayers += ServerBrowser()->FilteredPlayers(*pItem); + NumPlayers += pItem->m_NumFilteredPlayers; CUIRect Row; CUIRect SelectHitBox; @@ -407,7 +407,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) DoButton_Icon(IMAGE_BROWSEICONS, SPRITE_BROWSE_HEART, &Icon); } - str_format(aTemp, sizeof(aTemp), "%i/%i", ServerBrowser()->FilteredPlayers(*pItem), ServerBrowser()->Max(*pItem)); + str_format(aTemp, sizeof(aTemp), "%i/%i", pItem->m_NumFilteredPlayers, ServerBrowser()->Max(*pItem)); if(g_Config.m_BrFilterString[0] && (pItem->m_QuickSearchHit&IServerBrowser::QUICK_PLAYER)) TextRender()->TextColor(0.4f,0.4f,1.0f,1); UI()->DoLabelScaled(&Button, aTemp, 12.0f, 1);