CPASAnimState: Make use of size_t for indices

Same behavior, but plays nicer with containers.

This can technically result in less zero-extensions with regards to
memory indexing and registers, but this wasn't the underlying reason for the change.
This commit is contained in:
Lioncash 2020-04-06 13:02:18 -04:00
parent 4043b63721
commit 0b74a3e995
4 changed files with 16 additions and 13 deletions

View File

@ -5,15 +5,18 @@ namespace urde {
CPASAnimInfo::CPASAnimInfo(u32 id, rstl::reserved_vector<CPASAnimParm::UParmValue, 8>&& parms) CPASAnimInfo::CPASAnimInfo(u32 id, rstl::reserved_vector<CPASAnimParm::UParmValue, 8>&& parms)
: x0_id(id), x4_parms(std::move(parms)) {} : x0_id(id), x4_parms(std::move(parms)) {}
CPASAnimParm::UParmValue CPASAnimInfo::GetAnimParmValue(u32 idx) const { CPASAnimParm::UParmValue CPASAnimInfo::GetAnimParmValue(size_t idx) const {
if (idx >= x4_parms.size()) if (idx >= x4_parms.size()) {
return CPASAnimParm::UParmValue{}; return CPASAnimParm::UParmValue{};
}
return x4_parms[idx]; return x4_parms[idx];
} }
CPASAnimParm CPASAnimInfo::GetAnimParmData(u32 idx, CPASAnimParm::EParmType type) const { CPASAnimParm CPASAnimInfo::GetAnimParmData(size_t idx, CPASAnimParm::EParmType type) const {
if (idx >= x4_parms.size()) if (idx >= x4_parms.size()) {
return CPASAnimParm::NoParameter(); return CPASAnimParm::NoParameter();
}
const CPASAnimParm::UParmValue& parm = x4_parms[idx]; const CPASAnimParm::UParmValue& parm = x4_parms[idx];
switch (type) { switch (type) {

View File

@ -14,8 +14,8 @@ public:
explicit CPASAnimInfo(u32 id) : x0_id(id) {} explicit CPASAnimInfo(u32 id) : x0_id(id) {}
explicit CPASAnimInfo(u32 id, rstl::reserved_vector<CPASAnimParm::UParmValue, 8>&& parms); explicit CPASAnimInfo(u32 id, rstl::reserved_vector<CPASAnimParm::UParmValue, 8>&& parms);
u32 GetAnimId() const { return x0_id; } u32 GetAnimId() const { return x0_id; }
CPASAnimParm::UParmValue GetAnimParmValue(u32 idx) const; CPASAnimParm::UParmValue GetAnimParmValue(size_t idx) const;
CPASAnimParm GetAnimParmData(u32, CPASAnimParm::EParmType) const; CPASAnimParm GetAnimParmData(size_t idx, CPASAnimParm::EParmType type) const;
}; };
} // namespace urde } // namespace urde

View File

@ -100,7 +100,7 @@ std::pair<float, s32> CPASAnimState::FindBestAnimation(const rstl::reserved_vect
u32 unweightedCount = 0; u32 unweightedCount = 0;
for (u32 i = 0; i < x4_parms.size(); ++i) { for (size_t i = 0; i < x4_parms.size(); ++i) {
CPASAnimParm::UParmValue val = info.GetAnimParmValue(i); CPASAnimParm::UParmValue val = info.GetAnimParmValue(i);
const CPASParmInfo& parmInfo = x4_parms[i]; const CPASParmInfo& parmInfo = x4_parms[i];
float parmWeight = parmInfo.GetParameterWeight(); float parmWeight = parmInfo.GetParameterWeight();
@ -142,7 +142,7 @@ std::pair<float, s32> CPASAnimState::FindBestAnimation(const rstl::reserved_vect
return {weight, PickRandomAnimation(rand)}; return {weight, PickRandomAnimation(rand)};
} }
float CPASAnimState::ComputeExactMatchWeight(u32, const CPASAnimParm& parm, CPASAnimParm::UParmValue parmVal) const { float CPASAnimState::ComputeExactMatchWeight(size_t, const CPASAnimParm& parm, CPASAnimParm::UParmValue parmVal) const {
switch (parm.GetParameterType()) { switch (parm.GetParameterType()) {
case CPASAnimParm::EParmType::Int32: case CPASAnimParm::EParmType::Int32:
return (parm.GetInt32Value() == parmVal.m_int ? 1.f : 0.f); return (parm.GetInt32Value() == parmVal.m_int ? 1.f : 0.f);
@ -161,7 +161,7 @@ float CPASAnimState::ComputeExactMatchWeight(u32, const CPASAnimParm& parm, CPAS
return 0.f; return 0.f;
} }
float CPASAnimState::ComputePercentErrorWeight(u32 idx, const CPASAnimParm& parm, float CPASAnimState::ComputePercentErrorWeight(size_t idx, const CPASAnimParm& parm,
CPASAnimParm::UParmValue parmVal) const { CPASAnimParm::UParmValue parmVal) const {
float range = 0.f; float range = 0.f;
float val = 0.f; float val = 0.f;
@ -205,7 +205,7 @@ float CPASAnimState::ComputePercentErrorWeight(u32 idx, const CPASAnimParm& parm
return (val < FLT_EPSILON ? 1.f : 0.f); return (val < FLT_EPSILON ? 1.f : 0.f);
} }
float CPASAnimState::ComputeAngularPercentErrorWeight(u32 idx, const CPASAnimParm& parm, float CPASAnimState::ComputeAngularPercentErrorWeight(size_t idx, const CPASAnimParm& parm,
CPASAnimParm::UParmValue parmVal) const { CPASAnimParm::UParmValue parmVal) const {
float range = 0.f; float range = 0.f;
float val = 0.f; float val = 0.f;

View File

@ -16,9 +16,9 @@ class CPASAnimState {
std::vector<CPASAnimInfo> x14_anims; std::vector<CPASAnimInfo> x14_anims;
mutable std::vector<s32> x24_selectionCache; mutable std::vector<s32> x24_selectionCache;
float ComputeExactMatchWeight(u32 idx, const CPASAnimParm& parm, CPASAnimParm::UParmValue parmVal) const; float ComputeExactMatchWeight(size_t idx, const CPASAnimParm& parm, CPASAnimParm::UParmValue parmVal) const;
float ComputePercentErrorWeight(u32 idx, const CPASAnimParm& parm, CPASAnimParm::UParmValue parmVal) const; float ComputePercentErrorWeight(size_t idx, const CPASAnimParm& parm, CPASAnimParm::UParmValue parmVal) const;
float ComputeAngularPercentErrorWeight(u32 idx, const CPASAnimParm& parm, CPASAnimParm::UParmValue parmVal) const; float ComputeAngularPercentErrorWeight(size_t idx, const CPASAnimParm& parm, CPASAnimParm::UParmValue parmVal) const;
public: public:
explicit CPASAnimState(CInputStream& in); explicit CPASAnimState(CInputStream& in);