Skip to content

Commit 87002d0

Browse files
committed
optimize 3a59e61
also apply some optimization from #1582
1 parent 3a59e61 commit 87002d0

File tree

7 files changed

+33
-44
lines changed

7 files changed

+33
-44
lines changed

src/Ext/Anim/Hooks.AnimCreateUnit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
DEFINE_HOOK(0x737F6D, UnitClass_TakeDamage_Destroy, 0x7)
1616
{
1717
GET(UnitClass* const, pThis, ESI);
18-
REF_STACK(args_ReceiveDamage const, Receivedamageargs, STACK_OFFSET(0x44, 0x4));
18+
REF_STACK(args_ReceiveDamage const, receiveDamageArgs, STACK_OFFSET(0x44, 0x4));
1919

2020
R->ECX(R->ESI());
2121
TechnoExt::ExtMap.Find(pThis)->ReceiveDamage = true;
22-
AnimTypeExt::ProcessDestroyAnims(pThis, Receivedamageargs.Attacker);
22+
AnimTypeExt::ProcessDestroyAnims(pThis, receiveDamageArgs.Attacker);
2323
pThis->Destroy();
2424

2525
return 0x737F74;

src/Ext/Techno/Hooks.Firing.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -841,30 +841,28 @@ DEFINE_HOOK(0x6F3AEB, TechnoClass_GetFLH, 0x6)
841841
GET_STACK(CoordStruct*, pCoords, STACK_OFFSET(0xD8, 0x4));
842842

843843
bool allowOnTurret = true;
844-
bool useBurstMirroring = true;
845844
CoordStruct flh = CoordStruct::Empty;
846845

847846
if (weaponIndex >= 0)
848847
{
849848
bool found = false;
850849
flh = TechnoExt::GetBurstFLH(pThis, weaponIndex, found);
850+
851851
if (!found)
852852
{
853853
if (auto const pInf = abstract_cast<InfantryClass*>(pThis))
854854
flh = TechnoExt::GetSimpleFLH(pInf, weaponIndex, found);
855855

856856
if (!found)
857857
flh = pThis->GetWeapon(weaponIndex)->FLH;
858-
}
859-
else
860-
{
861-
useBurstMirroring = false;
858+
859+
if (pThis->CurrentBurstIndex % 2 != 0)
860+
flh.Y = -flh.Y;
862861
}
863862
}
864863
else
865864
{
866-
int index = -weaponIndex - 1;
867-
useBurstMirroring = false;
865+
const int index = -weaponIndex - 1;
868866
auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pType);
869867

870868
if (index < static_cast<int>(pTypeExt->AlternateFLHs.size()))
@@ -874,9 +872,6 @@ DEFINE_HOOK(0x6F3AEB, TechnoClass_GetFLH, 0x6)
874872
allowOnTurret = false;
875873
}
876874

877-
if (useBurstMirroring && pThis->CurrentBurstIndex % 2 != 0)
878-
flh.Y = -flh.Y;
879-
880875
*pCoords = TechnoExt::GetFLHAbsoluteCoords(pThis, flh, allowOnTurret);
881876
R->EAX(pCoords);
882877

src/Ext/Techno/Hooks.ReceiveDamage.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,24 @@ DEFINE_HOOK(0x701E18, TechnoClass_ReceiveDamage_ReflectDamage, 0x7)
397397

398398
return 0;
399399
}
400+
DEFINE_HOOK(0x5F547E, ObjectClass_ReceiveDamage_FlashDuration, 0x6)
401+
{
402+
enum { SkipGameCode = 0x5F545C };
403+
404+
GET(ObjectClass*, pThis, ESI);
405+
GET(const int, nNewHealth, EDX);
406+
REF_STACK(args_ReceiveDamage const, receiveDamageArgs, STACK_OFFSET(0x24, 0x4));
407+
408+
if (pThis->Health == nNewHealth)
409+
return SkipGameCode;
410+
411+
int nFlashDuration = 7;
412+
413+
if (auto const pWH = receiveDamageArgs.WH)
414+
nFlashDuration = WarheadTypeExt::ExtMap.Find(pWH)->Flash_Duration.Get(nFlashDuration);
415+
416+
if (nFlashDuration > 0)
417+
pThis->Flash(nFlashDuration);
418+
419+
return SkipGameCode;
420+
}

src/Ext/TechnoType/Hooks.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -128,30 +128,3 @@ DEFINE_HOOK(0x71464A, TechnoTypeClass_ReadINI_Speed, 0x7)
128128

