Skip to content

Commit

Permalink
Refactor CTeeRenderInfo usage
Browse files Browse the repository at this point in the history
- Add `CTeeRenderInfo::ApplyColors` function to reduce duplicate code.
- Use `CTeeRenderInfo::Apply` function in more cases.
- Use `CSkins::Find` function instead of implementing default skin handling manually with the `FindOrNullptr` function for chat settings preview.
- Remove redundant initialization of `CTeeRenderInfo::m_CustomColoredSkin` member.
- Replace empty client skin with `default` instead of checking for empty skin names later.
- Remove unnecessary check for empty skin name for ghost rendering. The `CSkins::Find` function will return the default skin instead, which is more correct then invalidating the ghost skin render info.
  • Loading branch information
Robyt3 committed Oct 10, 2024
1 parent f2090d6 commit 1165a82
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 86 deletions.
25 changes: 2 additions & 23 deletions src/game/client/components/ghost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,20 +388,8 @@ void CGhost::InitRenderInfos(CGhostItem *pGhost)
char aSkinName[MAX_SKIN_LENGTH];
IntsToStr(&pGhost->m_Skin.m_Skin0, 6, aSkinName, std::size(aSkinName));
CTeeRenderInfo *pRenderInfo = &pGhost->m_RenderInfo;

pRenderInfo->Apply(m_pClient->m_Skins.Find(aSkinName));
pRenderInfo->m_CustomColoredSkin = pGhost->m_Skin.m_UseCustomColor;
if(pGhost->m_Skin.m_UseCustomColor)
{
pRenderInfo->m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(pGhost->m_Skin.m_ColorBody).UnclampLighting(ColorHSLA::DARKEST_LGT));
pRenderInfo->m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(pGhost->m_Skin.m_ColorFeet).UnclampLighting(ColorHSLA::DARKEST_LGT));
}
else
{
pRenderInfo->m_ColorBody = ColorRGBA(1, 1, 1);
pRenderInfo->m_ColorFeet = ColorRGBA(1, 1, 1);
}

pRenderInfo->ApplyColors(pGhost->m_Skin.m_UseCustomColor, pGhost->m_Skin.m_ColorBody, pGhost->m_Skin.m_ColorFeet);
pRenderInfo->m_Size = 64;
}

Expand Down Expand Up @@ -687,16 +675,7 @@ void CGhost::OnRefreshSkins()
return;
char aSkinName[MAX_SKIN_LENGTH];
IntsToStr(&Ghost.m_Skin.m_Skin0, 6, aSkinName, std::size(aSkinName));
CTeeRenderInfo *pRenderInfo = &Ghost.m_RenderInfo;
if(aSkinName[0] != '\0')
{
pRenderInfo->Apply(m_pClient->m_Skins.Find(aSkinName));
}
else
{
pRenderInfo->m_OriginalRenderSkin.Reset();
pRenderInfo->m_ColorableRenderSkin.Reset();
}
Ghost.m_RenderInfo.Apply(m_pClient->m_Skins.Find(aSkinName));
};

