Skip to content

Commit 400ae49

Browse files
committed
Optimize AE animation update logic
1 parent 7f5d96d commit 400ae49

File tree

7 files changed

+65
-32
lines changed

7 files changed

+65
-32
lines changed

src/Ext/Techno/Body.Update.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,7 +1910,10 @@ void TechnoExt::ExtData::UpdateAttachEffects()
19101910
}
19111911

19121912
if (altered)
1913+
{
19131914
this->RecalculateStatMultipliers();
1915+
this->UpdateAEAnimLogic();
1916+
}
19141917

19151918
if (markForRedraw)
19161919
pThis->MarkForRedraw();
@@ -1980,7 +1983,10 @@ void TechnoExt::ExtData::UpdateSelfOwnedAttachEffects()
19801983
const int count = AttachEffectClass::Attach(pThis, pThis->Owner, pThis, pThis, pTypeExt->AttachEffects);
19811984

19821985
if (altered && !count)
1986+
{
19831987
this->RecalculateStatMultipliers();
1988+
this->UpdateAEAnimLogic();
1989+
}
19841990
}
19851991

19861992
// Updates CumulativeAnimations AE's on techno.
@@ -2025,6 +2031,15 @@ void TechnoExt::ExtData::UpdateCumulativeAttachEffects(AttachEffectTypeClass* pA
20252031
}
20262032
}
20272033

2034+
// Update AttachEffect animation logic.
2035+
void TechnoExt::ExtData::UpdateAEAnimLogic()
2036+
{
2037+
for (auto const& attachEffect : this->AttachedEffects)
2038+
{
2039+
attachEffect->UpdateAnimLogic();
2040+
}
2041+
}
2042+
20282043
// Recalculates AttachEffect stat multipliers and other bonuses.
20292044
void TechnoExt::ExtData::RecalculateStatMultipliers()
20302045
{

src/Ext/Techno/Body.cpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -480,37 +480,31 @@ bool TechnoExt::IsTypeImmune(TechnoClass* pThis, TechnoClass* pSource)
480480
return false;
481481
}
482482