129129
return SkipGameCode;
130130
}
131-
132-
DEFINE_HOOK(0x5F547E, ObjectClass_ReceiveDamage_FlashDuration, 0x6)
133-
{
134-
GET(ObjectClass*, pThis, ESI);
135-
GET(int, nNewHealth, EDX);
136-
LEA_STACK(args_ReceiveDamage*, pArgs, STACK_OFFSET(0x24, 0x4));
137-
enum { SkipGameCode = 0x5F545C };
138-
139-
if (pThis->Health == nNewHealth)
140-
return SkipGameCode;
141-
142-
int nFlashDuration = 7;
143-
if (auto pWH = pArgs->WH)
144-
{
145-
if (auto pWHEXT = WarheadTypeExt::ExtMap.Find(pWH))
146-
{
147-
nFlashDuration = pWHEXT->Flash_Duration.Get(nFlashDuration);
148-
}
149-
}
150-
151-
if (nFlashDuration > 0)
152-
{
153-
pThis->Flash(nFlashDuration);
154-
}
155-
156-
return SkipGameCode;
157-
}

src/Ext/WarheadType/Body.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
119119
INI_EX exINI(pINI);
120120

121121
// Miscs
122-
this->Flash_Duration.Read(exINI, pSection, "Flash.Duration");
123122
this->Reveal.Read(exINI, pSection, "Reveal");
124123
this->CreateGap.Read(exINI, pSection, "CreateGap");
125124
this->TransactMoney.Read(exINI, pSection, "TransactMoney");
@@ -337,6 +336,7 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
337336
this->AffectsOwner.Read(exINI, pSection, "AffectsOwner");
338337
this->EffectsRequireVerses.Read(exINI, pSection, "EffectsRequireVerses");
339338
this->Malicious.Read(exINI, pSection, "Malicious");
339+
this->Flash_Duration.Read(exINI, pSection, "Flash.Duration");
340340

341341
// List all Warheads here that respect CellSpread
342342
// Used in WarheadTypeExt::ExtData::Detonate
@@ -403,7 +403,6 @@ template <typename T>
403403
void WarheadTypeExt::ExtData::Serialize(T& Stm)
404404
{
405405
Stm
406-
.Process(this->Flash_Duration)
407406
.Process(this->Reveal)
408407
.Process(this->CreateGap)
409408
.Process(this->TransactMoney)
@@ -590,6 +589,7 @@ void WarheadTypeExt::ExtData::Serialize(T& Stm)
590589
.Process(this->AffectsOwner)
591590
.Process(this->EffectsRequireVerses)
592591
.Process(this->Malicious)
592+
.Process(this->Flash_Duration)
593593

594594
.Process(this->WasDetonatedOnAllMapObjects)
595595
.Process(this->RemainingAnimCreationInterval)

src/Ext/WarheadType/Body.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class WarheadTypeExt
2121
{
2222
public:
2323

24-
Nullable<int> Flash_Duration;
2524
Valueable<int> Reveal;
2625
Valueable<int> CreateGap;
2726
Valueable<int> TransactMoney;
@@ -211,6 +210,7 @@ class WarheadTypeExt
211210
Nullable<bool> AffectsOwner;
212211
Valueable<bool> EffectsRequireVerses;
213212
Valueable<bool> Malicious;
213+
Nullable<int> Flash_Duration;
214214

215215
double Crit_RandomBuffer;
216216
double Crit_CurrentChance;
@@ -230,7 +230,6 @@ class WarheadTypeExt
230230

231231
public:
232232
ExtData(WarheadTypeClass* OwnerObject) : Extension<WarheadTypeClass>(OwnerObject)
233-
, Flash_Duration { 0 }
234233
, Reveal { 0 }
235234
, CreateGap { 0 }
236235
, TransactMoney { 0 }
@@ -398,6 +397,7 @@ class WarheadTypeExt
398397
, AffectsOwner {}
399398
, EffectsRequireVerses { true }
400399
, Malicious { true }
400+
, Flash_Duration {}
401401

402402
, Crit_RandomBuffer { 0.0 }
403403
, Crit_CurrentChance { 0.0 }

src/Utilities/EnumFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bool EnumFunctions::IsCellEligible(CellClass* const pCell, AffectedTarget allowe
1818

1919
if (explicitEmptyCells)
2020
{
21-
const auto pTechno = pCell->GetContent() ? abstract_cast<TechnoClass*>(pCell->GetContent()) : nullptr;
21+
const auto pTechno = abstract_cast<TechnoClass*>(pCell->GetContent());
2222

2323
if (!pTechno && !(allowed & AffectedTarget::NoContent))
2424
return false;

0 commit comments

Comments
 (0)