for(auto &Ghost : m_aActiveGhosts)
Expand Down
12 changes: 1 addition & 11 deletions src/game/client/components/menus_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1846,17 +1846,7 @@ CTeeRenderInfo CMenus::GetTeeRenderInfo(vec2 Size, const char *pSkinName, bool C
{
CTeeRenderInfo TeeInfo;
TeeInfo.Apply(m_pClient->m_Skins.Find(pSkinName));
TeeInfo.m_CustomColoredSkin = CustomSkinColors;
if(CustomSkinColors)
{
TeeInfo.m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(CustomSkinColorBody).UnclampLighting(ColorHSLA::DARKEST_LGT));
TeeInfo.m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(CustomSkinColorFeet).UnclampLighting(ColorHSLA::DARKEST_LGT));
}
else
{
TeeInfo.m_ColorBody = ColorRGBA(1.0f, 1.0f, 1.0f);
TeeInfo.m_ColorFeet = ColorRGBA(1.0f, 1.0f, 1.0f);
}
TeeInfo.ApplyColors(CustomSkinColors, CustomSkinColorBody, CustomSkinColorFeet);
TeeInfo.m_Size = minimum(Size.x, Size.y);
return TeeInfo;
}
Expand Down
34 changes: 8 additions & 26 deletions src/game/client/components/menus_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,17 +593,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
// which invalidates the skin.
CTeeRenderInfo OwnSkinInfo;
OwnSkinInfo.Apply(m_pClient->m_Skins.Find(pSkinName));
OwnSkinInfo.m_CustomColoredSkin = *pUseCustomColor;
if(*pUseCustomColor)
{
OwnSkinInfo.m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(*pColorBody).UnclampLighting(ColorHSLA::DARKEST_LGT));
OwnSkinInfo.m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(*pColorFeet).UnclampLighting(ColorHSLA::DARKEST_LGT));
}
else
{
OwnSkinInfo.m_ColorBody = ColorRGBA(1.0f, 1.0f, 1.0f);
OwnSkinInfo.m_ColorFeet = ColorRGBA(1.0f, 1.0f, 1.0f);
}
OwnSkinInfo.ApplyColors(*pUseCustomColor, *pColorBody, *pColorFeet);
OwnSkinInfo.m_Size = 50.0f;

// Tee
Expand Down Expand Up @@ -786,10 +776,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
Item.m_Rect.VSplitLeft(60.0f, &Button, &Label);

CTeeRenderInfo Info = OwnSkinInfo;
Info.m_CustomColoredSkin = *pUseCustomColor;
Info.m_OriginalRenderSkin = pSkinToBeDraw->m_OriginalSkin;
Info.m_ColorableRenderSkin = pSkinToBeDraw->m_ColorableSkin;
Info.m_SkinMetrics = pSkinToBeDraw->m_Metrics;
Info.Apply(pSkinToBeDraw);

vec2 OffsetToMid;
CRenderTools::GetRenderTeeOffsetToRenderedTee(CAnimState::GetIdle(), &Info, OffsetToMid);
Expand Down Expand Up @@ -2514,7 +2501,6 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView)

static std::vector<SPreviewLine> s_vLines;

const auto *pDefaultSkin = GameClient()->m_Skins.Find("default");
enum ELineFlag
{
FLAG_TEAM = 1 << 0,
Expand Down Expand Up @@ -2552,15 +2538,11 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView)
str_copy(pLine->m_aName, pName);
str_copy(pLine->m_aText, pText);
};
auto &&SetLineSkin = [RealTeeSize, &pDefaultSkin](int Index, const CSkin *pSkin) {
auto &&SetLineSkin = [RealTeeSize](int Index, const CSkin *pSkin) {
if(Index >= (int)s_vLines.size())
return;
s_vLines[Index].m_RenderInfo.m_Size = RealTeeSize;
s_vLines[Index].m_RenderInfo.m_CustomColoredSkin = false;
if(pSkin != nullptr)
s_vLines[Index].m_RenderInfo.m_OriginalRenderSkin = pSkin->m_OriginalSkin;
else if(pDefaultSkin != nullptr)
s_vLines[Index].m_RenderInfo.m_OriginalRenderSkin = pDefaultSkin->m_OriginalSkin;
s_vLines[Index].m_RenderInfo.Apply(pSkin);
};

auto &&RenderPreview = [&](int LineIndex, int x, int y, bool Render = true) {
Expand Down Expand Up @@ -2666,10 +2648,10 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView)
SetPreviewLine(PREVIEW_CLIENT, -1, "", "Echo command executed", FLAG_CLIENT, 0);
}

SetLineSkin(1, GameClient()->m_Skins.FindOrNullptr("pinky"));
SetLineSkin(2, pDefaultSkin);
SetLineSkin(3, GameClient()->m_Skins.FindOrNullptr("cammostripes"));
SetLineSkin(4, GameClient()->m_Skins.FindOrNullptr("beast"));
SetLineSkin(1, GameClient()->m_Skins.Find("pinky"));
SetLineSkin(2, GameClient()->m_Skins.Find("default"));
SetLineSkin(3, GameClient()->m_Skins.Find("cammostripes"));
SetLineSkin(4, GameClient()->m_Skins.Find("beast"));

