Skip to content

Commit d6307cd

Browse files
committed
Optimize the use of GET_STACK with CoordStruct
1 parent d0add0f commit d6307cd

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

src/Ext/Aircraft/Hooks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ DEFINE_HOOK(0x414F10, AircraftClass_AI_Trailer, 0x5)
261261
enum { SkipGameCode = 0x414F47 };
262262

263263
GET(AircraftClass*, pThis, ESI);
264-
GET_STACK(CoordStruct, coords, STACK_OFFSET(0x40, -0xC));
264+
REF_STACK(const CoordStruct, coords, STACK_OFFSET(0x40, -0xC));
265265

266266
auto const pTrailerAnim = GameCreate<AnimClass>(pThis->Type->Trailer, coords, 1, 1);
267267
auto const pTrailerAnimExt = AnimExt::ExtMap.Find(pTrailerAnim);

src/Ext/Bullet/Body.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void BulletExt::SimulatedFiringUnlimbo(BulletClass* pBullet, HouseClass* pHouse,
342342
const auto speed = speedMult * sqrt(horizontalDistance * gravity * 1.2); // 0x48AB90
343343

344344
// Simulate firing Arcing bullet
345-
if (horizontalDistance < 1e-10 || !speed)
345+
if (horizontalDistance < 1e-10 || speed < 1e-10)
346346
{
347347
// No solution
348348
velocity.Z = speed;
@@ -398,10 +398,10 @@ void BulletExt::ApplyArcingFix(BulletClass* pThis, const CoordStruct& sourceCoor
398398
// WW calculates the launch angle (and limits it) before calculating the velocity
399399
// Here, some magic numbers are used to directly simulate its calculation
400400
const auto speedMult = (lobber ? 0.45 : (distanceCoords.Z > 0 ? 0.68 : 1.0)); // Simulated 0x48A9D0
401-
const double gravity = BulletTypeExt::GetAdjustedGravity(pThis->Type);
402-
const double speed = speedMult * sqrt(horizontalDistance * gravity * 1.2); // 0x48AB90
401+
const auto gravity = BulletTypeExt::GetAdjustedGravity(pThis->Type);
402+
const auto speed = speedMult * sqrt(horizontalDistance * gravity * 1.2); // 0x48AB90
403403

404-
if (horizontalDistance < 1e-10 || !speed)
404+
if (horizontalDistance < 1e-10 || speed < 1e-10)
405405
{
406406
// No solution
407407
velocity.Z = speed;

src/Ext/Bullet/Hooks.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,9 @@ DEFINE_HOOK(0x466897, BulletClass_AI_Trailer, 0x6)
102102
enum { SkipGameCode = 0x4668BD };
103103

104104
GET(BulletClass*, pThis, EBP);
105-
GET_STACK(CoordStruct, coords, STACK_OFFSET(0x1A8, -0x184));
105+
REF_STACK(const CoordStruct, coords, STACK_OFFSET(0x1A8, -0x184));
106106

107107
auto const pTrailerAnim = GameCreate<AnimClass>(pThis->Type->Trailer, coords, 1, 1);
108-
109108
auto const pTrailerAnimExt = AnimExt::ExtMap.Find(pTrailerAnim);
110109
auto const pOwner = pThis->Owner ? pThis->Owner->Owner : BulletAITemp::ExtData->FirerHouse;
111110
AnimExt::SetAnimOwnerHouseKind(pTrailerAnim, pOwner, nullptr, false, true);
@@ -277,11 +276,11 @@ DEFINE_HOOK(0x46902C, BulletClass_Explode_Cluster, 0x6)
277276
enum { SkipGameCode = 0x469091 };
278277

279278
GET(BulletClass*, pThis, ESI);
280-
GET_STACK(CoordStruct, origCoords, STACK_OFFSET(0x3C, -0x30));
279+
REF_STACK(const CoordStruct, origCoords, STACK_OFFSET(0x3C, -0x30));
281280

282281
auto const pTypeExt = BulletTypeExt::ExtMap.Find(pThis->Type);
283-
int min = pTypeExt->ClusterScatter_Min.Get();
284-
int max = pTypeExt->ClusterScatter_Max.Get();
282+
const int min = pTypeExt->ClusterScatter_Min.Get();
283+
const int max = pTypeExt->ClusterScatter_Max.Get();
285284
auto coords = origCoords;
286285

287286
for (int i = 0; i < pThis->Type->Cluster; i++)
@@ -425,36 +424,37 @@ DEFINE_JUMP(LJMP, 0x468D08, 0x468D2F);
425424

426425
DEFINE_HOOK(0x6FF008, TechnoClass_Fire_BeforeMoveTo, 0x8)
427426
{
428-
GET(BulletClass*, pBullet, EBX);
429-
const auto projectile = pBullet->Type;
427+
GET(BulletClass* const, pBullet, EBX);
428+
429+
const auto pBulletType = pBullet->Type;
430430

431-
if (projectile->Arcing && !BulletTypeExt::ExtMap.Find(projectile)->Arcing_AllowElevationInaccuracy)
431+
if (pBulletType->Arcing && !BulletTypeExt::ExtMap.Find(pBulletType)->Arcing_AllowElevationInaccuracy)
432432
{
433-
LEA_STACK(BulletVelocity*, velocity, STACK_OFFSET(0xB0, -0x60));
434-
LEA_STACK(CoordStruct*, crdSrc, STACK_OFFSET(0xB0, -0x6C));
433+
REF_STACK(BulletVelocity, velocity, STACK_OFFSET(0xB0, -0x60));
434+
REF_STACK(const CoordStruct, crdSrc, STACK_OFFSET(0xB0, -0x6C));
435+
REF_STACK(const CoordStruct, crdOffset, STACK_OFFSET(0xB0, -0x1C));
436+
REF_STACK(const CoordStruct, fireCoords, STACK_OFFSET(0xB0, -0x6C));
435437

436-
GET_STACK(CoordStruct, crdOffset, STACK_OFFSET(0xB0, -0x1C));
437-
GET_STACK(CoordStruct, fireCoords, STACK_OFFSET(0xB0, -0x6C));
438438
const auto crdTgt = crdOffset + fireCoords;
439-
440-
BulletExt::ApplyArcingFix(pBullet, *crdSrc, crdTgt, *velocity);
439+
BulletExt::ApplyArcingFix(pBullet, crdSrc, crdTgt, velocity);
441440
}
442441

443442
return 0;
444443
}
445444

446445
DEFINE_HOOK(0x44D46E, BuildingClass_Mission_Missile_BeforeMoveTo, 0x8)
447446
{
448-
GET(BulletClass*, pBullet, EDI);
449-
const auto projectile = pBullet->Type;
447+
GET(BulletClass* const, pBullet, EDI);
448+
449+
const auto pBulletType = pBullet->Type;
450450

451-
if (projectile->Arcing && !BulletTypeExt::ExtMap.Find(projectile)->Arcing_AllowElevationInaccuracy)
451+
if (pBulletType->Arcing && !BulletTypeExt::ExtMap.Find(pBulletType)->Arcing_AllowElevationInaccuracy)
452452
{
453-
LEA_STACK(BulletVelocity*, velocity, STACK_OFFSET(0xE8, -0xD0));
454-
LEA_STACK(CoordStruct*, crdSrc, STACK_OFFSET(0xE8, -0x8C));
455-
GET_STACK(CoordStruct, crdTgt, STACK_OFFSET(0xE8, -0x4C));
453+
REF_STACK(BulletVelocity, velocity, STACK_OFFSET(0xE8, -0xD0));
454+
REF_STACK(const CoordStruct, crdSrc, STACK_OFFSET(0xE8, -0x8C));
455+
REF_STACK(const CoordStruct, crdTgt, STACK_OFFSET(0xE8, -0x4C));
456456

457-
BulletExt::ApplyArcingFix(pBullet, *crdSrc, crdTgt, *velocity);
457+
BulletExt::ApplyArcingFix(pBullet, crdSrc, crdTgt, velocity);
458458
}
459459

460460
return 0;

0 commit comments

Comments
 (0)