CPASAnimState: Remove const_cast usages

A cache is typically a use case for mutable (as the outside user of the
class wouldn't directly rely on the cache as part of the API, this would
only function to assist the API perform better), so we can mark the
selection cache as mutable and make the code nicer to read overall.
This commit is contained in:
Lioncash 2020-02-28 04:33:39 -05:00
parent 08604d770a
commit fe05c42be4
2 changed files with 5 additions and 5 deletions

View File

@ -87,7 +87,7 @@ s32 CPASAnimState::PickRandomAnimation(CRandom16& rand) const {
std::pair<float, s32> CPASAnimState::FindBestAnimation(const rstl::reserved_vector<CPASAnimParm, 8>& parms,
CRandom16& rand, s32 ignoreAnim) const {
const_cast<std::vector<s32>*>(&x24_selectionCache)->clear();
x24_selectionCache.clear();
float weight = -1.f;
for (const CPASAnimInfo& info : x14_anims) {
@ -130,11 +130,11 @@ std::pair<float, s32> CPASAnimState::FindBestAnimation(const rstl::reserved_vect
calcWeight = 1.0f;
if (calcWeight > weight) {
const_cast<std::vector<s32>*>(&x24_selectionCache)->clear();
const_cast<std::vector<s32>*>(&x24_selectionCache)->push_back(info.GetAnimId());
x24_selectionCache.clear();
x24_selectionCache.push_back(info.GetAnimId());
weight = calcWeight;
} else if (weight == calcWeight) {
const_cast<std::vector<s32>*>(&x24_selectionCache)->push_back(info.GetAnimId());
x24_selectionCache.push_back(info.GetAnimId());
weight = calcWeight;
}
}

View File

@ -14,7 +14,7 @@ class CPASAnimState {
s32 x0_id;
std::vector<CPASParmInfo> x4_parms;
std::vector<CPASAnimInfo> x14_anims;
std::vector<s32> x24_selectionCache;
mutable std::vector<s32> x24_selectionCache;
public:
CPASAnimState(CInputStream& in);