CPlayerState: Move arrays into an anonymous namespace where applicable

Keeps local arrays together and makes it impossible to accidentally
violate the ODR.
This commit is contained in:
Lioncash 2019-09-19 15:33:38 -04:00
parent bc285913c8
commit f4fd182741
2 changed files with 18 additions and 10 deletions

View File

@ -11,10 +11,13 @@
#include <zeus/Math.hpp>
namespace urde {
const u32 CPlayerState::PowerUpMaxValues[41] = {1, 1, 1, 1, 250, 1, 1, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 14, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
namespace {
constexpr u32 PowerUpMaxValues[41] = {
1, 1, 1, 1, 250, 1, 1, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 14, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
};
const char* CPlayerState::PowerUpNames[41] = {
[[maybe_unused]] constexpr const char* PowerUpNames[41] = {
"Power Beam",
"Ice Beam",
"Wave Beam",
@ -58,6 +61,15 @@ const char* CPlayerState::PowerUpNames[41] = {
"Artifact of Newborn",
};
constexpr u32 costs[] = {
5, 10, 10, 10, 1,
};
constexpr float ComboAmmoPeriods[] = {
0.2f, 0.1f, 0.2f, 0.2f, 1.f,
};
} // Anonymous namespace
CPlayerState::CPlayerState() : x188_staticIntf(5) {
x0_24_alive = true;
x24_powerups.resize(41);
@ -122,12 +134,8 @@ void CPlayerState::PutTo(CBitStreamWriter& stream) {
stream.WriteEncoded(x180_scanCompletionRate.second, CBitStreamWriter::GetBitCount(0x100));
}
static const u32 costs[] = {5, 10, 10, 10, 1};
u32 CPlayerState::GetMissileCostForAltAttack() const { return costs[u32(x8_currentBeam)]; }
static const float ComboAmmoPeriods[] = {0.2f, 0.1f, 0.2f, 0.2f, 1.f};
float CPlayerState::GetComboFireAmmoPeriod() const { return ComboAmmoPeriods[u32(x8_currentBeam)]; }
u32 CPlayerState::CalculateItemCollectionRate() const {
@ -375,6 +383,8 @@ void CPlayerState::InitializeScanTimes() {
x170_scanTimes.emplace_back(state.first, 0.f);
}
u32 CPlayerState::GetPowerUpMaxValue(EItemType type) { return PowerUpMaxValues[u32(type)]; }
const std::unordered_map<std::string_view, CPlayerState::EItemType> CPlayerState::g_TypeNameMap = {
{"powerbeam"sv, EItemType::PowerBeam},
{"icebeam"sv, EItemType::IceBeam},

View File

@ -90,8 +90,6 @@ public:
private:
static const std::unordered_map<std::string_view, EItemType> g_TypeNameMap;
static const u32 PowerUpMaxValues[41];
static const char* PowerUpNames[41];
struct CPowerUp {
u32 x0_amount = 0;
u32 x4_capacity = 0;
@ -176,7 +174,7 @@ public:
CPlayerState();
CPlayerState(CBitStreamReader& stream);
void PutTo(CBitStreamWriter& stream);
static u32 GetPowerUpMaxValue(EItemType type) { return PowerUpMaxValues[u32(type)]; }
static u32 GetPowerUpMaxValue(EItemType type);
static EItemType ItemNameToType(std::string_view name);
bool CanTakeDamage() const { return m_canTakeDamage; }
void SetCanTakeDamage(bool c) { m_canTakeDamage = c; }