From f96ea81d69a33adf98aedec5a2b15de87fe47699 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 6 Apr 2020 13:21:04 -0400 Subject: [PATCH] CPASDatabase: Resolve sign-conversion warnings We can leverage size_t here to resolve sign-conversion warnings. While we're in the same area, we can remove a use of at() for std::vector, given a bounds check already precedes it. --- Runtime/Character/CBodyStateInfo.cpp | 2 +- Runtime/Character/CPASDatabase.hpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Runtime/Character/CBodyStateInfo.cpp b/Runtime/Character/CBodyStateInfo.cpp index 09325a628..a3a480127 100644 --- a/Runtime/Character/CBodyStateInfo.cpp +++ b/Runtime/Character/CBodyStateInfo.cpp @@ -8,7 +8,7 @@ namespace urde { CBodyStateInfo::CBodyStateInfo(CActor& actor, EBodyType type) { x34_24_changeLocoAtEndOfAnimOnly = false; const CPASDatabase& pasDatabase = actor.GetModelData()->GetAnimationData()->GetCharacterInfo().GetPASDatabase(); - for (int i = 0; i < pasDatabase.GetNumAnimStates(); ++i) { + for (size_t i = 0; i < pasDatabase.GetNumAnimStates(); ++i) { const CPASAnimState* state = pasDatabase.GetAnimStateByIndex(i); std::unique_ptr bs; diff --git a/Runtime/Character/CPASDatabase.hpp b/Runtime/Character/CPASDatabase.hpp index f6918b321..e06afeec4 100644 --- a/Runtime/Character/CPASDatabase.hpp +++ b/Runtime/Character/CPASDatabase.hpp @@ -23,7 +23,7 @@ public: std::pair FindBestAnimation(const CPASAnimParmData& data, s32 ignoreAnim) const; std::pair FindBestAnimation(const CPASAnimParmData& data, CRandom16& rand, s32 ignoreAnim) const; s32 GetDefaultState() const { return x10_defaultState; } - s32 GetNumAnimStates() const { return x0_states.size(); } + size_t GetNumAnimStates() const { return x0_states.size(); } const CPASAnimState* GetAnimState(s32 id) const { for (const CPASAnimState& state : x0_states) if (id == state.GetStateId()) @@ -31,11 +31,12 @@ public: return nullptr; } - const CPASAnimState* GetAnimStateByIndex(s32 index) const { - if (index < 0 || index >= x0_states.size()) + const CPASAnimState* GetAnimStateByIndex(size_t index) const { + if (index >= x0_states.size()) { return nullptr; + } - return &x0_states.at(index); + return &x0_states[index]; } bool HasState(s32 id) const {