2022-03-25 11:54:11 +00:00
|
|
|
#include <game/client/gameclient.h>
|
|
|
|
|
|
|
|
#include "freezebars.h"
|
|
|
|
|
|
|
|
void CFreezeBars::RenderFreezeBar(const int ClientID)
|
|
|
|
{
|
|
|
|
const float FreezeBarWidth = 64.0f;
|
|
|
|
const float FreezeBarHalfWidth = 32.0f;
|
2022-03-29 21:24:39 +00:00
|
|
|
const float FreezeBarHight = 16.0f;
|
2022-03-25 11:54:11 +00:00
|
|
|
|
2022-03-27 16:18:53 +00:00
|
|
|
// pCharacter contains the predicted character for local players or the last snap for players who are spectated
|
|
|
|
CCharacterCore *pCharacter = &m_pClient->m_aClients[ClientID].m_Predicted;
|
2022-06-09 19:48:52 +00:00
|
|
|
if(pCharacter->m_FreezeEnd <= 0.0f || pCharacter->m_FreezeTick == 0 || !m_pClient->m_Snap.m_aCharacters[ClientID].m_HasExtendedDisplayInfo)
|
2022-03-25 11:54:11 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-03-29 21:24:39 +00:00
|
|
|
|
2022-03-27 16:18:53 +00:00
|
|
|
const int Max = pCharacter->m_FreezeEnd - pCharacter->m_FreezeTick;
|
|
|
|
float FreezeProgress = clamp(Max - (Client()->GameTick(g_Config.m_ClDummy) - pCharacter->m_FreezeTick), 0, Max) / (float)Max;
|
2022-03-25 11:54:11 +00:00
|
|
|
if(FreezeProgress <= 0.0f)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-27 16:18:53 +00:00
|
|
|
vec2 Position = m_pClient->m_aClients[ClientID].m_RenderPos;
|
2022-03-25 11:54:11 +00:00
|
|
|
Position.x -= FreezeBarHalfWidth;
|
|
|
|
Position.y += 32;
|
|
|
|
|
|
|
|
float Alpha = m_pClient->IsOtherTeam(ClientID) ? g_Config.m_ClShowOthersAlpha / 100.0f : 1.0f;
|
|
|
|
|
2022-03-29 21:24:39 +00:00
|
|
|
RenderFreezeBarPos(Position.x, Position.y, FreezeBarWidth, FreezeBarHight, FreezeProgress, Alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFreezeBars::RenderFreezeBarPos(float x, const float y, const float width, const float height, float Progress, const float Alpha)
|
|
|
|
{
|
|
|
|
Progress = clamp(Progress, 0.0f, 1.0f);
|
2022-03-30 09:12:48 +00:00
|
|
|
|
|
|
|
// what percentage of the end pieces is used for the progress indicator and how much is the rest
|
|
|
|
// half of the ends are used for the progress display
|
|
|
|
const float RestPct = 0.5f;
|
|
|
|
const float ProgPct = 0.5f;
|
|
|
|
|
2022-03-29 21:24:39 +00:00
|
|
|
const float EndWidth = height; // to keep the correct scale - the height of the sprite is as long as the width
|
|
|
|
const float BarHeight = height;
|
2022-03-30 09:12:48 +00:00
|
|
|
const float WholeBarWidth = width;
|
2022-03-29 21:24:39 +00:00
|
|
|
const float MiddleBarWidth = WholeBarWidth - (EndWidth * 2.0f);
|
2022-03-30 09:12:48 +00:00
|
|
|
const float EndProgressWidth = EndWidth * ProgPct;
|
|
|
|
const float EndRestWidth = EndWidth * RestPct;
|
2022-03-29 21:24:39 +00:00
|
|
|
const float ProgressBarWidth = WholeBarWidth - (EndProgressWidth * 2.0f);
|
|
|
|
const float EndProgressProportion = EndProgressWidth / ProgressBarWidth;
|
|
|
|
const float MiddleProgressProportion = MiddleBarWidth / ProgressBarWidth;
|
|
|
|
|
|
|
|
// beginning piece
|
|
|
|
float BeginningPieceProgress = 1;
|
|
|
|
if(Progress <= EndProgressProportion)
|
|
|
|
{
|
|
|
|
BeginningPieceProgress = Progress / EndProgressProportion;
|
|
|
|
}
|
2022-03-30 09:12:48 +00:00
|
|
|
|
2022-03-29 21:24:39 +00:00
|
|
|
// full
|
2022-06-03 16:27:30 +00:00
|
|
|
Graphics()->WrapClamp();
|
2022-03-29 21:24:39 +00:00
|
|
|
Graphics()->TextureSet(m_pClient->m_HudSkin.m_SpriteHudFreezeBarFullLeft);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(1.f, 1.f, 1.f, Alpha);
|
2022-03-30 09:12:48 +00:00
|
|
|
// Subset: top_l, top_m, btm_m, btm_l
|
2022-06-03 16:27:30 +00:00
|
|
|
Graphics()->QuadsSetSubsetFree(0, 0, RestPct + ProgPct * BeginningPieceProgress, 0, RestPct + ProgPct * BeginningPieceProgress, 1, 0, 1);
|
2022-03-30 09:12:48 +00:00
|
|
|
IGraphics::CQuadItem QuadFullBeginning(x, y, EndRestWidth + EndProgressWidth * BeginningPieceProgress, BarHeight);
|
2022-03-29 21:24:39 +00:00
|
|
|
Graphics()->QuadsDrawTL(&QuadFullBeginning, 1);
|
|
|
|
Graphics()->QuadsEnd();
|
2022-03-30 09:12:48 +00:00
|
|
|
|
|
|
|
// empty
|
|
|
|
if(BeginningPieceProgress < 1.0f)
|
2022-03-29 21:24:39 +00:00
|
|
|
{
|
|
|
|
Graphics()->TextureSet(m_pClient->m_HudSkin.m_SpriteHudFreezeBarEmptyRight);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(1.f, 1.f, 1.f, Alpha);
|
2022-03-30 09:12:48 +00:00
|
|
|
// Subset: top_m, top_l, btm_l, btm_m | it is mirrored on the horizontal axe and rotated 180 degrees
|
2022-06-03 16:27:30 +00:00
|
|
|
Graphics()->QuadsSetSubsetFree(ProgPct - ProgPct * BeginningPieceProgress, 0, 0, 0, 0, 1, ProgPct - ProgPct * BeginningPieceProgress, 1);
|
2022-03-30 09:12:48 +00:00
|
|
|
IGraphics::CQuadItem QuadEmptyBeginning(x + EndRestWidth + EndProgressWidth * BeginningPieceProgress, y, EndProgressWidth * (1.0f - BeginningPieceProgress), BarHeight);
|
2022-03-29 21:24:39 +00:00
|
|
|
Graphics()->QuadsDrawTL(&QuadEmptyBeginning, 1);
|
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
// middle piece
|
|
|
|
x += EndWidth;
|
|
|
|
|
|
|
|
float MiddlePieceProgress = 1;
|
|
|
|
if(Progress <= EndProgressProportion + MiddleProgressProportion)
|
|
|
|
{
|
|
|
|
if(Progress <= EndProgressProportion)
|
|
|
|
{
|
|
|
|
MiddlePieceProgress = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MiddlePieceProgress = (Progress - EndProgressProportion) / MiddleProgressProportion;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const float FullMiddleBarWidth = MiddleBarWidth * MiddlePieceProgress;
|
|
|
|
const float EmptyMiddleBarWidth = MiddleBarWidth - FullMiddleBarWidth;
|
|
|
|
|
2022-03-30 09:12:48 +00:00
|
|
|
// full freeze bar
|
2022-03-29 21:24:39 +00:00
|
|
|
Graphics()->TextureSet(m_pClient->m_HudSkin.m_SpriteHudFreezeBarFull);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(1.f, 1.f, 1.f, Alpha);
|
|
|
|
// select the middle portion of the sprite so we don't get edge bleeding
|
2022-03-30 09:12:48 +00:00
|
|
|
if(FullMiddleBarWidth <= EndWidth)
|
2022-03-29 21:24:39 +00:00
|
|
|
{
|
|
|
|
// prevent pixel puree, select only a small slice
|
2022-03-30 09:12:48 +00:00
|
|
|
// Subset: top_l, top_m, btm_m, btm_l
|
2022-06-03 16:27:30 +00:00
|
|
|
Graphics()->QuadsSetSubsetFree(0, 0, FullMiddleBarWidth / EndWidth, 0, FullMiddleBarWidth / EndWidth, 1, 0, 1);
|
2022-03-29 21:24:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-30 09:12:48 +00:00
|
|
|
// Subset: top_l, top_r, btm_r, btm_l
|
2022-06-03 16:27:30 +00:00
|
|
|
Graphics()->QuadsSetSubsetFree(0, 0, 1, 0, 1, 1, 0, 1);
|
2022-03-29 21:24:39 +00:00
|
|
|
}
|
|
|
|
IGraphics::CQuadItem QuadFull(x, y, FullMiddleBarWidth, BarHeight);
|
|
|
|
Graphics()->QuadsDrawTL(&QuadFull, 1);
|
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
|
2022-03-30 09:12:48 +00:00
|
|
|
// empty freeze bar
|
2022-03-29 21:24:39 +00:00
|
|
|
Graphics()->TextureSet(m_pClient->m_HudSkin.m_SpriteHudFreezeBarEmpty);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(1.f, 1.f, 1.f, Alpha);
|
|
|
|
// select the middle portion of the sprite so we don't get edge bleeding
|
2022-03-30 09:12:48 +00:00
|
|
|
if(EmptyMiddleBarWidth <= EndWidth)
|
2022-03-29 21:24:39 +00:00
|
|
|
{
|
|
|
|
// prevent pixel puree, select only a small slice
|
2022-03-30 09:12:48 +00:00
|
|
|
// Subset: top_m, top_l, btm_l, btm_m | it is mirrored on the horizontal axe and rotated 180 degrees
|
2022-06-03 16:27:30 +00:00
|
|
|
Graphics()->QuadsSetSubsetFree(EmptyMiddleBarWidth / EndWidth, 0, 0, 0, 0, 1, EmptyMiddleBarWidth / EndWidth, 1);
|
2022-03-29 21:24:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-30 09:12:48 +00:00
|
|
|
// Subset: top_r, top_l, btm_l, btm_r | it is mirrored on the horizontal axe and rotated 180 degrees
|
2022-06-03 16:27:30 +00:00
|
|
|
Graphics()->QuadsSetSubsetFree(1, 0, 0, 0, 0, 1, 1, 1);
|
2022-03-29 21:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IGraphics::CQuadItem QuadEmpty(x + FullMiddleBarWidth, y, EmptyMiddleBarWidth, BarHeight);
|
|
|
|
Graphics()->QuadsDrawTL(&QuadEmpty, 1);
|
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
|
|
|
|
// end piece
|
|
|
|
x += MiddleBarWidth;
|
|
|
|
float EndingPieceProgress = 1;
|
|
|
|
if(Progress <= 1)
|
|
|
|
{
|
|
|
|
if(Progress <= (EndProgressProportion + MiddleProgressProportion))
|
|
|
|
{
|
|
|
|
EndingPieceProgress = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EndingPieceProgress = (Progress - EndProgressProportion - MiddleProgressProportion) / EndProgressProportion;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(EndingPieceProgress > 0.0f)
|
|
|
|
{
|
2022-03-30 09:12:48 +00:00
|
|
|
// full
|
2022-03-29 21:24:39 +00:00
|
|
|
Graphics()->TextureSet(m_pClient->m_HudSkin.m_SpriteHudFreezeBarFullLeft);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(1.f, 1.f, 1.f, Alpha);
|
2022-03-30 09:12:48 +00:00
|
|
|
// Subset: top_r, top_m, btm_m, btm_r | it is mirrored on the horizontal axe and rotated 180 degrees
|
2022-06-03 16:27:30 +00:00
|
|
|
Graphics()->QuadsSetSubsetFree(1, 0, 1.0f - ProgPct * EndingPieceProgress, 0, 1.0f - ProgPct * EndingPieceProgress, 1, 1, 1);
|
2022-03-30 09:12:48 +00:00
|
|
|
IGraphics::CQuadItem QuadFullEnding(x, y, EndProgressWidth * EndingPieceProgress, BarHeight);
|
2022-03-29 21:24:39 +00:00
|
|
|
Graphics()->QuadsDrawTL(&QuadFullEnding, 1);
|
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
}
|
|
|
|
// empty
|
|
|
|
Graphics()->TextureSet(m_pClient->m_HudSkin.m_SpriteHudFreezeBarEmptyRight);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(1.f, 1.f, 1.f, Alpha);
|
2022-03-30 09:12:48 +00:00
|
|
|
// Subset: top_m, top_r, btm_r, btm_m
|
2022-06-03 16:27:30 +00:00
|
|
|
Graphics()->QuadsSetSubsetFree(ProgPct - ProgPct * (1.0f - EndingPieceProgress), 0, 1, 0, 1, 1, ProgPct - ProgPct * (1.0f - EndingPieceProgress), 1);
|
2022-03-30 09:12:48 +00:00
|
|
|
IGraphics::CQuadItem QuadEmptyEnding(x + EndProgressWidth * EndingPieceProgress, y, EndProgressWidth * (1.0f - EndingPieceProgress) + EndRestWidth, BarHeight);
|
2022-03-29 21:24:39 +00:00
|
|
|
Graphics()->QuadsDrawTL(&QuadEmptyEnding, 1);
|
|
|
|
Graphics()->QuadsEnd();
|
2022-03-30 09:12:48 +00:00
|
|
|
|
2022-03-29 21:24:39 +00:00
|
|
|
Graphics()->QuadsSetSubset(0, 0, 1, 1);
|
|
|
|
Graphics()->SetColor(1.f, 1.f, 1.f, 1.f);
|
2022-06-03 16:27:30 +00:00
|
|
|
Graphics()->WrapNormal();
|
2022-03-25 11:54:11 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 16:18:53 +00:00
|
|
|
inline bool CFreezeBars::IsPlayerInfoAvailable(int ClientID) const
|
|
|
|
{
|
|
|
|
const void *pPrevInfo = Client()->SnapFindItem(IClient::SNAP_PREV, NETOBJTYPE_PLAYERINFO, ClientID);
|
|
|
|
const void *pInfo = Client()->SnapFindItem(IClient::SNAP_CURRENT, NETOBJTYPE_PLAYERINFO, ClientID);
|
|
|
|
return pPrevInfo && pInfo;
|
|
|
|
}
|
|
|
|
|
2022-03-25 11:54:11 +00:00
|
|
|
void CFreezeBars::OnRender()
|
|
|
|
{
|
2022-05-10 16:41:46 +00:00
|
|
|
if(!g_Config.m_ClShowFreezeBars)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-03-25 11:54:11 +00:00
|
|
|
// get screen edges to avoid rendering offscreen
|
|
|
|
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
|
|
|
|
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
|
|
|
|
// expand the edges to prevent popping in/out onscreen
|
|
|
|
//
|
|
|
|
// it is assumed that the tee with the freeze bar fit into a 240x240 box centered on the tee
|
|
|
|
// this may need to be changed or calculated differently in the future
|
|
|
|
float BorderBuffer = 120;
|
|
|
|
ScreenX0 -= BorderBuffer;
|
|
|
|
ScreenX1 += BorderBuffer;
|
|
|
|
ScreenY0 -= BorderBuffer;
|
|
|
|
ScreenY1 += BorderBuffer;
|
|
|
|
|
|
|
|
int LocalClientID = m_pClient->m_Snap.m_LocalClientID;
|
|
|
|
|
|
|
|
// render everyone else's freeze bar, then our own
|
|
|
|
for(int ClientID = 0; ClientID < MAX_CLIENTS; ClientID++)
|
|
|
|
{
|
2022-03-27 16:18:53 +00:00
|
|
|
if(ClientID == LocalClientID || !m_pClient->m_Snap.m_aCharacters[ClientID].m_Active || !IsPlayerInfoAvailable(ClientID))
|
2022-03-25 11:54:11 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//don't render if the tee is offscreen
|
|
|
|
vec2 *pRenderPos = &m_pClient->m_aClients[ClientID].m_RenderPos;
|
|
|
|
if(pRenderPos->x < ScreenX0 || pRenderPos->x > ScreenX1 || pRenderPos->y < ScreenY0 || pRenderPos->y > ScreenY1)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderFreezeBar(ClientID);
|
|
|
|
}
|
2022-03-27 16:18:53 +00:00
|
|
|
if(LocalClientID != -1 && m_pClient->m_Snap.m_aCharacters[LocalClientID].m_Active && IsPlayerInfoAvailable(LocalClientID))
|
2022-03-25 11:54:11 +00:00
|
|
|
{
|
|
|
|
RenderFreezeBar(LocalClientID);
|
|
|
|
}
|
|
|
|
}
|