Skip to content

Commit efffab6

Browse files
committed
optimize interaction between shield, conversion, tint and per frame logic
- ConvertCheck would only be checked when an actual conversion happens, instead of per frame - conversion always trigger a retint, removed duplicated retints - codestyle things
1 parent bd1e307 commit efffab6

File tree

9 files changed

+76
-92
lines changed

9 files changed

+76
-92
lines changed

src/Ext/Techno/Body.Update.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ void TechnoExt::ExtData::OnEarlyUpdate()
4949

5050
void TechnoExt::ExtData::ApplyInterceptor()
5151
{
52-
const auto pThis = this->OwnerObject();
5352
const auto pTypeExt = this->TypeExtData;
5453
const auto pInterceptorType = pTypeExt->InterceptorType.get();
5554

5655
if (!pInterceptorType)
5756
return;
5857

58+
const auto pThis = this->OwnerObject();
5959
const auto pTarget = pThis->Target;
6060

6161
if (pTarget)
@@ -177,13 +177,13 @@ void TechnoExt::ExtData::ApplyInterceptor()
177177

178178
void TechnoExt::ExtData::DepletedAmmoActions()
179179
{
180-
auto const pThis = this->OwnerObject();
181180
auto const pTypeExt = this->TypeExtData;
182181
auto const pType = pTypeExt->OwnerObject();
183182

184183
if (pType->Ammo <= 0)
185184
return;
186185

186+
auto const pThis = this->OwnerObject();
187187
auto const rtti = pThis->WhatAmI();
188188
UnitClass* pUnit = nullptr;
189189

@@ -206,8 +206,8 @@ void TechnoExt::ExtData::DepletedAmmoActions()
206206
return;
207207

208208
int const ammo = pThis->Ammo;
209-
bool canDeploy = TechnoExt::HasAmmoToDeploy(pThis) && (min < 0 || ammo >= min) && (max < 0 || ammo <= max);
210-
bool isDeploying = pThis->CurrentMission == Mission::Unload || pThis->QueuedMission == Mission::Unload;
209+
const bool canDeploy = TechnoExt::HasAmmoToDeploy(pThis) && (min < 0 || ammo >= min) && (max < 0 || ammo <= max);
210+
const bool isDeploying = pThis->CurrentMission == Mission::Unload || pThis->QueuedMission == Mission::Unload;
211211

212212
if (canDeploy && !isDeploying)
213213
{
@@ -234,13 +234,12 @@ bool TechnoExt::ExtData::CheckDeathConditions(bool isInLimbo)
234234
return false;
235235

236236
auto const pThis = this->OwnerObject();
237-
auto const pType = pThis->GetTechnoType();
238237

239238
// Self-destruction must be enabled
240239
const auto howToDie = pTypeExt->AutoDeath_Behavior.Get();
241240

242241
// Death if no ammo
243-
if (pType->Ammo > 0 && pThis->Ammo <= 0 && pTypeExt->AutoDeath_OnAmmoDepletion)
242+
if (pTypeExt->OwnerObject()->Ammo > 0 && pThis->Ammo <= 0 && pTypeExt->AutoDeath_OnAmmoDepletion)
244243
{
245244
TechnoExt::KillSelf(pThis, howToDie, pTypeExt->AutoDeath_VanishAnimation, isInLimbo);
246245
return true;
@@ -311,10 +310,14 @@ bool TechnoExt::ExtData::CheckDeathConditions(bool isInLimbo)
311310

312311
void TechnoExt::ExtData::EatPassengers()
313312
{
314-
auto const pThis = this->OwnerObject();
315313
auto const pTypeExt = this->TypeExtData;
316314

317-
if (!pTypeExt->PassengerDeletionType || !TechnoExt::IsActiveIgnoreEMP(pThis))
315+
if (!pTypeExt->PassengerDeletionType)
316+
return;
317+
318+
auto const pThis = this->OwnerObject();
319+
320+
if (!TechnoExt::IsActiveIgnoreEMP(pThis))
318321
return;
319322

320323
auto const pDelType = pTypeExt->PassengerDeletionType.get();
@@ -414,7 +417,7 @@ void TechnoExt::ExtData::EatPassengers()
414417
}
415418

416419
// Handle gunner change.
417-
auto const pTransportType = pThis->GetTechnoType();
420+
auto const pTransportType = pTypeExt->OwnerObject();
418421

419422
if (pTransportType->Gunner)
420423
{
@@ -639,6 +642,13 @@ void TechnoExt::ExtData::UpdateTypeData(TechnoTypeClass* pCurrentType)
639642

640643
this->UpdateSelfOwnedAttachEffects();
641644

645+
if (auto const pShield = this->Shield.get())
646+
pShield->ConvertCheck(pCurrentType);
647+
648+
// Recalculate and redraw
649+
this->UpdateTintValues();
650+
pThis->MarkForRedraw();
651+
642652
// Recreate Laser Trails
643653
if (const size_t trailCount = this->LaserTrails.size())
644654
{
@@ -1317,6 +1327,7 @@ void TechnoExt::ExtData::UpdateLaserTrails()
13171327
void TechnoExt::ExtData::UpdateMindControlAnim()
13181328
{
13191329
auto const pThis = this->OwnerObject();
1330+
13201331
if (pThis->IsMindControlled())
13211332
{
13221333
if (pThis->MindControlRingAnim && !this->MindControlRingAnimType)
@@ -1390,9 +1401,7 @@ void TechnoExt::ExtData::UpdateGattlingRateDownReset()
13901401
this->ShouldUpdateGattlingValue = false;
13911402

13921403
if (oldStage != 0)
1393-
{
13941404
pThis->GattlingRateDown(0);
1395-
}
13961405
}
13971406
}
13981407
}
@@ -1865,7 +1874,6 @@ void TechnoExt::ExtData::UpdateSelfOwnedAttachEffects()
18651874
auto const pTypeExt = this->TypeExtData;
18661875
std::vector<std::unique_ptr<AttachEffectClass>>::iterator it;
18671876
std::vector<std::pair<WeaponTypeClass*, TechnoClass*>> expireWeapons;
1868-
bool markForRedraw = false;
18691877
bool altered = false;
18701878

18711879
// Delete ones on old type and not on current.
@@ -1894,7 +1902,6 @@ void TechnoExt::ExtData::UpdateSelfOwnedAttachEffects()
18941902
}
18951903
}
18961904

1897-
markForRedraw |= pType->HasTint();
18981905
it = this->AttachedEffects.erase(it);
18991906
altered = true;
19001907
}
@@ -1917,9 +1924,6 @@ void TechnoExt::ExtData::UpdateSelfOwnedAttachEffects()
19171924

19181925
if (altered && !count)
19191926
this->RecalculateStatMultipliers();
1920-
1921-
if (markForRedraw)
1922-
pThis->MarkForRedraw();
19231927
}
19241928

19251929
// Updates CumulativeAnimations AE's on techno.

src/Ext/Techno/Body.Visuals.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ void TechnoExt::ProcessDigitalDisplays(TechnoClass* pThis)
439439
case AbstractType::Building:
440440
{
441441
pDisplayTypes = &RulesExt::Global()->Buildings_DefaultDigitalDisplayTypes;
442-
const auto pBuildingType = static_cast<BuildingTypeClass*>(pThis->GetTechnoType());
442+
const auto pBuildingType = static_cast<BuildingTypeClass*>(pTypeExt->OwnerObject());
443443
const int height = pBuildingType->GetFoundationHeight(false);
444444
length = height * 7 + height / 2;
445445
break;
@@ -478,7 +478,7 @@ void TechnoExt::ProcessDigitalDisplays(TechnoClass* pThis)
478478
int value = -1;
479479
int maxValue = 0;
480480

481-
GetValuesForDisplay(pThis, pDisplayType->InfoType, value, maxValue, pDisplayType->InfoIndex);
481+
GetValuesForDisplay(pThis, pType, pDisplayType->InfoType, value, maxValue, pDisplayType->InfoIndex);
482482

483483
if (value <= -1 || maxValue <= 0)
484484
continue;
@@ -503,10 +503,8 @@ void TechnoExt::ProcessDigitalDisplays(TechnoClass* pThis)
503503
}
504504
}
505505

