mirror of https://github.com/AxioDL/metaforce.git
CPlayerState: Use std::array where applicable
Prevents implicit array->pointer decay and makes for a more convenient data type.
This commit is contained in:
parent
f4fd182741
commit
f49c8e9d6c
|
@ -1,5 +1,8 @@
|
|||
#include "Runtime/CPlayerState.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
#include "Runtime/CMemoryCardSys.hpp"
|
||||
#include "Runtime/CStateManager.hpp"
|
||||
#include "Runtime/GameGlobalObjects.hpp"
|
||||
|
@ -12,12 +15,12 @@
|
|||
|
||||
namespace urde {
|
||||
namespace {
|
||||
constexpr u32 PowerUpMaxValues[41] = {
|
||||
constexpr std::array<u32, 41> PowerUpMaxValues{
|
||||
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,
|
||||
};
|
||||
|
||||
[[maybe_unused]] constexpr const char* PowerUpNames[41] = {
|
||||
[[maybe_unused]] constexpr std::array<const char*, 41> PowerUpNames{
|
||||
"Power Beam",
|
||||
"Ice Beam",
|
||||
"Wave Beam",
|
||||
|
@ -61,11 +64,11 @@ constexpr u32 PowerUpMaxValues[41] = {
|
|||
"Artifact of Newborn",
|
||||
};
|
||||
|
||||
constexpr u32 costs[] = {
|
||||
constexpr std::array<u32, 5> costs{
|
||||
5, 10, 10, 10, 1,
|
||||
};
|
||||
|
||||
constexpr float ComboAmmoPeriods[] = {
|
||||
constexpr std::array<float, 5> ComboAmmoPeriods{
|
||||
0.2f, 0.1f, 0.2f, 0.2f, 1.f,
|
||||
};
|
||||
} // Anonymous namespace
|
||||
|
@ -87,12 +90,13 @@ CPlayerState::CPlayerState(CBitStreamReader& stream) : x188_staticIntf(5) {
|
|||
x8_currentBeam = EBeamId(stream.ReadEncoded(CBitStreamReader::GetBitCount(5)));
|
||||
x20_currentSuit = EPlayerSuit(stream.ReadEncoded(CBitStreamReader::GetBitCount(4)));
|
||||
x24_powerups.resize(41);
|
||||
for (u32 i = 0; i < x24_powerups.size(); ++i) {
|
||||
if (PowerUpMaxValues[i] == 0)
|
||||
for (size_t i = 0; i < x24_powerups.size(); ++i) {
|
||||
if (PowerUpMaxValues[i] == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
u32 a = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(PowerUpMaxValues[i])));
|
||||
u32 b = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(PowerUpMaxValues[i])));
|
||||
const u32 a = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(PowerUpMaxValues[i])));
|
||||
const u32 b = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(PowerUpMaxValues[i])));
|
||||
x24_powerups[i] = CPowerUp(a, b);
|
||||
}
|
||||
|
||||
|
@ -117,7 +121,7 @@ void CPlayerState::PutTo(CBitStreamWriter& stream) {
|
|||
stream.WriteEncoded(hp.iHP, 32);
|
||||
stream.WriteEncoded(u32(x8_currentBeam), CBitStreamWriter::GetBitCount(5));
|
||||
stream.WriteEncoded(u32(x20_currentSuit), CBitStreamWriter::GetBitCount(4));
|
||||
for (u32 i = 0; i < x24_powerups.size(); ++i) {
|
||||
for (size_t i = 0; i < x24_powerups.size(); ++i) {
|
||||
const CPowerUp& pup = x24_powerups[i];
|
||||
stream.WriteEncoded(pup.x0_amount, CBitStreamWriter::GetBitCount(PowerUpMaxValues[i]));
|
||||
stream.WriteEncoded(pup.x4_capacity, CBitStreamWriter::GetBitCount(PowerUpMaxValues[i]));
|
||||
|
@ -134,9 +138,9 @@ void CPlayerState::PutTo(CBitStreamWriter& stream) {
|
|||
stream.WriteEncoded(x180_scanCompletionRate.second, CBitStreamWriter::GetBitCount(0x100));
|
||||
}
|
||||
|
||||
u32 CPlayerState::GetMissileCostForAltAttack() const { return costs[u32(x8_currentBeam)]; }
|
||||
u32 CPlayerState::GetMissileCostForAltAttack() const { return costs[size_t(x8_currentBeam)]; }
|
||||
|
||||
float CPlayerState::GetComboFireAmmoPeriod() const { return ComboAmmoPeriods[u32(x8_currentBeam)]; }
|
||||
float CPlayerState::GetComboFireAmmoPeriod() const { return ComboAmmoPeriods[size_t(x8_currentBeam)]; }
|
||||
|
||||
u32 CPlayerState::CalculateItemCollectionRate() const {
|
||||
u32 total = GetItemCapacity(EItemType::PowerBombs);
|
||||
|
@ -383,7 +387,7 @@ void CPlayerState::InitializeScanTimes() {
|
|||
x170_scanTimes.emplace_back(state.first, 0.f);
|
||||
}
|
||||
|
||||
u32 CPlayerState::GetPowerUpMaxValue(EItemType type) { return PowerUpMaxValues[u32(type)]; }
|
||||
u32 CPlayerState::GetPowerUpMaxValue(EItemType type) { return PowerUpMaxValues[size_t(type)]; }
|
||||
|
||||
const std::unordered_map<std::string_view, CPlayerState::EItemType> CPlayerState::g_TypeNameMap = {
|
||||
{"powerbeam"sv, EItemType::PowerBeam},
|
||||
|
|
Loading…
Reference in New Issue