From 828610580452099a7d3659c2f5f4daaef7b5ed13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 19 Feb 2023 10:59:22 +0100 Subject: [PATCH] Use `RecreateTextContainer`, reorder parameters The `RecreateTextContainer` function calls `DeleteTextContainer` and then `CreateTextContainer`. The arguments of `RecreateTextContainer` and `RecreateTextContainerSoft` are reordered so all functions take the text container as their first argument. --- src/engine/client/text.cpp | 4 ++-- src/engine/textrender.h | 4 ++-- src/game/client/components/hud.cpp | 22 ++++++---------------- src/game/client/components/nameplates.cpp | 8 ++------ 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index 01649ed33..9c5548e19 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -1530,13 +1530,13 @@ public: } // just deletes and creates text container - void RecreateTextContainer(CTextCursor *pCursor, int &TextContainerIndex, const char *pText, int Length = -1) override + void RecreateTextContainer(int &TextContainerIndex, CTextCursor *pCursor, const char *pText, int Length = -1) override { DeleteTextContainer(TextContainerIndex); CreateTextContainer(TextContainerIndex, pCursor, pText, Length); } - void RecreateTextContainerSoft(CTextCursor *pCursor, int &TextContainerIndex, const char *pText, int Length = -1) override + void RecreateTextContainerSoft(int &TextContainerIndex, CTextCursor *pCursor, const char *pText, int Length = -1) override { STextContainer &TextContainer = GetTextContainer(TextContainerIndex); TextContainer.m_StringInfo.m_vCharacterQuads.clear(); diff --git a/src/engine/textrender.h b/src/engine/textrender.h index 22305a5f7..2f73e547c 100644 --- a/src/engine/textrender.h +++ b/src/engine/textrender.h @@ -137,8 +137,8 @@ public: // either creates a new text container or appends to a existing one virtual bool CreateOrAppendTextContainer(int &TextContainerIndex, CTextCursor *pCursor, const char *pText, int Length = -1) = 0; // just deletes and creates text container - virtual void RecreateTextContainer(CTextCursor *pCursor, int &TextContainerIndex, const char *pText, int Length = -1) = 0; - virtual void RecreateTextContainerSoft(CTextCursor *pCursor, int &TextContainerIndex, const char *pText, int Length = -1) = 0; + virtual void RecreateTextContainer(int &TextContainerIndex, CTextCursor *pCursor, const char *pText, int Length = -1) = 0; + virtual void RecreateTextContainerSoft(int &TextContainerIndex, CTextCursor *pCursor, const char *pText, int Length = -1) = 0; virtual void DeleteTextContainer(int &TextContainerIndex) = 0; virtual void UploadTextContainer(int TextContainerIndex) = 0; diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index 2bea0f21c..04cfd7869 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -214,12 +214,10 @@ void CHud::RenderScoreHud() // draw score if(aRecreateTeamScore[t]) { - TextRender()->DeleteTextContainer(m_aScoreInfo[t].m_TextScoreContainerIndex); - CTextCursor Cursor; TextRender()->SetCursor(&Cursor, m_Width - ScoreWidthMax + (ScoreWidthMax - m_aScoreInfo[t].m_ScoreTextWidth) / 2 - Split, StartY + t * 20 + (18.f - 14.f) / 2.f, 14.0f, TEXTFLAG_RENDER); Cursor.m_LineWidth = -1; - TextRender()->CreateTextContainer(m_aScoreInfo[t].m_TextScoreContainerIndex, &Cursor, aScoreTeam[t]); + TextRender()->RecreateTextContainer(m_aScoreInfo[t].m_TextScoreContainerIndex, &Cursor, aScoreTeam[t]); } if(m_aScoreInfo[t].m_TextScoreContainerIndex != -1) { @@ -250,14 +248,12 @@ void CHud::RenderScoreHud() { mem_copy(m_aScoreInfo[t].m_aPlayerNameText, pName, sizeof(m_aScoreInfo[t].m_aPlayerNameText)); - TextRender()->DeleteTextContainer(m_aScoreInfo[t].m_OptionalNameTextContainerIndex); - float w = TextRender()->TextWidth(8.0f, pName, -1, -1.0f); CTextCursor Cursor; TextRender()->SetCursor(&Cursor, minimum(m_Width - w - 1.0f, m_Width - ScoreWidthMax - ImageSize - 2 * Split), StartY + (t + 1) * 20.0f - 2.0f, 8.0f, TEXTFLAG_RENDER); Cursor.m_LineWidth = -1; - TextRender()->CreateTextContainer(m_aScoreInfo[t].m_OptionalNameTextContainerIndex, &Cursor, pName); + TextRender()->RecreateTextContainer(m_aScoreInfo[t].m_OptionalNameTextContainerIndex, &Cursor, pName); } if(m_aScoreInfo[t].m_OptionalNameTextContainerIndex != -1) @@ -392,12 +388,10 @@ void CHud::RenderScoreHud() if(RecreateScores) { - TextRender()->DeleteTextContainer(m_aScoreInfo[t].m_TextScoreContainerIndex); - CTextCursor Cursor; TextRender()->SetCursor(&Cursor, m_Width - ScoreWidthMax + (ScoreWidthMax - m_aScoreInfo[t].m_ScoreTextWidth) - Split, StartY + t * 20 + (18.f - 14.f) / 2.f, 14.0f, TEXTFLAG_RENDER); Cursor.m_LineWidth = -1; - TextRender()->CreateTextContainer(m_aScoreInfo[t].m_TextScoreContainerIndex, &Cursor, aScore[t]); + TextRender()->RecreateTextContainer(m_aScoreInfo[t].m_TextScoreContainerIndex, &Cursor, aScore[t]); } // draw score if(m_aScoreInfo[t].m_TextScoreContainerIndex != -1) @@ -418,13 +412,11 @@ void CHud::RenderScoreHud() { mem_copy(m_aScoreInfo[t].m_aPlayerNameText, pName, sizeof(m_aScoreInfo[t].m_aPlayerNameText)); - TextRender()->DeleteTextContainer(m_aScoreInfo[t].m_OptionalNameTextContainerIndex); - CTextCursor Cursor; float w = TextRender()->TextWidth(8.0f, pName, -1, -1.0f); TextRender()->SetCursor(&Cursor, minimum(m_Width - w - 1.0f, m_Width - ScoreWidthMax - ImageSize - 2 * Split - PosSize), StartY + (t + 1) * 20.0f - 2.0f, 8.0f, TEXTFLAG_RENDER); Cursor.m_LineWidth = -1; - TextRender()->CreateTextContainer(m_aScoreInfo[t].m_OptionalNameTextContainerIndex, &Cursor, pName); + TextRender()->RecreateTextContainer(m_aScoreInfo[t].m_OptionalNameTextContainerIndex, &Cursor, pName); } if(m_aScoreInfo[t].m_OptionalNameTextContainerIndex != -1) @@ -458,12 +450,10 @@ void CHud::RenderScoreHud() { mem_copy(m_aScoreInfo[t].m_aRankText, aBuf, sizeof(m_aScoreInfo[t].m_aRankText)); - TextRender()->DeleteTextContainer(m_aScoreInfo[t].m_TextRankContainerIndex); - CTextCursor Cursor; TextRender()->SetCursor(&Cursor, m_Width - ScoreWidthMax - ImageSize - Split - PosSize, StartY + t * 20 + (18.f - 10.f) / 2.f, 10.0f, TEXTFLAG_RENDER); Cursor.m_LineWidth = -1; - TextRender()->CreateTextContainer(m_aScoreInfo[t].m_TextRankContainerIndex, &Cursor, aBuf); + TextRender()->RecreateTextContainer(m_aScoreInfo[t].m_TextRankContainerIndex, &Cursor, aBuf); } if(m_aScoreInfo[t].m_TextRankContainerIndex != -1) { @@ -526,7 +516,7 @@ void CHud::RenderTextInfo() if(m_FPSTextContainerIndex == -1) TextRender()->CreateTextContainer(m_FPSTextContainerIndex, &Cursor, "0"); else - TextRender()->RecreateTextContainerSoft(&Cursor, m_FPSTextContainerIndex, aBuf); + TextRender()->RecreateTextContainerSoft(m_FPSTextContainerIndex, &Cursor, aBuf); TextRender()->SetRenderFlags(OldFlags); ColorRGBA TColor(1, 1, 1, 1); ColorRGBA TOutColor(0, 0, 0, 0.3f); diff --git a/src/game/client/components/nameplates.cpp b/src/game/client/components/nameplates.cpp index 19107e494..96850490c 100644 --- a/src/game/client/components/nameplates.cpp +++ b/src/game/client/components/nameplates.cpp @@ -92,8 +92,6 @@ void CNamePlates::RenderNameplatePos(vec2 Position, const CNetObj_PlayerInfo *pP mem_copy(m_aNamePlates[ClientID].m_aName, pName, sizeof(m_aNamePlates[ClientID].m_aName)); m_aNamePlates[ClientID].m_NameTextFontSize = FontSize; - TextRender()->DeleteTextContainer(m_aNamePlates[ClientID].m_NameTextContainerIndex); - CTextCursor Cursor; TextRender()->SetCursor(&Cursor, 0, 0, FontSize, TEXTFLAG_RENDER); Cursor.m_LineWidth = -1; @@ -105,7 +103,7 @@ void CNamePlates::RenderNameplatePos(vec2 Position, const CNetObj_PlayerInfo *pP m_aNamePlates[ClientID].m_NameTextWidth = TextRender()->TextWidth(FontSize, pName, -1, -1.0f); - TextRender()->CreateTextContainer(m_aNamePlates[ClientID].m_NameTextContainerIndex, &Cursor, pName); + TextRender()->RecreateTextContainer(m_aNamePlates[ClientID].m_NameTextContainerIndex, &Cursor, pName); Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1); } @@ -117,8 +115,6 @@ void CNamePlates::RenderNameplatePos(vec2 Position, const CNetObj_PlayerInfo *pP mem_copy(m_aNamePlates[ClientID].m_aClanName, pClan, sizeof(m_aNamePlates[ClientID].m_aClanName)); m_aNamePlates[ClientID].m_ClanNameTextFontSize = FontSizeClan; - TextRender()->DeleteTextContainer(m_aNamePlates[ClientID].m_ClanNameTextContainerIndex); - CTextCursor Cursor; TextRender()->SetCursor(&Cursor, 0, 0, FontSizeClan, TEXTFLAG_RENDER); Cursor.m_LineWidth = -1; @@ -130,7 +126,7 @@ void CNamePlates::RenderNameplatePos(vec2 Position, const CNetObj_PlayerInfo *pP m_aNamePlates[ClientID].m_ClanNameTextWidth = TextRender()->TextWidth(FontSizeClan, pClan, -1, -1.0f); - TextRender()->CreateTextContainer(m_aNamePlates[ClientID].m_ClanNameTextContainerIndex, &Cursor, pClan); + TextRender()->RecreateTextContainer(m_aNamePlates[ClientID].m_ClanNameTextContainerIndex, &Cursor, pClan); Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1); } }