From 74426b05a35377d1edebe27157ef67135689a8c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 21 Jul 2024 12:53:29 +0200 Subject: [PATCH] Avoid copies of server info in `CGameClient::OnNewSnapshot` Only copy the server info with the `GetServerInfo` function once, as it should not change within a call of the `CGameClient::OnNewSnapshot` function. --- src/game/client/gameclient.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index af84e4912..af6ea217d 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -1161,7 +1161,7 @@ void CGameClient::ProcessEvents() } } -static CGameInfo GetGameInfo(const CNetObj_GameInfoEx *pInfoEx, int InfoExSize, CServerInfo *pFallbackServerInfo) +static CGameInfo GetGameInfo(const CNetObj_GameInfoEx *pInfoEx, int InfoExSize, const CServerInfo *pFallbackServerInfo) { int Version = -1; if(InfoExSize >= 12) @@ -1376,6 +1376,9 @@ void CGameClient::OnNewSnapshot() } #endif + CServerInfo ServerInfo; + Client()->GetServerInfo(&ServerInfo); + bool FoundGameInfoEx = false; bool GotSwitchStateTeam = false; m_aSwitchStateTeam[g_Config.m_ClDummy] = -1; @@ -1614,8 +1617,6 @@ void CGameClient::OnNewSnapshot() continue; } FoundGameInfoEx = true; - CServerInfo ServerInfo; - Client()->GetServerInfo(&ServerInfo); m_GameInfo = GetGameInfo((const CNetObj_GameInfoEx *)Item.m_pData, Item.m_DataSize, &ServerInfo); } else if(Item.m_Type == NETOBJTYPE_GAMEDATA) @@ -1701,8 +1702,6 @@ void CGameClient::OnNewSnapshot() if(!FoundGameInfoEx) { - CServerInfo ServerInfo; - Client()->GetServerInfo(&ServerInfo); m_GameInfo = GetGameInfo(0, 0, &ServerInfo); } @@ -1807,12 +1806,10 @@ void CGameClient::OnNewSnapshot() } } - CServerInfo CurrentServerInfo; - Client()->GetServerInfo(&CurrentServerInfo); CTuningParams StandardTuning; - if(CurrentServerInfo.m_aGameType[0] != '0') + if(ServerInfo.m_aGameType[0] != '0') { - if(str_comp(CurrentServerInfo.m_aGameType, "DM") != 0 && str_comp(CurrentServerInfo.m_aGameType, "TDM") != 0 && str_comp(CurrentServerInfo.m_aGameType, "CTF") != 0) + if(str_comp(ServerInfo.m_aGameType, "DM") != 0 && str_comp(ServerInfo.m_aGameType, "TDM") != 0 && str_comp(ServerInfo.m_aGameType, "CTF") != 0) m_ServerMode = SERVERMODE_MOD; else if(mem_comp(&StandardTuning, &m_aTuning[g_Config.m_ClDummy], 33) == 0) m_ServerMode = SERVERMODE_PURE;