Merge pull request #8627 from Robyt3/Client-GetServerInfo-Cleanup

Avoid copies of server info in `CGameClient::OnNewSnapshot`
This commit is contained in:
heinrich5991 2024-07-21 11:19:10 +00:00 committed by GitHub
commit cd3a97c125
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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; int Version = -1;
if(InfoExSize >= 12) if(InfoExSize >= 12)
@ -1376,6 +1376,9 @@ void CGameClient::OnNewSnapshot()
} }
#endif #endif
CServerInfo ServerInfo;
Client()->GetServerInfo(&ServerInfo);
bool FoundGameInfoEx = false; bool FoundGameInfoEx = false;
bool GotSwitchStateTeam = false; bool GotSwitchStateTeam = false;
m_aSwitchStateTeam[g_Config.m_ClDummy] = -1; m_aSwitchStateTeam[g_Config.m_ClDummy] = -1;
@ -1614,8 +1617,6 @@ void CGameClient::OnNewSnapshot()
continue; continue;
} }
FoundGameInfoEx = true; FoundGameInfoEx = true;
CServerInfo ServerInfo;
Client()->GetServerInfo(&ServerInfo);
m_GameInfo = GetGameInfo((const CNetObj_GameInfoEx *)Item.m_pData, Item.m_DataSize, &ServerInfo); m_GameInfo = GetGameInfo((const CNetObj_GameInfoEx *)Item.m_pData, Item.m_DataSize, &ServerInfo);
} }
else if(Item.m_Type == NETOBJTYPE_GAMEDATA) else if(Item.m_Type == NETOBJTYPE_GAMEDATA)
@ -1701,8 +1702,6 @@ void CGameClient::OnNewSnapshot()
if(!FoundGameInfoEx) if(!FoundGameInfoEx)
{ {
CServerInfo ServerInfo;
Client()->GetServerInfo(&ServerInfo);
m_GameInfo = GetGameInfo(0, 0, &ServerInfo); m_GameInfo = GetGameInfo(0, 0, &ServerInfo);
} }
@ -1807,12 +1806,10 @@ void CGameClient::OnNewSnapshot()
} }
} }
CServerInfo CurrentServerInfo;
Client()->GetServerInfo(&CurrentServerInfo);
CTuningParams StandardTuning; 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; m_ServerMode = SERVERMODE_MOD;
else if(mem_comp(&StandardTuning, &m_aTuning[g_Config.m_ClDummy], 33) == 0) else if(mem_comp(&StandardTuning, &m_aTuning[g_Config.m_ClDummy], 33) == 0)
m_ServerMode = SERVERMODE_PURE; m_ServerMode = SERVERMODE_PURE;