506-
void TechnoExt::GetValuesForDisplay(TechnoClass* pThis, DisplayInfoType infoType, int& value, int& maxValue, int infoIndex)
506+
void TechnoExt::GetValuesForDisplay(TechnoClass* pThis, TechnoTypeClass* pType, DisplayInfoType infoType, int& value, int& maxValue, int infoIndex)
507507
{
508-
const auto pType = pThis->GetTechnoType();
509-
510508
switch (infoType)
511509
{
512510
case DisplayInfoType::Health:

src/Ext/Techno/Body.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ bool TechnoExt::ConvertToType(FootClass* pThis, TechnoTypeClass* pToType)
338338
auto const pTypeExt = TechnoExt::ExtMap.Find(pThis);
339339
pTypeExt->UpdateTypeData(pToType);
340340
pTypeExt->UpdateTypeData_Foot();
341-
pTypeExt->UpdateTintValues();
342341
return true;
343342
}
344343

@@ -437,7 +436,6 @@ bool TechnoExt::ConvertToType(FootClass* pThis, TechnoTypeClass* pToType)
437436
auto const pTypeExt = TechnoExt::ExtMap.Find(pThis);
438437
pTypeExt->UpdateTypeData(pToType);
439438
pTypeExt->UpdateTypeData_Foot();
440-
pTypeExt->UpdateTintValues();
441439
return true;
442440
}
443441