// Backgrounds first
if(!g_Config.m_ClChatOld)
Expand Down
1 change: 0 additions & 1 deletion src/game/client/components/players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,6 @@ void CPlayers::OnRender()
}
CTeeRenderInfo RenderInfoSpec;
RenderInfoSpec.Apply(m_pClient->m_Skins.Find("x_spec"));
RenderInfoSpec.m_CustomColoredSkin = false;
RenderInfoSpec.m_Size = 64.0f;
const int LocalClientId = m_pClient->m_Snap.m_LocalClientId;

Expand Down
33 changes: 8 additions & 25 deletions src/game/client/gameclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1542,30 +1542,21 @@ void CGameClient::OnNewSnapshot()
}
IntsToStr(&pInfo->m_Clan0, 3, pClient->m_aClan, std::size(pClient->m_aClan));
pClient->m_Country = pInfo->m_Country;

IntsToStr(&pInfo->m_Skin0, 6, pClient->m_aSkinName, std::size(pClient->m_aSkinName));
if(pClient->m_aSkinName[0] == '\0' ||
(!m_GameInfo.m_AllowXSkins && (pClient->m_aSkinName[0] == 'x' && pClient->m_aSkinName[1] == '_')))
{
str_copy(pClient->m_aSkinName, "default");
}

pClient->m_UseCustomColor = pInfo->m_UseCustomColor;
pClient->m_ColorBody = pInfo->m_ColorBody;
pClient->m_ColorFeet = pInfo->m_ColorFeet;

// prepare the info
if(!m_GameInfo.m_AllowXSkins && (pClient->m_aSkinName[0] == 'x' && pClient->m_aSkinName[1] == '_'))
str_copy(pClient->m_aSkinName, "default");

pClient->m_SkinInfo.m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(pClient->m_ColorBody).UnclampLighting(ColorHSLA::DARKEST_LGT));
pClient->m_SkinInfo.m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(pClient->m_ColorFeet).UnclampLighting(ColorHSLA::DARKEST_LGT));
pClient->m_SkinInfo.m_Size = 64;

// find new skin
pClient->m_SkinInfo.Apply(m_Skins.Find(pClient->m_aSkinName));
pClient->m_SkinInfo.m_CustomColoredSkin = pClient->m_UseCustomColor;

if(!pClient->m_UseCustomColor)
{
pClient->m_SkinInfo.m_ColorBody = ColorRGBA(1, 1, 1);
pClient->m_SkinInfo.m_ColorFeet = ColorRGBA(1, 1, 1);
}

pClient->m_SkinInfo.ApplyColors(pClient->m_UseCustomColor, pClient->m_ColorBody, pClient->m_ColorFeet);
pClient->UpdateRenderInfo(IsTeamPlay());
}
}
Expand Down Expand Up @@ -3755,15 +3746,7 @@ void CGameClient::RefreshSkins()

for(auto &Client : m_aClients)
{
if(Client.m_aSkinName[0] != '\0')
{
Client.m_SkinInfo.Apply(m_Skins.Find(Client.m_aSkinName));
}
else
{
Client.m_SkinInfo.m_OriginalRenderSkin.Reset();
Client.m_SkinInfo.m_ColorableRenderSkin.Reset();
}
Client.m_SkinInfo.Apply(m_Skins.Find(Client.m_aSkinName));
Client.UpdateRenderInfo(IsTeamPlay());
}

Expand Down
15 changes: 15 additions & 0 deletions src/game/client/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ class CTeeRenderInfo
m_SkinMetrics = pSkin->m_Metrics;
}

void ApplyColors(bool CustomColoredSkin, int ColorBody, int ColorFeet)
{
m_CustomColoredSkin = CustomColoredSkin;
if(CustomColoredSkin)
{
m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(ColorBody).UnclampLighting(ColorHSLA::DARKEST_LGT));
m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(ColorFeet).UnclampLighting(ColorHSLA::DARKEST_LGT));
}
else
{
m_ColorBody = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
m_ColorFeet = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
}
}

CSkin::SSkinTextures m_OriginalRenderSkin;
CSkin::SSkinTextures m_ColorableRenderSkin;

Expand Down

0 comments on commit 1165a82

Please sign in to comment.