483-
/// <summary>
484-
/// Gets whether or not techno has listed AttachEffect types active on it
485-
/// </summary>
486-
/// <param name="attachEffectTypes">Attacheffect types.</param>
487-
/// <param name="requireAll">Whether or not to require all listed types to be present or if only one will satisfy the check.</param>
488-
/// <param name="ignoreSameSource">Ignore AttachEffects that come from set invoker and source.</param>
489-
/// <param name="pInvoker">Invoker Techno used for same source check.</param>
490-
/// <param name="pSource">Source AbstractClass instance used for same source check.</param>
491-
/// <returns>True if techno has active AttachEffects that satisfy the source, false if not.</returns>
483+
// Gets whether or not techno has listed AttachEffect types active on it
492484
bool TechnoExt::ExtData::HasAttachedEffects(std::vector<AttachEffectTypeClass*> const& attachEffectTypes, bool requireAll, bool ignoreSameSource,
493-
TechnoClass* pInvoker, AbstractClass* pSource, std::vector<int> const* minCounts, std::vector<int> const* maxCounts) const
485+
TechnoClass* pInvoker, AbstractClass* pSource, std::vector<int> const* minCounts, std::vector<int> const* maxCounts, bool requireAnims) const
494486
{
495487
unsigned int foundCount = 0;
496488
unsigned int typeCounter = 1;
497489
const bool checkSource = ignoreSameSource && pInvoker && pSource;
498490

499-
for (auto const& type : attachEffectTypes)
491+
for (auto const& pType : attachEffectTypes)
500492
{
501493
for (auto const& attachEffect : this->AttachedEffects)
502494
{
503-
if (attachEffect->GetType() == type && attachEffect->IsActive())
495+
auto const pAttachedType = attachEffect->GetType();
496+
497+
if (pAttachedType == pType && attachEffect->IsActive() && (!requireAnims || !pAttachedType->HasAnim() || attachEffect->HasAnim()))
504498
{
505499
if (checkSource && attachEffect->IsFromSource(pInvoker, pSource))
506500
continue;
507501

508502
const unsigned int minSize = minCounts ? minCounts->size() : 0;
509503
const unsigned int maxSize = maxCounts ? maxCounts->size() : 0;
510504

511-
if (type->Cumulative && (minSize > 0 || maxSize > 0))
505+
if (pType->Cumulative && (minSize > 0 || maxSize > 0))
512506
{
513-
const int cumulativeCount = this->GetAttachedEffectCumulativeCount(type, ignoreSameSource, pInvoker, pSource);
507+
const int cumulativeCount = this->GetAttachedEffectCumulativeCount(pType, ignoreSameSource, pInvoker, pSource);
514508

515509
if (minSize > 0)
516510
{
@@ -546,14 +540,7 @@ bool TechnoExt::ExtData::HasAttachedEffects(std::vector<AttachEffectTypeClass*>
546540
return false;
547541
}
548542

549-
/// <summary>
550-
/// Gets how many counts of same cumulative AttachEffect type instance techno has active on it.
551-
/// </summary>
552-
/// <param name="pAttachEffectType">AttachEffect type.</param>
553-
/// <param name="ignoreSameSource">Ignore AttachEffects that come from set invoker and source.</param>
554-
/// <param name="pInvoker">Invoker Techno used for same source check.</param>
555-
/// <param name="pSource">Source AbstractClass instance used for same source check.</param>
556-
/// <returns>Number of active cumulative AttachEffect type instances on the techno. 0 if the AttachEffect type is not cumulative.</returns>
543+
// Gets how many counts of same cumulative AttachEffect type instance techno has active on it.
557544
int TechnoExt::ExtData::GetAttachedEffectCumulativeCount(AttachEffectTypeClass* pAttachEffectType, bool ignoreSameSource, TechnoClass* pInvoker, AbstractClass* pSource) const
558545
{
559546
if (!pAttachEffectType->Cumulative)

src/Ext/Techno/Body.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class TechnoExt
191191
void UpdateKeepTargetOnMove();
192192
void UpdateWarpInDelay();
193193
void UpdateCumulativeAttachEffects(AttachEffectTypeClass* pAttachEffectType, AttachEffectClass* pRemoved = nullptr);
194+
void UpdateAEAnimLogic();
194195
void RecalculateStatMultipliers();
195196
void UpdateTemporal();
196197
void UpdateMindControlAnim();
@@ -200,7 +201,7 @@ class TechnoExt
200201
void InitializeLaserTrails();
201202
void InitializeAttachEffects();
202203
void UpdateSelfOwnedAttachEffects();
203-
bool HasAttachedEffects(std::vector<AttachEffectTypeClass*> const& attachEffectTypes, bool requireAll, bool ignoreSameSource, TechnoClass* pInvoker, AbstractClass* pSource, std::vector<int> const* minCounts, std::vector<int> const* maxCounts) const;
204+
bool HasAttachedEffects(std::vector<AttachEffectTypeClass*> const& attachEffectTypes, bool requireAll, bool ignoreSameSource, TechnoClass* pInvoker, AbstractClass* pSource, std::vector<int> const* minCounts, std::vector<int> const* maxCounts, bool requireAnims = false) const;
204205
int GetAttachedEffectCumulativeCount(AttachEffectTypeClass* pAttachEffectType, bool ignoreSameSource = false, TechnoClass* pInvoker = nullptr, AbstractClass* pSource = nullptr) const;
205206
void InitializeDisplayInfo();
206207
void ApplyMindControlRangeLimit();

src/New/Entity/AttachEffectClass.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ AttachEffectClass::~AttachEffectClass()
100100
if (it != AttachEffectClass::Array.end())
101101
AttachEffectClass::Array.erase(it);
102102

103-
this->KillAnim();
103+
if (this->Animation)
104+
{
105+
this->Animation->UnInit();
106+
this->Animation = nullptr;
107+
}
104108

105109
if (this->Invoker)
106110
TechnoExt::ExtMap.Find(this->Invoker)->AttachedEffectInvokerCount--;
@@ -250,8 +254,6 @@ void AttachEffectClass::AI()
250254

251255
if (!this->Animation && this->CanShowAnim())
252256
this->CreateAnim();
253-
254-
this->AnimCheck();
255257
}
256258

257259
void AttachEffectClass::AI_Temporal()
@@ -286,12 +288,10 @@ void AttachEffectClass::AI_Temporal()
286288
break;
287289
}
288290
}
289-
290-
this->AnimCheck();
291291
}
292292
}
293293

294-
void AttachEffectClass::AnimCheck()
294+
void AttachEffectClass::UpdateAnimLogic()
295295
{
296296
if (this->Type->Animation_HideIfAttachedWith.size() > 0)
297297
{
@@ -319,7 +319,7 @@ void AttachEffectClass::AnimCheck()
319319

320320
for (auto const& drawOffset : this->Type->Animation_DrawOffsets)
321321
{
322-
if (drawOffset.RequiredTypes.size() < 1 || pTechnoExt->HasAttachedEffects(drawOffset.RequiredTypes, false, false, nullptr, nullptr, nullptr, nullptr))
322+
if (drawOffset.RequiredTypes.size() < 1 || pTechnoExt->HasAttachedEffects(drawOffset.RequiredTypes, false, false, nullptr, nullptr, nullptr, nullptr, true))
323323
pAnimExt->AEDrawOffset += drawOffset.Offset;
324324
}
325325
}
@@ -431,6 +431,7 @@ void AttachEffectClass::CreateAnim()
431431

432432
pAnim->RemainingIterations = 0xFFu;
433433
this->Animation = pAnim;
434+
TechnoExt::ExtMap.Find(this->Techno)->UpdateAEAnimLogic();
434435
}
435436
}
436437

@@ -440,8 +441,13 @@ void AttachEffectClass::KillAnim()
440441
{
441442
this->Animation->UnInit();
442443
this->Animation = nullptr;
444+
TechnoExt::ExtMap.Find(this->Techno)->UpdateAEAnimLogic();
443445
}
444446
}
447+
bool AttachEffectClass::HasAnim()
448+
{
449+
return this->Animation != nullptr;
450+
}
445451

