mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-09 17:48:19 +00:00
Remove separate CreateI
and DestroyI
functions
Improve readability by removing the indirection when creating and removing damage indicators.
This commit is contained in:
parent
90562b5157
commit
782c9a54bf
|
@ -15,34 +15,18 @@ CDamageInd::CDamageInd()
|
||||||
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_StartTime = LocalTime();
|
||||||
pItem->m_Dir = -Dir;
|
pItem->m_Dir = -Dir;
|
||||||
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);
|
||||||
}
|
++m_NumItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDamageInd::OnRender()
|
void CDamageInd::OnRender()
|
||||||
|
@ -70,7 +54,10 @@ void CDamageInd::OnRender()
|
||||||
|
|
||||||
float Life = 0.75f - (LocalTime() - m_aItems[i].m_StartTime);
|
float Life = 0.75f - (LocalTime() - m_aItems[i].m_StartTime);
|
||||||
if(Life < 0.0f)
|
if(Life < 0.0f)
|
||||||
DestroyI(&m_aItems[i]);
|
{
|
||||||
|
--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((Life - 0.60f) / 0.15f, 0.0f, 1.0f));
|
||||||
|
|
|
@ -25,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:
|
||||||
|
|
Loading…
Reference in a new issue