From 782c9a54bfa3df35a4a1281daf493a00e5713613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 26 Jul 2024 18:30:47 +0200 Subject: [PATCH] Remove separate `CreateI` and `DestroyI` functions Improve readability by removing the indirection when creating and removing damage indicators. --- src/game/client/components/damageind.cpp | 41 ++++++++---------------- src/game/client/components/damageind.h | 3 -- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/src/game/client/components/damageind.cpp b/src/game/client/components/damageind.cpp index 8ea48067f..dfcba20e3 100644 --- a/src/game/client/components/damageind.cpp +++ b/src/game/client/components/damageind.cpp @@ -15,34 +15,18 @@ CDamageInd::CDamageInd() 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) { - CItem *pItem = CreateI(); - if(pItem) - { - pItem->m_Pos = Pos; - pItem->m_StartTime = LocalTime(); - pItem->m_Dir = -Dir; - pItem->m_StartAngle = -random_angle(); - pItem->m_Color = ColorRGBA(1.0f, 1.0f, 1.0f, Alpha); - } + if(m_NumItems >= MAX_ITEMS) + return; + + CItem *pItem = &m_aItems[m_NumItems]; + pItem->m_Pos = Pos; + pItem->m_StartTime = LocalTime(); + pItem->m_Dir = -Dir; + pItem->m_StartAngle = -random_angle(); + pItem->m_Color = ColorRGBA(1.0f, 1.0f, 1.0f, Alpha); + ++m_NumItems; } void CDamageInd::OnRender() @@ -70,7 +54,10 @@ void CDamageInd::OnRender() float Life = 0.75f - (LocalTime() - m_aItems[i].m_StartTime); if(Life < 0.0f) - DestroyI(&m_aItems[i]); + { + --m_NumItems; + m_aItems[i] = m_aItems[m_NumItems]; + } 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)); diff --git a/src/game/client/components/damageind.h b/src/game/client/components/damageind.h index 75c3eec66..bedae4ca6 100644 --- a/src/game/client/components/damageind.h +++ b/src/game/client/components/damageind.h @@ -25,9 +25,6 @@ class CDamageInd : public CComponent CItem m_aItems[MAX_ITEMS]; int m_NumItems; - CItem *CreateI(); - void DestroyI(CItem *pItem); - int m_DmgIndQuadContainerIndex; public: