From 27865fdd89eee6a0201d3ea815b5b48268efb85e Mon Sep 17 00:00:00 2001 From: def Date: Wed, 21 Nov 2018 21:26:05 +0100 Subject: [PATCH] Fix Race scoreboard ordering for times > 166 minutes (9999 seconds) --- src/game/client/gameclient.cpp | 77 +++++++++++++++------------------- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 340df4a1c..7ed0cc19b 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -1,5 +1,8 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ + +#include + #include #include #include @@ -62,7 +65,6 @@ #include #include "components/race_demo.h" #include "components/ghost.h" -#include CGameClient g_GameClient; @@ -1227,61 +1229,48 @@ void CGameClient::OnNewSnapshot() for(int i = 0; i < MAX_CLIENTS; ++i) { - // update friend state - m_aClients[i].m_Friend = !(i == m_Snap.m_LocalClientID - || !m_Snap.m_paPlayerInfos[i] - || !Friends()->IsFriend(m_aClients[i].m_aName, m_aClients[i].m_aClan, true)); + // update friend state + m_aClients[i].m_Friend = !(i == m_Snap.m_LocalClientID + || !m_Snap.m_paPlayerInfos[i] + || !Friends()->IsFriend(m_aClients[i].m_aName, m_aClients[i].m_aClan, true)); - // update foe state - m_aClients[i].m_Foe = !(i == m_Snap.m_LocalClientID - || !m_Snap.m_paPlayerInfos[i] - || !Foes()->IsFriend(m_aClients[i].m_aName, m_aClients[i].m_aClan, true)); + // update foe state + m_aClients[i].m_Foe = !(i == m_Snap.m_LocalClientID + || !m_Snap.m_paPlayerInfos[i] + || !Foes()->IsFriend(m_aClients[i].m_aName, m_aClients[i].m_aClan, true)); } // sort player infos by name mem_copy(m_Snap.m_paInfoByName, m_Snap.m_paPlayerInfos, sizeof(m_Snap.m_paInfoByName)); - for(int k = 0; k < MAX_CLIENTS-1; k++) // ffs, bubblesort - { - for(int i = 0; i < MAX_CLIENTS-k-1; i++) + std::stable_sort(m_Snap.m_paInfoByName, m_Snap.m_paInfoByName + MAX_CLIENTS, + [this](const CNetObj_PlayerInfo* p1, const CNetObj_PlayerInfo* p2) -> bool { - if(m_Snap.m_paInfoByName[i+1] && (!m_Snap.m_paInfoByName[i] || str_comp_nocase(m_aClients[m_Snap.m_paInfoByName[i]->m_ClientID].m_aName, m_aClients[m_Snap.m_paInfoByName[i+1]->m_ClientID].m_aName) > 0)) - { - const CNetObj_PlayerInfo *pTmp = m_Snap.m_paInfoByName[i]; - m_Snap.m_paInfoByName[i] = m_Snap.m_paInfoByName[i+1]; - m_Snap.m_paInfoByName[i+1] = pTmp; - } - } - } + if (!p2) + return false; + if (!p1) + return true; + return str_comp_nocase(m_aClients[p1->m_ClientID].m_aName, m_aClients[p2->m_ClientID].m_aName) < 0; + }); + + CServerInfo Info; + Client()->GetServerInfo(&Info); + bool IsGameTypeRace = IsRace(&Info); // sort player infos by score mem_copy(m_Snap.m_paInfoByScore, m_Snap.m_paInfoByName, sizeof(m_Snap.m_paInfoByScore)); - for(int k = 0; k < MAX_CLIENTS-1; k++) // ffs, bubblesort - { - for(int i = 0; i < MAX_CLIENTS-k-1; i++) + std::stable_sort(m_Snap.m_paInfoByScore, m_Snap.m_paInfoByScore + MAX_CLIENTS, + [IsGameTypeRace](const CNetObj_PlayerInfo* p1, const CNetObj_PlayerInfo* p2) -> bool { - if(m_Snap.m_paInfoByScore[i+1] && (!m_Snap.m_paInfoByScore[i] || m_Snap.m_paInfoByScore[i]->m_Score < m_Snap.m_paInfoByScore[i+1]->m_Score)) - { - const CNetObj_PlayerInfo *pTmp = m_Snap.m_paInfoByScore[i]; - m_Snap.m_paInfoByScore[i] = m_Snap.m_paInfoByScore[i+1]; - m_Snap.m_paInfoByScore[i+1] = pTmp; - } - } - } - - // sort player infos by team - //int Teams[3] = { TEAM_RED, TEAM_BLUE, TEAM_SPECTATORS }; - int Index = 0; - //for(int Team = 0; Team < 3; ++Team) - //{ - // for(int i = 0; i < MAX_CLIENTS && Index < MAX_CLIENTS; ++i) - // { - // if(m_Snap.m_paPlayerInfos[i] && m_Snap.m_paPlayerInfos[i]->m_Team == Teams[Team]) - // m_Snap.m_paInfoByTeam[Index++] = m_Snap.m_paPlayerInfos[i]; - // } - //} + if (!p2) + return false; + if (!p1) + return true; + return (((IsGameTypeRace && p1->m_Score == -9999) ? std::numeric_limits::min() : p1->m_Score) > + ((IsGameTypeRace && p2->m_Score == -9999) ? std::numeric_limits::min() : p2->m_Score)); + }); // sort player infos by DDRace Team (and score between) - Index = 0; + int Index = 0; for(int Team = 0; Team <= MAX_CLIENTS; ++Team) { for(int i = 0; i < MAX_CLIENTS && Index < MAX_CLIENTS; ++i)