src/Ext/Techno/Body.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class TechnoExt
277277
static Point2D GetBuildingSelectBracketPosition(TechnoClass* pThis, BuildingSelectBracketPosition bracketPosition);
278278
static void DrawSelectBox(TechnoClass* pThis, const Point2D* pLocation, const RectangleStruct* pBounds, bool drawBefore = false);
279279
static void ProcessDigitalDisplays(TechnoClass* pThis);
280-
static void GetValuesForDisplay(TechnoClass* pThis, DisplayInfoType infoType, int& value, int& maxValue, int infoIndex);
280+
static void GetValuesForDisplay(TechnoClass* pThis, TechnoTypeClass* pType, DisplayInfoType infoType, int& value, int& maxValue, int infoIndex);
281281
static void GetDigitalDisplayFakeHealth(TechnoClass* pThis, int& value, int& maxValue);
282282
static void CreateDelayedFireAnim(TechnoClass* pThis, AnimTypeClass* pAnimType, int weaponIndex, bool attach, bool center, bool removeOnNoDelay, bool onTurret, CoordStruct firingCoords);
283283
static bool HandleDelayedFireWithPauseSequence(TechnoClass* pThis, WeaponTypeClass* pWeapon, int weaponIndex, int frame, int firingFrame);

src/Ext/Techno/Hooks.WeaponEffects.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ DEFINE_HOOK(0x6FF15F, TechnoClass_FireAt_ObstacleCellSet, 0x6)
3838
GET_BASE(AbstractClass*, pTarget, 0x8);
3939
LEA_STACK(CoordStruct*, pSourceCoords, STACK_OFFSET(0xB0, -0x6C));
4040

41-
auto coords = pTarget->GetCenterCoords();
42-
43-
if (const auto pBuilding = abstract_cast<BuildingClass*, true>(pTarget))
44-
coords = pBuilding->GetTargetCoords();
41+
const auto pBuilding = abstract_cast<BuildingClass*, true>(pTarget);
42+
const auto coords = pBuilding ? pBuilding->GetTargetCoords() : pTarget->GetCenterCoords();
4543

