From 07ebdd364c882df68b06ce26e49785bc66032e41 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 26 Apr 2020 01:02:02 -0400 Subject: [PATCH] CDamageVulnerability: Make constructors constexpr Eliminates any potential runtime initializers related to file-scope constant instances of this class. --- Runtime/World/CDamageVulnerability.cpp | 71 ++--------------------- Runtime/World/CDamageVulnerability.hpp | 78 +++++++++++++++++++++----- 2 files changed, 69 insertions(+), 80 deletions(-) diff --git a/Runtime/World/CDamageVulnerability.cpp b/Runtime/World/CDamageVulnerability.cpp index 565dcbf18..78938f847 100644 --- a/Runtime/World/CDamageVulnerability.cpp +++ b/Runtime/World/CDamageVulnerability.cpp @@ -2,7 +2,7 @@ namespace urde { -const CDamageVulnerability CDamageVulnerability::sNormalVulnerability( +constexpr CDamageVulnerability CDamageVulnerability::sNormalVulnerability( EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, @@ -10,7 +10,7 @@ const CDamageVulnerability CDamageVulnerability::sNormalVulnerability( EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EDeflectType::None); -const CDamageVulnerability CDamageVulnerability::sImmuneVulnerability( +constexpr CDamageVulnerability CDamageVulnerability::sImmuneVulnerability( EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, @@ -18,7 +18,7 @@ const CDamageVulnerability CDamageVulnerability::sImmuneVulnerability( EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EDeflectType::None); -const CDamageVulnerability CDamageVulnerability::sReflectVulnerability( +constexpr CDamageVulnerability CDamageVulnerability::sReflectVulnerability( EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, @@ -26,7 +26,7 @@ const CDamageVulnerability CDamageVulnerability::sReflectVulnerability( EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EDeflectType::One); -const CDamageVulnerability CDamageVulnerability::sPassThroughVulnerability( +constexpr CDamageVulnerability CDamageVulnerability::sPassThroughVulnerability( EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, @@ -95,69 +95,6 @@ CDamageVulnerability::CDamageVulnerability(CInputStream& in) { ConstructNew(in, propCount); } -CDamageVulnerability::CDamageVulnerability(EVulnerability power, EVulnerability ice, EVulnerability wave, - EVulnerability plasma, EVulnerability bomb, EVulnerability powerBomb, - EVulnerability missile, EVulnerability boostBall, EVulnerability phazon, - EVulnerability enemyWp1, EVulnerability enemyWp2, EVulnerability enemyWp3, - EVulnerability enemyWp4, EVulnerability v1, EVulnerability v2, - EDeflectType deflectType) -: x0_power(power) -, x4_ice(ice) -, x8_wave(wave) -, xc_plasma(plasma) -, x10_bomb(bomb) -, x14_powerbomb(powerBomb) -, x18_missile(missile) -, x1c_boostBall(boostBall) -, x20_phazon(phazon) -, x24_enemyWp1(enemyWp1) -, x28_enemyWp2Poison(enemyWp2) -, x2c_enemyWp3Lava(enemyWp3) -, x30_enemyWp4(enemyWp4) -, x34_unk1(v1) -, x38_unk2(v2) -, x3c_chargedPower(x0_power) -, x40_chargedIce(x4_ice) -, x44_chargedWave(x8_wave) -, x48_chargedPlasma(xc_plasma) -, x4c_superMissile(x0_power) -, x50_iceSpreader(x4_ice) -, x54_wavebuster(x8_wave) -, x58_flamethrower(xc_plasma) -, x5c_deflected(deflectType) {} - -CDamageVulnerability::CDamageVulnerability( - EVulnerability power, EVulnerability ice, EVulnerability wave, EVulnerability plasma, EVulnerability bomb, - EVulnerability powerBomb, EVulnerability missile, EVulnerability boostBall, EVulnerability phazon, - EVulnerability enemyWp1, EVulnerability enemyWp2, EVulnerability enemyWp3, EVulnerability enemyWp4, - EVulnerability v1, EVulnerability v2, EVulnerability chargedPower, EVulnerability chargedIce, - EVulnerability chargedWave, EVulnerability chargedPlasma, EVulnerability superMissile, EVulnerability iceSpreader, - EVulnerability waveBuster, EVulnerability flameThrower, EDeflectType deflected) -: x0_power(power) -, x4_ice(ice) -, x8_wave(wave) -, xc_plasma(plasma) -, x10_bomb(bomb) -, x14_powerbomb(powerBomb) -, x18_missile(missile) -, x1c_boostBall(boostBall) -, x20_phazon(phazon) -, x24_enemyWp1(enemyWp1) -, x28_enemyWp2Poison(enemyWp2) -, x2c_enemyWp3Lava(enemyWp3) -, x30_enemyWp4(enemyWp4) -, x34_unk1(v1) -, x38_unk2(v2) -, x3c_chargedPower(chargedPower) -, x40_chargedIce(chargedIce) -, x44_chargedWave(chargedWave) -, x48_chargedPlasma(chargedPlasma) -, x4c_superMissile(superMissile) -, x50_iceSpreader(iceSpreader) -, x54_wavebuster(waveBuster) -, x58_flamethrower(flameThrower) -, x5c_deflected(deflected) {} - EDeflectType CDamageVulnerability::GetDeflectionType(const CWeaponMode& mode) const { if (mode.IsCharged()) return x60_chargedDeflected; diff --git a/Runtime/World/CDamageVulnerability.hpp b/Runtime/World/CDamageVulnerability.hpp index 0e2620dd2..b73587ad5 100644 --- a/Runtime/World/CDamageVulnerability.hpp +++ b/Runtime/World/CDamageVulnerability.hpp @@ -36,8 +36,8 @@ class CDamageVulnerability { EVulnerability x58_flamethrower; EDeflectType x5c_deflected; - EDeflectType x60_chargedDeflected; - EDeflectType x64_comboDeflected; + EDeflectType x60_chargedDeflected{}; + EDeflectType x64_comboDeflected{}; void ConstructNew(CInputStream& in, int propCount); @@ -48,17 +48,69 @@ class CDamageVulnerability { public: explicit CDamageVulnerability(CInputStream& in); - CDamageVulnerability(EVulnerability power, EVulnerability ice, EVulnerability wave, EVulnerability plasma, - EVulnerability bomb, EVulnerability powerBomb, EVulnerability missile, EVulnerability boostBall, - EVulnerability phazon, EVulnerability enemyWp1, EVulnerability enemyWp2, EVulnerability enemyWp3, - EVulnerability enemyWp4, EVulnerability v1, EVulnerability v2, EDeflectType deflectType); - CDamageVulnerability(EVulnerability power, EVulnerability ice, EVulnerability wave, EVulnerability plasma, - EVulnerability bomb, EVulnerability powerBomb, EVulnerability missile, EVulnerability boostBall, - EVulnerability phazon, EVulnerability enemyWp1, EVulnerability enemyWp2, EVulnerability enemyWp3, - EVulnerability enemyWp4, EVulnerability v1, EVulnerability v2, EVulnerability chargedPower, - EVulnerability chargedIce, EVulnerability chargedWave, EVulnerability chargedPlasma, - EVulnerability superMissile, EVulnerability iceSpreader, EVulnerability waveBuster, - EVulnerability flameThrower, EDeflectType deflected); + + constexpr CDamageVulnerability(EVulnerability power, EVulnerability ice, EVulnerability wave, EVulnerability plasma, + EVulnerability bomb, EVulnerability powerBomb, EVulnerability missile, + EVulnerability boostBall, EVulnerability phazon, EVulnerability enemyWp1, + EVulnerability enemyWp2, EVulnerability enemyWp3, EVulnerability enemyWp4, + EVulnerability v1, EVulnerability v2, EDeflectType deflectType) + : x0_power(power) + , x4_ice(ice) + , x8_wave(wave) + , xc_plasma(plasma) + , x10_bomb(bomb) + , x14_powerbomb(powerBomb) + , x18_missile(missile) + , x1c_boostBall(boostBall) + , x20_phazon(phazon) + , x24_enemyWp1(enemyWp1) + , x28_enemyWp2Poison(enemyWp2) + , x2c_enemyWp3Lava(enemyWp3) + , x30_enemyWp4(enemyWp4) + , x34_unk1(v1) + , x38_unk2(v2) + , x3c_chargedPower(x0_power) + , x40_chargedIce(x4_ice) + , x44_chargedWave(x8_wave) + , x48_chargedPlasma(xc_plasma) + , x4c_superMissile(x0_power) + , x50_iceSpreader(x4_ice) + , x54_wavebuster(x8_wave) + , x58_flamethrower(xc_plasma) + , x5c_deflected(deflectType) {} + + constexpr CDamageVulnerability(EVulnerability power, EVulnerability ice, EVulnerability wave, EVulnerability plasma, + EVulnerability bomb, EVulnerability powerBomb, EVulnerability missile, + EVulnerability boostBall, EVulnerability phazon, EVulnerability enemyWp1, + EVulnerability enemyWp2, EVulnerability enemyWp3, EVulnerability enemyWp4, + EVulnerability v1, EVulnerability v2, EVulnerability chargedPower, + EVulnerability chargedIce, EVulnerability chargedWave, EVulnerability chargedPlasma, + EVulnerability superMissile, EVulnerability iceSpreader, EVulnerability waveBuster, + EVulnerability flameThrower, EDeflectType deflected) + : x0_power(power) + , x4_ice(ice) + , x8_wave(wave) + , xc_plasma(plasma) + , x10_bomb(bomb) + , x14_powerbomb(powerBomb) + , x18_missile(missile) + , x1c_boostBall(boostBall) + , x20_phazon(phazon) + , x24_enemyWp1(enemyWp1) + , x28_enemyWp2Poison(enemyWp2) + , x2c_enemyWp3Lava(enemyWp3) + , x30_enemyWp4(enemyWp4) + , x34_unk1(v1) + , x38_unk2(v2) + , x3c_chargedPower(chargedPower) + , x40_chargedIce(chargedIce) + , x44_chargedWave(chargedWave) + , x48_chargedPlasma(chargedPlasma) + , x4c_superMissile(superMissile) + , x50_iceSpreader(iceSpreader) + , x54_wavebuster(waveBuster) + , x58_flamethrower(flameThrower) + , x5c_deflected(deflected) {} EDeflectType GetDeflectionType(const CWeaponMode& mode) const;