From a97a59759255d806e9f17d9f094e9e10966cc1a4 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Tue, 11 Oct 2022 14:28:41 +0200 Subject: [PATCH] Inline `Is(GameType)` functions They are used for two purposes, coloring gametypes in the serverbrowser and enabling backward compatibility. These are independent, we shouldn't add more stuff to the backward compatibility, hence I split them up and inlined them. --- src/engine/client/client.cpp | 2 +- src/engine/client/serverbrowser.cpp | 65 +------------------- src/engine/serverbrowser.h | 12 ---- src/game/client/components/menus_browser.cpp | 16 ++--- src/game/client/gameclient.cpp | 19 +++--- 5 files changed, 20 insertions(+), 94 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 479e90f62..a2bf22c36 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -1578,7 +1578,7 @@ bool CClient::ShouldSendChatTimeoutCodeHeuristic() { return false; } - return IsDDNet(&m_CurrentServerInfo); + return str_find_nocase(m_CurrentServerInfo.m_aGameType, "ddracenet") || str_find_nocase(m_CurrentServerInfo.m_aGameType, "ddnet"); } static CServerCapabilities GetServerCapabilities(int Version, int Flags) diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index f5046c293..996d4916b 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -1564,70 +1564,7 @@ bool CServerInfo::ParseLocation(int *pResult, const char *pString) return true; } -bool IsVanilla(const CServerInfo *pInfo) -{ - return !str_comp(pInfo->m_aGameType, "DM") || !str_comp(pInfo->m_aGameType, "TDM") || !str_comp(pInfo->m_aGameType, "CTF"); -} - -bool IsCatch(const CServerInfo *pInfo) -{ - return str_find_nocase(pInfo->m_aGameType, "catch"); -} - -bool IsInsta(const CServerInfo *pInfo) -{ - return str_find_nocase(pInfo->m_aGameType, "idm") || str_find_nocase(pInfo->m_aGameType, "itdm") || str_find_nocase(pInfo->m_aGameType, "ictf"); -} - -bool IsFNG(const CServerInfo *pInfo) -{ - return str_find_nocase(pInfo->m_aGameType, "fng"); -} - -bool IsRace(const CServerInfo *pInfo) -{ - return str_find_nocase(pInfo->m_aGameType, "race") || str_find_nocase(pInfo->m_aGameType, "fastcap"); -} - -bool IsFastCap(const CServerInfo *pInfo) -{ - return str_find_nocase(pInfo->m_aGameType, "fastcap"); -} - -bool IsBlockInfectionZ(const CServerInfo *pInfo) -{ - return str_find_nocase(pInfo->m_aGameType, "blockz") || - str_find_nocase(pInfo->m_aGameType, "infectionz"); -} - -bool IsBlockWorlds(const CServerInfo *pInfo) -{ - return (str_startswith(pInfo->m_aGameType, "bw ")) || (str_comp_nocase(pInfo->m_aGameType, "bw") == 0); -} - -bool IsCity(const CServerInfo *pInfo) -{ - return str_find_nocase(pInfo->m_aGameType, "city"); -} - -bool IsDDRace(const CServerInfo *pInfo) -{ - return str_find_nocase(pInfo->m_aGameType, "ddrace") || str_find_nocase(pInfo->m_aGameType, "mkrace"); -} - -bool IsDDNet(const CServerInfo *pInfo) -{ - return str_find_nocase(pInfo->m_aGameType, "ddracenet") || str_find_nocase(pInfo->m_aGameType, "ddnet"); -} - -// other - bool Is64Player(const CServerInfo *pInfo) { - return str_find(pInfo->m_aGameType, "64") || str_find(pInfo->m_aName, "64") || IsDDNet(pInfo); -} - -bool IsPlus(const CServerInfo *pInfo) -{ - return str_find(pInfo->m_aGameType, "+"); + return str_find(pInfo->m_aGameType, "64") || str_find(pInfo->m_aName, "64") || str_find_nocase(pInfo->m_aGameType, "ddracenet") || str_find_nocase(pInfo->m_aGameType, "ddnet"); } diff --git a/src/engine/serverbrowser.h b/src/engine/serverbrowser.h index c11a4b110..409079639 100644 --- a/src/engine/serverbrowser.h +++ b/src/engine/serverbrowser.h @@ -85,19 +85,7 @@ public: static bool ParseLocation(int *pResult, const char *pString); }; -bool IsVanilla(const CServerInfo *pInfo); -bool IsCatch(const CServerInfo *pInfo); -bool IsInsta(const CServerInfo *pInfo); -bool IsFNG(const CServerInfo *pInfo); -bool IsRace(const CServerInfo *pInfo); -bool IsFastCap(const CServerInfo *pInfo); -bool IsDDRace(const CServerInfo *pInfo); -bool IsDDNet(const CServerInfo *pInfo); -bool IsBlockWorlds(const CServerInfo *pInfo); -bool IsCity(const CServerInfo *pInfo); - bool Is64Player(const CServerInfo *pInfo); -bool IsPlus(const CServerInfo *pInfo); class IServerBrowser : public IInterface { diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index d27868253..6fec08c97 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -464,19 +464,19 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) { ColorHSLA hsl = ColorHSLA(1.0f, 1.0f, 1.0f); - if(IsVanilla(pItem)) + if(str_comp(pItem->m_aGameType, "DM") == 0 || str_comp(pItem->m_aGameType, "TDM") == 0 || str_comp(pItem->m_aGameType, "CTF") == 0) hsl = ColorHSLA(0.33f, 1.0f, 0.75f); - else if(IsCatch(pItem)) + else if(str_find_nocase(pItem->m_aGameType, "catch")) hsl = ColorHSLA(0.17f, 1.0f, 0.75f); - else if(IsInsta(pItem)) + else if(str_find_nocase(pItem->m_aGameType, "idm") || str_find_nocase(pItem->m_aGameType, "itdm") || str_find_nocase(pItem->m_aGameType, "ictf")) hsl = ColorHSLA(0.00f, 1.0f, 0.75f); - else if(IsFNG(pItem)) + else if(str_find_nocase(pItem->m_aGameType, "fng")) hsl = ColorHSLA(0.83f, 1.0f, 0.75f); - else if(IsDDNet(pItem)) + else if(str_find_nocase(pItem->m_aGameType, "ddracenet") || str_find_nocase(pItem->m_aGameType, "ddnet")) hsl = ColorHSLA(0.58f, 1.0f, 0.75f); - else if(IsDDRace(pItem)) + else if(str_find_nocase(pItem->m_aGameType, "ddrace") || str_find_nocase(pItem->m_aGameType, "mkrace")) hsl = ColorHSLA(0.75f, 1.0f, 0.75f); - else if(IsRace(pItem)) + else if(str_find_nocase(pItem->m_aGameType, "race") || str_find_nocase(pItem->m_aGameType, "fastcap")) hsl = ColorHSLA(0.46f, 1.0f, 0.75f); ColorRGBA rgb = color_cast(hsl); @@ -1167,7 +1167,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View) if(!pSelectedServer->m_aClients[i].m_Player) str_copy(aTemp, "SPEC"); - else if(IsRace(pSelectedServer) && g_Config.m_ClDDRaceScoreBoard) + else if((str_find_nocase(pSelectedServer->m_aGameType, "race") || str_find_nocase(pSelectedServer->m_aGameType, "fastcap")) && g_Config.m_ClDDRaceScoreBoard) { if(pSelectedServer->m_aClients[i].m_Score == -9999 || pSelectedServer->m_aClients[i].m_Score == 0) aTemp[0] = 0; diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 9e4de7a66..376b95014 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -1009,15 +1009,16 @@ static CGameInfo GetGameInfo(const CNetObj_GameInfoEx *pInfoEx, int InfoExSize, bool FDDrace; if(Version < 1) { - Race = IsRace(pFallbackServerInfo); - FastCap = IsFastCap(pFallbackServerInfo); - FNG = IsFNG(pFallbackServerInfo); - DDRace = IsDDRace(pFallbackServerInfo); - DDNet = IsDDNet(pFallbackServerInfo); - BlockWorlds = IsBlockWorlds(pFallbackServerInfo); - City = IsCity(pFallbackServerInfo); - Vanilla = IsVanilla(pFallbackServerInfo); - Plus = IsPlus(pFallbackServerInfo); + const char *pGameType = pFallbackServerInfo->m_aGameType; + Race = str_find_nocase(pGameType, "race") || str_find_nocase(pGameType, "fastcap"); + FastCap = str_find_nocase(pGameType, "fastcap"); + FNG = str_find_nocase(pGameType, "fng"); + DDRace = str_find_nocase(pGameType, "ddrace") || str_find_nocase(pGameType, "mkrace"); + DDNet = str_find_nocase(pGameType, "ddracenet") || str_find_nocase(pGameType, "ddnet"); + BlockWorlds = str_startswith(pGameType, "bw ") || str_comp_nocase(pGameType, "bw") == 0; + City = str_find_nocase(pGameType, "city"); + Vanilla = str_comp(pGameType, "DM") == 0 || str_comp(pGameType, "TDM") == 0 || str_comp(pGameType, "CTF") == 0; + Plus = str_find(pGameType, "+"); FDDrace = false; } else