ITweakGunRes: Make use of std::array where applicable

Deduplicates a few array sizes and makes the member variables more
strongly typed.
This commit is contained in:
Lioncash 2020-02-25 15:43:25 -05:00
parent b608a72aad
commit e80d9c7192
3 changed files with 25 additions and 16 deletions

View File

@ -1,5 +1,7 @@
#pragma once
#include <array>
#include "ITweak.hpp"
#include "Runtime/IFactory.hpp"
#include "Runtime/CPlayerState.hpp"
@ -27,10 +29,11 @@ struct ITweakGunRes : ITweak {
ResId x30_powerBombExplode;
/* Power, Ice, Wave, Plasma, Phazon / Beam, Ball */
ResId x34_weapons[5][2];
ResId x84_muzzle[5];
ResId x94_charge[5];
ResId xa4_auxMuzzle[5];
using WeaponPair = std::array<ResId, 2>;
std::array<WeaponPair, 5> x34_weapons;
std::array<ResId, 5> x84_muzzle;
std::array<ResId, 5> x94_charge;
std::array<ResId, 5> xa4_auxMuzzle;
ResId xb4_grappleSegment;
ResId xb8_grappleClaw;
@ -57,10 +60,11 @@ struct ITweakGunRes : ITweak {
}
}
const ResId* GetWeaponPair(EBeamId beam) const {
auto b = int(beam);
if (b < 0 || b > 4)
const WeaponPair& GetWeaponPair(EBeamId beam) const {
const auto b = int(beam);
if (b < 0 || b > 4) {
return x34_weapons[0];
}
return x34_weapons[b];
}
@ -81,18 +85,23 @@ struct ITweakGunRes : ITweak {
x2c_bombExplode = factory.GetResourceIdByName(GetBombExplode())->id;
x30_powerBombExplode = factory.GetResourceIdByName(GetPowerBombExplode())->id;
for (int i = 0; i < 5; ++i)
for (int j = 0; j < 2; ++j)
x34_weapons[i][j] = factory.GetResourceIdByName(GetWeapon(i, j))->id;
for (size_t i = 0; i < x34_weapons.size(); ++i) {
for (size_t j = 0; j < x34_weapons[i].size(); ++j) {
x34_weapons[i][j] = factory.GetResourceIdByName(GetWeapon(i, j != 0))->id;
}
}
for (int i = 0; i < 5; ++i)
for (size_t i = 0; i < x84_muzzle.size(); ++i) {
x84_muzzle[i] = factory.GetResourceIdByName(GetMuzzleParticle(i))->id;
}
for (int i = 0; i < 5; ++i)
for (size_t i = 0; i < x94_charge.size(); ++i) {
x94_charge[i] = factory.GetResourceIdByName(GetChargeParticle(i))->id;
}
for (int i = 0; i < 5; ++i)
for (size_t i = 0; i < xa4_auxMuzzle.size(); ++i) {
xa4_auxMuzzle[i] = factory.GetResourceIdByName(GetAuxMuzzleParticle(i))->id;
}
xb4_grappleSegment = factory.GetResourceIdByName(GetGrappleSegmentParticle())->id;
xb8_grappleClaw = factory.GetResourceIdByName(GetGrappleClawParticle())->id;

View File

@ -76,7 +76,7 @@ CGunWeapon::CGunWeapon(CAssetId ancsId, EWeaponType type, TUniqueId playerId, EM
}
void CGunWeapon::AllocResPools(CPlayerState::EBeamId beam) {
const CAssetId* const wPair = g_tweakGunRes->GetWeaponPair(beam);
const auto& wPair = g_tweakGunRes->GetWeaponPair(beam);
const char* const* muzzleNames = &skMuzzleNames[size_t(beam) * 2];
const char* const* frozenNames = &skFrozenNames[size_t(beam) * 2];

View File

@ -107,8 +107,8 @@ void CPlayerGun::InitBombData() {
}
void CPlayerGun::InitMuzzleData() {
for (int i = 0; i < 5; ++i) {
x7c0_auxMuzzleEffects.push_back(g_SimplePool->GetObj(SObjectTag{FOURCC('PART'), g_tweakGunRes->xa4_auxMuzzle[i]}));
for (const auto muzzleID : g_tweakGunRes->xa4_auxMuzzle) {
x7c0_auxMuzzleEffects.push_back(g_SimplePool->GetObj(SObjectTag{FOURCC('PART'), muzzleID}));
x800_auxMuzzleGenerators.emplace_back(std::make_unique<CElementGen>(x7c0_auxMuzzleEffects.back()));
x800_auxMuzzleGenerators.back()->SetParticleEmission(false);
}