4644
// This is set to a temp variable as well, as accessing it everywhere needed from TechnoExt would be more complicated.
4745
FireAtTemp::pObstacleCell = TrajectoryHelper::FindFirstObstacle(*pSourceCoords, coords, pWeapon->Projectile, pThis->Owner);
@@ -117,12 +115,14 @@ DEFINE_HOOK(0x70C6B5, TechnoClass_Railgun_TargetCoords, 0x5)
117115
{
118116
GET(AbstractClass*, pTarget, EBX);
119117

120-
auto coords = pTarget->GetCenterCoords();
118+
CoordStruct coords;
121119

122120
if (const auto pBuilding = abstract_cast<BuildingClass*, true>(pTarget))
123121
coords = pBuilding->GetTargetCoords();
124122
else if (const auto pCell = abstract_cast<CellClass*, true>(pTarget))
125123
coords = pCell->GetCoordsWithBridge();
124+
else
125+
coords = pTarget->GetCenterCoords();
126126

127127
R->EAX(&coords);
128128
return 0;
@@ -318,15 +318,17 @@ DEFINE_HOOK(0x762AFF, WaveClass_AI_TargetSet, 0x6)
318318
{
319319
GET(WaveClass*, pThis, ESI);
320320

321-
if (pThis->Target && pThis->Owner)
321+
if (pThis->Target)
322322
{
323-
auto const pOwner = pThis->Owner;
324-
auto const pObstacleCell = TechnoExt::ExtMap.Find(pThis->Owner)->FiringObstacleCell;
325-
326-
if (pObstacleCell == pThis->Target && pOwner->Target)
323+
if (auto const pOwner = pThis->Owner)
327324
{
328-
FireAtTemp::pWaveOwnerTarget = pOwner->Target;
329-
pOwner->Target = pThis->Target;
325+
auto const pObstacleCell = TechnoExt::ExtMap.Find(pOwner)->FiringObstacleCell;
326+
327+
if (pObstacleCell == pThis->Target && pOwner->Target)
328+
{
329+
FireAtTemp::pWaveOwnerTarget = pOwner->Target;
330+
pOwner->Target = pThis->Target;
331+
}
330332
}
331333
}
332334

src/Ext/Techno/Hooks.WeaponRange.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,17 @@ DEFINE_HOOK(0x7012C2, TechnoClass_WeaponRange, 0x8)
1919
{
2020
result = WeaponTypeExt::GetRangeWithModifiers(pWeapon, pThis);
2121
auto const pType = pThis->GetTechnoType();
22-
auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pType);
2322

24-
if (pType->OpenTopped && !pTypeExt->OpenTopped_IgnoreRangefinding)
23+
if (pType->OpenTopped && !TechnoTypeExt::ExtMap.Find(pType)->OpenTopped_IgnoreRangefinding)
2524
{
2625
int smallestRange = INT32_MAX;
2726
auto pPassenger = abstract_cast<FootClass*>(pThis->Passengers.GetFirstPassenger());
2827

2928
while (pPassenger)
3029
{
3130
const int openTWeaponIndex = pPassenger->GetTechnoType()->OpenTransportWeapon;
32-
int tWeaponIndex = openTWeaponIndex;
33-
34-
if (openTWeaponIndex == -1)
35-
tWeaponIndex = pPassenger->SelectWeapon(pThis->Target);
36-
37-
WeaponTypeClass* pTWeapon = pPassenger->GetWeapon(tWeaponIndex)->WeaponType;
31+
const int tWeaponIndex = openTWeaponIndex == -1 ? pPassenger->SelectWeapon(pThis->Target) : openTWeaponIndex;
32+
auto const pTWeapon = pPassenger->GetWeapon(tWeaponIndex)->WeaponType;
3833

3934
if (pTWeapon && pTWeapon->FireInTransport)
4035
{

src/Ext/Techno/Hooks.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,13 @@ DEFINE_HOOK(0x6F42F7, TechnoClass_Init, 0x2)
227227
auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pType);
228228
pExt->TypeExtData = pTypeExt;
229229

230-
pExt->CurrentShieldType = pTypeExt->ShieldType;
230+
auto const pShieldType = pTypeExt->ShieldType;
231+
pExt->CurrentShieldType = pShieldType;
231232
pExt->InitializeAttachEffects();
232233
pExt->InitializeDisplayInfo();
233234
pExt->InitializeLaserTrails();
234235

235-
if (!pExt->AE.HasTint && !pExt->CurrentShieldType)
236+
if (!pExt->AE.HasTint && (!pShieldType || !pShieldType->HasTint() || pShieldType->Strength <= 0))
236237
pExt->UpdateTintValues();
237238

238239
if (pTypeExt->Harvester_Counted)

0 commit comments

Comments
 (0)