Avoid duplicate calculations of nameplate text width

Get name/clan bounding box size from the text container index instead of calculating it twice.
This commit is contained in:
Robert Müller 2024-06-26 20:05:20 +02:00
parent b30dde56b6
commit 0222e4ae96
2 changed files with 4 additions and 16 deletions

View file

@ -96,15 +96,11 @@ void CNamePlates::RenderNameplate(vec2 Position, const CNetObj_PlayerInfo *pPlay
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, 0, 0, FontSize, TEXTFLAG_RENDER);
Cursor.m_LineWidth = -1;
// create nameplates at standard zoom
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
RenderTools()->MapScreenToInterface(m_pClient->m_Camera.m_Center.x, m_pClient->m_Camera.m_Center.y);
NamePlate.m_NameTextWidth = TextRender()->TextWidth(FontSize, ClientData.m_aName, -1, -1.0f);
TextRender()->RecreateTextContainer(NamePlate.m_NameTextContainerIndex, &Cursor, ClientData.m_aName);
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
@ -118,21 +114,16 @@ void CNamePlates::RenderNameplate(vec2 Position, const CNetObj_PlayerInfo *pPlay
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, 0, 0, FontSizeClan, TEXTFLAG_RENDER);
Cursor.m_LineWidth = -1;
// create nameplates at standard zoom
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
RenderTools()->MapScreenToInterface(m_pClient->m_Camera.m_Center.x, m_pClient->m_Camera.m_Center.y);
NamePlate.m_ClanNameTextWidth = TextRender()->TextWidth(FontSizeClan, ClientData.m_aClan, -1, -1.0f);
TextRender()->RecreateTextContainer(NamePlate.m_ClanNameTextContainerIndex, &Cursor, ClientData.m_aClan);
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
}
float tw = NamePlate.m_NameTextWidth;
if(g_Config.m_ClNameplatesTeamcolors)
{
const int Team = m_pClient->m_Teams.Team(pPlayerInfo->m_ClientId);
@ -169,14 +160,14 @@ void CNamePlates::RenderNameplate(vec2 Position, const CNetObj_PlayerInfo *pPlay
if(NamePlate.m_NameTextContainerIndex.Valid())
{
YOffset -= FontSize;
TextRender()->RenderTextContainer(NamePlate.m_NameTextContainerIndex, TColor, TOutlineColor, Position.x - tw / 2.0f, YOffset);
TextRender()->RenderTextContainer(NamePlate.m_NameTextContainerIndex, TColor, TOutlineColor, Position.x - TextRender()->GetBoundingBoxTextContainer(NamePlate.m_NameTextContainerIndex).m_W / 2.0f, YOffset);
}
if(g_Config.m_ClNameplatesClan)
{
YOffset -= FontSizeClan;
if(NamePlate.m_ClanNameTextContainerIndex.Valid())
TextRender()->RenderTextContainer(NamePlate.m_ClanNameTextContainerIndex, TColor, TOutlineColor, Position.x - NamePlate.m_ClanNameTextWidth / 2.0f, YOffset);
TextRender()->RenderTextContainer(NamePlate.m_ClanNameTextContainerIndex, TColor, TOutlineColor, Position.x - TextRender()->GetBoundingBoxTextContainer(NamePlate.m_ClanNameTextContainerIndex).m_W / 2.0f, YOffset);
}
if(g_Config.m_ClNameplatesFriendMark && ClientData.m_Friend)

View file

@ -23,19 +23,16 @@ struct SPlayerNamePlate
{
m_NameTextContainerIndex.Reset();
m_ClanNameTextContainerIndex.Reset();
m_aName[0] = 0;
m_aClanName[0] = 0;
m_NameTextWidth = m_ClanNameTextWidth = 0.f;
m_aName[0] = '\0';
m_aClanName[0] = '\0';
m_NameTextFontSize = m_ClanNameTextFontSize = 0;
}
char m_aName[MAX_NAME_LENGTH];
float m_NameTextWidth;
STextContainerIndex m_NameTextContainerIndex;
float m_NameTextFontSize;
char m_aClanName[MAX_CLAN_LENGTH];
float m_ClanNameTextWidth;
STextContainerIndex m_ClanNameTextContainerIndex;
float m_ClanNameTextFontSize;
};