Skip to content

Commit

Permalink
Support rendering 0.7 bot skin decoration
Browse files Browse the repository at this point in the history
  • Loading branch information
Robyt3 committed Jan 11, 2025
1 parent 0978c6f commit 53251a8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/game/client/gameclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,8 @@ void CGameClient::OnNewSnapshot()
}
else if(m_aStats[pInfo->m_ClientId].IsActive())
m_aStats[pInfo->m_ClientId].JoinSpec(Client()->GameTick(g_Config.m_ClDummy));

UpdateBotSkinDecoration(pInfo->m_ClientId);
}
}
else if(Item.m_Type == NETOBJTYPE_DDNETPLAYER)
Expand Down
1 change: 1 addition & 0 deletions src/game/client/gameclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ class CGameClient : public IGameClient
template<typename T>
void ApplySkin7InfoFromGameMsg(const T *pMsg, int ClientId, int Conn);
void ApplySkin7InfoFromSnapObj(const protocol7::CNetObj_De_ClientInfo *pObj, int ClientId) override;
void UpdateBotSkinDecoration(int ClientId);
int OnDemoRecSnap7(class CSnapshot *pFrom, class CSnapshot *pTo, int Conn) override;
void *TranslateGameMsg(int *pMsgId, CUnpacker *pUnpacker, int Conn);
int TranslateSnap(CSnapshot *pSnapDstSix, CSnapshot *pSnapSrcSeven, int Conn, bool Dummy) override;
Expand Down
12 changes: 5 additions & 7 deletions src/game/client/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void CRenderTools::RenderTee7(const CAnimState *pAnim, const CTeeRenderInfo *pIn
{
vec2 Direction = Dir;
vec2 Position = Pos;
bool IsBot = false;
const bool IsBot = pInfo->m_aSixup[g_Config.m_ClDummy].m_BotTexture.IsValid();

// first pass we draw the outline
// second pass we draw the filling
Expand All @@ -299,24 +299,22 @@ void CRenderTools::RenderTee7(const CAnimState *pAnim, const CTeeRenderInfo *pIn
{
vec2 BodyPos = Position + vec2(pAnim->GetBody()->m_X, pAnim->GetBody()->m_Y) * AnimScale;
IGraphics::CQuadItem BodyItem(BodyPos.x, BodyPos.y, BaseSize, BaseSize);
IGraphics::CQuadItem BotItem(BodyPos.x + (2.f / 3.f) * AnimScale, BodyPos.y + (-16 + 2.f / 3.f) * AnimScale, BaseSize, BaseSize); // x+0.66, y+0.66 to correct some rendering bug
IGraphics::CQuadItem Item;

// draw bot visuals (background)
if(IsBot && !OutLine)
{
IGraphics::CQuadItem BotItem(BodyPos.x + (2.f / 3.f) * AnimScale, BodyPos.y + (-16 + 2.f / 3.f) * AnimScale, BaseSize, BaseSize); // x+0.66, y+0.66 to correct some rendering bug

// draw bot visuals (background)
Graphics()->TextureSet(pInfo->m_aSixup[g_Config.m_ClDummy].m_BotTexture);
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, Alpha);
SelectSprite7(client_data7::SPRITE_TEE_BOT_BACKGROUND);
Item = BotItem;
Graphics()->QuadsDraw(&Item, 1);
Graphics()->QuadsEnd();
}

// draw bot visuals (foreground)
if(IsBot && !OutLine)
{
// draw bot visuals (foreground)
Graphics()->TextureSet(pInfo->m_aSixup[g_Config.m_ClDummy].m_BotTexture);
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, Alpha);
Expand Down
2 changes: 1 addition & 1 deletion src/game/client/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class CTeeRenderInfo
PartColor = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
}
m_HatSpriteIndex = 0;
m_BotColor = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
m_BotColor = ColorRGBA(0.0f, 0.0f, 0.0f, 0.0f);
}
bool Valid() const
{
Expand Down
35 changes: 35 additions & 0 deletions src/game/client/sixup_translate_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,41 @@ void CGameClient::ApplySkin7InfoFromSnapObj(const protocol7::CNetObj_De_ClientIn
ApplySkin7InfoFromGameMsg(&Msg, ClientId, 0);
}

void CGameClient::UpdateBotSkinDecoration(int ClientId)
{
static const ColorRGBA s_aBotColors[] = {
ColorRGBA(0xff0000),
ColorRGBA(0xff6600),
ColorRGBA(0x4d9f45),
ColorRGBA(0xd59e29),
ColorRGBA(0x9fd3a9),
ColorRGBA(0xbdd85e),
ColorRGBA(0xc07f94),
ColorRGBA(0xc3a267),
ColorRGBA(0xf8a83b),
ColorRGBA(0xcce2bf),
ColorRGBA(0xe6b498),
ColorRGBA(0x74c7a3),
};

for(auto &Sixup : m_aClients[ClientId].m_SkinInfo.m_aSixup)
{
if((m_pClient->m_TranslationContext.m_aClients[ClientId].m_PlayerFlags7 & protocol7::PLAYERFLAG_BOT) != 0)
{
Sixup.m_BotTexture = m_Skins7.BotDecorationTexture();
if(!Sixup.m_BotColor.a) // bot color has not been set; pick a random color once
{
Sixup.m_BotColor = s_aBotColors[rand() % std::size(s_aBotColors)];
}
}
else
{
Sixup.m_BotTexture.Invalidate();
Sixup.m_BotColor = ColorRGBA(0.0f, 0.0f, 0.0f, 0.0f);
}
}
}

void *CGameClient::TranslateGameMsg(int *pMsgId, CUnpacker *pUnpacker, int Conn)
{
if(!m_pClient->IsSixup())
Expand Down

0 comments on commit 53251a8

Please sign in to comment.