mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge pull request #7279 from Robyt3/Menus-Performance
Improve performance of menus checker background, improve server browser performance
This commit is contained in:
commit
887522ea5b
|
@ -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;
|
||||
|
|
|
@ -2121,45 +2121,49 @@ void CMenus::RenderBackground()
|
|||
{
|
||||
Graphics()->BlendNormal();
|
||||
|
||||
float sw = 300 * Graphics()->ScreenAspect();
|
||||
float sh = 300;
|
||||
Graphics()->MapScreen(0, 0, sw, sh);
|
||||
const float ScreenHeight = 300.0f;
|
||||
const float ScreenWidth = ScreenHeight * Graphics()->ScreenAspect();
|
||||
Graphics()->MapScreen(0.0f, 0.0f, ScreenWidth, ScreenHeight);
|
||||
|
||||
// render background color
|
||||
Graphics()->TextureClear();
|
||||
Graphics()->QuadsBegin();
|
||||
ColorRGBA Bottom(ms_GuiColor.r, ms_GuiColor.g, ms_GuiColor.b, 1.0f);
|
||||
ColorRGBA Top(ms_GuiColor.r, ms_GuiColor.g, ms_GuiColor.b, 1.0f);
|
||||
IGraphics::CColorVertex Array[4] = {
|
||||
IGraphics::CColorVertex(0, Top.r, Top.g, Top.b, Top.a),
|
||||
IGraphics::CColorVertex(1, Top.r, Top.g, Top.b, Top.a),
|
||||
IGraphics::CColorVertex(2, Bottom.r, Bottom.g, Bottom.b, Bottom.a),
|
||||
IGraphics::CColorVertex(3, Bottom.r, Bottom.g, Bottom.b, Bottom.a)};
|
||||
Graphics()->SetColorVertex(Array, 4);
|
||||
IGraphics::CQuadItem QuadItem(0, 0, sw, sh);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
Graphics()->SetColor(ms_GuiColor.WithAlpha(1.0f));
|
||||
const IGraphics::CQuadItem BackgroundQuadItem = IGraphics::CQuadItem(0, 0, ScreenWidth, ScreenHeight);
|
||||
Graphics()->QuadsDrawTL(&BackgroundQuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
|
||||
// render the tiles
|
||||
Graphics()->TextureClear();
|
||||
Graphics()->QuadsBegin();
|
||||
float Size = 15.0f;
|
||||
float OffsetTime = std::fmod(LocalTime() * 0.15f, 2.0f);
|
||||
for(int y = -2; y < (int)(sw / Size); y++)
|
||||
for(int x = -2; x < (int)(sh / Size); x++)
|
||||
Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.045f);
|
||||
const float Size = 15.0f;
|
||||
const float OffsetTime = std::fmod(LocalTime() * 0.15f, 2.0f);
|
||||
IGraphics::CQuadItem aCheckerItems[64];
|
||||
size_t NumCheckerItems = 0;
|
||||
for(int y = -2; y < (int)(ScreenWidth / Size); y++)
|
||||
{
|
||||
for(int x = -2; x < (int)(ScreenHeight / Size); x++)
|
||||
{
|
||||
Graphics()->SetColor(0, 0, 0, 0.045f);
|
||||
QuadItem = IGraphics::CQuadItem((x - OffsetTime) * Size * 2 + (y & 1) * Size, (y + OffsetTime) * Size, Size, Size);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
aCheckerItems[NumCheckerItems] = IGraphics::CQuadItem((x - OffsetTime) * Size * 2 + (y & 1) * Size, (y + OffsetTime) * Size, Size, Size);
|
||||
NumCheckerItems++;
|
||||
if(NumCheckerItems == std::size(aCheckerItems))
|
||||
{
|
||||
Graphics()->QuadsDrawTL(aCheckerItems, NumCheckerItems);
|
||||
NumCheckerItems = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(NumCheckerItems != 0)
|
||||
Graphics()->QuadsDrawTL(aCheckerItems, NumCheckerItems);
|
||||
Graphics()->QuadsEnd();
|
||||
|
||||
// render border fade
|
||||
Graphics()->TextureSet(m_TextureBlob);
|
||||
Graphics()->QuadsBegin();
|
||||
Graphics()->SetColor(1, 1, 1, 1);
|
||||
QuadItem = IGraphics::CQuadItem(-100, -100, sw + 200, sh + 200);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
const IGraphics::CQuadItem BlobQuadItem = IGraphics::CQuadItem(-100, -100, ScreenWidth + 200, ScreenHeight + 200);
|
||||
Graphics()->QuadsDrawTL(&BlobQuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
|
||||
// restore screen
|
||||
|
|
|
@ -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