446452
void AttachEffectClass::UpdateCumulativeAnim()
447453
{
@@ -802,6 +808,8 @@ AttachEffectClass* AttachEffectClass::CreateAndAttach(AttachEffectTypeClass* pTy
802808
if (!currentTypeCount && pType->Cumulative && pType->CumulativeAnimations.size() > 0)
803809
pAE->HasCumulativeAnim = true;
804810

811+
TechnoExt::ExtMap.Find(pTarget)->UpdateAEAnimLogic();
812+
805813
return pAE;
806814
}
807815

@@ -882,7 +890,11 @@ int AttachEffectClass::DetachTypes(TechnoClass* pTarget, AEAttachInfoTypeClass c
882890
}
883891

884892
if (detachedCount > 0)
885-
TechnoExt::ExtMap.Find(pTarget)->RecalculateStatMultipliers();
893+
{
894+
auto const pExt = TechnoExt::ExtMap.Find(pTarget);
895+
pExt->RecalculateStatMultipliers();
896+
pExt->UpdateAEAnimLogic();
897+
}
886898

887899
if (markForRedraw)
888900
pTarget->MarkForRedraw();
@@ -985,6 +997,7 @@ int AttachEffectClass::RemoveAllOfType(AttachEffectTypeClass* pType, TechnoClass
985997
/// <param name="pTarget">Target techno.</param>
986998
void AttachEffectClass::TransferAttachedEffects(TechnoClass* pSource, TechnoClass* pTarget)
987999
{
1000+
int transferCount = 0;
9881001
const auto pSourceExt = TechnoExt::ExtMap.Find(pSource);
9891002
const auto pTargetExt = TechnoExt::ExtMap.Find(pTarget);
9901003
std::vector<std::unique_ptr<AttachEffectClass>>::iterator it;
@@ -1035,8 +1048,15 @@ void AttachEffectClass::TransferAttachedEffects(TechnoClass* pSource, TechnoClas
10351048
pAE->Duration = attachEffect->Duration;
10361049
}
10371050

1051+
transferCount++;
10381052
it = pSourceExt->AttachedEffects.erase(it);
10391053
}
1054+
1055+
if (transferCount)
1056+
{
1057+
pSourceExt->UpdateAEAnimLogic();
1058+
pTargetExt->UpdateAEAnimLogic();
1059+
}
10401060
}
10411061

10421062
#pragma endregion

src/New/Entity/AttachEffectClass.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ class AttachEffectClass
1818

1919
void AI();
2020
void AI_Temporal();
21+
void UpdateAnimLogic();
2122
void KillAnim();
2223
void CreateAnim();
24+
bool HasAnim();
2325
void UpdateCumulativeAnim();
2426
void TransferCumulativeAnim(AttachEffectClass* pSource);
2527
bool CanShowAnim() const;
@@ -48,7 +50,6 @@ class AttachEffectClass
4850
private:
4951
void OnlineCheck();
5052
void CloakCheck();
51-
void AnimCheck();
5253

5354
static AttachEffectClass* CreateAndAttach(AttachEffectTypeClass* pType, TechnoClass* pTarget, std::vector<std::unique_ptr<AttachEffectClass>>& targetAEs, HouseClass* pInvokerHouse, TechnoClass* pInvoker,
5455
AbstractClass* pSource, AEAttachParams const& attachInfo);

src/New/Type/AttachEffectTypeClass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ AnimTypeClass* AttachEffectTypeClass::GetCumulativeAnimation(int cumulativeCount
6262
return this->CumulativeAnimations.at(index);
6363
}
6464

65+
bool AttachEffectTypeClass::HasAnim()
66+
{
67+
if (this->Cumulative)
68+
return this->CumulativeAnimations.size() > 0 || this->Animation != nullptr;
69+
else
70+
return this->Animation != nullptr;
71+
}
72+
6573
void AttachEffectTypeClass::HandleEvent(TechnoClass* pTarget) const
6674
{
6775
if (const auto pTag = pTarget->AttachedTag)

src/New/Type/AttachEffectTypeClass.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class AttachEffectTypeClass final : public Enumerable<AttachEffectTypeClass>
173173
bool HasGroup(const std::string& groupID) const;
174174
bool HasGroups(const std::vector<std::string>& groupIDs, bool requireAll) const;
175175
AnimTypeClass* GetCumulativeAnimation(int cumulativeCount) const;
176+
bool HasAnim();
176177
void HandleEvent(TechnoClass* pTarget) const;
177178

178179
void LoadFromINI(CCINIClass* pINI);

0 commit comments

Comments
 (0)