mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-09 17:48:19 +00:00
Merge pull request #8669 from Robyt3/Client-Damageind-Refactoring
Refactor and optimize damage indicators, reset damage indicators when skipping in demo
This commit is contained in:
commit
2c61177745
|
@ -12,39 +12,21 @@
|
||||||
|
|
||||||
CDamageInd::CDamageInd()
|
CDamageInd::CDamageInd()
|
||||||
{
|
{
|
||||||
m_Lastupdate = 0;
|
|
||||||
m_NumItems = 0;
|
m_NumItems = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDamageInd::CItem *CDamageInd::CreateI()
|
|
||||||
{
|
|
||||||
if(m_NumItems < MAX_ITEMS)
|
|
||||||
{
|
|
||||||
CItem *p = &m_aItems[m_NumItems];
|
|
||||||
m_NumItems++;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDamageInd::DestroyI(CDamageInd::CItem *pItem)
|
|
||||||
{
|
|
||||||
m_NumItems--;
|
|
||||||
*pItem = m_aItems[m_NumItems];
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDamageInd::Create(vec2 Pos, vec2 Dir, float Alpha)
|
void CDamageInd::Create(vec2 Pos, vec2 Dir, float Alpha)
|
||||||
{
|
{
|
||||||
CItem *pItem = CreateI();
|
if(m_NumItems >= MAX_ITEMS)
|
||||||
if(pItem)
|
return;
|
||||||
{
|
|
||||||
|
CItem *pItem = &m_aItems[m_NumItems];
|
||||||
pItem->m_Pos = Pos;
|
pItem->m_Pos = Pos;
|
||||||
pItem->m_StartTime = LocalTime();
|
|
||||||
pItem->m_Dir = -Dir;
|
pItem->m_Dir = -Dir;
|
||||||
|
pItem->m_RemainingLife = 0.75f;
|
||||||
pItem->m_StartAngle = -random_angle();
|
pItem->m_StartAngle = -random_angle();
|
||||||
pItem->m_Color = ColorRGBA(1.0f, 1.0f, 1.0f, Alpha);
|
pItem->m_Color = ColorRGBA(1.0f, 1.0f, 1.0f, Alpha);
|
||||||
pItem->m_StartAlpha = Alpha;
|
++m_NumItems;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDamageInd::OnRender()
|
void CDamageInd::OnRender()
|
||||||
|
@ -52,41 +34,45 @@ void CDamageInd::OnRender()
|
||||||
if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
|
if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Graphics()->TextureSet(GameClient()->m_GameSkin.m_aSpriteStars[0]);
|
|
||||||
static float s_LastLocalTime = LocalTime();
|
static float s_LastLocalTime = LocalTime();
|
||||||
for(int i = 0; i < m_NumItems;)
|
float LifeAdjustment;
|
||||||
{
|
|
||||||
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
||||||
{
|
{
|
||||||
const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo();
|
const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo();
|
||||||
if(pInfo->m_Paused)
|
if(pInfo->m_Paused)
|
||||||
m_aItems[i].m_StartTime += LocalTime() - s_LastLocalTime;
|
LifeAdjustment = 0.0f;
|
||||||
else
|
else
|
||||||
m_aItems[i].m_StartTime += (LocalTime() - s_LastLocalTime) * (1.0f - pInfo->m_Speed);
|
LifeAdjustment = (LocalTime() - s_LastLocalTime) * pInfo->m_Speed;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED)
|
const auto &pGameInfoObj = GameClient()->m_Snap.m_pGameInfoObj;
|
||||||
m_aItems[i].m_StartTime += LocalTime() - s_LastLocalTime;
|
if(pGameInfoObj && pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED)
|
||||||
|
LifeAdjustment = 0.0f;
|
||||||
|
else
|
||||||
|
LifeAdjustment = LocalTime() - s_LastLocalTime;
|
||||||
}
|
}
|
||||||
|
s_LastLocalTime = LocalTime();
|
||||||
|
|
||||||
float Life = 0.75f - (LocalTime() - m_aItems[i].m_StartTime);
|
Graphics()->TextureSet(GameClient()->m_GameSkin.m_aSpriteStars[0]);
|
||||||
if(Life < 0.0f)
|
for(int i = 0; i < m_NumItems;)
|
||||||
DestroyI(&m_aItems[i]);
|
{
|
||||||
|
m_aItems[i].m_RemainingLife -= LifeAdjustment;
|
||||||
|
if(m_aItems[i].m_RemainingLife < 0.0f)
|
||||||
|
{
|
||||||
|
--m_NumItems;
|
||||||
|
m_aItems[i] = m_aItems[m_NumItems];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vec2 Pos = mix(m_aItems[i].m_Pos + m_aItems[i].m_Dir * 75.0f, m_aItems[i].m_Pos, clamp((Life - 0.60f) / 0.15f, 0.0f, 1.0f));
|
vec2 Pos = mix(m_aItems[i].m_Pos + m_aItems[i].m_Dir * 75.0f, m_aItems[i].m_Pos, clamp((m_aItems[i].m_RemainingLife - 0.60f) / 0.15f, 0.0f, 1.0f));
|
||||||
ColorRGBA Color = m_aItems[i].m_Color;
|
const float LifeAlpha = m_aItems[i].m_RemainingLife / 0.1f;
|
||||||
|
Graphics()->SetColor(m_aItems[i].m_Color.WithMultipliedAlpha(LifeAlpha));
|
||||||
float LifeAlpha = Life / 0.1f;
|
Graphics()->QuadsSetRotation(m_aItems[i].m_StartAngle + m_aItems[i].m_RemainingLife * 2.0f);
|
||||||
Color.a = m_aItems[i].m_StartAlpha * LifeAlpha;
|
|
||||||
Graphics()->SetColor(Color);
|
|
||||||
Graphics()->QuadsSetRotation(m_aItems[i].m_StartAngle + Life * 2.0f);
|
|
||||||
Graphics()->RenderQuadContainerAsSprite(m_DmgIndQuadContainerIndex, 0, Pos.x, Pos.y);
|
Graphics()->RenderQuadContainerAsSprite(m_DmgIndQuadContainerIndex, 0, Pos.x, Pos.y);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s_LastLocalTime = LocalTime();
|
|
||||||
|
|
||||||
Graphics()->QuadsSetRotation(0);
|
Graphics()->QuadsSetRotation(0);
|
||||||
Graphics()->SetColor(1.f, 1.f, 1.f, 1.f);
|
Graphics()->SetColor(1.f, 1.f, 1.f, 1.f);
|
||||||
|
@ -105,10 +91,7 @@ void CDamageInd::OnInit()
|
||||||
Graphics()->QuadContainerUpload(m_DmgIndQuadContainerIndex);
|
Graphics()->QuadContainerUpload(m_DmgIndQuadContainerIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDamageInd::Reset()
|
void CDamageInd::OnReset()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < m_NumItems;)
|
m_NumItems = 0;
|
||||||
{
|
|
||||||
DestroyI(&m_aItems[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,13 @@
|
||||||
|
|
||||||
class CDamageInd : public CComponent
|
class CDamageInd : public CComponent
|
||||||
{
|
{
|
||||||
int64_t m_Lastupdate;
|
|
||||||
struct CItem
|
struct CItem
|
||||||
{
|
{
|
||||||
vec2 m_Pos;
|
vec2 m_Pos;
|
||||||
vec2 m_Dir;
|
vec2 m_Dir;
|
||||||
float m_StartTime;
|
float m_RemainingLife;
|
||||||
float m_StartAngle;
|
float m_StartAngle;
|
||||||
ColorRGBA m_Color;
|
ColorRGBA m_Color;
|
||||||
float m_StartAlpha;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -27,9 +25,6 @@ class CDamageInd : public CComponent
|
||||||
CItem m_aItems[MAX_ITEMS];
|
CItem m_aItems[MAX_ITEMS];
|
||||||
int m_NumItems;
|
int m_NumItems;
|
||||||
|
|
||||||
CItem *CreateI();
|
|
||||||
void DestroyI(CItem *pItem);
|
|
||||||
|
|
||||||
int m_DmgIndQuadContainerIndex;
|
int m_DmgIndQuadContainerIndex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -37,7 +32,7 @@ public:
|
||||||
virtual int Sizeof() const override { return sizeof(*this); }
|
virtual int Sizeof() const override { return sizeof(*this); }
|
||||||
|
|
||||||
void Create(vec2 Pos, vec2 Dir, float Alpha);
|
void Create(vec2 Pos, vec2 Dir, float Alpha);
|
||||||
void Reset();
|
virtual void OnReset() override;
|
||||||
virtual void OnRender() override;
|
virtual void OnRender() override;
|
||||||
virtual void OnInit() override;
|
virtual void OnInit() override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,11 +53,6 @@ void CEffects::DamageIndicator(vec2 Pos, vec2 Dir, float Alpha)
|
||||||
m_pClient->m_DamageInd.Create(Pos, Dir, Alpha);
|
m_pClient->m_DamageInd.Create(Pos, Dir, Alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEffects::ResetDamageIndicator()
|
|
||||||
{
|
|
||||||
m_pClient->m_DamageInd.Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CEffects::PowerupShine(vec2 Pos, vec2 Size, float Alpha)
|
void CEffects::PowerupShine(vec2 Pos, vec2 Size, float Alpha)
|
||||||
{
|
{
|
||||||
if(!m_Add50hz)
|
if(!m_Add50hz)
|
||||||
|
|
|
@ -26,7 +26,6 @@ public:
|
||||||
void HammerHit(vec2 Pos, float Alpha = 1.0f);
|
void HammerHit(vec2 Pos, float Alpha = 1.0f);
|
||||||
void AirJump(vec2 Pos, float Alpha = 1.0f);
|
void AirJump(vec2 Pos, float Alpha = 1.0f);
|
||||||
void DamageIndicator(vec2 Pos, vec2 Dir, float Alpha = 1.0f);
|
void DamageIndicator(vec2 Pos, vec2 Dir, float Alpha = 1.0f);
|
||||||
void ResetDamageIndicator();
|
|
||||||
void PlayerSpawn(vec2 Pos, float Alpha = 1.0f);
|
void PlayerSpawn(vec2 Pos, float Alpha = 1.0f);
|
||||||
void PlayerDeath(vec2 Pos, int ClientId, float Alpha = 1.0f);
|
void PlayerDeath(vec2 Pos, int ClientId, float Alpha = 1.0f);
|
||||||
void PowerupShine(vec2 Pos, vec2 Size, float Alpha = 1.0f);
|
void PowerupShine(vec2 Pos, vec2 Size, float Alpha = 1.0f);
|
||||||
|
|
|
@ -78,6 +78,7 @@ void CMenus::HandleDemoSeeking(float PositionToSeek, float TimeToSeek)
|
||||||
if((PositionToSeek >= 0.0f && PositionToSeek <= 1.0f) || TimeToSeek != 0.0f)
|
if((PositionToSeek >= 0.0f && PositionToSeek <= 1.0f) || TimeToSeek != 0.0f)
|
||||||
{
|
{
|
||||||
m_pClient->m_Chat.Reset();
|
m_pClient->m_Chat.Reset();
|
||||||
|
m_pClient->m_DamageInd.OnReset();
|
||||||
m_pClient->m_InfoMessages.OnReset();
|
m_pClient->m_InfoMessages.OnReset();
|
||||||
m_pClient->m_Particles.OnReset();
|
m_pClient->m_Particles.OnReset();
|
||||||
m_pClient->m_Sounds.OnReset();
|
m_pClient->m_Sounds.OnReset();
|
||||||
|
|
|
@ -1010,7 +1010,6 @@ void CGameClient::OnShutdown()
|
||||||
|
|
||||||
void CGameClient::OnEnterGame()
|
void CGameClient::OnEnterGame()
|
||||||
{
|
{
|
||||||
m_Effects.ResetDamageIndicator();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGameClient::OnGameOver()
|
void CGameClient::OnGameOver()
|
||||||
|
|
Loading…
Reference in a new issue