From 6381f021b73e04245b44086f852095ce9203f1eb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 6 Apr 2020 13:09:11 -0400 Subject: [PATCH] CPASAnimState: Make use of size_t for GetAnimParmData() Given the rest of the interface now uses size_t, we can convert this over. While we're at it, we can also take the result of the at() call inside of it in order to avoid any copies of data altogether. --- Runtime/Character/CPASAnimState.cpp | 13 +++++++------ Runtime/Character/CPASAnimState.hpp | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Runtime/Character/CPASAnimState.cpp b/Runtime/Character/CPASAnimState.cpp index 8089601ea..3bde8b003 100644 --- a/Runtime/Character/CPASAnimState.cpp +++ b/Runtime/Character/CPASAnimState.cpp @@ -60,14 +60,15 @@ CPASAnimState::CPASAnimState(CInputStream& in) { CPASAnimState::CPASAnimState(int stateId) : x0_id(stateId) {} -CPASAnimParm CPASAnimState::GetAnimParmData(s32 animId, u32 parmIdx) const { - auto search = rstl::binary_find(x14_anims.begin(), x14_anims.end(), animId, - [](const CPASAnimInfo& item) { return item.GetAnimId(); }); - if (search == x14_anims.end()) +CPASAnimParm CPASAnimState::GetAnimParmData(s32 animId, size_t parmIdx) const { + const auto search = rstl::binary_find(x14_anims.cbegin(), x14_anims.cend(), animId, + [](const CPASAnimInfo& item) { return item.GetAnimId(); }); + if (search == x14_anims.cend()) { return CPASAnimParm::NoParameter(); + } - CPASParmInfo parm = x4_parms.at(parmIdx); - return (*search).GetAnimParmData(parmIdx, parm.GetParameterType()); + const CPASParmInfo& parm = x4_parms.at(parmIdx); + return search->GetAnimParmData(parmIdx, parm.GetParameterType()); } s32 CPASAnimState::PickRandomAnimation(CRandom16& rand) const { diff --git a/Runtime/Character/CPASAnimState.hpp b/Runtime/Character/CPASAnimState.hpp index 3874a32dc..375ba5257 100644 --- a/Runtime/Character/CPASAnimState.hpp +++ b/Runtime/Character/CPASAnimState.hpp @@ -27,7 +27,7 @@ public: explicit CPASAnimState(int stateId); s32 GetStateId() const { return x0_id; } s32 GetNumAnims() const { return x14_anims.size(); } - CPASAnimParm GetAnimParmData(s32 animId, u32 parmIdx) const; + CPASAnimParm GetAnimParmData(s32 animId, size_t parmIdx) const; std::pair FindBestAnimation(const rstl::reserved_vector& parms, CRandom16& rand, s32 ignoreAnim) const; };