From b60d6deb513d217727c92972061ce7afcb072c9a Mon Sep 17 00:00:00 2001 From: oy Date: Tue, 11 Jan 2011 23:03:01 +0100 Subject: made m_paInfoByScore within gameclient's snap state work and cleaned up render scoreboard --- src/game/client/components/scoreboard.cpp | 67 +++++++------------------------ src/game/client/gameclient.cpp | 15 +++++++ 2 files changed, 30 insertions(+), 52 deletions(-) (limited to 'src/game/client') diff --git a/src/game/client/components/scoreboard.cpp b/src/game/client/components/scoreboard.cpp index 5556861c..2292f40e 100644 --- a/src/game/client/components/scoreboard.cpp +++ b/src/game/client/components/scoreboard.cpp @@ -119,6 +119,9 @@ void CScoreboard::RenderSpectators(float x, float y, float w) void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const char *pTitle) { + if(Team == TEAM_SPECTATORS) + return; + //float ystart = y; float h = 750.0f; @@ -139,61 +142,19 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch } float tw = TextRender()->TextWidth(0, 48, pTitle, -1); + TextRender()->Text(0, x+10, y, 48, pTitle, -1); - if(Team == TEAM_SPECTATORS) - { - TextRender()->Text(0, x+w/2-tw/2, y, 48, pTitle, -1); - } - else + if(m_pClient->m_Snap.m_pGameobj) { - TextRender()->Text(0, x+10, y, 48, pTitle, -1); - - if(m_pClient->m_Snap.m_pGameobj) - { - char aBuf[128]; - int Score = Team == TEAM_RED ? m_pClient->m_Snap.m_pGameobj->m_TeamscoreRed : m_pClient->m_Snap.m_pGameobj->m_TeamscoreBlue; - str_format(aBuf, sizeof(aBuf), "%d", Score); - tw = TextRender()->TextWidth(0, 48, aBuf, -1); - TextRender()->Text(0, x+w-tw-30, y, 48, aBuf, -1); - } + char aBuf[128]; + int Score = Team == TEAM_RED ? m_pClient->m_Snap.m_pGameobj->m_TeamscoreRed : m_pClient->m_Snap.m_pGameobj->m_TeamscoreBlue; + str_format(aBuf, sizeof(aBuf), "%d", Score); + tw = TextRender()->TextWidth(0, 48, aBuf, -1); + TextRender()->Text(0, x+w-tw-30, y, 48, aBuf, -1); } y += 54.0f; - // find players - const CNetObj_PlayerInfo *paPlayers[MAX_CLIENTS] = {0}; - int NumPlayers = 0; - for(int i = 0; i < Client()->SnapNumItems(IClient::SNAP_CURRENT); i++) - { - IClient::CSnapItem Item; - const void *pData = Client()->SnapGetItem(IClient::SNAP_CURRENT, i, &Item); - - if(Item.m_Type == NETOBJTYPE_PLAYERINFO) - { - const CNetObj_PlayerInfo *pInfo = (const CNetObj_PlayerInfo *)pData; - if(pInfo->m_Team == Team) - { - paPlayers[NumPlayers] = pInfo; - if(++NumPlayers == MAX_CLIENTS) - break; - } - } - } - - // sort players - for(int k = 0; k < NumPlayers-1; k++) // ffs, bubblesort - { - for(int i = 0; i < NumPlayers-k-1; i++) - { - if(paPlayers[i]->m_Score < paPlayers[i+1]->m_Score) - { - const CNetObj_PlayerInfo *pTmp = paPlayers[i]; - paPlayers[i] = paPlayers[i+1]; - paPlayers[i+1] = pTmp; - } - } - } - // render headlines TextRender()->Text(0, x+10, y, 24.0f, Localize("Score"), -1); TextRender()->Text(0, x+125, y, 24.0f, Localize("Name"), -1); @@ -205,7 +166,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch float TeeSizeMod = 1.0f; float TeeOffset = 0.0f; - if(NumPlayers > 13) + if(m_pClient->m_Snap.m_aTeamSize[Team] > 13) { FontSize = 30.0f; LineHeight = 40.0f; @@ -214,9 +175,11 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch } // render player scores - for(int i = 0; i < NumPlayers; i++) + for(int i = 0; i < MAX_CLIENTS; i++) { - const CNetObj_PlayerInfo *pInfo = paPlayers[i]; + const CNetObj_PlayerInfo *pInfo = m_pClient->m_Snap.m_paInfoByScore[i]; + if(!pInfo || pInfo->m_Team != Team) + continue; // make sure that we render the correct team diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 2bebf486..9a05cc88 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -814,6 +814,21 @@ void CGameClient::OnNewSnapshot() } else m_Snap.m_Spectate = true; + + // sort player infos by score + mem_copy(m_Snap.m_paInfoByScore, m_Snap.m_paPlayerInfos, 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++) + { + 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; + } + } + } CTuningParams StandardTuning; CServerInfo CurrentServerInfo; -- cgit 1.4.1